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


Java PeerBuilderNAT類代碼示例

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


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

示例1: discoverAndBootstrap

import net.tomp2p.nat.PeerBuilderNAT; //導入依賴的package包/類
private void discoverAndBootstrap(InetSocketAddress... bootstrapNodes) throws OverlayException {
	InetSocketAddress theAddress = null;
	FutureDiscover futureDiscover = null;
	PeerNAT pn = null;
	for(InetSocketAddress addr : bootstrapNodes){
		log.info("Discovering and bootstrapping to: {}", addr);
		//loop
		PeerAddress paOrig = peer.peerBean().serverPeerAddress();
		futureDiscover = peer.peer().discover()
				.inetAddress(addr.getAddress())
				.ports(addr.getPort()).start();
		futureDiscover.awaitUninterruptibly();

		if(futureDiscover.isFailed()){
			log.info("NAT or Firewall present, trying UPNP.");
			pn = new PeerBuilderNAT(peer.peer()).start();
			FutureNAT fn = pn.startSetupPortforwarding(futureDiscover);
			fn.awaitUninterruptibly();

			if(fn.isFailed()){
				log.info("UPNP Failed, checking direct port forwarding.");
				peer.peerBean().serverPeerAddress(paOrig);
				futureDiscover = peer.peer().discover()
						.expectManualForwarding()
						.inetAddress(addr.getAddress())
						.ports(addr.getPort()).start();
				futureDiscover.awaitUninterruptibly();
				
			}
			if(fn.isSuccess() || futureDiscover.isSuccess()){
				theAddress = addr;
				break;
			}else{
				log.info("Discovering failed trying next node.");
			}
		}else {
			theAddress = addr;
			break;
		}
	}

	if(theAddress == null){
		setOverlayStatus(2);
		throw new OverlayException("Could not discover to any bootstrap node!");
	}
	//add collection of peer addresses
	FutureBootstrap futureBootstrap = peer.peer().bootstrap()
			.inetAddress(theAddress.getAddress())
			.ports(theAddress.getPort()).start();
	futureBootstrap.awaitUninterruptibly();

	if(futureBootstrap.isFailed()){
		setOverlayStatus(2);
		throw new OverlayException("Could not bootstrap to any bootstrap node!");
	}
	
	log.info("Finished bootsrapping, local address: {}", peer.peerAddress());
	updateUnadaInfo(peer);
	setOverlayStatus(0);
}
 
開發者ID:smartenit-eu,項目名稱:smartenit,代碼行數:61,代碼來源:Overlay.java

示例2: bootstrap

import net.tomp2p.nat.PeerBuilderNAT; //導入依賴的package包/類
private boolean bootstrap(){
	
	
	InetSocketAddress theAddress = null;
	FutureDiscover futureDiscover = null;
	for(InetSocketAddress addr : nodes){
		log.info("Discovering and bootstrapping to: {}", addr);
		//loop
		futureDiscover = peer.peer().discover()
				.expectManualForwarding()
				.inetAddress(addr.getAddress())
				.ports(addr.getPort()).start();
		
		futureDiscover.awaitUninterruptibly();
		if(futureDiscover.isSuccess()){
			theAddress = addr;
			break;
		}
	}
	
	if(theAddress == null){
		log.error("Could not discover with any of the provided nodes.");
		return false;
	}

	PeerNAT pn = new PeerBuilderNAT(peer.peer()).start();
	FutureNAT fn = pn.startSetupPortforwarding(futureDiscover);
	fn.awaitUninterruptibly();

	//add collection of peer addresses
	FutureBootstrap futureBootstrap = peer.peer().bootstrap()
			.inetAddress(theAddress.getAddress())
			.ports(theAddress.getPort()).start();
	futureBootstrap.awaitUninterruptibly();

	if(futureBootstrap.isFailed()){
		log.error("Could not bootstrap to any bootstrap node!");
		return false;
	}

	log.info("Finished bootsrapping, local address: {}", peer.peerAddress());
	return true;
}
 
開發者ID:smartenit-eu,項目名稱:smartenit,代碼行數:44,代碼來源:Main.java

示例3: connectNode

import net.tomp2p.nat.PeerBuilderNAT; //導入依賴的package包/類
private void connectNode(NetworkConfiguration networkConfig) {
	String bindPort = "auto";
	if (isExpertMode) {
		print("Specify Port to bind this new peer or enter 'auto':");
		bindPort = awaitStringParameter();
	}

	if (!"auto".equalsIgnoreCase(bindPort)) {
		networkConfig.setPort(Integer.parseInt(bindPort));
	}

	if (node.connect(networkConfig)) {

		print("Network connection successfully established.");
		// connect the event bus
		node.getFileManager().subscribeFileEvents(new FileEventListener(node.getFileManager()));

		String address = config.getString("InetAddress");
		if (!"auto".equalsIgnoreCase(address)) {
			try {
				InetAddress inetAddress = InetAddress.getByName(address);
				print("Binding to address " + inetAddress);
				PeerAddress peerAddress = node.getPeer().peerBean().serverPeerAddress().changeAddress(inetAddress);
				node.getPeer().peerBean().serverPeerAddress(peerAddress);
			} catch (UnknownHostException e) {
				print("Cannot resolve address " + address);
			}
		}

		if (config.getBoolean("Relay.enabled")) {
			print("Starting relay functionality");
			String authenticationKey = config.getString("Relay.GCM.api-key");
			long bufferAge = config.getDuration("Relay.GCM.buffer-age-limit", TimeUnit.MILLISECONDS);

			MessageBufferConfiguration bufferConfiguration = new MessageBufferConfiguration().bufferAgeLimit(bufferAge);
			AndroidRelayServerConfig androidServer = new AndroidRelayServerConfig(authenticationKey, 5,
					bufferConfiguration);
			BufferedTCPRelayServerConfig tcpServer = new BufferedTCPRelayServerConfig(bufferConfiguration);

			new PeerBuilderNAT(node.getPeer().peer()).addRelayServerConfiguration(RelayType.ANDROID, androidServer)
					.addRelayServerConfiguration(RelayType.BUFFERED_OPENTCP, tcpServer).start();
		}
		exit();
	} else {
		print("Network connection could not be established.");
	}
}
 
開發者ID:Hive2Hive,項目名稱:Hive2Hive,代碼行數:48,代碼來源:NodeMenu.java


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