Search in sources :

Example 1 with I2NPMessageHandler

use of net.i2p.data.i2np.I2NPMessageHandler in project i2p.i2p by i2p.

the class FragmentHandler method receiveComplete.

private void receiveComplete(FragmentedMessage msg) {
    if (msg == null)
        return;
    _completed++;
    String stringified = null;
    if (_log.shouldLog(Log.DEBUG))
        stringified = msg.toString();
    byte[] data = null;
    try {
        int fragmentCount = msg.getFragmentCount();
        // toByteArray destroys the contents of the message completely
        data = msg.toByteArray();
        if (data == null)
            // fragments already released???
            throw new I2NPMessageException("null data");
        if (_log.shouldLog(Log.DEBUG))
            // + Base64.encode(data)
            _log.debug("RECV(" + data.length + "): ");
        // + " " + _context.sha().calculateHash(data).toBase64());
        // TODO read in as unknown message for outbound tunnels,
        // since this will just be packaged in a TunnelGatewayMessage.
        // Not a big savings since most everything is a GarlicMessage
        // and so the readMessage() call is fast.
        // The unencrypted messages at the OBEP are (V)TBMs
        // and perhaps an occasional DatabaseLookupMessage
        I2NPMessage m = new I2NPMessageHandler(_context).readMessage(data);
        // + msg.toString());
        noteReception(m.getUniqueId(), fragmentCount - 1, "complete: ");
        noteCompletion(m.getUniqueId());
        _receiver.receiveComplete(m, msg.getTargetRouter(), msg.getTargetTunnel());
    } catch (I2NPMessageException ime) {
        if (stringified == null)
            stringified = msg.toString();
        if (_log.shouldLog(Log.WARN)) {
            _log.warn("Error receiving fragmented message (corrupt?): " + stringified, ime);
            _log.warn("DUMP:\n" + HexDump.dump(data));
            _log.warn("RAW:\n" + Base64.encode(data));
        }
    }
}
Also used : I2NPMessageException(net.i2p.data.i2np.I2NPMessageException) I2NPMessage(net.i2p.data.i2np.I2NPMessage) I2NPMessageHandler(net.i2p.data.i2np.I2NPMessageHandler)

Example 2 with I2NPMessageHandler

use of net.i2p.data.i2np.I2NPMessageHandler in project i2p.i2p by i2p.

the class FragmentHandler method receiveComplete.

/**
 *  Zero-copy reception of an unfragmented message
 *  @since 0.9
 */
private void receiveComplete(byte[] data, int offset, int len, Hash router, TunnelId tunnelId) {
    _completed++;
    try {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("RECV unfrag(" + len + ')');
        // TODO read in as unknown message for outbound tunnels,
        // since this will just be packaged in a TunnelGatewayMessage.
        // Not a big savings since most everything is a GarlicMessage
        // and so the readMessage() call is fast.
        // The unencrypted messages at the OBEP are (V)TBMs
        // and perhaps an occasional DatabaseLookupMessage
        I2NPMessageHandler h = new I2NPMessageHandler(_context);
        h.readMessage(data, offset, len);
        I2NPMessage m = h.lastRead();
        // + msg.toString());
        noteReception(m.getUniqueId(), 0, "complete: ");
        noteCompletion(m.getUniqueId());
        _receiver.receiveComplete(m, router, tunnelId);
    } catch (I2NPMessageException ime) {
        if (_log.shouldLog(Log.WARN)) {
            _log.warn("Error receiving unfragmented message (corrupt?)", ime);
            _log.warn("DUMP:\n" + HexDump.dump(data, offset, len));
            _log.warn("RAW:\n" + Base64.encode(data, offset, len));
        }
    }
}
Also used : I2NPMessageException(net.i2p.data.i2np.I2NPMessageException) I2NPMessage(net.i2p.data.i2np.I2NPMessage) I2NPMessageHandler(net.i2p.data.i2np.I2NPMessageHandler)

Aggregations

I2NPMessage (net.i2p.data.i2np.I2NPMessage)2 I2NPMessageException (net.i2p.data.i2np.I2NPMessageException)2 I2NPMessageHandler (net.i2p.data.i2np.I2NPMessageHandler)2