Search in sources :

Example 6 with CommunicationPacket

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

the class I2PSendQueue method send.

/**
 * This method actually sends a packet via the router
 */
private void send(ScheduledPacket scheduledPacket) throws InterruptedException {
    CommunicationPacket i2pBotePacket = scheduledPacket.data;
    byte[] bytes = i2pBotePacket.toByteArray();
    PacketBatch batch = scheduledPacket.batch;
    boolean isBatchPacket = batch != null;
    log.debug("Sending " + (isBatchPacket ? "" : "non-") + "batch packet: [" + i2pBotePacket + "] to " + Util.toShortenedBase32(scheduledPacket.destination));
    try {
        sendDatagram(bytes, scheduledPacket.destination);
        // set sentTime, update queue and sentLatch, fire packet listeners
        scheduledPacket.data.setSentTime(System.currentTimeMillis());
        if (isBatchPacket)
            batch.decrementSentLatch();
        scheduledPacket.decrementSentLatch();
    } catch (Exception exc) {
        log.error("Can't send packet.", exc);
        // pause to avoid CPU hogging if the error doesn't go away
        TimeUnit.SECONDS.sleep(1);
    }
}
Also used : CommunicationPacket(i2p.bote.packet.CommunicationPacket) I2PSessionException(net.i2p.client.I2PSessionException)

Aggregations

CommunicationPacket (i2p.bote.packet.CommunicationPacket)6 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 I2PSessionException (net.i2p.client.I2PSessionException)1 DataFormatException (net.i2p.data.DataFormatException)1 Destination (net.i2p.data.Destination)1 Log (net.i2p.util.Log)1 Test (org.junit.Test)1