本文整理汇总了Java中lbms.plugins.mldht.kad.messages.GetPeersRequest.setDestination方法的典型用法代码示例。如果您正苦于以下问题:Java GetPeersRequest.setDestination方法的具体用法?Java GetPeersRequest.setDestination怎么用?Java GetPeersRequest.setDestination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lbms.plugins.mldht.kad.messages.GetPeersRequest
的用法示例。
在下文中一共展示了GetPeersRequest.setDestination方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import lbms.plugins.mldht.kad.messages.GetPeersRequest; //导入方法依赖的package包/类
@Override
void update () {
// check if the cache has any closer nodes after the initial query
if(useCache) {
Collection<KBucketEntry> cacheResults = cache.get(targetKey, requestConcurrency());
todo.addCandidates(null, cacheResults);
}
for(;;) {
synchronized (this) {
RequestPermit p = checkFreeSlot();
if(p == RequestPermit.NONE_ALLOWED)
break;
KBucketEntry e = todo.next2(kbe -> {
RequestCandidateEvaluator eval = new RequestCandidateEvaluator(this, closest, todo, kbe, inFlight);
return eval.goodForRequest(p);
}).orElse(null);
if(e == null)
break;
GetPeersRequest gpr = new GetPeersRequest(targetKey);
// we only request cross-seeding on find-node
gpr.setWant4(rpc.getDHT().getType() == DHTtype.IPV4_DHT);
gpr.setWant6(rpc.getDHT().getType() == DHTtype.IPV6_DHT);
gpr.setDestination(e.getAddress());
gpr.setScrape(scrapeHandler != null);
gpr.setNoSeeds(noSeeds);
if(!rpcCall(gpr, e.getID(), call -> {
if(useCache)
call.addListener(cache.getRPCListener());
call.builtFromEntry(e);
long rtt = e.getRTT();
long defaultTimeout = rpc.getTimeoutFilter().getStallTimeout();
if(rtt < DHTConstants.RPC_CALL_TIMEOUT_MAX) {
// the measured RTT is a mean and not the 90th percentile unlike the RPCServer's timeout filter
// -> add some safety margin to account for variance
rtt = (long) (rtt * (rtt < defaultTimeout ? 2 : 1.5));
call.setExpectedRTT(min(rtt, DHTConstants.RPC_CALL_TIMEOUT_MAX));
}
if(DHT.isLogLevelEnabled(LogLevel.Verbose)) {
List<InetSocketAddress> sources = todo.getSources(e).stream().map(KBucketEntry::getAddress).collect(Collectors.toList());
DHT.log("Task "+getTaskID()+" sending call to "+ e + " sources:" + sources, LogLevel.Verbose);
}
todo.addCall(call, e);
})) {
break;
}
}
}
}
示例2: init
import lbms.plugins.mldht.kad.messages.GetPeersRequest; //导入方法依赖的package包/类
public void init() throws Exception {
DHT.setLogLevel(LogLevel.Debug);
initialize();
dht = DHT.getDHT(DHTtype.IPV4_DHT);
dht.addIndexingLinstener(new DHTIndexingListener() {
@Override
public List<PeerAddressDBItem> incomingPeersRequest(Key infoHash, InetAddress sourceAddress, Key nodeID) {
logger.info("Incoming peer request: " + infoHash);
return Collections.emptyList();
}
});
dht.addStatusListener(new DHTStatusListener() {
@Override
public void statusChanged(DHTStatus newStatus, DHTStatus oldStatus) {
logger.info("DHT Status changed: " + newStatus);
}
});
dht.start(getConfiguration(), getServerListener());
Thread.sleep(10000);
logger.info("Servers: " + dht.getServers());
InetSocketAddress peer = null;
System.out.println(dht.getNode().getNumEntriesInRoutingTable());
for (RoutingTableEntry entry : dht.getNode().getBuckets()) {
for (KBucketEntry bucketEntry : entry.getBucket().getEntries()) {
if (bucketEntry.getAddress() != null) {
peer = bucketEntry.getAddress();
}
}
}
dht.getRandomServer().ping(peer);
// TODO how to get response? We are notified in the server listener that there is a response, but not what
// it is
Thread.sleep(10000);
System.out.println("-----sending get peers request-----");
GetPeersRequest request =
new GetPeersRequest(new Key(hexStringToByteArray("64DD3835A88FE9BE6826B4B701AD35177ABD376C")));
request.setID(dht.getRandomServer().getDerivedID());
request.setDestination(peer);
dht.getRandomServer().sendMessage(request);
Thread.sleep(10000);
System.out.println(dht.getRandomServer().getNumReceived());
System.out.println(dht.getNode().getNumEntriesInRoutingTable());
}