Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #183 from bookchin/master
Browse files Browse the repository at this point in the history
v1.2.6
  • Loading branch information
bookchin authored Jun 16, 2016
2 parents 4d853c6 + 08ca929 commit ab424e4
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
18 changes: 12 additions & 6 deletions lib/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,23 @@ Network.prototype._enterOverlay = function(callback) {

function _trySeeds() {
async.detectSeries(self._options.seeds, function(uri, next) {
self._logger.info('attemting to join network via %s', uri);
self._logger.info('attempting to join network via %s', uri);
self.connect(uri, function(err) {
if (err) {
self._logger.warn('failed to connect to seed %s', uri);
next(false);
} else {
self._logger.info('connected to the storj network via %s', uri);
next(true);
}

next(null, !err);
});
}, callback);
}, function(result) {
if (!result) {
return callback(new Error('Failed to join the network'));
}

callback(null);
});
}

if (this._options.seeds.length) {
Expand Down Expand Up @@ -599,12 +605,12 @@ Network.prototype._findTunnel = function(neighbors, callback) {
self._logger.info('requesting tunnelers from neighbor');
self._transport.send(neighbor, message, function(err, resp) {
if (err) {
return callback(null, false);
return callback(false);
}

tunnelers = tunnelers.concat(resp.result.tunnels);

callback(null, true);
callback(true);
});
}, function() {
if (!tunnelers.length) {
Expand Down
6 changes: 3 additions & 3 deletions lib/network/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Protocol.prototype._askNeighborsForTunnels = function(relayers, callback) {
}
}), function(err, response) {
if (err || !Array.isArray(response.result.tunnels)) {
return done(null, false);
return done(false);
}

if (response.result.tunnels && response.result.tunnels.length) {
Expand All @@ -338,10 +338,10 @@ Protocol.prototype._askNeighborsForTunnels = function(relayers, callback) {
);
}
});
return done(null, true);
return done(true);
}

done(null, false);
done(false);
});
}

Expand Down
15 changes: 14 additions & 1 deletion lib/tunnel/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@ TunnelGateway.prototype.open = function(callback) {

if (callback) {
this.once('open', callback);
this.once('error', callback);
}

this._server.listen(this._port, function() {
this._websock.on('error', this._handleError.bind(this));

this._server.on('listening', function() {
self._websock.on('connection', self._handleDataChannel.bind(self));
self._onGatewayOpen();
});

this._server.listen(this._port);
};

/**
Expand Down Expand Up @@ -258,6 +263,14 @@ TunnelGateway.prototype._handleDataChannel = function(socket) {
});
};

/**
* Bubbles error events
* @private
*/
TunnelGateway.prototype._handleError = function() {
this.emit('error', new Error('Failed to open tunnel gateway'));
};

/**
* Fired when server begins listening
* @private
Expand Down
1 change: 1 addition & 0 deletions lib/tunnel/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ TunnelServer.prototype.createGateway = function(callback) {
callback(null, gateway);
});

gateway.on('error', callback);
gateway.open();
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "storj",
"version": "1.2.5",
"version": "1.2.6",
"description": "implementation of the storj protocol for node.js and the browser",
"main": "index.js",
"directories": {
Expand Down Expand Up @@ -62,7 +62,7 @@
"ip": "^1.1.2",
"jsen": "^0.6.0",
"json-stable-stringify": "^1.0.1",
"kad": "^1.5.12",
"kad": "^1.5.13",
"kad-quasar": "^0.1.3",
"leveldown": "^1.4.6",
"levelup": "^1.3.1",
Expand Down
13 changes: 13 additions & 0 deletions test/tunnel/gateway.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ describe('TunnelGateway', function() {
after(gw.close.bind(gw));
});

it('should emit an error if no callback is supplied', function(done) {
var gw = new TunnelGateway();
var _listen = sinon.stub(gw._server, 'listen', function() {
gw._server.emit('error', new Error('EADDRINUSE'));
});
gw.on('error', function(err) {
_listen.restore();
expect(err.message).to.equal('Failed to open tunnel gateway');
done();
});
gw.open();
});

});

describe('#close', function() {
Expand Down

0 comments on commit ab424e4

Please sign in to comment.