/*
var peer = Peers({
interval: 5000
, timeout: 1000 * 60 * 60
})
761273
function Peers(options) {
    options = options || {}

    if (typeof options === "string") {
        options = { id: options }
    }
    var peers = new ExpiryModel()
        , interval = options.interval || 5000
        , timeout = options.timeout || 1000 * 60
        , heartbeats = {}
        , closed
        , id
        , timer

    peers.close = close
    peers.join = join

    peers.on("update", onupdate)

    return peers

    function join(meta) {
        id = meta.id
        peers.set(id, meta)

        if (!timer) {
            timer = setTimeout(heartbeat, interval)
        }
    }

    function onsynched() {
        peers.emit("synced")
    }

    function onupdate(key, value, ts) {
        // console.log("update", arguments)
        var now = Date.now()
        if (ts < now - timeout || closed) {
            return
        }

        if (!heartbeats[key]) {
            // console.log("emitting join")
            peers.emit("join", value)
        }

        // console.log("updating heartbeats", id)
        heartbeats[key] = ts
    }

    function close() {
        closed = true

        Object.keys(heartbeats).forEach(function (key) {
            var value = peers.get(key)

            ;delete heartbeats[key]
            peers.emit("leave", value)
        })

        if (timer) {
            clearTimeout(timer)
        }
    }

    function heartbeat() {
        if (closed) {
            return
        }

        var now = Date.now()
            , meta = peers.get(id)

        meta._heartbeat = now
        peers.set(id, meta)

        Object.keys(heartbeats).forEach(function (key) {
            // console.log("heartbeats", heartbeats, id)
            var time = heartbeats[key]

            if (time < now - timeout) {
                delete heartbeats[key]

                peers.emit("leave", peers.get(key))
            }
        })

        setTimeout(heartbeat, interval)
    }
}
817431
function() {
                var asyncGetReadyTime = new Date().getTime();

                asyncClient = new Async({
                    protocol: protocol,
                    queueHost: queueHost,
                    queuePort: queuePort,
                    queueUsername: queueUsername,
                    queuePassword: queuePassword,
                    queueReceive: queueReceive,
                    queueSend: queueSend,
                    queueConnectionTimeout: queueConnectionTimeout,
                    socketAddress: socketAddress,
                    serverName: serverName,
                    deviceId: deviceId,
                    wsConnectionWaitTime: wsConnectionWaitTime,
                    connectionRetryInterval: connectionRetryInterval,
                    connectionCheckTimeout: connectionCheckTimeout,
                    connectionCheckTimeoutThreshold: connectionCheckTimeoutThreshold,
                    messageTtl: messageTtl,
                    reconnectOnClose: reconnectOnClose,
                    asyncLogging: asyncLogging
                });

                asyncClient.on('asyncReady', function() {
                    if (actualTimingLog) {
                        Utility.chatStepLogger('Async Connection ', new Date().getTime() - asyncGetReadyTime);
                    }

                    peerId = asyncClient.getPeerId();

                    if (!userInfo) {
                        var getUserInfoTime = new Date().getTime();

                        getUserInfo(function(userInfoResult) {
                            if (actualTimingLog) {
                                Utility.chatStepLogger('Get User Info ', new Date().getTime() - getUserInfoTime);
                            }
                            if (!userInfoResult.hasError) {
                                userInfo = userInfoResult.result.user;

                                /**
                                 * Check if user has KeyId stored in their cache or not?
                                 */
                                if (canUseCache) {
                                    if (db) {
                                        db.users
                                            .where('id')
                                            .equals(userInfo.id)
                                            .toArray()
                                            .then(function(users) {
                                                if (users.length > 0 && typeof users[0].keyId != 'undefined') {
                                                    var user = users[0];

                                                    getEncryptionKey({
                                                        keyId: user.keyId
                                                    }, function(result) {
                                                        if (!result.hasError) {
                                                            cacheSecret = result.secretKey;
                                                        }
                                                        else {
                                                            if (result.message != '') {
                                                                try {
                                                                    var response = JSON.parse(result.message);
                                                                    if (response.error == 'invalid_param') {
                                                                        generateEncryptionKey({
                                                                            keyAlgorithm: 'AES',
                                                                            keySize: 256
                                                                        });
                                                                    }
                                                                }
                                                                catch (e) {
                                                                    console.log(e);
                                                                }
                                                            }
                                                        }
                                                    });
                                                }
                                                else {
                                                    generateEncryptionKey({
                                                        keyAlgorithm: 'AES',
                                                        keySize: 256
                                                    });
                                                }
                                            })
                                            .catch(function(error) {
                                                fireEvent('error', {
                                                    code: error.errorCode,
                                                    message: error.errorMessage,
                                                    error: error
                                                });
                                            });
                                    }
                                    else {
                                        fireEvent('error', {
                                            code: 6601,
                                            message: CHAT_ERRORS[6601],
                                            error: null
                                        });
                                    }
                                }

                                chatState = true;
                                fireEvent('chatReady');
                                chatSendQueueHandler();
                            }
                        });
                    }
                    else if (userInfo.id > 0) {
                        chatState = true;
                        fireEvent('chatReady');
                        chatSendQueueHandler();
                    }
                });

                asyncClient.on('stateChange', function(state) {
                    fireEvent('chatState', state);
                    chatFullStateObject = state;

                    switch (state.socketState) {
                        case 1: // CONNECTED
                            if (state.deviceRegister && state.serverRegister) {
                                chatState = true;
                                ping();
                            }
                            break;
                        case 0: // CONNECTING
                        case 2: // CLOSING
                        case 3: // CLOSED
                            chatState = false;
                            break;
                    }
                });

                asyncClient.on('connect', function(newPeerId) {
                    asyncGetReadyTime = new Date().getTime();
                    peerId = newPeerId;
                    fireEvent('connect');
                    ping();
                });

                asyncClient.on('disconnect', function(event) {
                    oldPeerId = peerId;
                    peerId = undefined;
                    fireEvent('disconnect', event);
                });

                asyncClient.on('reconnect', function(newPeerId) {
                    peerId = newPeerId;
                    fireEvent('reconnect');
                });

                asyncClient.on('message', function(params, ack) {
                    receivedAsyncMessageHandler(params);
                    ack && ack();
                });

                asyncClient.on('error', function(error) {
                    fireEvent('error', {
                        code: error.errorCode,
                        message: error.errorMessage,
                        error: error.errorEvent
                    });
                });
            }
