ソースを参照

prevent missing key errors

ericz 12 年 前
コミット
08957a0aa6
1 ファイル変更4 行追加1 行削除
  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();
   }