Changeset 30f25de


Ignore:
Timestamp:
Aug 4, 2018 2:35:00 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
a5a5f7d
Parents:
2cc362c
Message:

I2NP: Remove unused InputStream? parsing methods

Location:
router/java/src/net/i2p/data/i2np
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/data/i2np/DeliveryInstructions.java

    r2cc362c r30f25de  
    161161    @Deprecated
    162162    public void setDelaySeconds(long seconds) { _delaySeconds = seconds; }
    163    
    164     /**
    165      * @deprecated unused
    166      */
    167     @Deprecated
    168     public void readBytes(InputStream in) throws DataFormatException, IOException {
    169         long flags = DataHelper.readLong(in, 1);
    170         //if (_log.shouldLog(Log.DEBUG))
    171         //    _log.debug("Read flags: " + flags + " mode: " +  flagMode(flags));
    172        
    173      /****
    174         if (flagEncrypted(flags)) {
    175             SessionKey k = new SessionKey();
    176             k.readBytes(in);
    177             setEncryptionKey(k);
    178             setEncrypted(true);
    179         } else {
    180             setEncrypted(false);
    181         }
    182       ****/
    183        
    184         setDeliveryMode(flagMode(flags));
    185         switch (flagMode(flags)) {
    186             case FLAG_MODE_LOCAL:
    187                 break;
    188             case FLAG_MODE_DESTINATION:
    189                 //Hash destHash = new Hash();
    190                 //destHash.readBytes(in);
    191                 Hash destHash = Hash.create(in);
    192                 setDestination(destHash);
    193                 break;
    194             case FLAG_MODE_ROUTER:
    195                 //Hash routerHash = new Hash();
    196                 //routerHash.readBytes(in);
    197                 Hash routerHash = Hash.create(in);
    198                 setRouter(routerHash);
    199                 break;
    200             case FLAG_MODE_TUNNEL:
    201                 //Hash tunnelRouterHash = new Hash();
    202                 //tunnelRouterHash.readBytes(in);
    203                 Hash tunnelRouterHash = Hash.create(in);
    204                 setRouter(tunnelRouterHash);
    205                 TunnelId id = new TunnelId();
    206                 id.readBytes(in);
    207                 setTunnelId(id);
    208                 break;
    209         }
    210        
    211         if (flagDelay(flags)) {
    212             long delay = DataHelper.readLong(in, 4);
    213             setDelayRequested(true);
    214             setDelaySeconds(delay);
    215         } else {
    216             setDelayRequested(false);
    217         }
     163
     164    /**
     165     * @deprecated unused
     166     * @throws UnsupportedOperationException always
     167     */
     168    @Deprecated
     169    public void readBytes(InputStream in) {
     170        throw new UnsupportedOperationException();
    218171    }
    219172   
     
    578531
    579532        @Override
    580         public void readBytes(InputStream in) throws DataFormatException, IOException {
    581             throw new RuntimeException("immutable");
    582         }
    583 
    584         @Override
    585533        public int readBytes(byte data[], int offset) throws DataFormatException {
    586534            throw new RuntimeException("immutable");
  • router/java/src/net/i2p/data/i2np/FastI2NPMessageImpl.java

    r2cc362c r30f25de  
    1010
    1111import java.io.IOException;
    12 import java.io.InputStream;
    1312import java.io.OutputStream;
    1413
     
    5049    }
    5150   
    52     /**
    53      *  @deprecated unused
    54      *  @throws UnsupportedOperationException
    55      */
    56     @Deprecated
    57     @Override
    58     public void readBytes(InputStream in) throws DataFormatException, IOException {
    59         throw new UnsupportedOperationException();
    60     }
    61 
    62     /**
    63      *  @deprecated unused
    64      *  @throws UnsupportedOperationException
    65      */
    66     @Deprecated
    67     @Override
    68     public int readBytes(InputStream in, int type, byte buffer[]) throws I2NPMessageException, IOException {
    69         throw new UnsupportedOperationException();
    70     }
    71 
    7251    /**
    7352     *  Ignore, but save, the checksum, to be used later if necessary.
  • router/java/src/net/i2p/data/i2np/GarlicClove.java

    r2cc362c r30f25de  
    6262     */
    6363    @Deprecated
    64     public void readBytes(InputStream in) throws DataFormatException, IOException {
     64    public void readBytes(InputStream in) {
    6565        throw new UnsupportedOperationException();
    66 /****
    67         _instructions = new DeliveryInstructions();
    68         _instructions.readBytes(in);
    69         if (_log.shouldLog(Log.DEBUG))
    70             _log.debug("Read instructions: " + _instructions);
    71         try {
    72             _msg = _handler.readMessage(in);
    73         } catch (I2NPMessageException ime) {
    74             throw new DataFormatException("Unable to read the message from a garlic clove", ime);
    75         }
    76         _cloveId = DataHelper.readLong(in, 4);
    77         _expiration = DataHelper.readDate(in);
    78         if (_log.shouldLog(Log.DEBUG))
    79             _log.debug("CloveID read: " + _cloveId + " expiration read: " + _expiration);
    80         //_certificate = new Certificate();
    81         //_certificate.readBytes(in);
    82         _certificate = Certificate.create(in);
    83         if (_log.shouldLog(Log.DEBUG))
    84             _log.debug("Read cert: " + _certificate);
    85 ****/
    8666    }
    8767
  • router/java/src/net/i2p/data/i2np/I2NPMessage.java

    r2cc362c r30f25de  
    1010
    1111import java.io.IOException;
    12 import java.io.InputStream;
    1312
    1413import net.i2p.data.DataStructure;
     
    3231    public static final int MAX_SIZE = 64*1024;
    3332   
    34     /**
    35      * Read the body into the data structures, after the initial type byte, using
    36      * the current class's format as defined by the I2NP specification
    37      *
    38      * Unused - All transports provide encapsulation and so we have byte arrays available.
    39      *
    40      * @param in stream to read from
    41      *           starting at type if type is &lt; 0 (16 byte header)
    42      *           starting at ID if type is &gt;= 0 (15 byte header)
    43      * @param type I2NP message type. If less than zero, read the type from data
    44      * @param buffer scratch buffer to be used when reading and parsing
    45      * @return size of the message read (including headers)
    46      * @throws I2NPMessageException if the stream doesn't contain a valid message
    47      *          that this class can read.
    48      * @throws IOException if there is a problem reading from the stream
    49      * @deprecated unused
    50      */
    51     @Deprecated
    52     public int readBytes(InputStream in, int type, byte buffer[]) throws I2NPMessageException, IOException;
    53 
    5433    /**
    5534     * Read the body into the data structures, after the initial type byte, using
  • router/java/src/net/i2p/data/i2np/I2NPMessageHandler.java

    r2cc362c r30f25de  
    1010
    1111import java.io.IOException;
    12 import java.io.InputStream;
    1312
    1413import net.i2p.I2PAppContext;
     
    3433        _log = context.logManager().getLog(I2NPMessageHandler.class);
    3534        _lastSize = -1;
    36     }
    37    
    38     /**
    39      * Read an I2NPMessage from the stream and return the fully populated object.
    40      *
    41      * This is only called by I2NPMessageReader which is unused.
    42      * All transports provide encapsulation and so we have byte arrays available.
    43      *
    44      * @deprecated use the byte array method to avoid an extra copy if you have it
    45      *
    46      * @throws I2NPMessageException if there is a problem handling the particular
    47      *          message - if it is an unknown type or has improper formatting, etc.
    48      */
    49     @Deprecated
    50     public I2NPMessage readMessage(InputStream in) throws IOException, I2NPMessageException {
    51         if (_messageBuffer == null) _messageBuffer = new byte[38*1024]; // more than necessary
    52         try {
    53             int type = (int)DataHelper.readLong(in, 1);
    54             _lastReadBegin = System.currentTimeMillis();
    55             I2NPMessage msg = I2NPMessageImpl.createMessage(_context, type);
    56             try {
    57                 _lastSize = msg.readBytes(in, type, _messageBuffer);
    58             } catch (I2NPMessageException ime) {
    59                 throw ime;
    60             } catch (RuntimeException e) {
    61                 if (_log.shouldLog(Log.WARN))
    62                     _log.warn("Error reading the stream", e);
    63                 throw new I2NPMessageException("Unknown error reading the " + msg.getClass().getSimpleName(), e);
    64             }
    65             _lastReadEnd = System.currentTimeMillis();
    66             return msg;
    67         } catch (DataFormatException dfe) {
    68             throw new I2NPMessageException("Error reading the message", dfe);
    69         }
    7035    }
    7136   
     
    13095    public int getLastSize() { return _lastSize; }
    13196   
    132 /****
    133     public static void main(String args[]) {
    134         try {
    135             I2NPMessage msg = new I2NPMessageHandler(I2PAppContext.getGlobalContext()).readMessage(new FileInputStream(args[0]));
    136             System.out.println(msg);
    137         } catch (Exception e) {
    138             e.printStackTrace();
    139         }
    140     }
    141 ****/
    14297}
  • router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java

    r2cc362c r30f25de  
    7373
    7474    /**
    75      *  Read the whole message but only if it's exactly 1024 bytes.
     75     *  Read the whole message.
    7676     *  Unused - All transports provide encapsulation and so we have byte arrays available.
    7777     *
    7878     *  @deprecated unused
     79     *  @throws UnsupportedOperationException always
    7980     */
    8081    @Deprecated
    81     public void readBytes(InputStream in) throws DataFormatException, IOException {
    82         try {
    83             readBytes(in, -1, new byte[1024]);
    84         } catch (I2NPMessageException ime) {
    85             throw new DataFormatException("Bad bytes", ime);
    86         }
    87     }
    88 
    89     /**
    90      *  Read the header, then read the rest into buffer, then call
    91      *  readMessage in the implemented message type
    92      *
    93      *  This does a copy from the stream to the buffer, so if you already
    94      *  have a byte array, use the other readBytes() instead.
    95      *
    96      *<pre>
    97      *  Specifically:
    98      *    1 byte type (if caller didn't read already, as specified by the type param
    99      *    4 byte ID
    100      *    8 byte expiration
    101      *    2 byte size
    102      *    1 byte checksum
    103      *    size bytes of payload (read by readMessage() in implementation)
    104      *</pre>
    105      *
    106      *  Unused - All transports provide encapsulation and so we have byte arrays available.
    107      *
    108      *  @param type the message type or -1 if we should read it here
    109      *  @param buffer temp buffer to use
    110      *  @return total length of the message
    111      *  @deprecated unused
    112      */
    113     @Deprecated
    114     public int readBytes(InputStream in, int type, byte buffer[]) throws I2NPMessageException, IOException {
    115         try {
    116             if (type < 0)
    117                 type = (int)DataHelper.readLong(in, 1);
    118             _uniqueId = DataHelper.readLong(in, 4);
    119             _expiration = DataHelper.readLong(in, DataHelper.DATE_LENGTH);
    120             int size = (int)DataHelper.readLong(in, 2);
    121             byte checksum[] = new byte[CHECKSUM_LENGTH];
    122             int read = DataHelper.read(in, checksum);
    123             if (read != CHECKSUM_LENGTH)
    124                 throw new I2NPMessageException("checksum is too small [" + read + "]");
    125             //Hash h = new Hash();
    126             //h.readBytes(in);
    127             if (buffer.length < size) {
    128                 if (size > MAX_SIZE) throw new I2NPMessageException("size=" + size);
    129                 buffer = new byte[size];
    130             }
    131 
    132             int cur = 0;
    133             while (cur < size) {
    134                 int numRead = in.read(buffer, cur, size- cur);
    135                 if (numRead == -1) {
    136                     throw new I2NPMessageException("Payload is too short [" + numRead + ", wanted " + size + "]");
    137                 }
    138                 cur += numRead;
    139             }
    140 
    141             byte[] calc = SimpleByteCache.acquire(Hash.HASH_LENGTH);
    142             _context.sha().calculateHash(buffer, 0, size, calc, 0);
    143             //boolean eq = calc.equals(h);
    144             boolean eq = DataHelper.eq(checksum, 0, calc, 0, CHECKSUM_LENGTH);
    145             SimpleByteCache.release(calc);
    146             if (!eq)
    147                 throw new I2NPMessageException("Bad checksum on " + size + " byte I2NP " + getClass().getSimpleName());
    148 
    149             //long start = _context.clock().now();
    150             if (_log.shouldLog(Log.DEBUG))
    151                 _log.debug("Reading bytes: type = " + type + " / uniqueId : " + _uniqueId + " / expiration : " + _expiration);
    152             readMessage(buffer, 0, size, type);
    153             //long time = _context.clock().now() - start;
    154             //if (time > 50)
    155             //    _context.statManager().addRateData("i2np.readTime", time, time);
    156             return CHECKSUM_LENGTH + 1 + 2 + 4 + DataHelper.DATE_LENGTH + size;
    157         } catch (DataFormatException dfe) {
    158             throw new I2NPMessageException("Error reading the message header", dfe);
    159         }
     82    public void readBytes(InputStream in) {
     83        throw new UnsupportedOperationException();
    16084    }
    16185
Note: See TracChangeset for help on using the changeset viewer.