本文整理汇总了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);
}