diff --git a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java index 89076f9ce3..53e7e9d8dd 100644 --- a/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java +++ b/router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java @@ -29,6 +29,7 @@ import net.i2p.router.util.DecayingBloomFilter; import net.i2p.util.Addresses; import net.i2p.util.I2PThread; import net.i2p.util.Log; +import net.i2p.util.VersionComparator; /** * Coordinate the establishment of new sessions - both inbound and outbound. @@ -126,6 +127,14 @@ class EstablishmentManager { /** for the DSM and or netdb store */ private static final int DATA_MESSAGE_TIMEOUT = 10*1000; + /** + * Java I2P has always parsed the length of the extended options field, + * but i2pd hasn't recognized it until this release. + * No matter, the options weren't defined until this release anyway. + */ + private static final String VERSION_ALLOW_EXTENDED_OPTIONS = "0.9.24"; + + public EstablishmentManager(RouterContext ctx, UDPTransport transport) { _context = ctx; _log = ctx.logManager().getLog(EstablishmentManager.class); @@ -356,8 +365,10 @@ class EstablishmentManager { _transport.failed(msg, "Peer has bad key, cannot establish"); return; } + boolean allowExtendedOptions = VersionComparator.comp(toRouterInfo.getVersion(), + VERSION_ALLOW_EXTENDED_OPTIONS) >= 0; state = new OutboundEstablishState(_context, maybeTo, to, - toIdentity, + toIdentity, allowExtendedOptions, sessionKey, addr, _transport.getDHFactory()); OutboundEstablishState oldState = _outboundStates.putIfAbsent(to, state); boolean isNew = oldState == null; @@ -477,6 +488,7 @@ class EstablishmentManager { // Don't offer to relay to privileged ports. // Only offer for an IPv4 session. // TODO if already we have their RI, only offer if they need it (no 'C' cap) + // TODO if extended options, only if they asked for it if (_transport.canIntroduce() && state.getSentPort() >= 1024 && state.getSentIP().length == 4) { // ensure > 0 diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java index 63497b5ea3..cfb0d2f577 100644 --- a/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java +++ b/router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java @@ -56,6 +56,7 @@ class OutboundEstablishState { private RemoteHostId _remoteHostId; private final RemoteHostId _claimedAddress; private final RouterIdentity _remotePeer; + private final boolean _allowExtendedOptions; private final SessionKey _introKey; private final Queue _queuedMessages; private OutboundState _currentState; @@ -112,7 +113,8 @@ class OutboundEstablishState { */ public OutboundEstablishState(RouterContext ctx, RemoteHostId claimedAddress, RemoteHostId remoteHostId, - RouterIdentity remotePeer, SessionKey introKey, UDPAddress addr, + RouterIdentity remotePeer, boolean allowExtendedOptions, + SessionKey introKey, UDPAddress addr, DHSessionKeyBuilder.Factory dh) { _context = ctx; _log = ctx.logManager().getLog(OutboundEstablishState.class); @@ -125,6 +127,7 @@ class OutboundEstablishState { } _claimedAddress = claimedAddress; _remoteHostId = remoteHostId; + _allowExtendedOptions = allowExtendedOptions; _remotePeer = remotePeer; _introKey = introKey; _queuedMessages = new LinkedBlockingQueue(); @@ -157,6 +160,9 @@ class OutboundEstablishState { /** @return -1 if unset */ public long getIntroNonce() { return _introductionNonce; } + + /** @since 0.9.24 */ + public boolean isExtendedOptionsAllowed() { return _allowExtendedOptions; } /** * Queue a message to be sent after the session is established. diff --git a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java index 07f9ec3418..594388716b 100644 --- a/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java +++ b/router/java/src/net/i2p/router/transport/udp/PacketBuilder.java @@ -784,6 +784,8 @@ class PacketBuilder { */ public UDPPacket buildSessionRequestPacket(OutboundEstablishState state) { // TODO + // boolean ext = state.isExtendedOptionsAllowed(); + // if (ext) //byte[] options = new byte[3]; //UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE, options); UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE);