Esempio n. 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;
  }