Changeset 471c5d4


Ignore:
Timestamp:
Jun 2, 2019 10:59:39 AM (12 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c4ebc73
Parents:
eff2bdbf
Message:

I2CP: Cleanups for single-byte reads
Stub out new error codes for prop. 123

Location:
core/java/src/net/i2p/data/i2cp
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/i2cp/AbuseSeverity.java

    reff2bdbf r471c5d4  
    1010 */
    1111
     12import java.io.EOFException;
    1213import java.io.IOException;
    1314import java.io.InputStream;
     
    4142
    4243    public void readBytes(InputStream in) throws DataFormatException, IOException {
    43         _severityId = (int) DataHelper.readLong(in, 1);
     44        _severityId = in.read();
     45        if (_severityId < 0)
     46            throw new EOFException();
    4447    }
    4548
  • core/java/src/net/i2p/data/i2cp/HostLookupMessage.java

    reff2bdbf r471c5d4  
    77
    88import java.io.ByteArrayOutputStream;
     9import java.io.EOFException;
    910import java.io.IOException;
    1011import java.io.InputStream;
     
    128129            _reqID = DataHelper.readLong(in, 4);
    129130            _timeout = DataHelper.readLong(in, 4);
    130             _lookupType = (int) DataHelper.readLong(in, 1);
     131            _lookupType = in.read();
     132            if (_lookupType < 0)
     133                throw new EOFException();
    131134            if (_lookupType == LOOKUP_HASH) {
    132135                _hash = Hash.create(in);
  • core/java/src/net/i2p/data/i2cp/HostReplyMessage.java

    reff2bdbf r471c5d4  
    88
    99import java.io.ByteArrayOutputStream;
     10import java.io.EOFException;
    1011import java.io.IOException;
    1112import java.io.InputStream;
     
    3132    /** generic fail, other codes TBD */
    3233    public static final int RESULT_FAILURE = 1;
     34    /** @since 0.9.41 */
     35    public static final int RESULT_SECRET_REQUIRED = 2;
     36    /** @since 0.9.41 */
     37    public static final int RESULT_KEY_REQUIRED = 3;
     38    /** @since 0.9.41 */
     39    public static final int RESULT_SECRET_AND_KEY_REQUIRED = 4;
    3340
    3441    private static final long MAX_INT = (1L << 32) - 1;
     
    110117            _sessionId.readBytes(in);
    111118            _reqID = DataHelper.readLong(in, 4);
    112             _code = (int) DataHelper.readLong(in, 1);
     119            _code = in.read();
     120            if (_code < 0)
     121                throw new EOFException();
    113122            if (_code == RESULT_SUCCESS)
    114123                _dest = Destination.create(in);
  • core/java/src/net/i2p/data/i2cp/I2CPMessageHandler.java

    reff2bdbf r471c5d4  
    1010 */
    1111
     12import java.io.EOFException;
    1213import java.io.IOException;
    1314import java.io.InputStream;
     
    4647        if (length > MAX_LENGTH)
    4748            throw new I2CPMessageException("Invalid message length specified");
    48         try {
    49             int type = (int) DataHelper.readLong(in, 1);
    50             I2CPMessage msg = createMessage(type);
    51             // Note that the readMessage() calls don't, in general, read and discard
    52             // extra data, so we can't add new fields to the end of messages
    53             // in a compatible way. And the readers could read beyond the length too.
    54             // To fix this we'd have to read into a BAOS/BAIS or use a filter input stream
    55             msg.readMessage(in, length, type);
    56             return msg;
    57         } catch (DataFormatException dfe) {
    58             throw new I2CPMessageException("Error reading the message", dfe);
    59         }
     49        int type = in.read();
     50        if (type < 0)
     51            throw new EOFException();
     52        I2CPMessage msg = createMessage(type);
     53        // extra data, so we can't add new fields to the end of messages
     54        // in a compatible way. And the readers could read beyond the length too.
     55        // To fix this we'd have to read into a BAOS/BAIS or use a filter input stream
     56        msg.readMessage(in, length, type);
     57        return msg;
    6058    }
    6159
  • core/java/src/net/i2p/data/i2cp/I2CPMessageImpl.java

    reff2bdbf r471c5d4  
    1010 */
    1111
     12import java.io.EOFException;
    1213import java.io.IOException;
    1314import java.io.InputStream;
     
    4142        }
    4243        if (length < 0) throw new I2CPMessageException("Invalid message length specified");
    43         int type = -1;
    44         try {
    45             type = (int) DataHelper.readLong(in, 1);
    46         } catch (DataFormatException dfe) {
    47             throw new I2CPMessageException("Error reading the type byte", dfe);
    48         }
     44        int type = in.read();
     45        if (type < 0)
     46            throw new EOFException();
    4947        readMessage(in, length, type);
    5048    }
  • core/java/src/net/i2p/data/i2cp/MessageStatusMessage.java

    reff2bdbf r471c5d4  
    180180    public final static int STATUS_SEND_FAILURE_NO_LEASESET = 21;
    181181
     182    /**
     183     *  The far-end destination's lease set was a meta lease set,
     184     *  and cannot be sent to. The client should request the meta
     185     *  lease set's contents with a HostLookupMessage, and select
     186     *  one of the hashes contained within to lookup and send to.
     187     *  This is a guaranteed failure.
     188     *  @since 0.9.41
     189     */
     190    public final static int STATUS_SEND_FAILURE_META_LEASESET = 22;
    182191
    183192
     
    302311            _sessionId = (int) DataHelper.readLong(in, 2);
    303312            _messageId = DataHelper.readLong(in, 4);
    304             _status = (int) DataHelper.readLong(in, 1);
     313            _status = in.read();
     314            // EOF will be caught below
    305315            _size = DataHelper.readLong(in, 4);
    306316            _nonce = DataHelper.readLong(in, 4);
  • core/java/src/net/i2p/data/i2cp/RequestLeaseSetMessage.java

    reff2bdbf r471c5d4  
    9999            _sessionId = new SessionId();
    100100            _sessionId.readBytes(in);
    101             int numTunnels = (int) DataHelper.readLong(in, 1);
     101            int numTunnels = in.read();
     102            // EOF will be caught below
    102103            _endpoints.clear();
    103104            for (int i = 0; i < numTunnels; i++) {
  • core/java/src/net/i2p/data/i2cp/RequestVariableLeaseSetMessage.java

    reff2bdbf r471c5d4  
    1111
    1212import java.io.ByteArrayOutputStream;
     13import java.io.EOFException;
    1314import java.io.IOException;
    1415import java.io.InputStream;
     
    9293            _sessionId = new SessionId();
    9394            _sessionId.readBytes(in);
    94             int numTunnels = (int) DataHelper.readLong(in, 1);
     95            int numTunnels = in.read();
     96            if (numTunnels < 0)
     97                throw new EOFException();
    9598            for (int i = 0; i < numTunnels; i++) {
    9699                Lease lease = new Lease();
  • core/java/src/net/i2p/data/i2cp/SessionStatusMessage.java

    reff2bdbf r471c5d4  
    1111
    1212import java.io.ByteArrayOutputStream;
     13import java.io.EOFException;
    1314import java.io.IOException;
    1415import java.io.InputStream;
     
    7071            _sessionId = new SessionId();
    7172            _sessionId.readBytes(in);
    72             _status = (int) DataHelper.readLong(in, 1);
     73            _status = in.read();
     74            if (_status < 0)
     75                throw new EOFException();
    7376        } catch (DataFormatException dfe) {
    7477            throw new I2CPMessageException("Unable to load the message data", dfe);
Note: See TracChangeset for help on using the changeset viewer.