697759
function SyncFuture(timeout)
{
    var self = this;
    
    this.resolved = false;
    this.fiber = Fiber.current;
    this.yielding = false;
    this.timeout = timeout;
    this.time = null;
    
    this._timeoutId = null;
    this._result = undefined;
    this._error = null;
    this._start = +new Date;
    
    Sync.stat.totalFutures++;
    Sync.stat.activeFutures++;
    
    // Create timeout error to capture stack trace correctly
    self.timeoutError = new Error();
    Error.captureStackTrace(self.timeoutError, arguments.callee);
    
    this.ticket = function Future()
    {
        // clear timeout if present
        if (self._timeoutId) clearTimeout(self._timeoutId);
        // measure time
        self.time = new Date - self._start;
        
        // forbid to call twice
        if (self.resolved) return;
        self.resolved = true;

        // err returned as first argument
        var err = arguments[0];
        if (err) {
            self._error = err;
        }
        else {
            self._result = arguments[1];
        }
        
        // remove self from current fiber
        self.fiber.removeFuture(self.ticket);
        Sync.stat.activeFutures--;
        
        if (self.yielding && Fiber.current !== self.fiber) {
            self.yielding = false;
            self.fiber.run();
        }
        else if (self._error) {
            throw self._error;
        }
    }
    
    this.ticket.__proto__ = this;
    
    this.ticket.yield = function() {
        while (!self.resolved) {
            self.yielding = true;
            if (self.timeout) {
                self._timeoutId = setTimeout(function(){
                    self.timeoutError.message = 'Future function timed out at ' + self.timeout + ' ms';
                    self.ticket(self.timeoutError);
                }, self.timeout)
            }
            Fiber.yield();
        }
        if (self._error) throw self._error;
        return self._result;
    }
    
    this.ticket.__defineGetter__('result', function(){
        return this.yield();
    });
    
    this.ticket.__defineGetter__('error', function(){
        if (self._error) {
            return self._error;
        }
        try {
            this.result;
        }
        catch (e) {
            return e;
        }
        return null;
    });
    
    this.ticket.__defineGetter__('timeout', function(){
        return self.timeout;
    });
    
    this.ticket.__defineSetter__('timeout', function(value){
        self.timeout = value;
    });
    
    // append self to current fiber
    this.fiber.addFuture(this.ticket);
    
    return this.ticket;
}
190890
function legacySync (peer) {
    if(!legacy) return

    var drain //we need to keep a reference to drain
              //so we can abort it when we get an error.
    function hasLegacy (hashes) {
      var ary = Object.keys(hashes).filter(function (k) {
        return hashes[k] < 0
      })
      if(ary.length)
        peer.blobs.has(ary, function (err, haves) {
          if(err) drain.abort(err) //ERROR: abort this stream.
          else haves.forEach(function (have, i) {
            if(have) has(peer.id, ary[i], have)
          })
        })
    }

    function notPeer (err) {
      if(err) dead(peer.id)
    }

    drain = pull.drain(function (hash) {
      has(peer.id, hash, true)
    }, notPeer)


    pull(peer.blobs.changes(), drain)

    hasLegacy(want)

    //a stream of hashes
    pull(notify.listen(), pull.drain(hasLegacy, notPeer))
  }
