Skip to content

Commit

Permalink
SSU2: Drop small packets in UDPReceiver
Browse files Browse the repository at this point in the history
now that SSU1 is disabled.
SSU2 min packet size is 40 and does not support 0-byte hole punch
  • Loading branch information
zzzi2p committed Jan 17, 2024
1 parent 67f1593 commit ce5c75c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions router/java/src/net/i2p/router/transport/udp/UDPReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ public void run() {
_socket.receive(dpacket);
//}
int size = dpacket.getLength();
if (_log.shouldLog(Log.INFO))
_log.info("After blocking socket.receive: packet is " + size + " bytes on " + System.identityHashCode(packet));
//if (_log.shouldDebug())
// _log.debug("After blocking socket.receive: packet is " + size + " bytes on " + System.identityHashCode(packet));
packet.resetBegin();

// and block after we know how much we read but before
Expand All @@ -261,7 +261,7 @@ public void run() {
if (_context.commSystem().isDummy()) {
// testing
packet.release();
} else if (size > 0) {
} else if (size >= SSU2Util.MIN_DATA_LEN) {
//FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestInbound(size, "UDP receiver");
//_context.bandwidthLimiter().requestInbound(req, size, "UDP receiver");
FIFOBandwidthLimiter.Request req =
Expand All @@ -280,11 +280,9 @@ public void run() {
receive(packet);
//_context.statManager().addRateData("udp.receivePacketSize", size);
} else {
_context.statManager().addRateData("udp.receiveHolePunch", 1);
// nat hole punch packets are 0 bytes
if (_log.shouldLog(Log.INFO))
_log.info("Received a 0 byte udp packet from " + dpacket.getAddress() + ":" + dpacket.getPort());
_transport.getEstablisher().receiveHolePunch(dpacket.getAddress(), dpacket.getPort());
// SSU1 had 0 byte hole punch, SSU2 does not
if (_log.shouldWarn())
_log.warn("Dropping short " + size + " byte udp packet from " + dpacket.getAddress() + ":" + dpacket.getPort());
packet.release();
}
} catch (IOException ioe) {
Expand Down

0 comments on commit ce5c75c

Please sign in to comment.