예제 #1
0
  private FutureBootstrap bootstrap() {
    final FutureWrappedBootstrap<FutureDone<Pair<FutureRouting, FutureRouting>>> result =
        new FutureWrappedBootstrap<FutureDone<Pair<FutureRouting, FutureRouting>>>();
    result.setBootstrapTo(bootstrapTo);
    int conn = Math.max(routingConfiguration.getParallel(), requestP2PConfiguration.getParallel());
    FutureChannelCreator fcc = peer.getConnectionBean().reservation().create(conn, 0);

    fcc.addListener(
        new BaseFutureAdapter<FutureChannelCreator>() {
          @Override
          public void operationComplete(final FutureChannelCreator futureChannelCreator)
              throws Exception {
            if (futureChannelCreator.isSuccess()) {
              RoutingBuilder routingBuilder =
                  createBuilder(requestP2PConfiguration, routingConfiguration);
              FutureDone<Pair<FutureRouting, FutureRouting>> futureBootstrap =
                  peer.getDistributedRouting()
                      .bootstrap(
                          bootstrapTo, routingBuilder, futureChannelCreator.getChannelCreator());
              Utils.addReleaseListener(futureChannelCreator.getChannelCreator(), futureBootstrap);
              result.waitFor(futureBootstrap);
            } else {
              result.setFailed(futureChannelCreator);
            }
          }
        });
    return result;
  }
예제 #2
0
  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);
    }
  }
예제 #3
0
 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);
   }
 }