@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 }
@Override public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) { if (packet instanceof ResponsePacket) { UniqueId packetId = packet.getPacketId(); for (PacketBatch batch: runningBatches) if (batch.contains(packetId)) { DataPacket payload = ((ResponsePacket)packet).getPayload(); if (payload != null) batch.addResponse(sender, payload); else batch.addResponse(sender, new EmptyResponse()); } } }