public synchronized void putPacket(CommunicationPacket packet, Destination destination) { outgoingPackets.put(packet.getPacketId(), new PacketBatchItem(packet, destination)); sentSignal = new CountDownLatch((int)sentSignal.getCount() + 1); }
@Override public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) { BanList banList = BanList.getInstance(); banList.update(sender, packet); synchronized(peers) { if (banList.isBanned(sender)) { peers.remove(sender); return; } // respond to PeerListRequests if (packet instanceof PeerListRequest) { // send up to MAX_PEERS_TO_SEND high-reachability peers minus the sender itself List<Destination> peersToSend = new ArrayList<Destination>(); peersToSend.addAll(getGoodPeers(MAX_PEERS_TO_SEND)); peersToSend.remove(sender); PeerList response = new PeerList(peersToSend); log.debug("Sending a PeerList containing " + peersToSend.size() + " peers in response to a PeerListRequest from " + Util.toShortenedBase32(sender)); sendQueue.sendResponse(response, sender, packet.getPacketId()); } // If there are less than MAX_PEERS/2 peers, add the sender (which can be a relay peer or a DHT peer) // as a relay peer. The other MAX_PEERS/2 are reserved for peers from PeerListRequests since they are preferrable. if (peers.size() < MAX_PEERS/2) peers.add(new RelayPeer(sender)); } } }
@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()); } } }
DeletionInfoPacket delInfo = new DeletionInfoPacket(); delInfo.put(dhtKey, delAuthorization); Collection<ResponsePacket> response = ResponsePacket.create(delInfo, StatusCode.OK, packet.getPacketId()); sendQueue.send(response, sender);