Changeset 576984b


Ignore:
Timestamp:
Jan 10, 2014 2:24:15 AM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ba96f72
Parents:
5219791
Message:

I2CP:

  • Add SessionID to HostLookup/Reply? messages, for future use when we have multiple sessions
  • New SessionID constructor w/ value
  • Throw IAE on invalid SessionID values
  • Bump all comments from 0.9.10 to 0.9.11
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/client/ClientWriterRunner.java

    r5219791 r576984b  
    3434   
    3535    /**
    36      *  As of 0.9.10 does not start the thread, caller must call startWriting()
     36     *  As of 0.9.11 does not start the thread, caller must call startWriting()
    3737     */
    3838    public ClientWriterRunner(OutputStream out, I2PSessionImpl session) {
     
    4343
    4444    /**
    45      *  @since 0.9.10
     45     *  @since 0.9.11
    4646     */
    4747    public void startWriting() {
  • core/java/src/net/i2p/client/HostReplyMessageHandler.java

    r5219791 r576984b  
    1616 * Handle I2CP dest replies from the router
    1717 *
    18  * @since 0.9.10
     18 * @since 0.9.11
    1919 */
    2020class HostReplyMessageHandler extends HandlerImpl {
  • core/java/src/net/i2p/client/I2PSession.java

    r5219791 r576984b  
    269269     *</pre>
    270270     *
    271      *  Requires router side to be 0.9.10 or higher. If the router is older,
     271     *  Requires router side to be 0.9.11 or higher. If the router is older,
    272272     *  this will return null immediately.
    273273     *
    274      *  @since 0.9.10
     274     *  @since 0.9.11
    275275     */
    276276    public Destination lookupDest(String name) throws I2PSessionException;
     
    280280     *  Blocking. See above for details.
    281281     *  @param maxWait ms
    282      *  @since 0.9.10
     282     *  @since 0.9.11
    283283     *  @return null on failure
    284284     */
  • core/java/src/net/i2p/client/I2PSessionImpl.java

    r5219791 r576984b  
    121121    protected enum State {
    122122        OPENING,
    123         /** @since 0.9.10 */
     123        /** @since 0.9.11 */
    124124        GOTDATE,
    125125        OPEN,
     
    146146
    147147    /**
    148      *  Since 0.9.10, key is either a Hash or a String
     148     *  Since 0.9.11, key is either a Hash or a String
    149149     *  @since 0.8.9
    150150     */
    151151    private static final Map<Object, Destination> _lookupCache = new LHMCache<Object, Destination>(16);
    152     private static final String MIN_HOST_LOOKUP_VERSION = "0.9.10";
     152    private static final String MIN_HOST_LOOKUP_VERSION = "0.9.11";
    153153    private static final boolean TEST_LOOKUP = false;
    154154
     
    484484            Properties auth = null;
    485485            if ((!_context.isRouterContext()) && _options.containsKey(PROP_USER) && _options.containsKey(PROP_PW)) {
    486                 // Only supported by routers 0.9.10 or higher, but we don't know the version yet.       
     486                // Only supported by routers 0.9.11 or higher, but we don't know the version yet.       
    487487                // Auth will also be sent in the SessionConfig.
    488488                auth = new OrderedProperties();
     
    542542
    543543    /**
    544      *  @since 0.9.10 moved from connect()
     544     *  @since 0.9.11 moved from connect()
    545545     */
    546546    protected void waitForDate() throws InterruptedException, IOException {
     
    10411041     *  Called by the message handler
    10421042     *  on reception of HostReplyMessage
    1043      *  @since 0.9.10
     1043     *  @since 0.9.11
    10441044     */
    10451045    void destReceived(long nonce, Destination d) {
     
    10651065     *  Called by the message handler
    10661066     *  on reception of HostReplyMessage
    1067      *  @since 0.9.10
     1067     *  @since 0.9.11
    10681068     */
    10691069    void destLookupFailed(long nonce) {
     
    11031103        }
    11041104
    1105         /** @since 0.9.10 */
     1105        /** @since 0.9.11 */
    11061106        public LookupWaiter(Hash h, long nonce) {
    11071107            this.hash = h;
     
    11101110        }
    11111111
    1112         /** @since 0.9.10 */
     1112        /** @since 0.9.11 */
    11131113        public LookupWaiter(String name, long nonce) {
    11141114            this.hash = null;
     
    11611161                if (_log.shouldLog(Log.INFO))
    11621162                    _log.info("Sending HostLookup for " + h);
    1163                 sendMessage(new HostLookupMessage(h, nonce, maxWait));
     1163                SessionId id = _sessionId;
     1164                if (id == null)
     1165                    id = new SessionId(65535);
     1166                sendMessage(new HostLookupMessage(id, h, nonce, maxWait));
    11641167            } else {
    11651168                if (_log.shouldLog(Log.INFO))
     
    11931196     *  See interface for suggested implementation.
    11941197     *
    1195      *  Requires router side to be 0.9.10 or higher. If the router is older,
     1198     *  Requires router side to be 0.9.11 or higher. If the router is older,
    11961199     *  this will return null immediately.
    11971200     *
    1198      *  @since 0.9.10
     1201     *  @since 0.9.11
    11991202     */
    12001203    public Destination lookupDest(String name) throws I2PSessionException {
     
    12061209     *  Blocking. See above for details.
    12071210     *  @param maxWait ms
    1208      *  @since 0.9.10
     1211     *  @since 0.9.11
    12091212     *  @return null on failure
    12101213     */
     
    12481251            if (_log.shouldLog(Log.INFO))
    12491252                _log.info("Sending HostLookup for " + name);
    1250             sendMessage(new HostLookupMessage(name, nonce, maxWait));
     1253            SessionId id = _sessionId;
     1254            if (id == null)
     1255                id = new SessionId(65535);
     1256            sendMessage(new HostLookupMessage(id, name, nonce, maxWait));
    12511257            try {
    12521258                synchronized (waiter) {
  • core/java/src/net/i2p/client/I2PSimpleSession.java

    r5219791 r576984b  
    104104                Properties opts = getOptions();
    105105                // Send auth message if required
    106                 // Auth was not enforced on a simple session until 0.9.10
    107                 // We will get disconnected for router version < 0.9.10 since it doesn't
     106                // Auth was not enforced on a simple session until 0.9.11
     107                // We will get disconnected for router version < 0.9.11 since it doesn't
    108108                // support the AuthMessage
    109109                if ((!opts.containsKey(PROP_USER)) && (!opts.containsKey(PROP_PW))) {
  • core/java/src/net/i2p/data/i2cp/HostLookupMessage.java

    r5219791 r576984b  
    1818 * or a host. Replaces DestLookupMessage.
    1919 *
    20  * @since 0.9.10; do not send to routers older than 0.9.10.
     20 * @since 0.9.11; do not send to routers older than 0.9.11.
    2121 */
    2222public class HostLookupMessage extends I2CPMessageImpl {
     
    2828    private Hash _hash;
    2929    private String _host;
     30    private SessionId _sessionId;
    3031
    3132    public static final int LOOKUP_HASH = 0;
     
    4041     *  @param timeout ms 1 to 2**32 - 1
    4142     */
    42     public HostLookupMessage(Hash h, long reqID, long timeout) {
     43    public HostLookupMessage(SessionId id, Hash h, long reqID, long timeout) {
     44        if (id == null || h == null)
     45            throw new IllegalArgumentException();
    4346        if (reqID < 0 || reqID > MAX_INT)
    4447            throw new IllegalArgumentException();
     
    5558     *  @param timeout ms 1 to 2**32 - 1
    5659     */
    57     public HostLookupMessage(String host, long reqID, long timeout) {
     60    public HostLookupMessage(SessionId id, String host, long reqID, long timeout) {
     61        if (id == null || host == null)
     62            throw new IllegalArgumentException();
    5863        if (reqID < 0 || reqID > MAX_INT)
    5964            throw new IllegalArgumentException();
     
    6469        _timeout = timeout;
    6570        _lookupType = LOOKUP_HOST;
     71    }
     72
     73    public SessionId getSessionId() {
     74        return _sessionId;
    6675    }
    6776
     
    103112    protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
    104113        try {
     114            _sessionId = new SessionId();
     115            _sessionId.readBytes(in);
    105116            _reqID = DataHelper.readLong(in, 4);
    106117            _timeout = DataHelper.readLong(in, 4);
     
    125136            if (_hash == null)
    126137                throw new I2CPMessageException("Unable to write out the message as there is not enough data");
    127             len = 9 + Hash.HASH_LENGTH;
     138            len = 11 + Hash.HASH_LENGTH;
    128139        } else if (_lookupType == LOOKUP_HOST) {
    129140            if (_host == null)
    130141                throw new I2CPMessageException("Unable to write out the message as there is not enough data");
    131             len = 10 + _host.length();
     142            len = 12 + _host.length();
    132143        } else {
    133144            throw new I2CPMessageException("bad type");
     
    135146        ByteArrayOutputStream os = new ByteArrayOutputStream(len);
    136147        try {
     148            _sessionId.writeBytes(os);
    137149            DataHelper.writeLong(os, 4, _reqID);
    138150            DataHelper.writeLong(os, 4, _timeout);
     
    157169        StringBuilder buf = new StringBuilder();
    158170        buf.append("[HostLookupMessage: ");
     171        buf.append("\n\t").append(_sessionId);
    159172        buf.append("\n\tReqID: ").append(_reqID);
    160173        buf.append("\n\tTimeout: ").append(_timeout);
  • core/java/src/net/i2p/data/i2cp/HostReplyMessage.java

    r5219791 r576984b  
    1818 * Response to HostLookupMessage. Replaces DestReplyMessage.
    1919 *
    20  * @since 0.9.10
     20 * @since 0.9.11
    2121 */
    2222public class HostReplyMessage extends I2CPMessageImpl {
     
    2626    private long _reqID;
    2727    private int _code;
     28    private SessionId _sessionId;
    2829
    2930    public static final int RESULT_SUCCESS = 0;
     
    4142     *  @param reqID 0 to 2**32 - 1
    4243     */
    43     public HostReplyMessage(Destination d, long reqID) {
    44         if (d == null)
     44    public HostReplyMessage(SessionId id, Destination d, long reqID) {
     45        if (id == null || d == null)
    4546            throw new IllegalArgumentException();
    4647        if (reqID < 0 || reqID > MAX_INT)
     
    5657     *  @param reqID from the HostLookup 0 to 2**32 - 1
    5758     */
    58     public HostReplyMessage(int failureCode, long reqID) {
     59    public HostReplyMessage(SessionId id, int failureCode, long reqID) {
     60        if (id == null)
     61            throw new IllegalArgumentException();
    5962        if (failureCode <= 0 || failureCode > 255)
    6063            throw new IllegalArgumentException();
     
    6366        _code = failureCode;
    6467        _reqID = reqID;
     68    }
     69
     70    public SessionId getSessionId() {
     71        return _sessionId;
    6572    }
    6673
     
    8895    protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
    8996        try {
     97            _sessionId = new SessionId();
     98            _sessionId.readBytes(in);
    9099            _reqID = DataHelper.readLong(in, 4);
    91100            _code = (int) DataHelper.readLong(in, 1);
     
    98107
    99108    protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
    100         int len = 5;
     109        int len = 7;
    101110        if (_code == RESULT_SUCCESS) {
    102111            if (_dest == null)
     
    106115        ByteArrayOutputStream os = new ByteArrayOutputStream(len);
    107116        try {
     117            _sessionId.writeBytes(os);
    108118            DataHelper.writeLong(os, 4, _reqID);
    109119            DataHelper.writeLong(os, 1, _code);
     
    124134        StringBuilder buf = new StringBuilder();
    125135        buf.append("[HostReplyMessage: ");
     136        buf.append("\n\t").append(_sessionId);
    126137        buf.append("\n\tReqID: ").append(_reqID);
    127138        buf.append("\n\tCode: ").append(_code);
  • core/java/src/net/i2p/data/i2cp/SessionId.java

    r5219791 r576984b  
    3030    }
    3131
     32    /**
     33     *  @param id 0-65535
     34     *  @since 0.9.11
     35     */
     36    public SessionId(int id) {
     37        if (id < 0 || id > 65535)
     38            throw new IllegalArgumentException();
     39        _sessionId = id;
     40    }
     41
    3242    public int getSessionId() {
    3343        return _sessionId;
     
    3646    /** @param id 0-65535 */
    3747    public void setSessionId(int id) {
     48        if (id < 0 || id > 65535)
     49            throw new IllegalArgumentException();
    3850        _sessionId = id;
    3951    }
  • router/java/src/net/i2p/router/client/ClientMessageEventListener.java

    r5219791 r576984b  
    233233     *  @param props contains i2cp.username and i2cp.password, may be null
    234234     *  @return success
    235      *  @since 0.9.10
     235     *  @since 0.9.11
    236236     */
    237237    private boolean checkAuth(Properties props) {
     
    369369    /**
    370370     * override for testing
    371      * @since 0.9.10
     371     * @since 0.9.11
    372372     */
    373373    protected void handleHostLookup(HostLookupMessage message) {
    374374        _context.jobQueue().addJob(new LookupDestJob(_context, _runner, message.getReqID(),
    375                                                      message.getTimeout(), message.getHash(), message.getHostname()));
     375                                                     message.getTimeout(), message.getSessionId(),
     376                                                     message.getHash(), message.getHostname()));
    376377    }
    377378
  • router/java/src/net/i2p/router/client/LookupDestJob.java

    r5219791 r576984b  
    1515import net.i2p.data.i2cp.I2CPMessage;
    1616import net.i2p.data.i2cp.I2CPMessageException;
     17import net.i2p.data.i2cp.SessionId;
    1718import net.i2p.router.JobImpl;
    1819import net.i2p.router.RouterContext;
     
    2021/**
    2122 * Look up the lease of a hash, to convert it to a Destination for the client.
    22  * Or, since 0.9.10, lookup a host name in the naming service.
     23 * Or, since 0.9.11, lookup a host name in the naming service.
    2324 */
    2425class LookupDestJob extends JobImpl {
     
    2829    private final Hash _hash;
    2930    private final String _name;
     31    private final SessionId _sessID;
    3032
    3133    private static final long DEFAULT_TIMEOUT = 15*1000;
    3234
    3335    public LookupDestJob(RouterContext context, ClientConnectionRunner runner, Hash h) {
    34         this(context, runner, -1, DEFAULT_TIMEOUT, h, null);
     36        this(context, runner, -1, DEFAULT_TIMEOUT, null, h, null);
    3537    }
    3638
     
    3840     *  One of h or name non-null
    3941     *  @param reqID must be >= 0 if name != null
    40      *  @since 0.9.10
     42     *  @param sessID must non-null if reqID >= 0
     43     *  @since 0.9.11
    4144     */
    4245    public LookupDestJob(RouterContext context, ClientConnectionRunner runner,
    43                          long reqID, long timeout, Hash h, String name) {
     46                         long reqID, long timeout, SessionId sessID, Hash h, String name) {
    4447        super(context);
    4548        if ((h == null && name == null) ||
    4649            (h != null && name != null) ||
     50            (reqID >= 0 && sessID == null) ||
    4751            (reqID < 0 && name != null))
    4852            throw new IllegalArgumentException();
     
    5054        _reqID = reqID;
    5155        _timeout = timeout;
     56        _sessID = sessID;
    5257        if (name != null && name.length() == 60) {
    5358            // convert a b32 lookup to a hash lookup
     
    101106        I2CPMessage msg;
    102107        if (_reqID >= 0)
    103             msg = new HostReplyMessage(d, _reqID);
     108            msg = new HostReplyMessage(_sessID, d, _reqID);
    104109        else
    105110            msg = new DestReplyMessage(d);
     
    116121        I2CPMessage msg;
    117122        if (_reqID >= 0)
    118             msg = new HostReplyMessage(HostReplyMessage.RESULT_FAILURE, _reqID);
     123            msg = new HostReplyMessage(_sessID, HostReplyMessage.RESULT_FAILURE, _reqID);
    119124        else
    120125            msg = new DestReplyMessage(_hash);
Note: See TracChangeset for help on using the changeset viewer.