public FutureBootstrap start() { if (peer.isShutdown()) { return FUTURE_BOOTSTRAP_SHUTDOWN; } if (routingConfiguration == null) { routingConfiguration = new RoutingConfiguration(5, 10, 2); } if (requestP2PConfiguration == null) { int size = peer.getPeerBean().peerMap().size() + 1; requestP2PConfiguration = new RequestP2PConfiguration(Math.min(size, 3), 5, 3); } // if (broadcast) { return broadcast(); } if (peerAddress == null && inetAddress != null && bootstrapTo == null) { peerAddress = new PeerAddress(Number160.ZERO, inetAddress, portTCP, portUDP); return bootstrapPing(peerAddress); } else if (peerAddress != null && bootstrapTo == null) { bootstrapTo = new ArrayList<PeerAddress>(1); bootstrapTo.add(peerAddress); return bootstrap(); } else if (bootstrapTo != null) { return bootstrap(); } else { return FUTURE_BOOTSTRAP_NO_ADDRESS; } }
/** * Message passer for sending messages regarding tasks. OBS! Only ONE Passer may be present for a * Peer. * * @param peer This peer * @param client Client to put and get results * @param falseResults * @param pool */ public TaskPasserDeny( Peer peer, NetworkInterface client, Map<String, byte[]> falseResults, ExecutorService pool) { super(peer); this.falseResults = falseResults; this.pool = pool; this.myWorkerID = new WorkerID(peer.getPeerBean().getKeyPair().getPublic()); this.client = client; }
protected void preBuild(String name) { if (domainKey == null) { domainKey = DEFAULT_DOMAIN; } if (routingConfiguration == null) { routingConfiguration = new RoutingConfiguration(5, 10, 2); } if (requestP2PConfiguration == null) { requestP2PConfiguration = new RequestP2PConfiguration(3, 5, 3); } int size = peer.getPeerBean().peerMap().size() + 1; requestP2PConfiguration = requestP2PConfiguration.adjustMinimumResult(size); if (futureChannelCreator == null) { futureChannelCreator = peer.getConnectionBean() .reservation() .create(routingConfiguration, requestP2PConfiguration, this); } }
public static void startClient(String ipAddress) throws Exception { Random rnd = new Random(42L); Bindings b = new Bindings(Protocol.IPv4, Inet4Address.getByName("127.0.0.1"), 4001, 4001); // b.addInterface("eth0"); Peer client = new PeerMaker(new Number160(rnd)).setPorts(4001).setBindings(b).makeAndListen(); System.out.println( "Client started and Listening to: " + DiscoverNetworks.discoverInterfaces(b)); System.out.println("address visible to outside is " + client.getPeerAddress()); InetAddress address = Inet4Address.getByName(ipAddress); int masterPort = 4000; PeerAddress pa = new PeerAddress(Number160.ZERO, address, masterPort, masterPort); System.out.println("PeerAddress: " + pa); // Creates a connetion before we discover // client.createPeerConnection(pa, 10000); // Future Discover FutureDiscover futureDiscover = client.discover().setInetAddress(address).setPorts(masterPort).start(); futureDiscover.awaitUninterruptibly(); // Future Bootstrap - slave FutureBootstrap futureBootstrap = client.bootstrap().setInetAddress(address).setPorts(masterPort).start(); futureBootstrap.awaitUninterruptibly(); Collection<PeerAddress> addressList = client.getPeerBean().getPeerMap().getAll(); System.out.println(addressList.size()); if (futureDiscover.isSuccess()) { System.out.println("found that my outside address is " + futureDiscover.getPeerAddress()); } else { System.out.println("failed " + futureDiscover.getFailedReason()); } client.halt(); // Future Bootstrap - master // futureBootstrap = master.bootstrap(masterPA); // futureBootstrap.awaitUninterruptibly(); }
public static void startServer() throws Exception { Random rnd = new Random(43L); Bindings b = new Bindings(Protocol.IPv4, Inet4Address.getByName("127.0.0.1"), 4000, 4000); // b.addInterface("eth0"); Peer master = new PeerMaker(new Number160(rnd)).setPorts(4000).setBindings(b).makeAndListen(); System.out.println("Server started Listening to: " + DiscoverNetworks.discoverInterfaces(b)); System.out.println("address visible to outside is " + master.getPeerAddress()); while (true) { for (PeerAddress pa : master.getPeerBean().getPeerMap().getAll()) { System.out.println("PeerAddress: " + pa); FutureChannelCreator fcc = master.getConnectionBean().getConnectionReservation().reserve(1); fcc.awaitUninterruptibly(); ChannelCreator cc = fcc.getChannelCreator(); // FutureResponse fr1 = master.getHandshakeRPC().pingTCP(pa, cc); // fr1.awaitUninterruptibly(); // if (fr1.isSuccess()) // System.out.println("peer online T:" + pa); // else // System.out.println("offline " + pa); // FutureResponse fr2 = master.getHandshakeRPC().pingUDP(pa, cc); // fr2.awaitUninterruptibly(); master.getConnectionBean().getConnectionReservation().release(cc); // if (fr2.isSuccess()) // System.out.println("peer online U:" + pa); // else // System.out.println("offline " + pa); } Thread.sleep(1500); } }