[Pkg-javascript-commits] [ltx] 67/469: router: use incoming connections

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit f13565123a22883556d09b3eb50750e738e05e53
Author: Astro <astro at spaceboyz.net>
Date:   Sun Sep 5 17:08:38 2010 +0200

    router: use incoming connections
---
 lib/xmpp/router.js | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 29ce999..56c27f8 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -74,18 +74,22 @@ DomainContext.prototype.sendRaw = function(stanza, destDomain) {
 DomainContext.prototype.getOutStream = function(domain) {
     var self = this;
 
-    // TODO: check incoming as well
     if (this.s2sOut.hasOwnProperty(domain)) {
 	// There's one already
 	return this.s2sOut[domain];
+    } else if (this.s2sIn.hasOwnProperty(domain)) {
+	// We can(?) also use verified incoming streams
+	return this.s2sIn[domain];
     } else {
 	// Setup a new outgoing connection
 	var outStream = this.s2sOut[domain] =
 	    Server.makeOutgoingServer(domain);
 	dbgStream('outgoing', outStream);
-	outStream.addListener('error', function() {
+	outStream.addListener('close', function() {
 	    // TODO: purge queue
 	    delete self.s2sOut[domain];
+	});
+	outStream.addListener('error', function() {
 	    outStream.end();
 	});
 
@@ -128,14 +132,33 @@ DomainContext.prototype.verifyDialback = function(domain, id, key) {
 };
 
 /**
+ * Called by router when verification is done
+ */
+DomainContext.prototype.addInStream = function(domain, stream) {
+    var self = this;
+
+    if (this.s2sIn.hasOwnProperty(domain)) {
+	// Replace old
+	var oldStream = this.s2sIn[domain];
+	oldStream.end();
+    }
+
+    stream.isOnline = true;
+    stream.isVerified = true;
+    stream.addListener('close', function() {
+	if (self.s2sIn[domain] == stream)
+	    delete self.s2sIn[domain];
+    });
+    this.s2sIn[domain] = stream;
+};
+
+/**
  * TODO:
  * * recv stanzas
- * * send on incoming? no forwarding.
  * * jid check (<improper-addressing/>)
  * * karma
  * * nameprep
- * * listening
- * * allow only to hosted domains
+ * * no forwarding/allow only to hosted domains
  * * timeouts
  * * parser errors
  * * keepAlive
@@ -161,6 +184,16 @@ Router.prototype.acceptConnection = function(stream) {
 	var isValid = self.verifyDialback(from, to, id, key);
 	stream.send(Server.dialbackVerified(to, from, id, isValid));
     });
+    stream.addListener('dialbackResult', function(from, to, isValid) {
+	if (isValid && self.hasContext(to)) {
+	    self.getContext(to).addInStream(from, stream);
+	} else {
+	    // the connection can't be valid for another domain, so
+	    // this is safe
+	    stream.send('</stream:stream>');
+	    stream.end();
+	}
+    });
     // incoming server wants us to verify this connection
     stream.addListener('dialbackKey', function(from, to, key) {
 	var ctx = self.getContext(to);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list