[Pkg-javascript-commits] [ltx] 114/469: router: refactor dialback for outgoing connections

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:11 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 b07294621a6e5da95c631d7730a3c2ca597c39ec
Author: Astro <astro at spaceboyz.net>
Date:   Thu Sep 9 00:31:47 2010 +0200

    router: refactor dialback for outgoing connections
---
 lib/xmpp/router.js | 64 +++++++++++++++++++++++++++++++++---------------------
 1 file changed, 39 insertions(+), 25 deletions(-)

diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index 949c586..e22b70e 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -146,9 +146,7 @@ DomainContext.prototype.getOutStream = function(destDomain) {
 	    outStream.isConnected = true;
 	    switch(method) {
 	    case 'dialback':
-		// Prepare dialback
-		outStream.dbKey = generateKey();
-		outStream.send(Server.dialbackKey(self.domain, destDomain, outStream.dbKey));
+		self.startDialback(destDomain, outStream);
 		break;
 
 	    case 'external':
@@ -182,17 +180,8 @@ DomainContext.prototype.getOutStream = function(destDomain) {
 	};
 	outStream.addListener('auth', onAuth);
 
-	outStream.addListener('dialbackResult', function(from, to, isValid) {
-	    if (isValid) {
-		outStream.emit('online');
-	    } else {
-		// we cannot do anything else with this stream that
-		// failed dialback
-		outStream.end();
-	    }
-	});
 	outStream.addListener('online', function() {
-console.log('ONLINE!');
+	    console.log('ONLINE!');
 	    outStream.isAuthed = true;
 	    if (outStream.queue) {
 		outStream.queue.forEach(function(stanza) {
@@ -220,7 +209,7 @@ DomainContext.prototype.addInStream = function(srcDomain, stream) {
     }
 
     this.setupStream(srcDomain, stream);
-    stream.isOnline = true;
+    stream.isConnected = true;
     stream.isAuthed = true;
     stream.addListener('close', function() {
 	if (self.s2sIn[srcDomain] == stream)
@@ -269,13 +258,39 @@ DomainContext.prototype.setupStream = function(domain, stream) {
     });
 };
 
+// we want to get our outgoing connection verified, sends <db:result/>
+DomainContext.prototype.startDialback = function(destDomain, outStream) {
+    outStream.dbKey = generateKey();
+    outStream.send(Server.dialbackKey(this.domain, destDomain, outStream.dbKey));
+
+    var self = this;
+    var onResult = function(from, to, isValid) {
+	if (from != destDomain ||
+	    to != self.domain)
+	    // not for us
+	    return;
+
+	outStream.removeListener('dialbackResult', onResult);
+	if (isValid) {
+	    outStream.emit('online');
+	} else {
+	    // we cannot do anything else with this stream that
+	    // failed dialback
+	    outStream.end();
+	}
+    };
+    outStream.addListener('dialbackResult', onResult);
+};
+
+// incoming verification request for our outgoing connection that came
+// in via an inbound server connection
 DomainContext.prototype.verifyDialback = function(domain, id, key, cb) {
     var self = this;
     var outStream;
     if (this.s2sOut.hasOwnProperty(domain) &&
 	(outStream = this.s2sOut[domain])) {
 
-	if (outStream.isOnline) {
+	if (outStream.isConnected) {
 	    var isValid = outStream.streamAttrs.id === id &&
 			      outStream.dbKey === key;
 	    cb(isValid);
@@ -351,14 +366,20 @@ Router.prototype.acceptConnection = function(inStream) {
 
     // incoming server wants to verify an outgoing connection of ours
     inStream.addListener('dialbackVerify', function(from, to, id, key) {
+console.log({inDialbackVerify:[from,to,id,key]});
 	from = nameprep.prepare(from);
 	to = nameprep.prepare(to);
-	self.verifyDialback(from, to, id, key, function(isValid) {
-	    inStream.send(Server.dialbackVerified(to, from, id, isValid));
-	});
+
+	if (self.hasContext(to)) {
+	    self.getContext(to).verifyDialback(from, id, key, function(isValid) {
+		inStream.send(Server.dialbackVerified(to, from, id, isValid));
+	    });
+	} else
+	    inStream.send(Server.dialbackVerified(to, from, id, false));
     });
     // incoming connection wants to get verified
     inStream.addListener('dialbackKey', function(from, to, key) {
+console.log({inDialbackKey:[from,to,key]});
 	from = nameprep.prepare(from);
 	to = nameprep.prepare(to);
 	var destDomain = to;
@@ -475,13 +496,6 @@ Router.prototype.getContext = function(domain) {
 	return (this.ctxs[domain] = new DomainContext(this, domain));
 };
 
-Router.prototype.verifyDialback = function(from, to, id, key, cb) {
-    if (this.hasContext(to))
-	this.getContext(to).verifyDialback(from, id, key, cb);
-    else
-	cb(false);
-};
-
 
 /**
  * TODO: According to XEP-0185 we should hash from, to & streamId

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