Package net.tomp2p.peers

Examples of net.tomp2p.peers.PeerSocketAddress


   * @return rconMessage
   */
  private static Message createRconMessage(final Message message) {
    // get Relay InetAddress from unreachable peer
    Object[] relayInetAdresses = message.recipient().peerSocketAddresses().toArray();
    PeerSocketAddress socketAddress = null;
    if (relayInetAdresses.length > 0) {
      // we should be fair and choose one of the relays randomly
      socketAddress = (PeerSocketAddress) relayInetAdresses[Utils.randomPositiveInt(relayInetAdresses.length)];
    } else {
      throw new IllegalArgumentException(
              "There are no PeerSocketAdresses available for this relayed Peer. This should not be possible!");
    }
    // we need to make a copy of the original message
    Message rconMessage = new Message();
    rconMessage.sender(message.sender());
    rconMessage.version(message.version());
    // store the message id in the payload to get the cached message later
    rconMessage.intValue(message.messageId());
    // the message must have set the keepAlive Flag true. If not, the relay
    // peer will close the PeerConnection to the unreachable peer.
    rconMessage.keepAlive(true);
    // making the message ready to send
    PeerAddress recipient = message.recipient().changeAddress(socketAddress.inetAddress())
            .changePorts(socketAddress.tcpPort(), socketAddress.udpPort()).changeRelayed(false);
    rconMessage.recipient(recipient);
    rconMessage.command(RPC.Commands.RCON.getNr());
    rconMessage.type(Message.Type.REQUEST_1);
    return rconMessage;
  }
View Full Code Here


          break;
        case RELAY:
          List<PeerSocketAddress> psa = new ArrayList<>(message.recipient().peerSocketAddresses());
          LOG.debug("send neighbor request to random relay peer {}", psa);
          if (psa.size() > 0) {
            PeerSocketAddress ps = psa.get(random.nextInt(psa.size()));
            message.recipientRelay(message.recipient().changePeerSocketAddress(ps).changeRelayed(true));
            channelFuture = channelCreator.createUDP(broadcast, handlers, futureResponse);
          } else {
            futureResponse.failed("Peer is relayed, but no relay given");
            return;
View Full Code Here

    }
   
    public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender,
            int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
        InetAddress inetSend = InetAddress.getByName(inetSender);
        PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
        PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
                PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
        return n1;
    }
View Full Code Here

  public void testEncodeDecodeRelayedMessage() throws InvalidKeyException, SignatureException, IOException, NoSuchAlgorithmException,
      InvalidKeySpecException {
    Message message = UtilsNAT.createRandomMessage();

    List<PeerSocketAddress> relays = new ArrayList<PeerSocketAddress>();
    relays.add(new PeerSocketAddress(InetAddress.getLocalHost(), 8000, 9000));
    relays.add(new PeerSocketAddress(InetAddress.getLocalHost(), 8001, 9001));
    relays.add(new PeerSocketAddress(InetAddress.getLocalHost(), 8002, 9002));

    PeerAddress sender = UtilsNAT.createAddress().changeRelayed(true).changePeerSocketAddresses(relays)
        .changeFirewalledTCP(true).changeFirewalledUDP(true);
    message.sender(sender);
    message.senderSocket(sender.createSocketTCP());
View Full Code Here

    Collection<PeerSocketAddress> socketAddresses = new ArrayList<PeerSocketAddress>(relays.size());
    synchronized (relays) {
      for (BaseRelayConnection relay : relays) {
        PeerAddress pa = relay.relayAddress();
        socketAddresses.add(new PeerSocketAddress(pa.inetAddress(), pa.tcpPort(), pa.udpPort()));
      }
    }

    // update firewalled and isRelayed flags
    PeerAddress newAddress = peer.peerAddress().changeFirewalledTCP(!hasRelays).changeFirewalledUDP(!hasRelays)
View Full Code Here

    // always keep the connection open
    envelope.keepAlive(true);

    // this will be read RelayRPC.handlePiggyBackMessage
    Collection<PeerSocketAddress> peerSocketAddresses = new ArrayList<PeerSocketAddress>(1);
    peerSocketAddresses.add(new PeerSocketAddress(message.sender().inetAddress(), 0, 0));
    envelope.peerSocketAddresses(peerSocketAddresses);
   
    // holds the message that will be returned to he requester
    final FutureDone<Message> futureDone = new FutureDone<Message>();
View Full Code Here

    }

    public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender,
            int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
        InetAddress inetSend = InetAddress.getByName(inetSender);
        PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
        PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
            PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
        return n1;
    }
View Full Code Here

    }

    public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender,
            int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
        InetAddress inetSend = InetAddress.getByName(inetSender);
        PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
        PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
                PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
        return n1;
    }
View Full Code Here

    }

    public static PeerAddress createAddress(Number160 idSender, String inetSender, int tcpPortSender,
            int udpPortSender, boolean firewallUDP, boolean firewallTCP) throws UnknownHostException {
        InetAddress inetSend = InetAddress.getByName(inetSender);
        PeerSocketAddress peerSocketAddress = new PeerSocketAddress(inetSend, tcpPortSender, udpPortSender);
        PeerAddress n1 = new PeerAddress(idSender, peerSocketAddress, firewallTCP, firewallUDP, false, false, false,
                PeerAddress.EMPTY_PEER_SOCKET_ADDRESSES);
        return n1;
    }
View Full Code Here

  @Test
  public void testRelayAddresses1() throws Exception { // encode
    Message m1 = Utils2.createDummyMessage();
    m1.type(Message.Type.NOT_FOUND);
    List<PeerSocketAddress> tmp = new ArrayList<PeerSocketAddress>();
    tmp.add(new PeerSocketAddress(InetAddress.getLocalHost(), 15, 17));
    tmp.add(new PeerSocketAddress(InetAddress.getByName("0:0:0:0:0:0:0:1"), 16, 18));
    m1.peerSocketAddresses(tmp);
    Message m2 = encodeDecode(m1);
    Assert.assertEquals(tmp, m2.peerSocketAddresses());
    compareMessage(m1, m2);
  }
View Full Code Here

TOP

Related Classes of net.tomp2p.peers.PeerSocketAddress

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.