Number160 domainKey = message.key(1);
Collection<PeerAddress> neighbors = getNeighbors(locationKey, NEIGHBOR_SIZE);
if(neighbors == null) {
//return empty neighbor set
Message response = createResponseMessage(message, Type.NOT_FOUND);
response.neighborsSet(new NeighborSet(-1, Collections.<PeerAddress>emptyList()));
responder.response(response);
return;
}
// Create response message and set neighbors
final Message responseMessage = createResponseMessage(message, Type.OK);
LOG.debug("found the following neighbors {}", neighbors);
NeighborSet neighborSet = new NeighborSet(NEIGHBOR_LIMIT, neighbors);
responseMessage.neighborsSet(neighborSet);
// check for fastget, -1 if, no domain provided, so we cannot
// check content length, 0 for content not here , > 0 content here
// int contentLength = -1;
Number160 contentKey = message.key(2);
SimpleBloomFilter<Number160> keyBloomFilter = message.bloomFilter(0);
SimpleBloomFilter<Number160> contentBloomFilter = message.bloomFilter(1);
KeyCollection keyCollection = message.keyCollection(0);
// it is important to set an integer if a value is present
boolean isDigest = message.type() != Type.REQUEST_1;
if (isDigest) {
if (message.type() == Type.REQUEST_2) {
final DigestInfo digestInfo;
if (peerBean().digestStorage() == null) {
//no storage to search
digestInfo = new DigestInfo();
}
else if (contentKey != null && locationKey!=null && domainKey!=null) {
Number320 locationAndDomainKey = new Number320(locationKey, domainKey);
Number640 from = new Number640(locationAndDomainKey, contentKey, Number160.ZERO);
Number640 to = new Number640(locationAndDomainKey, contentKey, Number160.MAX_VALUE);
digestInfo = peerBean().digestStorage().digest(from, to, -1, true);
} else if ((keyBloomFilter != null || contentBloomFilter != null) && locationKey!=null && domainKey!=null) {
Number320 locationAndDomainKey = new Number320(locationKey, domainKey);
digestInfo = peerBean().digestStorage().digest(locationAndDomainKey, keyBloomFilter,
contentBloomFilter, -1, true, true);
} else if (keyCollection!=null && keyCollection.keys().size() == 2) {
Iterator<Number640> iterator = keyCollection.keys().iterator();
Number640 from = iterator.next();
Number640 to = iterator.next();
digestInfo = peerBean().digestStorage().digest(from, to, -1, true);
} else if (locationKey!=null && domainKey!=null){
Number320 locationAndDomainKey = new Number320(locationKey, domainKey);
Number640 from = new Number640(locationAndDomainKey, Number160.ZERO, Number160.ZERO);
Number640 to = new Number640(locationAndDomainKey, Number160.MAX_VALUE, Number160.MAX_VALUE);
digestInfo = peerBean().digestStorage().digest(from, to, -1, true);
} else {
LOG.warn("did not search for anything");
digestInfo = new DigestInfo();
}
responseMessage.intValue(digestInfo.size());
responseMessage.key(digestInfo.keyDigest());
responseMessage.key(digestInfo.contentDigest());
} else if (message.type() == Type.REQUEST_3) {
final DigestInfo digestInfo;
if(peerBean().digestTracker() == null) {
//no tracker to search
digestInfo = new DigestInfo();
} else {
digestInfo = peerBean().digestTracker().digest(locationKey, domainKey, contentKey);
if (digestInfo.size() == 0) {
LOG.debug("No entry found on peer {}", message.recipient());
}
}
responseMessage.intValue(digestInfo.size());
}
else if (message.type() == Type.REQUEST_4) {
synchronized (peerBean().peerStatusListeners()) {
for (PeerStatusListener peerStatusListener : peerBean().peerStatusListeners()) {
peerStatusListener.peerFailed(message.sender(), new PeerException(AbortCause.SHUTDOWN, "shutdown"));