Search in sources :

Example 1 with MalformedPacketException

use of i2p.bote.packet.MalformedPacketException in project i2p.i2p-bote by i2p.

the class I2PPacketDispatcher method dispatchPacket.

/**
 * Creates a packet from a byte array and fires listeners.
 * @param packetData
 * @param sender
 */
private void dispatchPacket(byte[] packetData, Destination sender) {
    CommunicationPacket packet;
    try {
        packet = CommunicationPacket.createPacket(packetData);
        logPacket(packet, sender);
        firePacketReceivedEvent(packet, sender);
    } catch (MalformedPacketException e) {
        log.warn("Ignoring unparseable packet.", e);
        firePacketReceivedEvent(new MalformedCommunicationPacket(), sender);
    }
}
Also used : CommunicationPacket(i2p.bote.packet.CommunicationPacket) MalformedCommunicationPacket(i2p.bote.packet.MalformedCommunicationPacket) MalformedPacketException(i2p.bote.packet.MalformedPacketException) MalformedCommunicationPacket(i2p.bote.packet.MalformedCommunicationPacket)

Example 2 with MalformedPacketException

use of i2p.bote.packet.MalformedPacketException in project i2p.i2p-bote by i2p.

the class RelayPacketHandler method packetReceived.

@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
    if (packet instanceof RelayRequest && dht.isReady()) {
        RelayRequest relayRequest = (RelayRequest) packet;
        CommunicationPacket payload;
        try {
            payload = relayRequest.getStoredPacket(i2pSession);
        } catch (DataFormatException e) {
            log.error("Invalid RelayRequest received from peer " + Util.toBase32(sender), e);
            return;
        } catch (MalformedPacketException e) {
            log.error("Invalid RelayRequest received from peer " + Util.toBase32(sender), e);
            return;
        }
        log.debug("Received a relay request, payload: " + payload);
        if (payload instanceof RelayRequest) {
            log.debug("Relay packet is of type " + payload.getClass().getSimpleName() + ", storing it in the relay packet folder.");
            relayPacketFolder.add((RelayRequest) payload);
            confirm(sender, relayRequest);
        } else if (payload instanceof StoreRequest) {
            log.debug("Relay packet is of type " + payload.getClass().getSimpleName() + ", storing it in the DHT.");
            final DhtStorablePacket dhtPacket = ((StoreRequest) payload).getPacketToStore();
            // do dht.store() in a separate thread so we don't block the notifier thread
            dhtTaskExecutor.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        dht.store(dhtPacket);
                        log.debug("Finished storing DHT packet: " + dhtPacket);
                    } catch (InterruptedException e) {
                        log.debug("Interrupted while storing packet in the DHT.");
                    } catch (DhtException e) {
                        log.error("Error storing packet in the DHT: " + dhtPacket, e);
                    }
                }
            });
            confirm(sender, relayRequest);
        } else
            log.error("Don't know how to handle relay packet of type " + payload.getClass());
    }
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) DataFormatException(net.i2p.data.DataFormatException) StoreRequest(i2p.bote.packet.dht.StoreRequest) CommunicationPacket(i2p.bote.packet.CommunicationPacket) MalformedPacketException(i2p.bote.packet.MalformedPacketException) RelayRequest(i2p.bote.packet.relay.RelayRequest)

Aggregations

CommunicationPacket (i2p.bote.packet.CommunicationPacket)2 MalformedPacketException (i2p.bote.packet.MalformedPacketException)2 MalformedCommunicationPacket (i2p.bote.packet.MalformedCommunicationPacket)1 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)1 StoreRequest (i2p.bote.packet.dht.StoreRequest)1 RelayRequest (i2p.bote.packet.relay.RelayRequest)1 DataFormatException (net.i2p.data.DataFormatException)1