@Override public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) { if (packet instanceof ResponsePacket) { ResponsePacket responsePacket = (ResponsePacket)packet; synchronized(pendingRequests) { FindClosePeersPacket request = getPacketById(pendingRequests.values(), responsePacket.getPacketId()); // find the request the node list is in response to // if the packet is in response to a pending request, update responses + notQueriedYet + pendingRequests if (request != null) { log.debug("Response to FindCloseNodesPacket received from " + Util.toShortenedBase32(sender)); responses.add(sender); DataPacket payload = responsePacket.getPayload(); if (payload instanceof PeerList) updatePeers((PeerList)payload, sender, receiveTime); pendingRequests.remove(sender); } } } else if (packet instanceof MalformedCommunicationPacket) pendingRequests.remove(sender); // since it is not generally possible to tell if an invalid comm packet is in response to a certain request, always remove invalid packets from the pending list }
public List<Destination> call() throws InterruptedException { log.debug("Looking up nodes closest to " + key); PacketListener packetListener = new IncomingPacketHandler(); i2pReceiver.addPacketListener(packetListener);