From 2824f16c49d87dbd03462fcce5396c85fd04a2c9 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 26 Nov 2014 17:40:34 +0800 Subject: [PATCH] don't assume peer var will exist --- server.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index ad4c33b..3370b56 100644 --- a/server.js +++ b/server.js @@ -174,7 +174,7 @@ Server.prototype._onHttpRequest = function (req, res) { } if (left === 0) swarm.complete += 1 else swarm.incomplete += 1 - swarm.peers[addr] = { + peer = swarm.peers[addr] = { ip: ip, port: port, peerId: peerId @@ -233,7 +233,7 @@ Server.prototype._onHttpRequest = function (req, res) { return error('invalid event') // early return } - if (left === 0) peer.complete = true + if (left === 0 && peer) peer.complete = true // send peers var peers = compact === 1 @@ -367,7 +367,7 @@ Server.prototype._onUdpRequest = function (msg, rinfo) { } if (left === 0) swarm.complete += 1 else swarm.incomplete += 1 - swarm.peers[addr] = { + peer = swarm.peers[addr] = { ip: ip, port: port, peerId: peerId @@ -426,7 +426,7 @@ Server.prototype._onUdpRequest = function (msg, rinfo) { return error('invalid event') // early return } - if (left === 0) peer.complete = true + if (left === 0 && peer) peer.complete = true // send peers var peers = self._getPeersCompact(swarm, numWant)