當前位置: 首頁>>代碼示例>>Java>>正文


Java GetPeersRequest類代碼示例

本文整理匯總了Java中lbms.plugins.mldht.kad.messages.GetPeersRequest的典型用法代碼示例。如果您正苦於以下問題:Java GetPeersRequest類的具體用法?Java GetPeersRequest怎麽用?Java GetPeersRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GetPeersRequest類屬於lbms.plugins.mldht.kad.messages包,在下文中一共展示了GetPeersRequest類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: incomingMessage

import lbms.plugins.mldht.kad.messages.GetPeersRequest; //導入依賴的package包/類
void incomingMessage(DHT dht, MessageBase msg) {
	if(msg.getType() != MessageBase.Type.REQ_MSG || msg.getMethod() != MessageBase.Method.GET_PEERS)
		return;
	if(connections.isEmpty())
		return;
	
	GetPeersRequest req = (GetPeersRequest) msg;
	
	StringBuilder b = new StringBuilder();
	Key k = req.getInfoHash();
	String addr = req.getOrigin().getAddress().getHostAddress();
	long now = System.currentTimeMillis();
	
	b.append(now).append('\t').append(k.toString(false)).append('\t').append(addr).append('\n');
	
	ByteBuffer buf = str2buf(b.toString());
	
	connections.forEach(c -> {
		c.add(buf.duplicate());
	});
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:22,代碼來源:Firehose.java

示例2: incomingPacket

import lbms.plugins.mldht.kad.messages.GetPeersRequest; //導入依賴的package包/類
void incomingPacket(DHT dht, MessageBase msg) {
	if(!running)
		return;
	if(msg.getType() != MessageBase.Type.REQ_MSG || msg.getMethod() != Method.GET_PEERS)
		return;
	
	GetPeersRequest req = (GetPeersRequest) msg;
	
	ByteBuffer buf = ByteBuffer.allocate(PEER_LENGTH);
	
	buf.put(req.getTarget().getHash());
	buf.put(req.getOrigin().getAddress().getAddress());
	buf.putShort((short) req.getOrigin().getPort());
	buf.putShort((short) 0);
	buf.flip();
	toSend.add(buf);
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:18,代碼來源:OpentrackerLiveSync.java

示例3: incomingMessage

import lbms.plugins.mldht.kad.messages.GetPeersRequest; //導入依賴的package包/類
void incomingMessage(DHT d, MessageBase m) {
	if(d.getMismatchDetector().isIdInconsistencyExpected(m.getOrigin(), m.getID()))
		return;
	
	if(m instanceof GetPeersRequest) {
		GetPeersRequest gpr = (GetPeersRequest) m;
		
		RPCServer srv = m.getServer();
		
		Key theirID = gpr.getID();
		
		if(d.getNode().isLocalId(theirID))
			return;
		
		Key ourId = srv.getDerivedID();
		Key target = gpr.getInfoHash();

		if(Stream.of(theirID, ourId, target).distinct().count() != 3)
			return;

		int myCloseness = ourId.distance(target).leadingOneBit();
		int theirCloseness = theirID.distance(target).leadingOneBit();
		
		
		if(theirCloseness > myCloseness && theirCloseness - myCloseness >= 8)
			return; // they're looking for something that's significantly closer to their own ID than we are
		process(gpr.getInfoHash(), theirID, gpr.getOrigin(), null);
	}
	if(m instanceof AnnounceRequest) {
		AnnounceRequest anr = (AnnounceRequest) m;
		process(anr.getInfoHash(), anr.getID(), anr.getOrigin(), anr.getNameUTF8().orElse(null));
	}
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:34,代碼來源:TorrentDumper.java

示例4: 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;
			}
		}
	}

}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:62,代碼來源:PeerLookupTask.java

示例5: 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);
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:70,代碼來源:DHT.java

示例6: incomingMessage

import lbms.plugins.mldht.kad.messages.GetPeersRequest; //導入依賴的package包/類
private void incomingMessage(DHT dht, MessageBase msg) {
	if(!running)
		return;
	
	if(msg.getType() == Type.REQ_MSG && msg.getMethod() == Method.GET_PEERS)
	{
		GetPeersRequest req = (GetPeersRequest) msg;
		long now = System.currentTimeMillis();
		Key k =	req.getTarget();
		String ipAddr = req.getOrigin().getAddress().getHostAddress();
		String key = k.toString(false);
		
		StringBuilder b = new StringBuilder();
		
		
		
		// zadd <hash> <timestamp> <ip>
		b.append("*4\r\n");

		b.append("$4\r\n");
		b.append("ZADD\r\n");

		b.append("$40\r\n");
		b.append(key).append("\r\n");
		
		String intAsString = Long.toString(now);
		b.append('$').append(intAsString.length()).append("\r\n");
		b.append(intAsString).append("\r\n");

		b.append('$').append(ipAddr.length()).append("\r\n");
		b.append(ipAddr).append("\r\n");
		
		// expire <hash> <ttl>
		
		b.append("*3\r\n");
		
		b.append("$6\r\n");
		b.append("EXPIRE\r\n");

		b.append("$40\r\n");
		b.append(key).append("\r\n");
		
		b.append('$').append(TTL.length()).append("\r\n");
		b.append(TTL).append("\r\n");
		
		SocketHandler handler = ensureOpen();

		// to avoid OOM we only fill the queue when we have an open connection
		if(handler.getChannel() != null && handler.getChannel().isConnected()) {
			writeQueue.add(str2buf(b.toString()));
			handler.tryWrite.run();
		}
		
					
	}
}
 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:57,代碼來源:PassiveRedisIndexer.java

示例7: 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());
}
 
開發者ID:Glamdring,項目名稱:scientific-publishing,代碼行數:54,代碼來源:DHTService.java

示例8: getPeers

import lbms.plugins.mldht.kad.messages.GetPeersRequest; //導入依賴的package包/類
public void getPeers (GetPeersRequest r); 
開發者ID:atomashpolskiy,項目名稱:bt,代碼行數:2,代碼來源:DHTBase.java


注:本文中的lbms.plugins.mldht.kad.messages.GetPeersRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。