Browse Source

prevent missing key errors

ericz 12 years ago
parent
commit
08957a0aa6
1 changed files with 4 additions and 1 deletions
  1. 4 1
      lib/server.js

+ 4 - 1
lib/server.js

@@ -345,7 +345,7 @@ PeerServer.prototype._processOutstanding = function(key, id) {
 };
 
 PeerServer.prototype._removePeer = function(key, id) {
-  if (this._clients[key][id]) {
+  if (this._clients[key] && this._clients[key][id]) {
     this._ips[this._clients[key][id].ip]--;
     delete this._clients[key][id];
   }
@@ -405,6 +405,9 @@ PeerServer.prototype._handleTransmission = function(key, message) {
 
 PeerServer.prototype._generateClientId = function(key) {
   var clientId = util.randomId();
+  if (!this._clients[key]) {
+    return clientId;
+  }
   while (!!this._clients[key][clientId]) {
     clientId = util.randomId();
   }