Search in sources :

Example 1 with ResponsePacket

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

the class I2PSendQueue method packetReceived.

// Implementation of PacketListener
@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
    if (packet instanceof ResponsePacket) {
        UniqueId packetId = packet.getPacketId();
        for (PacketBatch batch : runningBatches) if (batch.contains(packetId)) {
            DataPacket payload = ((ResponsePacket) packet).getPayload();
            if (payload != null)
                batch.addResponse(sender, payload);
            else
                batch.addResponse(sender, new EmptyResponse());
        }
    }
}
Also used : UniqueId(i2p.bote.UniqueId) ResponsePacket(i2p.bote.packet.ResponsePacket) DataPacket(i2p.bote.packet.DataPacket) EmptyResponse(i2p.bote.packet.EmptyResponse)

Example 2 with ResponsePacket

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

the class KademliaDHT method packetReceived.

// PacketListener implementation
@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
    if (packet instanceof FindClosePeersPacket)
        sendPeerList((FindClosePeersPacket) packet, sender);
    else if (packet instanceof StoreRequest) {
        DhtStorablePacket packetToStore = ((StoreRequest) packet).getPacketToStore();
        storeLocally(packetToStore, sender);
    } else if (packet instanceof RetrieveRequest) {
        RetrieveRequest retrieveRequest = (RetrieveRequest) packet;
        DhtStorageHandler storageHandler = storageHandlers.get(retrieveRequest.getDataType());
        if (storageHandler != null) {
            DhtStorablePacket storedPacket = storageHandler.retrieve(retrieveRequest.getKey());
            // if requested packet found, send it to the requester
            Collection<ResponsePacket> response = ResponsePacket.create(storedPacket, StatusCode.OK, retrieveRequest.getPacketId());
            if (storedPacket != null)
                log.debug("Packet found for retrieve request: [" + retrieveRequest + "], replying to sender: [" + Util.toBase32(sender) + "]");
            else
                log.debug("No matching packet found for retrieve request: [" + retrieveRequest + "]");
            sendQueue.send(response, sender);
        } else
            log.warn("No storage handler found for type " + packet.getClass().getSimpleName() + ".");
    } else if (packet instanceof DeleteRequest) {
        DeleteRequest delRequest = (DeleteRequest) packet;
        DhtStorageHandler storageHandler = storageHandlers.get(delRequest.getDataType());
        if (storageHandler instanceof DeletionAwareDhtFolder<?>)
            ((DeletionAwareDhtFolder<?>) storageHandler).process(delRequest);
    } else if (packet instanceof DeletionQuery) {
        DhtStorageHandler storageHandler = storageHandlers.get(EncryptedEmailPacket.class);
        if (storageHandler instanceof DeletionAwareDhtFolder) {
            Hash dhtKey = ((DeletionQuery) packet).getDhtKey();
            UniqueId delAuthorization = ((DeletionAwareDhtFolder<?>) storageHandler).getDeleteAuthorization(dhtKey);
            // If we know the Delete Authorization for the DHT key, send it to the peer
            if (delAuthorization != null) {
                DeletionInfoPacket delInfo = new DeletionInfoPacket();
                delInfo.put(dhtKey, delAuthorization);
                Collection<ResponsePacket> response = ResponsePacket.create(delInfo, StatusCode.OK, packet.getPacketId());
                sendQueue.send(response, sender);
            }
        }
    }
    // bucketManager is not registered as a PacketListener, so notify it here
    bucketManager.packetReceived(packet, sender, receiveTime);
}
Also used : DhtStorablePacket(i2p.bote.packet.dht.DhtStorablePacket) RetrieveRequest(i2p.bote.packet.dht.RetrieveRequest) UniqueId(i2p.bote.UniqueId) StoreRequest(i2p.bote.packet.dht.StoreRequest) Hash(net.i2p.data.Hash) FindClosePeersPacket(i2p.bote.packet.dht.FindClosePeersPacket) DeletionAwareDhtFolder(i2p.bote.folder.DeletionAwareDhtFolder) DeletionQuery(i2p.bote.packet.dht.DeletionQuery) DeletionInfoPacket(i2p.bote.packet.dht.DeletionInfoPacket) ResponsePacket(i2p.bote.packet.ResponsePacket) DhtStorageHandler(i2p.bote.network.DhtStorageHandler) DeleteRequest(i2p.bote.packet.dht.DeleteRequest)

Example 3 with ResponsePacket

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

the class RelayPacketSender method packetReceived.

@Override
public void packetReceived(CommunicationPacket packet, Destination sender, long receiveTime) {
    // synchronize access to lastSentPacket (which can be null, so synchronize on "this")
    synchronized (this) {
        if (lastSentPacket != null && packet instanceof ResponsePacket) {
            ResponsePacket responsePacket = (ResponsePacket) packet;
            boolean packetIdMatches = lastSentPacket.getPacketId().equals(responsePacket.getPacketId());
            boolean statusOk = StatusCode.OK == responsePacket.getStatusCode();
            if (packetIdMatches && statusOk)
                confirmationReceived.countDown();
        }
    }
}
Also used : ResponsePacket(i2p.bote.packet.ResponsePacket)

Aggregations

ResponsePacket (i2p.bote.packet.ResponsePacket)3 UniqueId (i2p.bote.UniqueId)2 DeletionAwareDhtFolder (i2p.bote.folder.DeletionAwareDhtFolder)1 DhtStorageHandler (i2p.bote.network.DhtStorageHandler)1 DataPacket (i2p.bote.packet.DataPacket)1 EmptyResponse (i2p.bote.packet.EmptyResponse)1 DeleteRequest (i2p.bote.packet.dht.DeleteRequest)1 DeletionInfoPacket (i2p.bote.packet.dht.DeletionInfoPacket)1 DeletionQuery (i2p.bote.packet.dht.DeletionQuery)1 DhtStorablePacket (i2p.bote.packet.dht.DhtStorablePacket)1 FindClosePeersPacket (i2p.bote.packet.dht.FindClosePeersPacket)1 RetrieveRequest (i2p.bote.packet.dht.RetrieveRequest)1 StoreRequest (i2p.bote.packet.dht.StoreRequest)1 Hash (net.i2p.data.Hash)1