本文整理匯總了Java中lbms.plugins.mldht.kad.messages.GetPeersRequest.isScrape方法的典型用法代碼示例。如果您正苦於以下問題:Java GetPeersRequest.isScrape方法的具體用法?Java GetPeersRequest.isScrape怎麽用?Java GetPeersRequest.isScrape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lbms.plugins.mldht.kad.messages.GetPeersRequest
的用法示例。
在下文中一共展示了GetPeersRequest.isScrape方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPeers
import lbms.plugins.mldht.kad.messages.GetPeersRequest; //導入方法依賴的package包/類
public void getPeers (GetPeersRequest r) {
if (!isRunning()) {
return;
}
// ignore requests we get from ourself
if (node.isLocalId(r.getID())) {
return;
}
BloomFilterBEP33 peerFilter = r.isScrape() ? db.createScrapeFilter(r.getInfoHash(), false) : null;
BloomFilterBEP33 seedFilter = r.isScrape() ? db.createScrapeFilter(r.getInfoHash(), true) : null;
boolean v6 = Inet6Address.class.isAssignableFrom(type.PREFERRED_ADDRESS_TYPE);
boolean heavyWeight = peerFilter != null;
int valuesTargetLength = v6 ? 35 : 50;
// scrape filter gobble up a lot of space, restrict list sizes
if(heavyWeight)
valuesTargetLength = v6 ? 15 : 30;
List<DBItem> dbl = db.sample(r.getInfoHash(), valuesTargetLength,type, r.isNoSeeds());
for(DHTIndexingListener listener : indexingListeners)
{
List<PeerAddressDBItem> toAdd = listener.incomingPeersRequest(r.getInfoHash(), r.getOrigin().getAddress(), r.getID());
if(dbl == null && !toAdd.isEmpty())
dbl = new ArrayList<>();
if(dbl != null && !toAdd.isEmpty())
dbl.addAll(toAdd);
}
// generate a token
ByteWrapper token = null;
if(db.insertForKeyAllowed(r.getInfoHash()))
token = db.genToken(r.getID(), r.getOrigin().getAddress(), r.getOrigin().getPort(), r.getInfoHash());
int want4 = r.doesWant4() ? DHTConstants.MAX_ENTRIES_PER_BUCKET : 0;
int want6 = r.doesWant6() ? DHTConstants.MAX_ENTRIES_PER_BUCKET : 0;
if(v6 && peerFilter != null)
want6 = Math.min(5, want6);
// only fulfill both wants if we have neither filters nor values to send
if(heavyWeight || dbl != null) {
if(v6)
want4 = 0;
else
want6 = 0;
}
GetPeersResponse resp = new GetPeersResponse(r.getMTID());
populateResponse(r.getTarget(), resp, want4, want6);
resp.setToken(token != null ? token.arr : null);
resp.setScrapePeers(peerFilter);
resp.setScrapeSeeds(seedFilter);
resp.setPeerItems(dbl);
resp.setDestination(r.getOrigin());
r.getServer().sendMessage(resp);
node.recieved(r);
}