Changeset 25b0603f


Ignore:
Timestamp:
Dec 9, 2011 5:36:49 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
50606a6
Parents:
937ae8ad
Message:
  • I2NP:
    • Earlier detection and better logging of truncated TunnelGatewayMessage? and DatabaseStoreMessage?
    • Fix and enhance UnknownI2NPMessage implementation
    • Don't deserialize or verify the checksum of the embeddedI2NP message in the TunnelGatewayMessage? at the IBGW, just use UnknownI2NPMessage and pass it along, except if zero hop; Still to do: similar thing at OBEP
    • Round expiration times when converting to/from seconds for SSU
    • Cleanups and javadoc
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    r937ae8ad r25b0603f  
     12011-12-09 zzz
     2  * Base64: Add decodestring command in main()
     3  * Console, i2psnark: More button CSS tweaks
     4  * I2NP:
     5    - Earlier detection and better logging of
     6      truncated TunnelGatewayMessage and DatabaseStoreMessage
     7    - Fix and enhance UnknownI2NPMessage implementation
     8    - Don't deserialize or verify the checksum of the
     9      embeddedI2NP message in the TunnelGatewayMessage
     10      at the IBGW, just use UnknownI2NPMessage and pass it along,
     11      except if zero hop; Still to do: similar thing at OBEP
     12    - Cleanups and javadoc
     13  * LeaseSet: Fix size calculations
     14  * UDP:
     15    - Fix major bug from 2005 that corrupted outbound messages
     16      that were an exact multiple of the fragment size.
     17    - Round expiration times when converting to seconds
     18    - Zero-copy of single-fragment messages in MessageReceiver
     19    - Optimizations, log tweaks, comments
     20
    1212011-12-06 zzz
    222  * Router:
  • router/java/src/net/i2p/data/i2np/DatabaseStoreMessage.java

    r937ae8ad r25b0603f  
    2424 * Defines the message a router sends to another router to test the network
    2525 * database reachability, as well as the reply message sent back.
     26 *
     27 * TODO: Don't decompress and recompress RouterInfos at the OBEP and IBGW.
     28 * Could this even change the message length or corrupt things?
    2629 *
    2730 * @author jrandom
     
    129132            int compressedSize = (int)DataHelper.fromLong(data, curIndex, 2);
    130133            curIndex += 2;
     134            if (compressedSize <= 0 || curIndex + compressedSize > data.length || (curIndex - offset) + compressedSize > dataSize)
     135                throw new I2NPMessageException("Compressed RI length: " + compressedSize +
     136                                               " but remaining bytes: " + Math.min(data.length - curIndex, dataSize - (curIndex - offset)));
    131137           
    132138            try {
     139                // TODO we could delay decompression, just copy to a new byte array and store in _byteCache
     140                // May not be necessary since the IBGW now uses UnknownI2NPMessage.
     141                // DSMs at the OBEP are generally garlic wrapped, so the OBEP won't see it.
     142                // If we do delay it, getEntry() will have to check if _dbEntry is null and _byteCache
     143                // is non-null, and then decompress.
    133144                byte decompressed[] = DataHelper.decompress(data, curIndex, compressedSize);
    134145                _dbEntry.readBytes(new ByteArrayInputStream(decompressed));
     
    136147                throw new I2NPMessageException("Error reading the routerInfo", dfe);
    137148            } catch (IOException ioe) {
    138                 throw new I2NPMessageException("Compressed routerInfo was corrupt", ioe);
     149                throw new I2NPMessageException("Corrupt compressed routerInfo size = " + compressedSize, ioe);
    139150            }
    140151        } else {
     
    146157   
    147158   
    148     /** calculate the message body's length (not including the header and footer */
     159    /**
     160     *  calculate the message body's length (not including the header and footer)
     161     *
     162     *  @throws IllegalStateException
     163     */
    149164    protected int calculateWrittenLength() {
     165        // TODO if _byteCache is non-null, don't check _dbEntry
     166        if (_dbEntry == null)
     167            throw new IllegalStateException("Missing entry");
    150168        int len = Hash.HASH_LENGTH + 1 + 4; // key+type+replyToken
    151169        if (_replyToken > 0)
     
    153171        int type = _dbEntry.getType();
    154172        if (type == DatabaseEntry.KEY_TYPE_LEASESET) {
    155             _byteCache = _dbEntry.toByteArray();
     173            if (_byteCache == null) {
     174                _byteCache = _dbEntry.toByteArray();
     175            }
    156176        } else if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
    157             byte uncompressed[] = _dbEntry.toByteArray();
    158             _byteCache = DataHelper.compress(uncompressed);
     177            // only decompress once
     178            if (_byteCache == null) {
     179                byte uncompressed[] = _dbEntry.toByteArray();
     180                _byteCache = DataHelper.compress(uncompressed);
     181            }
    159182            len += 2;
    160183        } else {
  • router/java/src/net/i2p/data/i2np/GarlicMessage.java

    r937ae8ad r25b0603f  
    1313import net.i2p.I2PAppContext;
    1414import net.i2p.data.DataHelper;
    15 import net.i2p.util.Log;
    1615
    1716/**
     
    2120 */
    2221public class GarlicMessage extends I2NPMessageImpl {
    23     private final static Log _log = new Log(GarlicMessage.class);
    2422    public final static int MESSAGE_TYPE = 11;
    2523    private byte[] _data;
  • router/java/src/net/i2p/data/i2np/I2NPMessageHandler.java

    r937ae8ad r25b0603f  
    5050            _lastReadBegin = System.currentTimeMillis();
    5151            I2NPMessage msg = I2NPMessageImpl.createMessage(_context, type);
    52             if (msg == null)
    53                 throw new I2NPMessageException("The type "+ type + " is an unknown I2NP message");
     52            // can't be null
     53            //if (msg == null)
     54            //    throw new I2NPMessageException("The type "+ type + " is an unknown I2NP message");
    5455            try {
    5556                _lastSize = msg.readBytes(in, type, _messageBuffer);
     
    8990        return lastRead();
    9091    }
     92
    9193    public int readMessage(byte data[], int offset) throws IOException, I2NPMessageException {
    9294        int cur = offset;
     
    9597        _lastReadBegin = System.currentTimeMillis();
    9698        I2NPMessage msg = I2NPMessageImpl.createMessage(_context, type);
    97         if (msg == null) {
    98             int sz = data.length-offset;
    99             boolean allZero = false;
    100             for (int i = offset; i < data.length; i++) {
    101                 if (data[i] != 0) {
    102                     allZero = false;
    103                     break;
    104                 }
    105             }
    106             throw new I2NPMessageException("The type "+ type + " is an unknown I2NP message (remaining sz="
    107                                            + sz + " all zeros? " + allZero + ")");
    108         }
     99        // can't be null
     100        //if (msg == null) {
     101        //    int sz = data.length-offset;
     102        //   boolean allZero = false;
     103        //    for (int i = offset; i < data.length; i++) {
     104        //        if (data[i] != 0) {
     105        //            allZero = false;
     106        //            break;
     107        //        }
     108        //    }
     109        //    throw new I2NPMessageException("The type "+ type + " is an unknown I2NP message (remaining sz="
     110        //                                   + sz + " all zeros? " + allZero + ")");
     111        //}
    109112        try {
    110113            _lastSize = msg.readBytes(data, type, cur);
     
    128131    public int getLastSize() { return _lastSize; }
    129132   
     133/****
    130134    public static void main(String args[]) {
    131135        try {
     
    136140        }
    137141    }
     142****/
    138143}
  • router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java

    r937ae8ad r25b0603f  
    2929 */
    3030public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPMessage {
    31     private final Log _log;
     31    protected final Log _log;
    3232    protected final I2PAppContext _context;
    3333    private long _expiration;
     
    3737    public final static int CHECKSUM_LENGTH = 1; //Hash.HASH_LENGTH;
    3838   
    39     private static final boolean RAW_FULL_SIZE = false;
     39    // Whether SSU used the full header or a truncated header.
     40    // We are stuck with the short header, can't change it now.
     41    //private static final boolean RAW_FULL_SIZE = false;
    4042   
    4143    /** unused */
    4244    private static final Map<Integer, Builder> _builders = new ConcurrentHashMap(1);
     45
    4346    /** @deprecated unused */
    4447    public static final void registerBuilder(Builder builder, int type) { _builders.put(Integer.valueOf(type), builder); }
     48
    4549    /** interface for extending the types of messages handled - unused */
    4650    public interface Builder {
     
    121125            SimpleByteCache.release(calc);
    122126            if (!eq)
    123                 throw new I2NPMessageException("Hash does not match for " + getClass().getName());
     127                throw new I2NPMessageException("Bad checksum on " + size + " byte I2NP " + getClass().getSimpleName());
    124128
    125129            //long start = _context.clock().now();
     
    183187        SimpleByteCache.release(calc);
    184188        if (!eq)
    185             throw new I2NPMessageException("Hash does not match for " + getClass().getName());
     189            throw new I2NPMessageException("Bad checksum on " + size + " byte I2NP " + getClass().getSimpleName());
    186190
    187191        //long start = _context.clock().now();
     
    221225        return calculateWrittenLength()+15 + CHECKSUM_LENGTH; // 16 bytes in the header
    222226    }
     227
     228    /**
     229     *  The raw header consists of a one-byte type and a 4-byte expiration in seconds only.
     230     *  Used by SSU only!
     231     */
    223232    public synchronized int getRawMessageSize() {
    224         if (RAW_FULL_SIZE)
    225             return getMessageSize();
    226         else
     233        //if (RAW_FULL_SIZE)
     234        //    return getMessageSize();
     235        //else
    227236            return calculateWrittenLength()+5;
    228237    }
     
    311320
    312321   
    313     /** used by SSU only */
     322    /**
     323     *  Write the message with a short 5-byte header.
     324     *  THe header consists of a one-byte type and a 4-byte expiration in seconds only.
     325     *  Used by SSU only!
     326     */
    314327    public int toRawByteArray(byte buffer[]) {
    315         if (RAW_FULL_SIZE)
    316             return toByteArray(buffer);
     328        //if (RAW_FULL_SIZE)
     329        //    return toByteArray(buffer);
    317330        try {
    318331            int off = 0;
    319332            DataHelper.toLong(buffer, off, 1, getType());
    320333            off += 1;
    321             DataHelper.toLong(buffer, off, 4, _expiration/1000); // seconds
     334            // January 19 2038? No, unsigned, good until Feb. 7 2106
     335            // in seconds, round up so we don't lose time every hop
     336            DataHelper.toLong(buffer, off, 4, (_expiration + 500) / 1000);
    322337            off += 4;
    323338            return writeMessageBody(buffer, off);
     
    345360*****/
    346361
    347     /** used by SSU only */
     362    /**
     363     *  Read the message with a short 5-byte header.
     364     *  THe header consists of a one-byte type and a 4-byte expiration in seconds only.
     365     *  Used by SSU only!
     366     */
    348367    public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte buffer[], int offset, int len, I2NPMessageHandler handler) throws I2NPMessageException {
    349368        int type = (int)DataHelper.fromLong(buffer, offset, 1);
     
    352371        if (msg == null)
    353372            throw new I2NPMessageException("Unknown message type: " + type);
    354         if (RAW_FULL_SIZE) {
    355             try {
    356                 msg.readBytes(buffer, type, offset);
    357             } catch (IOException ioe) {
    358                 throw new I2NPMessageException("Error reading the " + msg, ioe);
    359             }
    360             return msg;
    361         }
    362 
    363         try {
    364             long expiration = DataHelper.fromLong(buffer, offset, 4) * 1000; // seconds
     373        //if (RAW_FULL_SIZE) {
     374        //    try {
     375        //        msg.readBytes(buffer, type, offset);
     376        //    } catch (IOException ioe) {
     377        //        throw new I2NPMessageException("Error reading the " + msg, ioe);
     378        //    }
     379        //    return msg;
     380        //}
     381
     382        try {
     383            // January 19 2038? No, unsigned, good until Feb. 7 2106
     384            // in seconds, round up so we don't lose time every hop
     385            long expiration = (DataHelper.fromLong(buffer, offset, 4) * 1000) + 500;
    365386            offset += 4;
    366387            int dataSize = len - 1 - 4;
     
    378399     * Yes, this is fairly ugly, but its the only place it ever happens.
    379400     *
     401     * @return non-null, returns an UnknownI2NPMessage if unknown type
    380402     */
    381403    public static I2NPMessage createMessage(I2PAppContext context, int type) throws I2NPMessageException {
  • router/java/src/net/i2p/data/i2np/TunnelDataMessage.java

    r937ae8ad r25b0603f  
    2323 */
    2424public class TunnelDataMessage extends I2NPMessageImpl {
    25     private Log _log;
    2625    private long _tunnelId;
    2726    private TunnelId _tunnelIdObj;
     
    102101    public TunnelDataMessage(I2PAppContext context) {
    103102        super(context);
    104         _log = context.logManager().getLog(TunnelDataMessage.class);
    105103        setMessageExpiration(context.clock().now() + EXPIRATION_PERIOD);
    106104    }
  • router/java/src/net/i2p/data/i2np/TunnelGatewayMessage.java

    r937ae8ad r25b0603f  
    2222 */
    2323public class TunnelGatewayMessage extends I2NPMessageImpl {
    24     private Log _log;
    2524    private TunnelId _tunnelId;
    2625    private I2NPMessage _msg;
    2726    private byte _msgData[];
    28     private Exception _creator;
     27    //private Exception _creator;
    2928   
    3029    public final static int MESSAGE_TYPE = 19;
     
    3433    public TunnelGatewayMessage(I2PAppContext context) {
    3534        super(context);
    36         _log = context.logManager().getLog(TunnelGatewayMessage.class);
    3735        setMessageExpiration(context.clock().now() + EXPIRATION_PERIOD);
    3836        //_creator = new Exception("i made this");
     
    4240    public void setTunnelId(TunnelId id) { _tunnelId = id; }
    4341   
     42    /**
     43     *  Warning, at the IBGW, where the message was read in,
     44     *  this will be an UnknownI2NPMessage.
     45     *  If you need a real message class, use UnknownI2NPMessage.convert().
     46     */
    4447    public I2NPMessage getMessage() { return _msg; }
     48
    4549    public void setMessage(I2NPMessage msg) {
    4650        if (msg == null)
     
    6266    protected int writeMessageBody(byte out[], int curIndex) throws I2NPMessageException {
    6367        if ( (_tunnelId == null) || ( (_msg == null) && (_msgData == null) ) ) {
    64             _log.log(Log.CRIT, "failing to write out gateway message, created by: ", _creator);
     68            _log.log(Log.CRIT, "failing to write out gateway message");
    6569            throw new I2NPMessageException("Not enough data to write out (id=" + _tunnelId + " data=" + _msg + ")");
    6670        }
     
    8892
    8993    public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException, IOException {
    90         I2NPMessageHandler h = new I2NPMessageHandler(_context);
    91         readMessage(data, offset, dataSize, type, h);
     94        //I2NPMessageHandler h = new I2NPMessageHandler(_context);
     95        //readMessage(data, offset, dataSize, type, h);
     96        readMessage(data, offset, dataSize, type, null);
    9297    }
     98
     99    /**
     100     *  Note that for efficiency at the IBGW, this does not fully deserialize the included
     101     *  I2NP Message. It just puts it in an UnknownI2NPMessage.
     102     *
     103     *  @param handler unused, may be null
     104     */
    93105    @Override
    94106    public void readMessage(byte data[], int offset, int dataSize, int type, I2NPMessageHandler handler) throws I2NPMessageException, IOException {
     
    102114            throw new I2NPMessageException("Invalid tunnel Id " + _tunnelId);
    103115       
    104         DataHelper.fromLong(data, curIndex, 2);
     116        int len = (int) DataHelper.fromLong(data, curIndex, 2);
    105117        curIndex += 2;
    106         curIndex = handler.readMessage(data, curIndex);
    107         _msg = handler.lastRead();
    108         if (_msg == null)
    109             throw new I2NPMessageException("wtf, message read has no payload?");
     118        if (len <= 1 || curIndex + len > data.length || len > dataSize - 6)
     119            throw new I2NPMessageException("I2NP length in TGM: " + len +
     120                                           " but remaining bytes: " + Math.min(data.length - curIndex, dataSize - 6));
     121
     122        // OLD WAY full message parsing and instantiation
     123        //handler.readMessage(data, curIndex);
     124        //_msg = handler.lastRead();
     125        //if (_msg == null)
     126        //    throw new I2NPMessageException("wtf, message read has no payload?");
     127
     128        // NEW WAY save lots of effort at the IBGW by reading as an UnknownI2NPMessage instead
     129        // This will save a lot of object churn and processing,
     130        // primarily for unencrypted msgs (V)TBRM, DatabaseStoreMessage, and DSRMs.
     131        // DatabaseStoreMessages in particluar are intensive for readBytes()
     132        // since the RI is decompressed.
     133        // For a zero-hop IB tunnel, where we do need the real thing,
     134        // it is converted to a real message class in TunnelGatewayZeroHop
     135        // using UnknownI2NPMessage.convert() in TunnelGatewayZeroHop.
     136        // We also skip processing the checksum as it's covered by the TGM checksum.
     137        // If a zero-hop, the checksum will be verified in convert().
     138        int utype = data[curIndex++] & 0xff;
     139        UnknownI2NPMessage umsg = new UnknownI2NPMessage(_context, utype);
     140        umsg.readBytesIgnoreChecksum(data, curIndex);
     141        _msg = umsg;
    110142    }
    111143   
  • router/java/src/net/i2p/data/i2np/UnknownI2NPMessage.java

    r937ae8ad r25b0603f  
    1313import net.i2p.I2PAppContext;
    1414import net.i2p.data.DataHelper;
     15import net.i2p.data.Hash;
     16import net.i2p.util.SimpleByteCache;
    1517
    1618/**
     
    2426 * read it with readMessage() (i.e., it came from some other router)
    2527 *
    26  * @since 0.7.12
     28 * @since 0.7.12 but broken before 0.8.12
    2729 */
    2830public class UnknownI2NPMessage extends I2NPMessageImpl {
    2931    private byte _data[];
    30     private int _type;
     32    private final int _type;
     33    // we assume CHECKSUM_LENGTH = 1
     34    private byte _checksum;
    3135   
    3236    /** @param type 0-255 */
     
    3640    }
    3741   
    38     /** warning - only public for equals() */
    39     public byte[] getData() {
    40         return _data;
    41     }
    42 
    4342    public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException, IOException {
    4443        if (type != _type) throw new I2NPMessageException("Message type is incorrect for this message");
    45         int curIndex = offset;
    46         long size = DataHelper.fromLong(data, curIndex, 4);
    47         curIndex += 4;
    48         if (size > MAX_SIZE)
    49             throw new I2NPMessageException("wtf, size=" + size);
    50         _data = new byte[(int)size];
    51         System.arraycopy(data, curIndex, _data, 0, (int)size);
     44        if (dataSize > MAX_SIZE)
     45            throw new I2NPMessageException("wtf, size=" + dataSize);
     46        _data = new byte[dataSize];
     47        System.arraycopy(data, offset, _data, 0, dataSize);
    5248    }
    5349   
     
    5551    protected int calculateWrittenLength() {
    5652        if (_data == null)
    57             return 4;
     53            return 0;
    5854        else
    59             return 4 + _data.length;
     55            return _data.length;
    6056    }
    6157
    6258    /** write the message body to the output array, starting at the given index */
    6359    protected int writeMessageBody(byte out[], int curIndex) {
    64         if (_data == null) {
    65             out[curIndex++] = 0x0;
    66             out[curIndex++] = 0x0;
    67             out[curIndex++] = 0x0;
    68             out[curIndex++] = 0x0;
    69         } else {
    70             byte len[] = DataHelper.toLong(4, _data.length);
    71             System.arraycopy(len, 0, out, curIndex, 4);
    72             curIndex += 4;
     60        if (_data != null) {
    7361            System.arraycopy(_data, 0, out, curIndex, _data.length);
    7462            curIndex += _data.length;
     
    8068    public int getType() { return _type; }
    8169   
     70
     71    /**
     72     *  Read the full message including the header.
     73     *  This is the same as I2NPMessageImpl.readBytes(), except
     74     *  start after the type field, and
     75     *  do NOT verify the checksum, but simply save it for later
     76     *  so it can be verified in convert() if required.
     77     *
     78     *<pre>
     79     *  Standard message format AFTER the type field
     80     *    4 byte ID
     81     *    8 byte expiration
     82     *    2 byte size
     83     *    1 byte checksum (saved in case we need to check later)
     84     *    size bytes of payload, read by readMessage()
     85     *</pre>
     86     *
     87     *  @param offset starting at the ID (must skip the type)
     88     *  @return total length of the message
     89     *  @since 0.8.12
     90     */
     91    public void readBytesIgnoreChecksum(byte data[], int offset) throws I2NPMessageException, IOException {
     92        int cur = offset;
     93        setUniqueId(DataHelper.fromLong(data, cur, 4));
     94        cur += 4;
     95        setMessageExpiration(DataHelper.fromLong(data, cur, DataHelper.DATE_LENGTH));
     96        cur += DataHelper.DATE_LENGTH;
     97        int size = (int)DataHelper.fromLong(data, cur, 2);
     98        cur += 2;
     99        _checksum = data[cur];
     100        cur++;
     101
     102        if (cur + size > data.length)
     103            throw new I2NPMessageException("Payload is too short ["
     104                                           + "data.len=" + data.length
     105                                           + " offset=" + offset
     106                                           + " cur=" + cur
     107                                           + " wanted=" + size + ']');
     108
     109        readMessage(data, cur, size, _type);
     110    }
     111   
     112    /**
     113     *  Attempt to convert this message to a known message class.
     114     *  Must have been created with readBytesIgnoreChecksum previously,
     115     *  as this does the delayed verification using the saved checksum.
     116     *
     117     *  Used by TunnelGatewayZeroHop.
     118     *
     119     *  @throws I2NPMessageException if the conversion fails
     120     *  @since 0.8.12
     121     */
     122    public I2NPMessage convert() throws I2NPMessageException {
     123        I2NPMessage msg = I2NPMessageImpl.createMessage(_context, _type);
     124        if (msg instanceof UnknownI2NPMessage)
     125            throw new I2NPMessageException("Unable to convert unknown type " + _type);
     126        byte[] calc = SimpleByteCache.acquire(Hash.HASH_LENGTH);
     127        _context.sha().calculateHash(_data, 0, _data.length, calc, 0);
     128        boolean eq = _checksum == calc[0];
     129        SimpleByteCache.release(calc);
     130        if (!eq)
     131            throw new I2NPMessageException("Bad checksum on " + _data.length + " byte msg type " + _type);
     132        try {
     133            msg.readMessage(_data, 0, _data.length, _type);
     134        } catch (IOException ioe) {
     135            throw new I2NPMessageException("Unable to convert type " + _type, ioe);
     136        }
     137        msg.setUniqueId(getUniqueId());
     138        msg.setMessageExpiration(getMessageExpiration());
     139        return msg;
     140    }
     141
    82142    @Override
    83143    public int hashCode() {
    84         return _type + DataHelper.hashCode(getData());
     144        return _type + DataHelper.hashCode(_data);
    85145    }
    86146   
     
    89149        if ( (object != null) && (object instanceof UnknownI2NPMessage) ) {
    90150            UnknownI2NPMessage msg = (UnknownI2NPMessage)object;
    91             return _type == msg.getType() && DataHelper.eq(getData(), msg.getData());
     151            return _type == msg.getType() && DataHelper.eq(_data, msg._data);
    92152        } else {
    93153            return false;
     
    100160        buf.append("[UnknownI2NPMessage: ");
    101161        buf.append("\n\tType: ").append(_type);
    102         buf.append("\n\tLength: ").append(calculateWrittenLength() - 4);
     162        buf.append("\n\tLength: ").append(calculateWrittenLength());
    103163        buf.append("]");
    104164        return buf.toString();
  • router/java/src/net/i2p/router/RouterVersion.java

    r937ae8ad r25b0603f  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 17;
     21    public final static long BUILD = 18;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/tunnel/FragmentHandler.java

    r937ae8ad r25b0603f  
    478478                _log.debug("RECV(" + data.length + "): "); // + Base64.encode(data) 
    479479                           //+ " " + _context.sha().calculateHash(data).toBase64());
     480
     481            // TODO read in as unknown message for outbound tunnels,
     482            // since this will just be packaged in a TunnelGatewayMessage.
     483            // Not a big savings since most everything is a GarlicMessage
     484            // and so the readMessage() call is fast.
     485            // The unencrypted messages at the OBEP are (V)TBMs
     486            // and perhaps an occasional DatabaseLookupMessage
    480487            I2NPMessage m = new I2NPMessageHandler(_context).readMessage(data);
    481488            noteReception(m.getUniqueId(), fragmentCount-1, "complete: ");// + msg.toString());
  • router/java/src/net/i2p/router/tunnel/OutboundMessageDistributor.java

    r937ae8ad r25b0603f  
    6262            if (_log.shouldLog(Log.DEBUG))
    6363                _log.debug("queueing inbound message to ourselves: " + m);
     64            // TODO if UnknownI2NPMessage, convert it.
     65            // See FragmentHandler.receiveComplete()
    6466            _context.inNetMessagePool().add(m, null, null);
    6567            return;
  • router/java/src/net/i2p/router/tunnel/TunnelDispatcher.java

    r937ae8ad r25b0603f  
    453453                               + " and/or the content's expiration is in " + DataHelper.formatDuration(msg.getMessage().getMessageExpiration()-before)
    454454                               + " with messageId " + msg.getUniqueId() + "/" + msg.getMessage().getUniqueId() + " and message type "
    455                                + msg.getMessage().getClass().getName());
     455                               + msg.getMessage().getClass().getSimpleName());
    456456                return;
    457457            }
     
    472472                           + " messageId " + msg.getUniqueId()
    473473                           + "/" + msg.getMessage().getUniqueId()
    474                            + " messageType: " + msg.getMessage().getClass().getName()
     474                           + " messageType: " + msg.getMessage().getClass().getSimpleName()
    475475                           + " existing = " + _inboundGateways.size(), new Exception("source"));
    476476        }
  • router/java/src/net/i2p/router/tunnel/TunnelGatewayZeroHop.java

    r937ae8ad r25b0603f  
    44import net.i2p.data.TunnelId;
    55import net.i2p.data.i2np.I2NPMessage;
     6import net.i2p.data.i2np.I2NPMessageException;
    67import net.i2p.data.i2np.TunnelGatewayMessage;
     8import net.i2p.data.i2np.UnknownI2NPMessage;
    79import net.i2p.router.RouterContext;
    810import net.i2p.util.Log;
     
    3133    /**
    3234     * Add a message to be sent down the tunnel, where we are the inbound gateway.
     35     * This requires converting the message included in the TGM from an
     36     * UnknownI2NPMessage to the correct message class.
     37     * See TunnelGatewayMessage for details.
    3338     *
    3439     * @param msg message received to be sent through the tunnel
     
    3641    @Override
    3742    public void add(TunnelGatewayMessage msg) {
    38         add(msg.getMessage(), null, null);
     43        I2NPMessage imsg = msg.getMessage();
     44        if (_config.isInbound()) {
     45            if (imsg instanceof UnknownI2NPMessage) {
     46                // Do the delayed deserializing - convert to a standard message class
     47                try {
     48                    UnknownI2NPMessage umsg = (UnknownI2NPMessage) imsg;
     49                    imsg = umsg.convert();
     50                } catch (I2NPMessageException ime) {
     51                    if (_log.shouldLog(Log.WARN))
     52                        _log.warn("Unable to convert to std. msg. class at zero-hop IBGW", ime);
     53                    return;
     54                }
     55            }
     56        }
     57        add(imsg, null, null);
    3958    }
    4059   
     
    5170    public void add(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) {
    5271        if (_log.shouldLog(Log.DEBUG))
    53             _log.debug("zero hop gateway: distribute " + (_config.isInbound() ? "inbound " : " outbound ")
     72            _log.debug("zero hop gateway: distribute " + (_config.isInbound() ? "inbound" : " outbound")
    5473                       + " to " + (toRouter != null ? toRouter.toBase64().substring(0,4) : "" )
    5574                       + "." + (toTunnel != null ? toTunnel.getTunnelId() + "" : "")
Note: See TracChangeset for help on using the changeset viewer.