Exemple #1
0
  public Peer createAndAttachRemotePeer() {
    final Peer peer;
    try {
      peer = new PeerMaker(new Number160(rnd)).setPorts(5003).buildAndListen();
    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail();
      return null;
    }
    final FutureBootstrap fb = peer.bootstrapBroadcast(seed.getPeerAddress().portTCP());
    fb.awaitUninterruptibly();
    peer.discover(fb.getBootstrapTo().iterator().next());
    fb.addListener(
        new BaseFutureListener<BaseFuture>() {
          @Override
          public void operationComplete(BaseFuture future) throws Exception {
            Collection<PeerAddress> addresses = fb.getBootstrapTo();
            if (addresses != null && !addresses.isEmpty()) {
              peer.discover(addresses.iterator().next()).awaitUninterruptibly();
            } else {
              Assert.assertTrue("Unable to boostrap to peers in the network", false);
            }
          }

          @Override
          public void exceptionCaught(Throwable t) throws Exception {
            t.fillInStackTrace();
          }
        });
    return peer;
  }
  public P2PClient() throws Exception {

    this.localIP = getLocalPeerIP();
    this.serviceID = "medical";
    this.peerID = Number160.createHash(localIP);
    this.peer = new Peer(peerID);
    this.peer.listen(4000, 4000);
    PeerAddress superAddr = new PeerAddress(Number160.createHash(1), "109.231.77.242", 8888, 8888);
    FutureDiscover future = this.peer.discover(superAddr);
    future.awaitUninterruptibly();
    FutureBootstrap fb = this.peer.bootstrap(superAddr);
    fb.awaitUninterruptibly();
    peer.discover(fb.getBootstrapTo().iterator().next()).awaitUninterruptibly();
  }