158382
function TChannelPeer(channel, hostPort, options) {
    assert(hostPort !== '0.0.0.0:0', 'Cannot create ephemeral peer');

    options = options || {};
    EventEmitter.call(this);

    this.stateChangedEvent = this.defineEvent('stateChanged');
    this.allocConnectionEvent = this.defineEvent('allocConnection');
    this.removeConnectionEvent = this.defineEvent('removeConnection');
    this.deltaOutConnectionEvent = this.defineEvent('deltaOutConnection');

    this.channel = channel;
    this.socketInitTimeout = channel.initTimeout;
    this.logger = this.channel.logger;
    this.timers = this.channel.timers;
    this.random = this.channel.random;
    this.hostPort = hostPort;
    this.connections = [];
    this.pendingIdentified = 0;
    this.heapElements = [];
    this.scoreStrategy = null;
    this.draining = null;
    this.boundOnIdentified = onIdentified;
    this.boundOnConnectionError = onConnectionError;
    this.boundOnConnectionClose = onConnectionClose;
    this.boundOnPendingChange = onPendingChange;
    this.scoreRange = null;

    // Timestamp when next conn attempt is allowed
    this.nextConnAttemptTime = 0;
    // How long to delay conn attempt by on failure (ms)
    this.nextConnAttemptDelay = 0;
    // Whether we are doing a connection attempt
    this.hasConnectionAttempt = false;

    this.waitForIdentifiedListeners = [];

    this.reportInterval = options.reportInterval || DEFAULT_REPORT_INTERVAL;
    if (this.reportInterval > 0 && this.channel.emitConnectionMetrics) {
        this.reportTimer = this.timers.setTimeout(
            onReport, this.reportInterval
        );
    }

    this.connectionAttemptDelay = this.channel.connectionAttemptDelay ||
        INITIAL_CONN_ATTEMPT_DELAY;
    this.maxConnectionAttemptDelay = this.channel.maxConnectionAttemptDelay ||
        MAX_CONN_ATTEMPT_DELAY;

    this.setPreferConnectionDirection(options.preferConnectionDirection || 'any');

    var self = this;

    function onIdentified(_, conn) {
        self.onIdentified(conn);
    }

    function onConnectionError(err, conn) {
        self.onConnectionError(err, conn);
    }

    function onConnectionClose(_, conn) {
        self.onConnectionClose(conn);
    }

    function onPendingChange(pending, conn) {
        self.onPendingChange(conn, pending);
    }

    function onReport() {
        if (!self.hostPort) {
            return;
        }

        var count = self.countConnections('out');
        if (self.channel.emitConnectionMetrics) {
            self.channel.emitFastStat(
                'tchannel.connections.active',
                'gauge',
                count,
                new stat.ConnectionsActiveTags(
                    self.channel.hostPort,
                    self.hostPort
                )
            );
        }

        self.reportTimer = self.timers.setTimeout(
            onReport, self.reportInterval
        );
    }
}
261927
function rxServer(val) {  // {{{2
/**
 * Called, when received "server" message as a client.
 */

  if (! (
    val.space === this.peer.space.name &&
    val.peer === this.peer.name
  )) {
    O.log.error(this, 'This is not the right peer');
    this.close();
    return;
  }

  this.rx = rxConfirm;

  this.tx({
    space: O.here.space.name,
    peer: O.here.name,
  });
  return;
}
405183
def getPeers(self, offset=0, limit=1000):
        
        select = models.Peer.select().order_by(
            models.Peer.url).limit(limit).offset(offset)
        return [peers.Peer(p.url, record=p) for p in select]
