Search in sources :

Example 1 with I2PInvalidDatagramException

use of net.i2p.client.datagram.I2PInvalidDatagramException in project i2p.i2p by i2p.

the class SAMDatagramSession method messageReceived.

protected void messageReceived(byte[] msg, int proto, int fromPort, int toPort) {
    byte[] payload;
    Destination sender;
    try {
        synchronized (dgramDissector) {
            dgramDissector.loadI2PDatagram(msg);
            sender = dgramDissector.getSender();
            payload = dgramDissector.extractPayload();
        }
    } catch (DataFormatException e) {
        if (_log.shouldLog(Log.DEBUG)) {
            _log.debug("Dropping ill-formatted I2P repliable datagram", e);
        }
        return;
    } catch (I2PInvalidDatagramException e) {
        if (_log.shouldLog(Log.DEBUG)) {
            _log.debug("Dropping ill-signed I2P repliable datagram", e);
        }
        return;
    }
    try {
        recv.receiveDatagramBytes(sender, payload, proto, fromPort, toPort);
    } catch (IOException e) {
        _log.error("Error forwarding message to receiver", e);
        close();
    }
}
Also used : Destination(net.i2p.data.Destination) DataFormatException(net.i2p.data.DataFormatException) IOException(java.io.IOException) I2PInvalidDatagramException(net.i2p.client.datagram.I2PInvalidDatagramException)

Example 2 with I2PInvalidDatagramException

use of net.i2p.client.datagram.I2PInvalidDatagramException in project i2p.i2p by i2p.

the class KRPC method messageAvailable.

// I2PSessionMuxedListener interface ----------------
/**
 * Instruct the client that the given session has received a message
 *
 * Will be called only if you register via addMuxedSessionListener().
 * Will be called only for the proto(s) and toPort(s) you register for.
 *
 * @param session session to notify
 * @param msgId message number available
 * @param size size of the message - why it's a long and not an int is a mystery
 * @param proto 1-254 or 0 for unspecified
 * @param fromPort 1-65535 or 0 for unspecified
 * @param toPort 1-65535 or 0 for unspecified
 */
public void messageAvailable(I2PSession session, int msgId, long size, int proto, int fromPort, int toPort) {
    // TODO throttle
    try {
        byte[] payload = session.receiveMessage(msgId);
        if (payload == null)
            return;
        _rxPkts.incrementAndGet();
        _rxBytes.addAndGet(payload.length);
        if (toPort == _qPort) {
            // repliable
            I2PDatagramDissector dgDiss = new I2PDatagramDissector();
            dgDiss.loadI2PDatagram(payload);
            payload = dgDiss.getPayload();
            Destination from = dgDiss.getSender();
            // TODO per-dest throttle
            receiveMessage(from, fromPort, payload);
        } else if (toPort == _rPort) {
            // raw
            receiveMessage(null, fromPort, payload);
        } else {
            if (_log.shouldLog(Log.WARN))
                _log.warn("msg on bad port");
        }
    } catch (DataFormatException e) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("bad msg");
    } catch (I2PInvalidDatagramException e) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("bad msg");
    } catch (I2PSessionException e) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("bad msg");
    }
}
Also used : Destination(net.i2p.data.Destination) I2PDatagramDissector(net.i2p.client.datagram.I2PDatagramDissector) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException) I2PInvalidDatagramException(net.i2p.client.datagram.I2PInvalidDatagramException)

Example 3 with I2PInvalidDatagramException

use of net.i2p.client.datagram.I2PInvalidDatagramException in project i2p.i2p-bote by i2p.

the class I2PPacketDispatcher method messageAvailable.

@Override
public void messageAvailable(I2PSession session, int msgId, long size) {
    byte[] msg = new byte[0];
    try {
        msg = session.receiveMessage(msgId);
    } catch (I2PSessionException e) {
        log.error("Can't get new message from I2PSession.", e);
    }
    if (msg == null) {
        log.error("I2PSession returned a null message: msgId=" + msgId + ", size=" + size + ", " + session);
        return;
    }
    I2PDatagramDissector datagramDissector = new I2PDatagramDissector();
    try {
        datagramDissector.loadI2PDatagram(msg);
        // TODO keep this line or remove it?
        datagramDissector.verifySignature();
        byte[] payload = datagramDissector.extractPayload();
        Destination sender = datagramDissector.getSender();
        dispatchPacket(payload, sender);
    } catch (DataFormatException e) {
        log.error("Invalid datagram received.", e);
    } catch (I2PInvalidDatagramException e) {
        log.error("Datagram failed verification.", e);
    } catch (Exception e) {
        log.error("Error processing datagram.", e);
    }
}
Also used : Destination(net.i2p.data.Destination) I2PDatagramDissector(net.i2p.client.datagram.I2PDatagramDissector) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException) I2PInvalidDatagramException(net.i2p.client.datagram.I2PInvalidDatagramException) DataFormatException(net.i2p.data.DataFormatException) I2PSessionException(net.i2p.client.I2PSessionException) MalformedPacketException(i2p.bote.packet.MalformedPacketException) I2PInvalidDatagramException(net.i2p.client.datagram.I2PInvalidDatagramException)

Aggregations

I2PInvalidDatagramException (net.i2p.client.datagram.I2PInvalidDatagramException)3 DataFormatException (net.i2p.data.DataFormatException)3 Destination (net.i2p.data.Destination)3 I2PSessionException (net.i2p.client.I2PSessionException)2 I2PDatagramDissector (net.i2p.client.datagram.I2PDatagramDissector)2 MalformedPacketException (i2p.bote.packet.MalformedPacketException)1 IOException (java.io.IOException)1