best = _rt.findClosest(bi.getHashKey(), exclude);
// If the ttl has run out, there is nowhere to route, or if the next hop is further away in hash-space from
// the data, we download it ourselves.
// TODO: Make this robust against download failure
if ((ttl < 1) || (best == null) || bi.getHashKey().closerTo(_rt.getPeer().getHash(), best.getHash())) {
HttpBlockReceiver hbr = new HttpBlockReceiver(bi, prb);
if (requestor != null) {
new Thread() {
public void run() {
forwardData(requestor, prb, uid, forwarders, false);
/*
* Only add the block to the DS if we didn't request it, this helps to prevent the datastore
* getting "flushed" every time we do a request
*/
try {
_ds.addDataAsBlock(bi.getHashKey(), prb.getBlock());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}.start();
}
hbr.start();
return false;
}
// Ok, we are going to ask another peer for the data, first construct our request
// And send it to our best guess
if (!forwarders.contains(_rt.getPeer())) {