// Look up an older packet for responses // Return true if the packet is unique; false if we have seen it before private boolean rememberPacket(GnutellaPacket pkt) { GnutellaConnection gc = (GnutellaConnection) packetTable.get(pkt.getGUID()); if (gc != null) return false; if (DEBUG) System.err.println("**** REMEMBERING: " + pkt + " from " + pkt.getConnection()); packetTable.put(pkt.getGUID(), pkt.getConnection()); return true; }
private void doClean(timerEvent ev) { // Cleaner event if (VERBOSE) System.err.println("-- Cleaning up packetTable"); // Might cause some recent packets to be dropped packetTable.clear(); if (VERBOSE) { Runtime r = Runtime.getRuntime(); System.err.println( "TOTAL: " + r.totalMemory() / 1024 + "KB FREE: " + r.freeMemory() / 1024 + "KB"); } // Reregister timer event timer.registerEvent(CLEAN_TIMER_FREQUENCY, ev, mySink); }
// Forward an incoming packet to the corresponding source private void forwardPacket(GnutellaPacket pkt) { GnutellaConnection gc; gc = (GnutellaConnection) packetTable.get(pkt.getGUID()); if (gc == null) { if (VERBOSE) System.err.println("-- Received reply with no request: " + pkt); return; } if (DEBUG) System.err.println("**** REPLYING: " + pkt + " to " + gc); if ((pkt.ttl == 0) || (--pkt.ttl == 0)) { if (VERBOSE) System.err.println("-- Dropping packet, TTL expired: " + pkt); } pkt.hops++; gc.enqueue_lossy(pkt); }