Package net.tomp2p.peers

Examples of net.tomp2p.peers.PeerAddress


    @Test
    public void sendPingTCPDiscover() throws IOException, InterruptedException {
        Peer sender = null;
        ChannelCreator cc = null;
        try {
            PeerAddress pa = new PeerAddress(Number160.ZERO, Inet4Address.getByName(IP), PORT, PORT);
            sender = new PeerBuilder(new Number160("0x9876")).ports(PORT).enableMaintenance(false)
                    .start();
            PingRPC handshake = new PingRPC(sender.peerBean(), sender.connectionBean());
            FutureChannelCreator fcc = sender.connectionBean().reservation().create(0, 1);
            fcc.awaitUninterruptibly();
View Full Code Here


    @Test
    public void sendPingTCPProbe() throws IOException, InterruptedException {
        Peer sender = null;
        ChannelCreator cc = null;
        try {
            PeerAddress pa = new PeerAddress(Number160.ZERO, Inet4Address.getByName(IP), PORT, PORT);
            sender = new PeerBuilder(new Number160("0x9876")).ports(PORT).enableMaintenance(false)
                    .start();
            PingRPC handshake = new PingRPC(sender.peerBean(), sender.connectionBean());
            FutureChannelCreator fcc = sender.connectionBean().reservation().create(0, 1);
            fcc.awaitUninterruptibly();
View Full Code Here

  }

  public static void startClientNAT(String ip) throws Exception {
    Random r = new Random(43L);
    PeerDHT peer = new PeerBuilderDHT(new PeerBuilder(new Number160(r)).ports(clientPort).behindFirewall().start()).start();
    PeerAddress bootStrapServer = new PeerAddress(Number160.ZERO, InetAddress.getByName(ip), serverPort, serverPort);
    FutureDiscover fd = peer.peer().discover().peerAddress(bootStrapServer).start();
    System.out.println("About to wait...");
    fd.awaitUninterruptibly();
    if (fd.isSuccess()) {
      System.out.println("*** FOUND THAT MY OUTSIDE ADDRESS IS " + fd.peerAddress());
View Full Code Here

            final OperationMapper<K> operation) {
        // final int parallel=min+parallelDiff;
        int active = 0;
        for (int i = 0; i < min + parallelDiff; i++) {
            if (futures.get(i) == null) {
                PeerAddress next = directHit.pollFirst();
                if(next == null) {
                  next = potentialHit.pollFirst();
                }
                if (next != null) {
                    active++;
View Full Code Here

                RND.nextInt(BIT_16)));
        psa.add(new PeerSocketAddress(InetAddress.getByName("4123:4567:89ab:cdef:0123:4567:89ab:cde4"),
                RND.nextInt(BIT_16), RND.nextInt(BIT_16)));
        psa.add(new PeerSocketAddress(InetAddress.getByName("192.168.230.232"), RND.nextInt(BIT_16),
                RND.nextInt(BIT_16)));
        PeerAddress pa3 = new PeerAddress(new Number160("0x657435a424444522456"), new PeerSocketAddress(
                InetAddress.getByName("192.168.230.236"), RND.nextInt(BIT_16), RND.nextInt(BIT_16)), true, true, true, true, false,
                psa);
       
        Message m1 = Utils2.createDummyMessage();
        Collection<PeerAddress> tmp = new ArrayList<PeerAddress>();
View Full Code Here

                RND.nextInt(BIT_16)));
        psa.add(new PeerSocketAddress(InetAddress.getByName("4123:4567:89ab:cdef:0123:4567:89ab:cde4"),
                RND.nextInt(BIT_16), RND.nextInt(BIT_16)));
        psa.add(new PeerSocketAddress(InetAddress.getByName("192.168.230.232"), RND.nextInt(BIT_16),
                RND.nextInt(BIT_16)));
        PeerAddress pa3 = new PeerAddress(new Number160("0x657435a424444522456"), new PeerSocketAddress(
                InetAddress.getByName("192.168.230.236"), RND.nextInt(BIT_16), RND.nextInt(BIT_16)), true, true, true, true, true,
                psa);
       
        Message m1 = Utils2.createDummyMessage();
        Collection<PeerAddress> tmp = new ArrayList<PeerAddress>();
View Full Code Here

  public DispatchHandler associatedHandler(final Message message) {
    if (message == null || !(message.isRequest())) {
      return null;
    }

    PeerAddress recipient = message.recipient();

    // Search for handler, 0 is ping. If we send with peerid = ZERO, then we
    // take the first one we found
    if (recipient.peerId().isZero() && message.command() == RPC.Commands.PING.getNr()) {
      Number160 peerId = peerBeanMaster.serverPeerAddress().peerId();
      return searchHandler(peerId, peerId, RPC.Commands.PING.getNr());
      // else we search for the handler that we are responsible for
    } else {
      DispatchHandler handler = searchHandler(recipient.peerId(), recipient.peerId(), message.command());
      if (handler != null) {
        return handler;
      }

      // if we could not find a handler that we are responsible for, we
      // are most likely a relay. Since we have no id of the relay, we
      // just take the first one.
      Map<Number320, DispatchHandler> map = searchHandler(Integer.valueOf(message.command()));
      for (Map.Entry<Number320, DispatchHandler> entry : map.entrySet()) {
        if (entry.getKey().domainKey().equals(recipient.peerId())) {
          return entry.getValue();
        }
      }
      return null;
    }
View Full Code Here

        if (peer.isShutdown()) {
            return FUTURE_DISCOVER_SHUTDOWN;
        }

        if (peerAddress == null && inetAddress != null) {
            peerAddress = new PeerAddress(Number160.ZERO, inetAddress, portTCP, portUDP);
        }
        if (peerAddress == null) {
            throw new IllegalArgumentException("need peeraddress or inetaddress");
        }
        if (configuration == null) {
View Full Code Here

                configuration);
       
        futureResponseTCP.addListener(new BaseFutureAdapter<FutureResponse>() {
            @Override
            public void operationComplete(FutureResponse future) throws Exception {
                PeerAddress serverAddress = peer.peerBean().serverPeerAddress();
                if (futureResponseTCP.isSuccess()) {
                    Collection<PeerAddress> tmp = futureResponseTCP.responseMessage().neighborsSet(0)
                            .neighbors();
                    futureDiscover.reporter(futureResponseTCP.responseMessage().sender());
                    if (tmp.size() == 1) {
                        PeerAddress seenAs = tmp.iterator().next();
                        LOG.info("I'm seen as {} by peer {}. I see myself as {}",
                                seenAs, peerAddress, peer.peerAddress().inetAddress());
                        if (!peer.peerAddress().inetAddress().equals(seenAs.inetAddress())) {
                            // check if we have this interface in that we can
                            // listen to
                            Bindings bindings2 = new Bindings().addAddress(seenAs.inetAddress());
                         
                            DiscoverResults discoverResults = DiscoverNetworks.discoverInterfaces(bindings2);
                            String status = discoverResults.status();
                            LOG.info("2nd interface discovery: {}", status);
                            if (discoverResults.newAddresses().size() > 0
                                    && discoverResults.newAddresses().contains(seenAs.inetAddress())) {
                                serverAddress = serverAddress.changeAddress(seenAs.inetAddress());
                                peer.peerBean().serverPeerAddress(serverAddress);
                                LOG.info("we were having the wrong interface, change it to: {}", serverAddress);
                            } else {
                                // now we know our internal IP, where we receive
                                // packets
                                final Ports ports = peer.connectionBean().channelServer().channelServerConfiguration().portsForwarding();
                                if (ports.isManualPort()) {
                                  final PeerAddress serverAddressOrig = serverAddress;
                                    serverAddress = serverAddress.changePorts(ports.tcpPort(),
                                            ports.udpPort());
                                    serverAddress = serverAddress.changeAddress(seenAs.inetAddress());
                                    //manual port forwarding detected, set flag
                                    serverAddress = serverAddress.changePortForwarding(true);
                                    peer.peerBean().serverPeerAddress(serverAddress);
                                    peer.peerBean().serverPeerAddress().internalPeerSocketAddress(serverAddressOrig.peerSocketAddress());
                                    LOG.info("manual ports, change it to: {}", serverAddress);
                                } else {
                                    // we need to find a relay, because there is a NAT in the way.
                                  // we cannot use futureResponseTCP.responseMessage().recipient() as this may return also IPv6 addresses
                                    futureDiscover
View Full Code Here

                @Override
                public void operationComplete(FutureChannelCreator future) throws Exception {
                    if (future.isSuccess()) {
                        addPingListener(futurePing, futureLateJoin);
                        for (InetAddress broadcastAddress: discoverResults.existingBroadcastAddresses()) {
                            final PeerAddress peerAddress = new PeerAddress(Number160.ZERO, broadcastAddress,
                                    port, port);
                            FutureResponse validBroadcast = peer.pingRPC().pingBroadcastUDP(
                                    peerAddress, future.channelCreator(), connectionConfiguration);
                            if (!futureLateJoin.add(validBroadcast)) {
                                // the latejoin future is fininshed if the add returns false
View Full Code Here

TOP

Related Classes of net.tomp2p.peers.PeerAddress

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.