[Pkg-javascript-commits] [ltx] 69/469: router: fixes, TODO, clarification

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 47df1492840cc83cf154d9790a312f0a5670a295
Author: Astro <astro at spaceboyz.net>
Date:   Sun Sep 5 18:00:21 2010 +0200

    router: fixes, TODO, clarification
---
 lib/xmpp/router.js | 57 +++++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 56c27f8..77b7b1e 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -125,7 +125,7 @@ DomainContext.prototype.verifyDialback = function(domain, id, key) {
 	var isValid = outStream.streamAttrs.id === id &&
 	    outStream.dbKey === key;
 
-	outStream.send(Server.dialbackResult(this.domain, domain, isValid));
+	//outStream.send(Server.dialbackResult(this.domain, domain, isValid));
 	return isValid;
     } else
 	return false;
@@ -167,46 +167,55 @@ function Router(s2sPort) {
     var self = this;
     this.ctxs = {};
 
-    net.createServer(function(stream) {
-	self.acceptConnection(stream);
+    net.createServer(function(inStream) {
+	self.acceptConnection(inStream);
     }).listen(s2sPort || 5269);
 }
 exports.Router = Router;
 
-Router.prototype.acceptConnection = function(stream) {
+// TODO: don't use from & to supplied by remote all over the place
+Router.prototype.acceptConnection = function(inStream) {
     var self = this;
-    dbgStream('incoming', stream);
 
-    Server.makeIncomingServer(stream);
+    Server.makeIncomingServer(inStream);
+    console.log('INCOMING from ' + inStream.remoteAddress);
+    dbgStream('incoming', inStream);
 
     // incoming server wants to verify an outgoing connection of ours
-    stream.addListener('dialbackVerify', function(from, to, id, key) {
+    inStream.addListener('dialbackVerify', function(from, to, id, key) {
 	var isValid = self.verifyDialback(from, to, id, key);
-	stream.send(Server.dialbackVerified(to, from, id, isValid));
+	inStream.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) {
+    // incoming connection wants to get verified
+    inStream.addListener('dialbackKey', function(from, to, key) {
 	var ctx = self.getContext(to);
-	var outStream = ctx.sendRaw(Server.dialbackVerify(to, from, stream.streamId, key),
+	var outStream = ctx.sendRaw(Server.dialbackVerify(to, from, inStream.streamId, key),
 				    from);
 
-	var onVerified;
+	// TODO: hook inStream close
+	var onVerified, onClose;
 	onVerified = function(from, to, id, isValid) {
-	    // TODO: what if outgoing connection is gone?
-	    ctx.sendRaw(Server.dialbackResult(to, from, isValid), from);
+	    inStream.send(Server.dialbackResult(to, from, isValid));
+
+	    if (isValid && self.hasContext(to)) {
+		self.getContext(to).addInStream(from, inStream);
+	    } else {
+		// the connection isn't used for another domain, so
+		// closing is safe
+		inStream.send('</stream:stream>');
+		inStream.end();
+	    }
+
 	    outStream.removeListener('dialbackVerified', onVerified);
+	    outStream.removeListener('close', onClose);
+	};
+	onClose = function() {
+	    // outgoing connection didn't work out, tell the incoming
+	    // connection
+	    inStream.send(Server.dialbackResult(to, from, false));
 	};
 	outStream.addListener('dialbackVerified', onVerified);
+	outStream.addListener('close', onClose);
     });
 };
 

-- 
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