don't assume peer var will exist

This commit is contained in:
Feross Aboukhadijeh 2014-11-26 17:40:34 +08:00
parent 20d08f6d03
commit 2824f16c49

View File

@ -174,7 +174,7 @@ Server.prototype._onHttpRequest = function (req, res) {
} }
if (left === 0) swarm.complete += 1 if (left === 0) swarm.complete += 1
else swarm.incomplete += 1 else swarm.incomplete += 1
swarm.peers[addr] = { peer = swarm.peers[addr] = {
ip: ip, ip: ip,
port: port, port: port,
peerId: peerId peerId: peerId
@ -233,7 +233,7 @@ Server.prototype._onHttpRequest = function (req, res) {
return error('invalid event') // early return return error('invalid event') // early return
} }
if (left === 0) peer.complete = true if (left === 0 && peer) peer.complete = true
// send peers // send peers
var peers = compact === 1 var peers = compact === 1
@ -367,7 +367,7 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
} }
if (left === 0) swarm.complete += 1 if (left === 0) swarm.complete += 1
else swarm.incomplete += 1 else swarm.incomplete += 1
swarm.peers[addr] = { peer = swarm.peers[addr] = {
ip: ip, ip: ip,
port: port, port: port,
peerId: peerId peerId: peerId
@ -426,7 +426,7 @@ Server.prototype._onUdpRequest = function (msg, rinfo) {
return error('invalid event') // early return return error('invalid event') // early return
} }
if (left === 0) peer.complete = true if (left === 0 && peer) peer.complete = true
// send peers // send peers
var peers = self._getPeersCompact(swarm, numWant) var peers = self._getPeersCompact(swarm, numWant)