Changeset 1e89fac


Ignore:
Timestamp:
Nov 18, 2015 6:12:23 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
599989de
Parents:
4c72c08
Message:

SSU: Add support for requesting a relay tag via
Session Request extended options (ticket #1465)

Location:
router/java/src/net/i2p/router/transport/udp
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java

    r4c72c08 r1e89fac  
    132132     * but i2pd hasn't recognized it until this release.
    133133     * No matter, the options weren't defined until this release anyway.
    134      */
    135     private static final String VERSION_ALLOW_EXTENDED_OPTIONS = "0.9.24";
     134     *
     135     * FIXME 0.9.22 for testing, change to 0.9.24 for release
     136     *
     137     */
     138    private static final String VERSION_ALLOW_EXTENDED_OPTIONS = "0.9.22";
    136139
    137140
     
    368371                    boolean allowExtendedOptions = VersionComparator.comp(toRouterInfo.getVersion(),
    369372                                                                          VERSION_ALLOW_EXTENDED_OPTIONS) >= 0;
     373                    // w/o ext options, it's always 'requested', no need to set
     374                    boolean requestIntroduction = allowExtendedOptions && _transport.introducersRequired();
    370375                    state = new OutboundEstablishState(_context, maybeTo, to,
    371376                                                       toIdentity, allowExtendedOptions,
     377                                                       requestIntroduction,
    372378                                                       sessionKey, addr, _transport.getDHFactory());
    373379                    OutboundEstablishState oldState = _outboundStates.putIfAbsent(to, state);
     
    489495            // Only offer for an IPv4 session.
    490496            // TODO if already we have their RI, only offer if they need it (no 'C' cap)
    491             // TODO if extended options, only if they asked for it
    492             if (_transport.canIntroduce() && state.getSentPort() >= 1024 &&
     497            // if extended options, only if they asked for it
     498            if (state.isIntroductionRequested() &&
     499                _transport.canIntroduce() && state.getSentPort() >= 1024 &&
    493500                state.getSentIP().length == 4) {
    494501                // ensure > 0
  • router/java/src/net/i2p/router/transport/udp/InboundEstablishState.java

    r4c72c08 r1e89fac  
    6363    // count for backoff
    6464    private int _createdSentCount;
     65    // default true
     66    private boolean _introductionRequested = true;
    6567   
    6668    public enum InboundState {
     
    151153            _bobIP = new byte[req.readIPSize()];
    152154        req.readIP(_bobIP, 0);
     155        byte[] ext = req.readExtendedOptions();
     156        if (ext != null && ext.length >= UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH) {
     157            _introductionRequested = (ext[1] & (byte) UDPPacket.SESS_REQ_EXT_FLAG_REQUEST_RELAY_TAG) != 0;
     158        }
    153159        if (_log.shouldLog(Log.DEBUG))
    154160            _log.debug("Receive sessionRequest, BobIP = " + Addresses.toString(_bobIP));
     
    161167    public synchronized byte[] getReceivedX() { return _receivedX; }
    162168    public synchronized byte[] getReceivedOurIP() { return _bobIP; }
     169    /**
     170     *  True (default) if no extended options in session request,
     171     *  or value of flag bit in the extended options.
     172     *  @since 0.9.24
     173     */
     174    public synchronized boolean isIntroductionRequested() { return _introductionRequested; }
    163175   
    164176    /**
  • router/java/src/net/i2p/router/transport/udp/OutboundEstablishState.java

    r4c72c08 r1e89fac  
    5858    private final RouterIdentity _remotePeer;
    5959    private final boolean _allowExtendedOptions;
     60    private final boolean _needIntroduction;
    6061    private final SessionKey _introKey;
    6162    private final Queue<OutNetMessage> _queuedMessages;
     
    109110     *  @param remoteHostId non-null, == claimedAddress if direct, or a hash-based one if indirect
    110111     *  @param remotePeer must have supported sig type
     112     *  @param allowExtenededOptions are we allowed to send extended options to Bob?
     113     *  @param needIntroduction should we ask Bob to be an introducer for us?
     114               ignored unless allowExtendedOptions is true
    111115     *  @param introKey Bob's introduction key, as published in the netdb
    112116     *  @param addr non-null
     
    115119                                  RemoteHostId remoteHostId,
    116120                                  RouterIdentity remotePeer, boolean allowExtendedOptions,
     121                                  boolean needIntroduction,
    117122                                  SessionKey introKey, UDPAddress addr,
    118123                                  DHSessionKeyBuilder.Factory dh) {
     
    129134        _remoteHostId = remoteHostId;
    130135        _allowExtendedOptions = allowExtendedOptions;
     136        _needIntroduction = needIntroduction;
    131137        _remotePeer = remotePeer;
    132138        _introKey = introKey;
     
    162168    public long getIntroNonce() { return _introductionNonce; }
    163169
    164     /** @since 0.9.24 */
     170    /**
     171     *  Are we allowed to send extended options to this peer?
     172     *  @since 0.9.24
     173     */
    165174    public boolean isExtendedOptionsAllowed() { return _allowExtendedOptions; }
     175
     176    /**
     177     *  Should we ask this peer to be an introducer for us?
     178     *  Ignored unless allowExtendedOptions is true
     179     *  @since 0.9.24
     180     */
     181    public boolean needIntroduction() { return _needIntroduction; }
    166182   
    167183    /**
  • router/java/src/net/i2p/router/transport/udp/PacketBuilder.java

    r4c72c08 r1e89fac  
    784784     */
    785785    public UDPPacket buildSessionRequestPacket(OutboundEstablishState state) {
    786         // TODO
    787         // boolean ext = state.isExtendedOptionsAllowed();
    788         // if (ext)
    789         //byte[] options = new byte[3];
    790         //UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE, options);
    791         UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE);
     786        int off = HEADER_SIZE;
     787        byte[] options;
     788        boolean ext = state.isExtendedOptionsAllowed();
     789        if (ext) {
     790            options = new byte[UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH];
     791            if (state.needIntroduction())
     792                options[1] = (byte) UDPPacket.SESS_REQ_EXT_FLAG_REQUEST_RELAY_TAG;
     793            off += UDPPacket.SESS_REQ_MIN_EXT_OPTIONS_LENGTH + 1;
     794        } else {
     795            options = null;
     796        }
     797        UDPPacket packet = buildPacketHeader(SESSION_REQUEST_FLAG_BYTE, options);
    792798        DatagramPacket pkt = packet.getPacket();
    793799        byte data[] = pkt.getData();
    794         int off = HEADER_SIZE; // + 1 + options.length;
    795800
    796801        byte toIP[] = state.getSentIP();
  • router/java/src/net/i2p/router/transport/udp/UDPPacket.java

    r4c72c08 r1e89fac  
    102102    public static final byte HEADER_FLAG_EXTENDED_OPTIONS = (1 << 2);
    103103
     104    // Extended options for session request
     105    public static final int SESS_REQ_MIN_EXT_OPTIONS_LENGTH = 2;
     106    // bytes 0-1 are flags
     107    /**
     108     * set to 1 to request a session tag, i.e. we want him to be an introducer for us
     109     */
     110    public static final int SESS_REQ_EXT_FLAG_REQUEST_RELAY_TAG = 0x01;
     111
    104112    // various flag fields for use in the data packets
    105113    public static final byte DATA_FLAG_EXPLICIT_ACK = (byte)(1 << 7);
  • router/java/src/net/i2p/router/transport/udp/UDPPacketReader.java

    r4c72c08 r1e89fac  
    105105    /**
    106106     * Returns extended option data, 0-255 bytes, or null if none.
     107     * Returned array does NOT include the length byte.
    107108     *
    108109     * @return extended options or null if none is included
     
    176177    /* ------- Begin Reader Classes ------- */
    177178
     179    /**
     180     * Base
     181     *
     182     * @since 0.9.24
     183     */
     184    public abstract class Reader {
     185        /**
     186         * Returns extended option data from the header, 0-255 bytes, or null if none.
     187         * Returned array does NOT include the length byte.
     188         *
     189         * @return extended options or null if none is included
     190         * @since 0.9.24
     191         */
     192        public byte[] readExtendedOptions() {
     193            return UDPPacketReader.this.readExtendedOptions();
     194        }
     195    }
     196
    178197    /** Help read the SessionRequest payload */
    179     public class SessionRequestReader {
     198    public class SessionRequestReader extends Reader {
    180199        public static final int X_LENGTH = 256;
    181200        public void readX(byte target[], int targetOffset) {
     
    199218   
    200219    /** Help read the SessionCreated payload */
    201     public class SessionCreatedReader {
     220    public class SessionCreatedReader extends Reader {
    202221        public static final int Y_LENGTH = 256;
    203222        public void readY(byte target[], int targetOffset) {
     
    254273   
    255274    /** parse out the confirmed message */
    256     public class SessionConfirmedReader {
     275    public class SessionConfirmedReader extends Reader {
    257276        /** which fragment is this? */
    258277        public int readCurrentFragmentNum() {
     
    307326   
    308327    /** parse out the data message */
    309     public class DataReader {
     328    public class DataReader extends Reader {
    310329
    311330        /**
     
    643662   
    644663    /** Help read the PeerTest payload */
    645     public class PeerTestReader {
     664    public class PeerTestReader extends Reader {
    646665        private static final int NONCE_LENGTH = 4;
    647666       
     
    684703   
    685704    /** Help read the RelayRequest payload */
    686     public class RelayRequestReader {
     705    public class RelayRequestReader extends Reader {
    687706        public long readTag() {
    688707            long rv = DataHelper.fromLong(_message, readBodyOffset(), 4);
     
    768787   
    769788    /** Help read the RelayIntro payload */
    770     public class RelayIntroReader {
     789    public class RelayIntroReader extends Reader {
    771790        public int readIPSize() {
    772791            int offset = readBodyOffset();
     
    809828   
    810829    /** Help read the RelayResponse payload */
    811     public class RelayResponseReader {
     830    public class RelayResponseReader extends Reader {
    812831        public int readCharlieIPSize() {
    813832            int offset = readBodyOffset();
Note: See TracChangeset for help on using the changeset viewer.