当前位置: 首页>>代码示例>>Java>>正文


Java DHTtype类代码示例

本文整理汇总了Java中lbms.plugins.mldht.kad.DHT.DHTtype的典型用法代码示例。如果您正苦于以下问题:Java DHTtype类的具体用法?Java DHTtype怎么用?Java DHTtype使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DHTtype类属于lbms.plugins.mldht.kad.DHT包,在下文中一共展示了DHTtype类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: PackBucketEntry

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
/**
 * Packs a BucketEntry into the provided buffer.
 *
 * @param e Entry to insert
 * @param buffer must be at least 26bytes per Entry
 * @param off Offset to use
 * @throws IllegalArgumentException if buffer is too small
 */
public static void PackBucketEntry (KBucketEntry e, byte[] buffer, int off, DHTtype type) {
	// first check size
	if (off + type.NODES_ENTRY_LENGTH > buffer.length) {
		throw new IllegalArgumentException("Not enough room in buffer");
	}
	ByteBuffer bb = ByteBuffer.wrap(buffer, off, type.NODES_ENTRY_LENGTH);

	InetSocketAddress addr = e.getAddress();
	if(type == DHTtype.IPV6_DHT && addr.getAddress() instanceof Inet4Address)
		throw new IllegalArgumentException("Attempting to serialize an IPv4 bucket entry into nodes6 buffer");
	// copy ID, IP address and port into the buffer
	bb.put(e.getID().getHash());
	bb.put(addr.getAddress().getAddress());
	//bt::WriteUint32(ptr,20,addr.ipAddress().IPv4Addr());
	bb.putShort((short) addr.getPort());
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:25,代码来源:PackUtil.java

示例2: UnpackBucketEntry

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
/**
 * Unpacks a Entry from a byte array
 *
 * @param buffer byte array with serialized entry
 * @param off the Offset to use
 * @return deserialized Entry
 * @throws IllegalArgumentException if buffer is to small
 */
public static KBucketEntry UnpackBucketEntry (byte[] buffer, int off, DHTtype type) {
	if (off + type.NODES_ENTRY_LENGTH > buffer.length) {
		throw new IllegalArgumentException("Not enough room in buffer");
	}
	ByteBuffer bb = ByteBuffer.wrap(buffer, off, type.NODES_ENTRY_LENGTH);

	byte[] key = new byte[20];
	bb.get(key);

	byte[] inetaddr = new byte[type.NODES_ENTRY_LENGTH - 20 - 2];
	bb.get(inetaddr);

	InetSocketAddress addr = null;
	//UnknownHostException shouldn't occur since IP is provided
	try {

		addr = new InetSocketAddress(InetAddress.getByAddress(inetaddr), Short.toUnsignedInt(bb.getShort()));
	} catch (UnknownHostException e) {
		e.printStackTrace();
		throw new RuntimeException(e);
	}

	return new KBucketEntry(addr, new Key(key), 0);
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:33,代码来源:PackUtil.java

示例3: asNodeList

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
public NodeList asNodeList() {
	return new NodeList() {
		
		@Override
		public int packedSize() {
			return entries.size() * owner.getType().NODES_ENTRY_LENGTH;
		}
		
		@Override
		public Stream<KBucketEntry> entries() {
			return entries.stream();
		}

		@Override
		public AddressType type() {
			return owner.getType() == DHTtype.IPV4_DHT ? AddressType.V4 : AddressType.V6;
		}
	};
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:20,代码来源:KClosestNodesSearch.java

示例4: roundTripPut

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
StorageItem roundTripPut(StorageItem in) throws IOException, MessageException {
	// create message from item
	PutRequest req = new PutRequest();
	req.populateFromStorage(in);
	req.setID(Key.createRandomKey());
	req.setMTID(new byte[4]);
	req.setToken(new byte[4]);

	// encode
	ByteBuffer encoded = ByteBuffer.allocate(1500);
	req.encode(encoded);
	
	// decode
	Map<String, Object> decoded = new BDecoder().decode(encoded.duplicate());
	MessageDecoder decoder = new MessageDecoder(null, DHTtype.IPV4_DHT);
	decoder.toDecode(encoded, decoded);
	PutRequest roundTripped = (PutRequest) decoder.parseMessage();
	
	// re-create item from round-tripped message
	return new StorageItem(roundTripped);
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:22,代码来源:Bep44.java

示例5: MldhtService

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
@Inject
public MldhtService(IRuntimeLifecycleBinder lifecycleBinder, Config config, DHTConfig dhtConfig) {
    this.dht = new DHT(dhtConfig.shouldUseIPv6()? DHTtype.IPV6_DHT : DHTtype.IPV4_DHT);
    this.config = toMldhtConfig(dhtConfig);
    this.localAddress = config.getAcceptorAddress();
    this.useRouterBootstrap = dhtConfig.shouldUseRouterBootstrap();
    this.publicBootstrapNodes = dhtConfig.getPublicBootstrapNodes();
    this.bootstrapNodes = dhtConfig.getBootstrapNodes();

    lifecycleBinder.onStartup(LifecycleBinding.bind(this::start).description("Initialize DHT facilities").async().build());
    lifecycleBinder.onShutdown("Shutdown DHT facilities", this::shutdown);
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:13,代码来源:MldhtService.java

示例6: getInetAddress

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
public InetAddress getInetAddress() {
	try
	{
		if (item.length == DHTtype.IPV4_DHT.ADDRESS_ENTRY_LENGTH)
			return InetAddress.getByAddress(Arrays.copyOf(item, 4));
		if (item.length == DHTtype.IPV6_DHT.ADDRESS_ENTRY_LENGTH)
			return InetAddress.getByAddress(Arrays.copyOf(item, 16));
	} catch (UnknownHostException e)
	{
		// should not happen
		e.printStackTrace();
	}
	
	return null;
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:16,代码来源:PeerAddressDBItem.java

示例7: getAddressType

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
public Class<? extends InetAddress> getAddressType() {
	if(item.length == DHTtype.IPV4_DHT.ADDRESS_ENTRY_LENGTH)
		return DHTtype.IPV4_DHT.PREFERRED_ADDRESS_TYPE;
	if(item.length == DHTtype.IPV6_DHT.ADDRESS_ENTRY_LENGTH)
		return DHTtype.IPV6_DHT.PREFERRED_ADDRESS_TYPE;
	return null;
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:8,代码来源:PeerAddressDBItem.java

示例8: getPort

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
public int getPort() {
	if (item.length == DHTtype.IPV4_DHT.ADDRESS_ENTRY_LENGTH)
		return (item[4] & 0xFF) << 8 | (item[5] & 0xFF);
	if (item.length == DHTtype.IPV6_DHT.ADDRESS_ENTRY_LENGTH)
		return (item[16] & 0xFF) << 8 | (item[17] & 0xFF);
	return 0;
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:8,代码来源:PeerAddressDBItem.java

示例9: update

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
@Override
void update () {
	// go over the todo list and send find node calls
	// until we have nothing left

		while (canDoRequest()) {
			synchronized (todo) {

			KBucketEntry e = todo.stream().findAny().orElse(null);
			if(e == null)
				break;
			
			if (visited.contains(e.getAddress()))
				continue;
			
			// send a findNode to the node
			FindNodeRequest fnr;

			fnr = new FindNodeRequest(Key.createRandomKey());
			fnr.setWant4(rpc.getDHT().getType() == DHTtype.IPV4_DHT);
			fnr.setWant6(rpc.getDHT().getType() == DHTtype.IPV6_DHT);
			fnr.setDestination(e.getAddress());
			rpcCall(fnr,e.getID(), c -> {
				todo.remove(e);
				visited.add(e.getAddress());
			});
		}
	}
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:30,代码来源:KeyspaceCrawler.java

示例10: update

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
@Override
void update () {
	for(;;) {
		// while(!todo.isEmpty() && canDoRequest() && !isClosestSetStable() && !nextTodoUseless())
		RequestPermit p = checkFreeSlot();
		if(p == RequestPermit.NONE_ALLOWED)
			return;
		
		KBucketEntry e = todo.next().orElse(null);
		
		if(e == null)
			return;
		
		if(!new RequestCandidateEvaluator(this, closest, todo, e, inFlight).goodForRequest(p))
			return;
			
		// send a findNode to the node
		FindNodeRequest fnr = new FindNodeRequest(targetKey);
		fnr.setWant4(rpc.getDHT().getType() == DHTtype.IPV4_DHT || rpc.getDHT().getSiblings().stream().anyMatch(sib -> sib.isRunning() && sib.getType() == DHTtype.IPV4_DHT && sib.getNode().getNumEntriesInRoutingTable() < DHTConstants.BOOTSTRAP_IF_LESS_THAN_X_PEERS));
		fnr.setWant6(rpc.getDHT().getType() == DHTtype.IPV6_DHT || rpc.getDHT().getSiblings().stream().anyMatch(sib -> sib.isRunning() && sib.getType() == DHTtype.IPV6_DHT && sib.getNode().getNumEntriesInRoutingTable() < DHTConstants.BOOTSTRAP_IF_LESS_THAN_X_PEERS));
		fnr.setDestination(e.getAddress());
		
		if(!rpcCall(fnr,e.getID(), (call) -> {
			long rtt = e.getRTT();
			rtt = rtt + rtt / 2; // *1.5 since this is the average and not the 90th percentile like the timeout filter
			if(rtt < DHTConstants.RPC_CALL_TIMEOUT_MAX && rtt < rpc.getTimeoutFilter().getStallTimeout())
				call.setExpectedRTT(rtt); // only set a node-specific timeout if it's better than what the server would apply anyway
			call.builtFromEntry(e);
			todo.addCall(call, e);
			
			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);
			}
		})) {
			break;
		}
			
	}
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:41,代码来源:NodeLookup.java

示例11: callFinished

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
@Override
void callFinished (RPCCall c, MessageBase rsp) {

	// check the response and see if it is a good one
	if (rsp.getMethod() != Method.FIND_NODE || rsp.getType() != Type.RSP_MSG)
		return;
	
	KBucketEntry match = todo.acceptResponse(c);
	
	if(match == null)
		return;

	FindNodeResponse fnr = (FindNodeResponse) rsp;
	
	closest.insert(match);
	
	
	for (DHTtype type : DHTtype.values())
	{
		NodeList nodes = fnr.getNodes(type);
		if (nodes == null)
			continue;
		if (type == rpc.getDHT().getType()) {
			Set<KBucketEntry> entries = nodes.entries().filter(e -> !AddressUtils.isBogon(e.getAddress()) && !node.isLocalId(e.getID())).collect(Collectors.toSet());
			todo.addCandidates(match, entries);
		} else {
			rpc.getDHT().getSiblings().stream().filter(sib -> sib.getType() == type).forEach(sib -> {
				nodes.entries().forEach(e -> {
					sib.addDHTNode(e.getAddress().getAddress().getHostAddress(), e.getAddress().getPort());
				});
			});
		}
	}

}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:36,代码来源:NodeLookup.java

示例12: update

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
@Override
void update() {
	for(;;) {
		RequestPermit p = checkFreeSlot();
		if(p == RequestPermit.NONE_ALLOWED)
			return;
		
		KBucketEntry e = todo.next().orElse(null);
		if(e == null)
			return;
		
		if(!new RequestCandidateEvaluator(this, closest, todo, e, inFlight).goodForRequest(p))
			return;
			
		GetRequest r = new GetRequest(targetKey);
		
		r.setWant4(node.getDHT().getType() == DHTtype.IPV4_DHT);
		r.setWant6(node.getDHT().getType() == DHTtype.IPV6_DHT);
		r.setDestination(e.getAddress());
		if(expectedSequence != -1)
			r.setSeq(expectedSequence);
		
		if(!rpcCall(r, e.getID(), c -> {
			c.builtFromEntry(e);
			todo.addCall(c, e);
			int rtt = e.getRTT() * 2;
			if(rtt < DHTConstants.RPC_CALL_TIMEOUT_MAX && rtt < rpc.getTimeoutFilter().getStallTimeout())
				c.setExpectedRTT(rtt);
		})) {
			break;
		}
			
		
		
	}
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:37,代码来源:GetLookupTask.java

示例13: getNodes

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
public NodeList getNodes(DHTtype type)
{
	if(type == DHTtype.IPV4_DHT)
		return nodes;
	if(type == DHTtype.IPV6_DHT)
		return nodes6;
	return null;
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:9,代码来源:AbstractLookupResponse.java

示例14: toString

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
@Override
public String toString() {
	return super.toString() +
		(nodes != null ? "contains: "+ (nodes.packedSize()/DHTtype.IPV4_DHT.NODES_ENTRY_LENGTH) + " nodes " : "") +
		(nodes6 != null ? "contains: "+ (nodes6.packedSize()/DHTtype.IPV6_DHT.NODES_ENTRY_LENGTH) + " nodes6 " : "") +
		(token != null ? "token "+token.length+" | " : "");
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:8,代码来源:AbstractLookupResponse.java

示例15: extractNodes

import lbms.plugins.mldht.kad.DHT.DHTtype; //导入依赖的package包/类
private Optional<NodeList> extractNodes(Map<String, Object> args, String key, DHTtype nodesType) throws MessageException {
	byte[] raw = typedGet(args, key, byte[].class).orElse(null);
	if(raw == null)
		return Optional.empty();
	if(raw.length % nodesType.NODES_ENTRY_LENGTH != 0)
		throw new MessageException("expected "+key+" length to be a multiple of "+nodesType.NODES_ENTRY_LENGTH+", received "+raw.length, ErrorCode.ProtocolError);
	return Optional.of(NodeList.fromBuffer(ByteBuffer.wrap(raw), nodesType == DHTtype.IPV4_DHT ? AddressType.V4 : AddressType.V6));
}
 
开发者ID:atomashpolskiy,项目名称:bt,代码行数:9,代码来源:MessageDecoder.java


注:本文中的lbms.plugins.mldht.kad.DHT.DHTtype类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。