Skip to content

Commit

Permalink
Fix TL negitiation error to jabber.org. Caused because default socket…
Browse files Browse the repository at this point in the history
… handlers were removed. Probably used internally by node.js.
  • Loading branch information
dhruvbird committed Apr 14, 2013
1 parent 78e04fd commit 9983bbe
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -14,7 +14,7 @@
"tav": "~0.1.0",
"underscore": "~1.3.3",
"eventpipe": "~0.0.5",
"dns-srv": "0.1.0",
"dns-srv": "0.2.0",
"semver": "~1.0.8",
"ws": "= 0.4.19",
"node-lumberjack": "= 0.0.4",
Expand Down
4 changes: 3 additions & 1 deletion run-server.js
Expand Up @@ -81,7 +81,9 @@ function main() {
value: false
},
config: {
note: "The config file to load (default: /etc/bosh.js.conf). NOTE: Command " +
note: "The config file to load (default: /etc/bosh.js.conf). If a relative path " +
"specified, then it is assumed to be relative not to your Current Working Directory " +
"but to the install directory for node-xmpp-bosh. *NOTE*: Command " +
"line options (if specified) will override options in the config file",
value: BOSH_DEFAULT_CONFIG_PATH
}
Expand Down
6 changes: 1 addition & 5 deletions src/lookup-service.js
Expand Up @@ -85,11 +85,9 @@ dutil.copy(XMPPLookupService.prototype, {
// a sequential ordering on the delivery of these events (for
// example the 'connect' and the 'data' events need to come in
// the order they arrived).
var _add_all_listeners = SRV.removeListeners(socket);

function _on_socket_connect(e) {
log.trace('Connection to %s succeeded',self._domain_name);
_add_all_listeners(SRV.REMOVE_PREVIOUS_LISTENERS);
log.trace('Connection to %s succeeded', self._domain_name);

// Re-trigger the connect event.
self.emit('connect', e);
Expand All @@ -112,14 +110,12 @@ dutil.copy(XMPPLookupService.prototype, {
log.trace('try_connect_SRV_lookup - %s, %s',self._domain_name, self._port);

// Then try a normal SRV lookup.

var attempt = SRV.connect(socket, ['_xmpp-client._tcp'],
self._domain_name, self._port);
}

function give_up_trying_to_connect(e) {
log.warn('Giving up connection attempts to %s',self._domain_name);
_add_all_listeners(SRV.REMOVE_PREVIOUS_LISTENERS);

// Trigger the error event.
self.emit('error', 'host-unknown');
Expand Down
25 changes: 16 additions & 9 deletions src/xmpp-proxy.js
@@ -1,4 +1,4 @@
// -*- tab-width:4 -*-
// -*- tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

/*
* Copyright (c) 2011 Dhruv Matani
Expand Down Expand Up @@ -89,6 +89,9 @@ util.inherits(XMPPProxy, events.EventEmitter);

exports.Proxy = XMPPProxy;

const ATTACH_SOCKET_HANDLERS = true;
const SKIP_SOCKET_HANDLERS = false;

dutil.copy(XMPPProxy.prototype, {
_detach_handlers: function() {
if (this._lookup_service) {
Expand All @@ -100,17 +103,19 @@ dutil.copy(XMPPProxy.prototype, {
this._sock.removeAllListeners('close');
},

_attach_handlers: function() {
_attach_handlers: function(socket_handlers_fate) {
// Ideally, 'connect' and 'close' should be once() listeners
// but having them as on() listeners has helped us catch some
// nasty bugs, so we let them be.
if (this._lookup_service) {
this._lookup_service.on('connect', us.bind(this._on_connect, this));
this._lookup_service.on('error', us.bind(this._on_lookup_error, this));
}
this._sock.on ('data', us.bind(this._on_data, this));
this._sock.once('close', us.bind(this._on_close, this));
this._sock.on ('error', dutil.NULL_FUNC);
if (socket_handlers_fate == ATTACH_SOCKET_HANDLERS) {
this._sock.on ('data', us.bind(this._on_data, this));
this._sock.once('close', us.bind(this._on_close, this));
this._sock.on ('error', dutil.NULL_FUNC);
}
},

_attach_handlers_to_parser: function() {
Expand Down Expand Up @@ -144,7 +149,7 @@ dutil.copy(XMPPProxy.prototype, {
// The socket is now the cleartext stream
this._sock = ct;

this._attach_handlers();
this._attach_handlers(ATTACH_SOCKET_HANDLERS);
},

_get_stream_xml_open: function(stream_attrs) {
Expand Down Expand Up @@ -206,7 +211,7 @@ dutil.copy(XMPPProxy.prototype, {
connect: function() {
// console.log(this);
this._sock = new net.Stream();
this._attach_handlers();
this._attach_handlers(SKIP_SOCKET_HANDLERS);
this._attach_handlers_to_parser();
this._lookup_service.connect(this._sock);
},
Expand Down Expand Up @@ -275,9 +280,11 @@ dutil.copy(XMPPProxy.prototype, {

// Always, we connect on behalf of the real client.
this.send(_ss_open);

this.emit('connect', this._void_star);
}
this._sock.on ('data', us.bind(this._on_data, this));
this._sock.once('close', us.bind(this._on_close, this));
this._sock.on ('error', dutil.NULL_FUNC);
},

_on_data: function(d) {
Expand Down Expand Up @@ -307,7 +314,7 @@ dutil.copy(XMPPProxy.prototype, {
this.emit('restart', stanza, this._void_star);
}
this._suppress_stream_restart_event = false;
},
},

_on_stream_end: function(attr) {
log.info("%s %s stream terminated", this._void_star.session.sid, this._void_star.name);
Expand Down

0 comments on commit 9983bbe

Please sign in to comment.