diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java index d8a2e3a1f35379aa47c7d43655208497e770586b..2b11a019eed1f3cefe2381e8ec10df09b5f4f3cd 100644 --- a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java +++ b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState2.java @@ -72,7 +72,30 @@ class OutboundEstablishState2 extends OutboundEstablishState implements SSU2Payl throw new IllegalArgumentException("bad IP", uhe); } } - _mtu = addr.getMTU(); + // We need the MTU so the Session Confirmed can fit the RI in + int mtu = addr.getMTU(); + if (mtu == 0) { + if (ra.getTransportStyle().equals("SSU2")) { + mtu = PeerState2.DEFAULT_MTU; + } else { + if (_bobIP.length == 16) + mtu = PeerState2.DEFAULT_SSU_IPV6_MTU; + else + mtu = PeerState2.DEFAULT_SSU_IPV4_MTU; + } + } else { + // TODO if too small, give up now + if (ra.getTransportStyle().equals("SSU2")) { + mtu = Math.min(Math.max(mtu, PeerState2.MIN_MTU), PeerState2.MAX_MTU); + } else { + if (_bobIP.length == 16) + mtu = Math.min(Math.max(mtu, PeerState2.MIN_SSU_IPV6_MTU), PeerState2.MAX_SSU_IPV6_MTU); + else + mtu = Math.min(Math.max(mtu, PeerState2.MIN_SSU_IPV4_MTU), PeerState2.MAX_SSU_IPV4_MTU); + } + } + _mtu = mtu; + // TODO if RI too big, give up now if (addr.getIntroducerCount() > 0) { if (_log.shouldLog(Log.DEBUG)) _log.debug("new outbound establish to " + remotePeer.calculateHash() + ", with address: " + addr); @@ -87,13 +110,13 @@ class OutboundEstablishState2 extends OutboundEstablishState implements SSU2Payl do { rcid = ctx.random().nextLong(); } while (_sendConnID == rcid); + _rcvConnID = rcid; _token = _transport.getEstablisher().getOutboundToken(_remotePeer.calculateHash()); _routerAddress = ra; if (_token != 0) createNewState(ra); - _rcvConnID = rcid; byte[] ik = introKey.getData(); _sendHeaderEncryptKey1 = ik; _rcvHeaderEncryptKey1 = ik; diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java index 91cf5c8e0f85c5e800dead8fc20b3ec4cd532d30..cf7c157a284aa6e32f36405b20092f49d66c7e53 100644 --- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java +++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder2.java @@ -453,7 +453,6 @@ class PacketBuilder2 { len = info.length; } - UDPPacket packets[] = new UDPPacket[numFragments]; packets[0] = buildSessionConfirmedPacket(state, numFragments, info, len, gzip); if (numFragments > 1) { @@ -909,7 +908,7 @@ class PacketBuilder2 { _log.error("Bad token req msg out", gse); throw new RuntimeException("Bad token req msg out", gse); } - SSU2Header.encryptHandshakeHeader(packet, hdrKey1, hdrKey2); + SSU2Header.encryptLongHeader(packet, hdrKey1, hdrKey2); } /** diff --git a/router/java/src/net/i2p/router/transport/udp/PeerState2.java b/router/java/src/net/i2p/router/transport/udp/PeerState2.java index 86c590626f39382ba3867c8e54e8c9cdc3337a40..f9c1e5d0955ae8b410a52f42fe146fefcd642d53 100644 --- a/router/java/src/net/i2p/router/transport/udp/PeerState2.java +++ b/router/java/src/net/i2p/router/transport/udp/PeerState2.java @@ -48,7 +48,17 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback private final SSU2Bitfield _ackedMessages; private byte[] _sessConfForReTX; + // As SSU + public static final int MIN_SSU_IPV4_MTU = 1292; + public static final int MAX_SSU_IPV4_MTU = 1484; + public static final int DEFAULT_SSU_IPV4_MTU = MAX_SSU_IPV4_MTU; + public static final int MIN_SSU_IPV6_MTU = 1280; + public static final int MAX_SSU_IPV6_MTU = 1488; + public static final int DEFAULT_SSU_IPV6_MTU = MIN_SSU_IPV6_MTU; // should always be published + // As SSU2 public static final int MIN_MTU = 1280; + public static final int MAX_MTU = 1500; + public static final int DEFAULT_MTU = MAX_MTU; /** * @param rtt from the EstablishState, or 0 if not available