879026
function pushOutBoundPeersToExplorer(){
	if(!conf.IF_BYZANTINE)
		return;
	if (conf.bLight )
		return;
	findOutboundPeerOrConnect
	(
		explorerUrl,
		( err, oWsByExplorerUrl ) =>
		{
			if ( ! err )
			{
				let arrOutboundPeerUrls = arrOutboundPeers.map(function (ws) {
					return ws.peer;
				});
				sendJustsaying( oWsByExplorerUrl, 'push_outbound_peers', arrOutboundPeerUrls );
			}
		}
	);
}
945486
function(node, success, error, timeout) {
        //ask for all items
        var iq = $iq({from:this.jid, to:this.service, type:'get'})
          .c('pubsub', { xmlns:Strophe.NS.PUBSUB })
          .c('items', {node:node});

        return this._connection.sendIQ(iq.tree(), success, error, timeout);
    }
903269
function SmartRelay(socket, options) {
  stream.Transform.call(this, {});

  this.options = merge(Object.create(SmartRelay.DEFAULTS), options || {});
  this.socket = socket;
  this.recentData = [];

  this.peers = function () {
    return [];
  };
}
782078
private void update(Peer peer) {
		String id = peer.getId();
		Peer previous = peers.get(id);
		switch(previous.getStatus()) {
			case ACTIVE:
				timeouts.get(id).cancel(true);
				timeouts.put(id, executor.schedule(new Deactivate(id), delay, MILLISECONDS));
				break;
			case INACTIVE:
				peers.put(peer.getId(), peer);
				timeouts.get(id).cancel(true);
				timeouts.put(id, executor.schedule(new Deactivate(id), delay, MILLISECONDS));
				notifyActive(peer);
				break;
			default:
				String error = "Unexpected peer status: " + previous.getStatus();
				throw new RuntimeException(error);
		}
	}
109545
private synchronized boolean addPeer(final PeerInfo peer) {

		final String uuid = peer.getUuid();

		if (!peers.containsKey(uuid)) {

			peers.put(uuid, peer);

			peer.setLastSeen(System.currentTimeMillis());
			onAddPeer(peer);

			return true;
		}

		// not added
		return false;
	}
539496
function PeerDrain(peer, options, callback) {
    var chan = peer.channel.topChannel || peer.channel;

    assert(options, 'options is required');
    assert(options.reason, 'a reason is required');
    assert(!chan.draining, 'cannot drain a peer while channel is draining');
    assert(!options.goal ||
           options.goal === GOAL_NOOP ||
           options.goal === GOAL_CLOSE_DRAINED ||
           options.goal === GOAL_CLOSE_PEER,
           'expected a valid goal (if any)');

    this.goal = options.goal || PeerDrain.GOAL_NOOP;
    this.channel = chan;
    this.peer = peer;
    this.timeout = options.timeout || 0;
    this.reason = options.reason;
    this.direction = options.direction || 'both';
    this.callback = callback || null;
    this.timer = null;
    this.drained = null;
    this.startedAt = 0;
    this.stoppedAt = 0;
    this.finishedAt = 0;
    this.thenFinish = thenFinish;

    var self = this;

    function thenFinish(err) {
        var now = self.channel.timers.now();
        self.finish(err, now);
    }
}
797442
function(opt_syncRateSeconds, callback) {
      var query = misc.parseUrlQuery();
      var url = (query.hftUrl || window.location.href).replace("ws:", "http:");

      var syncRateMS = (opt_syncRateSeconds || 10) * 1000;
      var timeOffset = 0;

      var syncToServer = function(queueNext) {
        var sendTime = getLocalTime();
        io.sendJSON(url, {cmd: 'time'}, function(exception, obj) {
          if (exception) {
            console.error("syncToServer: " + exception);
          } else {
            var receiveTime = getLocalTime();
            var duration = receiveTime - sendTime;
            var serverTime = obj.time + duration * 0.5;
            timeOffset = serverTime - receiveTime;
            if (callback) {
              callback();
              callback = undefined;
            }
            //g_services.logger.log("duration: ", duration, " timeOff:", timeOffset);
          }

          if (queueNext) {
            setTimeout(function() {
              syncToServer(true);
            }, syncRateMS);
          }
        });
      };
      var syncToServerNoQueue = function() {
        syncToServer(false);
      };
      syncToServer(true);
      setTimeout(syncToServerNoQueue, 1000);
      setTimeout(syncToServerNoQueue, 2000);
      setTimeout(syncToServerNoQueue, 4000);

      /**
       * Gets the current time in seconds.
       * @private
       */
      this.getTime = function() {
        return getLocalTime() + timeOffset;
      };

    }
