Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remote client host register fix #30

Closed
wants to merge 1 commit into from

2 participants

@nisaacson

When clients on a different host register with a seaport server, the servers host is stored in the client entry rather than the clients. This commit applies the fix outlined in issue #19

@substack
Owner

Can you configure your editor to thrash less? There are a lot of unnecessary lines in the diff.

@nisaacson

will do

@nisaacson nisaacson closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 8, 2013
  1. @nisaacson
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 19 deletions.
  1. +19 −19 index.js
View
38 index.js
@@ -22,7 +22,7 @@ exports.connect = function () {
}
var port = args[0] || opts.port;
var host = args[1] || opts.host;
-
+
if (typeof port === 'string' && typeof host === 'number') {
host = args[0];
port = args[1];
@@ -34,33 +34,33 @@ exports.connect = function () {
if (typeof port === 'string' && /^\d+$/.test(port)) {
port = Number(port);
}
-
+
var s = seaport(opts);
var conIx = 0;
-
+
var c = (function reconnect () {
if (s.closed) return;
-
+
var hubs = [ { port : port, host : host } ].concat(s.query('seaport'));
var c = net.connect.call(null, hubs[conIx].port, hubs[conIx].host);
conIx = (conIx + 1) % hubs.length;
-
+
var active = true;
-
+
c.on('connect', s.emit.bind(s, 'connect'));
-
+
c.on('end', onend);
c.on('error', onend);
c.on('close', onend);
-
+
var stream = s.createStream();
c.pipe(stream).pipe(c);
stream.on('synced', s.emit.bind(s, 'synced'));
-
+
return c;
-
+
function onend () {
if (s.closed) return;
if (!active) return;
@@ -69,26 +69,26 @@ exports.connect = function () {
setTimeout(reconnect, 1000);
}
})();
-
+
s.on('close', function () {
if (c) c.end();
});
-
+
return s;
};
exports.createServer = function (opts) {
var s = seaport(opts);
-
+
s.server = net.createServer(function (c) {
c.on('error', function (error) {
c.emit('end');
});
- c.pipe(s.createStream(c.address().address)).pipe(c);
+ c.pipe(s.createStream(c.remoteAddress)).pipe(c);
});
s.listen = s.server.listen.bind(s.server);
s.address = s.server.address.bind(s.server);
-
+
s.peer = function () {
if (!s.address()) {
var args = arguments;
@@ -101,19 +101,19 @@ exports.createServer = function (opts) {
var c = exports.connect.apply(this, arguments);
s.on('close', c.close.bind(c));
stream.pipe(c.createStream()).pipe(stream);
-
+
c.register({
role : 'seaport@' + version,
port : s.address().port
});
};
-
+
s.on('close', function () {
s.server.close();
});
-
+
s.server.on('listening', s.emit.bind(s, 'listening'));
s.server.on('connection', s.emit.bind(s, 'connection'));
-
+
return s;
};
Something went wrong with that request. Please try again.