Skip to content

Commit

Permalink
Merge pull request #55 from braydonf/bug/addr-port
Browse files Browse the repository at this point in the history
fixed bug with incoming connections not having a port on addr
  • Loading branch information
martindale committed Mar 23, 2015
2 parents df632f3 + c555671 commit fa06ce0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ Pool.prototype.listen = function() {
} else {
addr.ip.v4 = socket.remoteAddress;
}
addr.port = socket.remotePort;

addr = self._addAddr(addr);
self._addConnectedPeer(socket, addr);
Expand Down
22 changes: 22 additions & 0 deletions test/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,28 @@ describe('Pool', function() {
pool.listen();
});

it('include port for addr on incoming connections', function(done) {
var port = 12345;
sinon.stub(net, 'createServer', function(callback) {
callback({
remoteAddress: '127.0.0.1',
remotePort: port
});
return {
listen: sinon.stub()
};
});
var pool = new Pool({network: Networks.livenet, maxSize: 1});
pool._addAddr = function(addr) {
should.exist(addr.port);
addr.port.should.equal(port);
net.createServer.restore();
done();
};
pool._addConnectedPeer = sinon.stub();
pool.listen();
});

it('should handle an ipv4 connection', function(done) {
var ipv4 = '127.0.0.1';
sinon.stub(net, 'createServer', function(callback) {
Expand Down

0 comments on commit fa06ce0

Please sign in to comment.