public Endpoint endpoint() { checkNotNull( port, "Must either pass port to ctor, or call createNetwork() first to set the port"); return new Endpoint( InetAddress.getLoopbackAddress().getHostAddress(), port, OptionalInt.of(port)); }
private Peer mockPeer() { final Peer peer = mock(Peer.class); final BytesValue id = SECP256K1.KeyPair.generate().getPublicKey().getEncodedBytes(); when(peer.getId()).thenReturn(id); when(peer.getEndpoint()).thenReturn(new Endpoint("127.0.0.1", 30303, OptionalInt.of(30303))); return peer; } }
@Test public void shouldDecodeValidPongPacket() { final Packet packet = decode(VALID_PONG_PACKET); final PongPacketData packetData = packet.getPacketData(PongPacketData.class).get(); assertThat(packet.getType()).isSameAs(PacketType.PONG); assertThat(packetData.getTo()) .isEqualTo(new Endpoint("180.181.122.26", 1025, OptionalInt.of(30303))); assertThat(packetData.getPingHash()) .isEqualTo( BytesValue.fromHexString( "0x46896547d3b4259aa1a67bd26e7ec58ab4be650c5552ef0360caf9dae489d53b")); assertThat(packetData.getExpiration()).isEqualTo(1535585736); assertThat(packet.getNodeId()) .isEqualTo( BytesValue.fromHexString( "0x669f45b66acf3b804c26ce13cfdd1f7e3d0ff4ed85060841b9af3af6dbfbacd05181e1c9363161446a307f3ca24e707856a01e4bf1eed5e1aefc14011a5c1c1c")); assertThat(packet.getHash()) .isEqualTo( BytesValue.fromHexString( "0xa1581c1705e744976d0341011c4490b3ab0b48283407ae5cf7526b9487174896")); }
private List<DiscoveryPeer> createPeersInLastBucket(final Peer host, final int n) { final List<DiscoveryPeer> newPeers = new ArrayList<DiscoveryPeer>(n); // Flipping the most significant bit of the keccak256 will place the peer // in the last bucket for the corresponding host peer. final Bytes32 keccak256 = host.keccak256(); final MutableBytesValue template = MutableBytesValue.create(keccak256.size()); byte msb = keccak256.get(0); msb ^= MOST_SIGNFICANT_BIT_MASK; template.set(0, msb); for (int i = 0; i < n; i++) { template.setInt(template.size() - 4, i); final Bytes32 newKeccak256 = Bytes32.leftPad(template.copy()); final DiscoveryPeer newPeer = mock(DiscoveryPeer.class); when(newPeer.keccak256()).thenReturn(newKeccak256); final MutableBytesValue newId = MutableBytesValue.create(64); UInt256.of(i).getBytes().copyTo(newId, newId.size() - UInt256Value.SIZE); when(newPeer.getId()).thenReturn(newId); when(newPeer.getEndpoint()) .thenReturn( new Endpoint( host.getEndpoint().getHost(), 100 + counter.incrementAndGet(), OptionalInt.empty())); newPeers.add(newPeer); } return newPeers; }
new DefaultPeer( localId, new Endpoint( InetAddress.getLoopbackAddress().getHostAddress(), localListenPort,
new DefaultPeer( listenId, new Endpoint( InetAddress.getLoopbackAddress().getHostAddress(), listenPort,
new DefaultPeer( listenId, new Endpoint( InetAddress.getLoopbackAddress().getHostAddress(), listenPort,
new DefaultPeer( listenId, new Endpoint( InetAddress.getLoopbackAddress().getHostAddress(), listenPort,