本文整理匯總了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);
}
示例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;
}
示例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.");
}
}