private void logPacket(I2PBotePacket packet, Destination sender) { String senderHash = Util.toShortenedBase32(sender); log.debug("I2P packet received: [" + packet + "] Sender: [" + senderHash + "], notifying " + packetListeners.size() + " PacketListeners."); }
/** * Updates the <code>notQueriedYet</code> set with the peers from a <code>peerListPacket</code>, * and adds the <code>sender</code> to <code>responses</code>. * @param peerListPacket * @param sender * @param receiveTime */ private void updatePeers(PeerList peerListPacket, Destination sender, long receiveTime) { log.debug("Peer List Packet received: #peers=" + peerListPacket.getPeers().size() + ", sender="+ Util.toShortenedBase32(sender)); // update the list of peers to query Collection<Destination> peersReceived = peerListPacket.getPeers(); addPeersToBeQueried(peersReceived); }
@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 }
StringBuilder debugMsg = new StringBuilder("Creating relay chain: ["); for (int i=relayPeers.size()-1; i>=0; i--) { debugMsg.append(Util.toShortenedBase32(relayPeers.get(i))); if (i > 0) debugMsg.append(" --> ");
@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)); } } }
log.debug("Confirmation received from relay peer " + Util.toShortenedBase32(nextDestination) + ", deleting packet: " + packet); iterator.remove();
/** This method actually sends a packet via the router */ private void send(ScheduledPacket scheduledPacket) throws InterruptedException { CommunicationPacket i2pBotePacket = scheduledPacket.data; byte[] bytes = i2pBotePacket.toByteArray(); PacketBatch batch = scheduledPacket.batch; boolean isBatchPacket = batch != null; log.debug("Sending " + (isBatchPacket?"":"non-") + "batch packet: [" + i2pBotePacket + "] to " + Util.toShortenedBase32(scheduledPacket.destination)); try { sendDatagram(bytes, scheduledPacket.destination); // set sentTime, update queue and sentLatch, fire packet listeners scheduledPacket.data.setSentTime(System.currentTimeMillis()); if (isBatchPacket) batch.decrementSentLatch(); scheduledPacket.decrementSentLatch(); } catch (Exception exc) { log.error("Can't send packet.", exc); // pause to avoid CPU hogging if the error doesn't go away TimeUnit.SECONDS.sleep(1); } }
if (hasTimedOut(request.getValue(), REQUEST_TIMEOUT)) { Destination peer = request.getKey(); log.debug("FindCloseNodes request to peer " + Util.toShortenedBase32(peer) + " timed out."); bucketManager.noResponse(peer); pendingRequests.remove(peer);
log.error("Invalid hash for email packet: " + emailPacket + " Sender: " + Util.toShortenedBase32(peer));