[Pkg-javascript-commits] [ltx] 91/469: router: asynchronous verifyDialback()

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:07 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 c2c3b4cf2522a0f0faac492034d5b14242539606
Author: Astro <astro at spaceboyz.net>
Date:   Mon Sep 6 03:17:45 2010 +0200

    router: asynchronous verifyDialback()
---
 lib/xmpp/router.js | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index c310d3b..0d57714 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -196,17 +196,28 @@ DomainContext.prototype.setupStream = function(domain, stream) {
     });
 };
 
-DomainContext.prototype.verifyDialback = function(domain, id, key) {
+DomainContext.prototype.verifyDialback = function(domain, id, key, cb) {
+    var self = this;
     var outStream;
     if (this.s2sOut.hasOwnProperty(domain) &&
 	(outStream = this.s2sOut[domain])) {
 
-	var isValid = outStream.streamAttrs.id === id &&
-	    outStream.dbKey === key;
-
-	return isValid;
+	if (outStream.isOnline) {
+	    var isValid = outStream.streamAttrs.id === id &&
+			      outStream.dbKey === key;
+	    cb(isValid);
+	} else {
+	    // Not online, wait for outStream.streamAttrs
+	    outStream.addListener('online', function() {
+				      // recurse
+				      self.verifyDialback(domain, id, key, cb);
+				  });
+	    outStream.addListener('close', function() {
+				      cb(false);
+				  });
+	}
     } else
-	return false;
+	cb(false);
 };
 
 DomainContext.prototype.receive = function(stanza) {
@@ -245,8 +256,9 @@ Router.prototype.acceptConnection = function(inStream) {
     inStream.addListener('dialbackVerify', function(from, to, id, key) {
 	from = nameprep.prepare(from);
 	to = nameprep.prepare(to);
-	var isValid = self.verifyDialback(from, to, id, key);
-	inStream.send(Server.dialbackVerified(to, from, id, isValid));
+	self.verifyDialback(from, to, id, key, function(isValid) {
+	    inStream.send(Server.dialbackVerified(to, from, id, isValid));
+	});
     });
     // incoming connection wants to get verified
     inStream.addListener('dialbackKey', function(from, to, key) {
@@ -338,9 +350,11 @@ Router.prototype.getContext = function(domain) {
 	return (this.ctxs[domain] = new DomainContext(this, domain));
 };
 
-Router.prototype.verifyDialback = function(from, to, id, key) {
-    return this.hasContext(to) &&
-	this.getContext(to).verifyDialback(from, id, key);
+Router.prototype.verifyDialback = function(from, to, id, key, cb) {
+    if (this.hasContext(to))
+	this.getContext(to).verifyDialback(from, id, key, cb);
+    else
+	cb(false);
 };
 
 

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