PeerAddress implements Comparable<PeerAddress>, Serializable { public byte[] toByteArray() { byte[] me = new byte[size]; toByteArray(me, 0); return me; } PeerAddress(final byte[] me);  PeerAddress(final byte[] me, final int initialOffset);  PeerAddress(final ByteBuf channelBuffer);  PeerAddress(final Number160 id);  PeerAddress(final Number160 id, final InetAddress address);  PeerAddress(final Number160 id, final PeerSocketAddress peerSocketAddress,
            final boolean firewalledTCP, final boolean firewalledUDP, final boolean isRelayed,
            boolean isSlow, boolean portForwarding, final Collection<PeerSocketAddress> peerSocketAddresses);  PeerAddress(final Number160 peerId, final InetAddress inetAddress, final int tcpPort,
            final int udpPort);  PeerAddress(final Number160 id, final InetAddress inetAddress, final int tcpPort,
            final int udpPort, final int options);  PeerAddress(final Number160 id, final String address, final int tcpPort, final int udpPort);  PeerAddress(final Number160 id, final InetSocketAddress inetSocketAddress); int offset(); int size(); byte[] toByteArray(); int toByteArray(final byte[] me, final int offset); PeerSocketAddress peerSocketAddress(); InetAddress inetAddress(); InetSocketAddress createSocketTCP(); InetSocketAddress createSocketUDP(); InetSocketAddress createSocketUDP(int port); Number160 peerId(); byte options(); byte relays(); @Override String toString(); @Override int compareTo(final PeerAddress nodeAddress); @Override boolean equals(final Object obj); @Override int hashCode(); int udpPort(); int tcpPort(); boolean isFirewalledUDP(); boolean isFirewalledTCP(); boolean isIPv6(); boolean isIPv4(); boolean isRelayed(); boolean isSlow(); boolean isPortForwarding(); PeerAddress changeRelayed(final boolean isRelayed); PeerAddress changeSlow(final boolean isSlow); PeerAddress changePortForwarding(final boolean portForwarding); PeerAddress changeFirewalledUDP(final boolean firewalledUDP); PeerAddress changeFirewalledTCP(final boolean firewalledTCP); PeerAddress changePorts(final int tcpPort, final int udpPort); PeerAddress changeAddress(final InetAddress inetAddress); PeerAddress changePeerId(final Number160 peerId); PeerAddress changePeerSocketAddresses(Collection<PeerSocketAddress> peerSocketAddresses); PeerAddress changePeerSocketAddress(PeerSocketAddress peerSocketAddress); Collection<PeerSocketAddress> peerSocketAddresses(); static int size(final int header); static int size(final int options, final int relays); int relaySize(); PeerSocketAddress internalPeerSocketAddress(); PeerAddress internalPeerSocketAddress(PeerSocketAddress internalPeerSocketAddress); static final int MAX_SIZE; static final int MIN_SIZE; static final Collection<PeerSocketAddress> EMPTY_PEER_SOCKET_ADDRESSES; }
@Test public void testPeerAddress2() throws UnknownHostException { Number160 id = new Number160("0x657435a424444522456"); InetAddress address = InetAddress.getByName("192.168.240.230"); int portTCP = RND.nextInt(BIT_16); int portUDP = RND.nextInt(BIT_16); PeerAddress pa = new PeerAddress(id, address, portTCP, portUDP); byte[] me = pa.toByteArray(); PeerAddress pa2 = new PeerAddress(me); compare(pa, pa2); }
@Test public void testPeerAddress5() throws UnknownHostException { Collection<PeerSocketAddress> psa = new ArrayList<PeerSocketAddress>(); psa.add(new PeerSocketAddress(InetAddress.getByName("192.168.230.230"), RND.nextInt(BIT_16), RND.nextInt(BIT_16))); psa.add(new PeerSocketAddress(InetAddress.getByName("2123:4567:89ab:cdef:0123:4567:89ab:cde2"), RND.nextInt(BIT_16), RND.nextInt(BIT_16))); psa.add(new PeerSocketAddress(InetAddress.getByName("192.168.230.231"), RND.nextInt(BIT_16), 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); final int length = 200; byte[] me = new byte[length]; final int offset = 50; pa3.toByteArray(me, offset); PeerAddress pa4 = new PeerAddress(me, offset); compare(pa3, pa4); }
@Test public void testPeerAddress7() throws UnknownHostException { Collection<PeerSocketAddress> psa = new ArrayList<PeerSocketAddress>(); psa.add(new PeerSocketAddress(InetAddress.getByName("1123:4567:89ab:cdef:0123:4567:89ab:cde1"), RND.nextInt(BIT_16), RND.nextInt(BIT_16))); psa.add(new PeerSocketAddress(InetAddress.getByName("2123:4567:89ab:cdef:0123:4567:89ab:cde2"), RND.nextInt(BIT_16), RND.nextInt(BIT_16))); psa.add(new PeerSocketAddress(InetAddress.getByName("3123:4567:89ab:cdef:0123:4567:89ab:cde3"), RND.nextInt(BIT_16), 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("5123:4567:89ab:cdef:0123:4567:89ab:cde5"), RND.nextInt(BIT_16), RND.nextInt(BIT_16))); PeerAddress pa3 = new PeerAddress(new Number160("0x657435a424444522456"), new PeerSocketAddress( InetAddress.getByName("1123:4567:89ab:cdef:0123:4567:89ab:cde0"), RND.nextInt(BIT_16), RND.nextInt(BIT_16)), true, true, true, true, true, psa); Assert.assertEquals(142, pa3.toByteArray().length); }