236437
function networkConnections(callback) {

  return new Promise((resolve) => {
    process.nextTick(() => {
      let result = [];
      if (_linux || _freebsd || _openbsd) {
        let cmd = 'netstat -tuna | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN\\|VERBUNDEN"';
        if (_freebsd || _openbsd) cmd = 'netstat -na | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN\\|VERBUNDEN"';
        exec(cmd, { maxBuffer: 1024 * 2000 }, function (error, stdout) {
          if (!error) {
            let lines = stdout.toString().split('\n');
            lines.forEach(function (line) {
              line = line.replace(/ +/g, ' ').split(' ');
              if (line.length >= 6) {
                let localip = line[3];
                let localport = '';
                let localaddress = line[3].split(':');
                if (localaddress.length > 1) {
                  localport = localaddress[localaddress.length - 1];
                  localaddress.pop();
                  localip = localaddress.join(':');
                }
                let peerip = line[4];
                let peerport = '';
                let peeraddress = line[4].split(':');
                if (peeraddress.length > 1) {
                  peerport = peeraddress[peeraddress.length - 1];
                  peeraddress.pop();
                  peerip = peeraddress.join(':');
                }
                let connstate = line[5];
                if (connstate === 'VERBUNDEN') connstate = 'ESTABLISHED';
                if (connstate) {
                  result.push({
                    protocol: line[0],
                    localaddress: localip,
                    localport: localport,
                    peeraddress: peerip,
                    peerport: peerport,
                    state: connstate
                  });
                }
              }
            });
            if (callback) {
              callback(result);
            }
            resolve(result);
          } else {
            cmd = 'ss -tuna | grep "ESTAB\\|SYN-SENT\\|SYN-RECV\\|FIN-WAIT1\\|FIN-WAIT2\\|TIME-WAIT\\|CLOSE\\|CLOSE-WAIT\\|LAST-ACK\\|LISTEN\\|CLOSING"';
            exec(cmd, { maxBuffer: 1024 * 2000 }, function (error, stdout) {

              if (!error) {
                let lines = stdout.toString().split('\n');
                lines.forEach(function (line) {
                  line = line.replace(/ +/g, ' ').split(' ');
                  if (line.length >= 6) {
                    let localip = line[4];
                    let localport = '';
                    let localaddress = line[4].split(':');
                    if (localaddress.length > 1) {
                      localport = localaddress[localaddress.length - 1];
                      localaddress.pop();
                      localip = localaddress.join(':');
                    }
                    let peerip = line[5];
                    let peerport = '';
                    let peeraddress = line[5].split(':');
                    if (peeraddress.length > 1) {
                      peerport = peeraddress[peeraddress.length - 1];
                      peeraddress.pop();
                      peerip = peeraddress.join(':');
                    }
                    let connstate = line[1];
                    if (connstate === 'ESTAB') connstate = 'ESTABLISHED';
                    if (connstate === 'TIME-WAIT') connstate = 'TIME_WAIT';
                    if (connstate) {
                      result.push({
                        protocol: line[0],
                        localaddress: localip,
                        localport: localport,
                        peeraddress: peerip,
                        peerport: peerport,
                        state: connstate
                      });
                    }
                  }
                });
              }
              if (callback) {
                callback(result);
              }
              resolve(result);
            });
          }
        });
      }
      if (_darwin) {
        let cmd = 'netstat -nat | grep "ESTABLISHED\\|SYN_SENT\\|SYN_RECV\\|FIN_WAIT1\\|FIN_WAIT2\\|TIME_WAIT\\|CLOSE\\|CLOSE_WAIT\\|LAST_ACK\\|LISTEN\\|CLOSING\\|UNKNOWN"';
        exec(cmd, { maxBuffer: 1024 * 2000 }, function (error, stdout) {
          if (!error) {

            let lines = stdout.toString().split('\n');

            lines.forEach(function (line) {
              line = line.replace(/ +/g, ' ').split(' ');
              if (line.length >= 6) {
                let localip = line[3];
                let localport = '';
                let localaddress = line[3].split('.');
                if (localaddress.length > 1) {
                  localport = localaddress[localaddress.length - 1];
                  localaddress.pop();
                  localip = localaddress.join('.');
                }
                let peerip = line[4];
                let peerport = '';
                let peeraddress = line[4].split('.');
                if (peeraddress.length > 1) {
                  peerport = peeraddress[peeraddress.length - 1];
                  peeraddress.pop();
                  peerip = peeraddress.join('.');
                }
                let connstate = line[5];
                if (connstate) {
                  result.push({
                    protocol: line[0],
                    localaddress: localip,
                    localport: localport,
                    peeraddress: peerip,
                    peerport: peerport,
                    state: connstate
                  });
                }
              }
            });
            if (callback) {
              callback(result);
            }
            resolve(result);
          }
        });
      }
      if (_windows) {
        let cmd = 'netstat -na';
        try {
          exec(cmd, util.execOptsWin, function (error, stdout) {
            if (!error) {

              let lines = stdout.toString().split('\r\n');

              lines.forEach(function (line) {
                line = line.trim().replace(/ +/g, ' ').split(' ');
                if (line.length >= 4) {
                  let localip = line[1];
                  let localport = '';
                  let localaddress = line[1].split(':');
                  if (localaddress.length > 1) {
                    localport = localaddress[localaddress.length - 1];
                    localaddress.pop();
                    localip = localaddress.join(':');
                  }
                  let peerip = line[2];
                  let peerport = '';
                  let peeraddress = line[2].split(':');
                  if (peeraddress.length > 1) {
                    peerport = peeraddress[peeraddress.length - 1];
                    peeraddress.pop();
                    peerip = peeraddress.join(':');
                  }
                  let connstate = line[3];
                  if (connstate === 'HERGESTELLT') connstate = 'ESTABLISHED';
                  if (connstate.startsWith('ABH')) connstate = 'LISTEN';
                  if (connstate === 'SCHLIESSEN_WARTEN') connstate = 'CLOSE_WAIT';
                  if (connstate === 'WARTEND') connstate = 'TIME_WAIT';
                  if (connstate === 'SYN_GESENDET') connstate = 'SYN_SENT';

                  if (connstate === 'LISTENING') connstate = 'LISTEN';
                  if (connstate === 'SYN_RECEIVED') connstate = 'SYN_RECV';
                  if (connstate === 'FIN_WAIT_1') connstate = 'FIN_WAIT1';
                  if (connstate === 'FIN_WAIT_2') connstate = 'FIN_WAIT2';
                  if (connstate) {
                    result.push({
                      protocol: line[0].toLowerCase(),
                      localaddress: localip,
                      localport: localport,
                      peeraddress: peerip,
                      peerport: peerport,
                      state: connstate
                    });
                  }
                }
              });
              if (callback) {
                callback(result);
              }
              resolve(result);
            }
          });
        } catch (e) {
          if (callback) { callback(result); }
          resolve(result);
        }
      }
    });
  });
}
952092
function closeOldestServer() {
        var oldest = null;
        Object.keys(self._peerServers).forEach(function (k) {
          if (oldest == null) {
            oldest = k;
          }
          else {
            if (self._peerServers[k].lastActive <
              self._peerServers[oldest].lastActive) {
              oldest = k;
            }
          }
        });
        if (oldest) {
          closeServer(self, self._peerServers[oldest], null, false);
        }
      }
1027920
@Override
  public void handlePeerReady(SharingPeer peer) {
    initIfNecessary(peer);

    RequestsCollection requestsCollection = getRequestsCollection(peer);
    requestsCollection.sendAllRequests();
  }