[Pkg-javascript-commits] [ltx] 115/469: router: more dialback refactoring
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 fdf120fbc80a23c7c0d3b682353af0a62177209a
Author: Astro <astro at spaceboyz.net>
Date: Thu Sep 9 00:49:57 2010 +0200
router: more dialback refactoring
---
lib/xmpp/router.js | 114 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 64 insertions(+), 50 deletions(-)
diff --git a/lib/xmpp/router.js b/lib/xmpp/router.js
index e22b70e..c5dc329 100644
--- a/lib/xmpp/router.js
+++ b/lib/xmpp/router.js
@@ -67,6 +67,7 @@ DomainContext.prototype.send = function(stanza) {
if (outStream.isAuthed)
outStream.send(stanza);
else {
+ // TODO: queues per domain in domaincontext
outStream.queue = outStream.queue || [];
outStream.queue.push(stanza);
}
@@ -296,6 +297,9 @@ DomainContext.prototype.verifyDialback = function(domain, id, key, cb) {
cb(isValid);
} else {
// Not online, wait for outStream.streamAttrs
+ // (they may have our stream header & dialback key, but
+ // our slow connection hasn't received their stream
+ // header)
outStream.addListener('online', function() {
// recurse
self.verifyDialback(domain, id, key, cb);
@@ -308,6 +312,61 @@ DomainContext.prototype.verifyDialback = function(domain, id, key, cb) {
cb(false);
};
+DomainContext.prototype.verifyIncoming = function(fromDomain, inStream, dbKey) {
+ var self = this;
+ var outStream = this.sendRaw(Server.dialbackVerify(this.domain, fromDomain,
+ inStream.streamId, dbKey),
+ fromDomain);
+
+ // these are needed before for removeListener()
+ var onVerified = function(from, to, id, isValid) {
+ from = nameprep.prepare(from);
+ to = nameprep.prepare(to);
+ if (from !== fromDomain ||
+ to !== self.domain ||
+ id != inStream.streamId)
+ // not for us
+ return;
+
+ // tell them about it
+ inStream.send(Server.dialbackResult(to, from, isValid));
+
+ if (isValid) {
+ // finally validated them!
+ self.addInStream(from, inStream);
+ } else {
+ // the connection isn't used for another domain, so
+ // closing is safe
+ inStream.send('</stream:stream>');
+ inStream.end();
+ }
+
+ rmCbs();
+ };
+ var onClose = function() {
+ // outgoing connection didn't work out, tell the incoming
+ // connection
+ inStream.send(Server.dialbackResult(to, from, false));
+
+ rmCbs();
+ };
+ var onCloseIn = function() {
+ // t'was the incoming stream that wanted to get
+ // verified, nothing to do remains
+
+ rmCbs();
+ };
+ var rmCbs = function() {
+ outStream.removeListener('dialbackVerified', onVerified);
+ outStream.removeListener('close', onClose);
+ inStream.removeListener('close', onCloseIn);
+ };
+ outStream.addListener('dialbackVerified', onVerified);
+ outStream.addListener('close', onClose);
+ inStream.addListener('close', onCloseIn);
+
+};
+
DomainContext.prototype.receive = function(stanza) {
if (this.stanzaListener)
this.stanzaListener(stanza);
@@ -366,71 +425,26 @@ 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);
if (self.hasContext(to)) {
self.getContext(to).verifyDialback(from, id, key, function(isValid) {
+ // look if this was a connection of ours
inStream.send(Server.dialbackVerified(to, from, id, isValid));
});
} else
+ // we don't host the 'to' domain
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;
+
if (self.hasContext(to)) {
- var ctx = self.getContext(to);
- var outStream = ctx.sendRaw(Server.dialbackVerify(to, from, inStream.streamId, key),
- from);
-
- // these are needed before for removeListener()
- var onVerified, onClose, onCloseIn, rmCbs;
- onVerified = function(from, to, id, isValid) {
- from = nameprep.prepare(from);
- to = nameprep.prepare(to);
- if (to !== destDomain ||
- id != inStream.streamId) // not for us
- return;
-
- 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();
- }
-
- rmCbs();
- };
- onClose = function() {
- // outgoing connection didn't work out, tell the incoming
- // connection
- inStream.send(Server.dialbackResult(to, from, false));
-
- rmCbs();
- };
- onCloseIn = function() {
- // t'was the incoming stream that wanted to get
- // verified, nothing to do remains
-
- rmCbs();
- };
- rmCbs = function() {
- outStream.removeListener('dialbackVerified', onVerified);
- outStream.removeListener('close', onClose);
- inStream.removeListener('close', onCloseIn);
- };
- outStream.addListener('dialbackVerified', onVerified);
- outStream.addListener('close', onClose);
- inStream.addListener('close', onCloseIn);
+ // trigger verification via outgoing connection
+ self.getContext(to).verifyIncoming(from, inStream, key);
} else {
inStream.error('host-unknown', to + ' is not served here');
}
--
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