Пример #1
0
  /** Note that this function will _EAT_ messages until it finds a ping to respond to. */
  private void replyToPing(BlockingConnection c, boolean ultrapeer) throws Exception {
    // respond to a ping iff one is given.
    Message m = null;
    byte[] guid;
    try {
      while (!(m instanceof PingRequest)) {
        m = c.receive(500);
      }
      guid = ((PingRequest) m).getGUID();
    } catch (InterruptedIOException iioe) {
      // nothing's coming, send a fake pong anyway.
      guid = new GUID().bytes();
    }

    Socket socket = c.getSocket();
    PingReply reply =
        pingReplyFactory.createExternal(
            guid, (byte) 7, socket.getLocalPort(), ultrapeer ? ultrapeerIP : oldIP, ultrapeer);
    reply.hop();
    c.send(reply);
    c.flush();
  }