Search in sources :

Example 1 with HashRequest

use of com.biglybt.core.torrent.TOTorrentFileHashTree.HashRequest in project BiglyBT by BiglySoftware.

the class PEPeerControlHashHandlerImpl method receivedOrRejectedHashes.

private void receivedOrRejectedHashes(PEPeerTransport peer, byte[] root_hash, int base_layer, int index, int length, int proof_layers, // null if rejected
byte[][] hashes) {
    try {
        TOTorrentFileHashTree tree = file_map.get(root_hash);
        if (tree != null) {
            if (hashes != null) {
                tree.receivedHashes(root_hash, base_layer, index, length, proof_layers, hashes);
            }
            List<HashListener> listeners = null;
            synchronized (peer_requests) {
                List<PeerHashRequest> peer_reqs = peer_requests.get(peer);
                if (peer_reqs != null) {
                    Iterator<PeerHashRequest> it = peer_reqs.iterator();
                    PeerHashRequest match = null;
                    while (it.hasNext()) {
                        PeerHashRequest peer_request = it.next();
                        HashRequest req = peer_request.getRequest();
                        if (Arrays.equals(root_hash, req.getRootHash()) && base_layer == req.getBaseLayer() && index == req.getOffset() && length == req.getLength() && proof_layers == req.getProofLayers()) {
                            match = peer_request;
                            it.remove();
                            break;
                        }
                    }
                    if (match != null) {
                        if (peer_reqs.isEmpty()) {
                            peer_requests.remove(peer);
                        }
                        if (!active_requests.remove(match)) {
                            Debug.out("entry not found");
                        }
                        removeFromPieceRequests(match);
                        match.setComplete();
                        listeners = match.getListeners();
                    }
                }
            }
            if (listeners != null) {
                for (HashListener l : listeners) {
                    try {
                        l.complete(hashes != null);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            }
        }
    } catch (Throwable e) {
        Debug.out(e);
    }
}
Also used : TOTorrentFileHashTree(com.biglybt.core.torrent.TOTorrentFileHashTree) HashListener(com.biglybt.core.disk.DiskManagerCheckRequestListener.HashListener) HashRequest(com.biglybt.core.torrent.TOTorrentFileHashTree.HashRequest)

Example 2 with HashRequest

use of com.biglybt.core.torrent.TOTorrentFileHashTree.HashRequest in project BiglyBT by BiglySoftware.

the class PEPeerControlHashHandlerImpl method removeFromPieceRequests.

private void removeFromPieceRequests(PeerHashRequest peer_request) {
    if (active_requests.isEmpty()) {
        piece_requests = null;
    } else {
        HashRequest req = peer_request.getRequest();
        int offset = req.getOffset() + peer_request.getFile().getFirstPieceNumber();
        int pos = offset;
        int end = offset + req.getLength();
        while (pos < end && pos < piece_requests.length) {
            PeerHashRequest[] existing = piece_requests[pos];
            if (existing == null) {
                Debug.out("entry not found");
            } else if (existing.length == 1) {
                if (existing[0] != peer_request) {
                    Debug.out("entry not found");
                } else {
                    piece_requests[pos] = null;
                }
            } else {
                PeerHashRequest[] temp = new PeerHashRequest[existing.length - 1];
                int temp_pos = 0;
                boolean found = false;
                for (PeerHashRequest pr : existing) {
                    if (pr == peer_request) {
                        found = true;
                    } else {
                        if (temp_pos == temp.length) {
                            break;
                        } else {
                            temp[temp_pos++] = pr;
                        }
                    }
                }
                if (found) {
                    piece_requests[pos] = temp;
                } else {
                    Debug.out("entry not found");
                }
            }
            pos++;
        }
    }
}
Also used : HashRequest(com.biglybt.core.torrent.TOTorrentFileHashTree.HashRequest)

Aggregations

HashRequest (com.biglybt.core.torrent.TOTorrentFileHashTree.HashRequest)2 HashListener (com.biglybt.core.disk.DiskManagerCheckRequestListener.HashListener)1 TOTorrentFileHashTree (com.biglybt.core.torrent.TOTorrentFileHashTree)1