Search in sources :

Example 1 with PingPeerMessage

use of co.rsk.net.discovery.message.PingPeerMessage in project rskj by rsksmart.

the class UDPChannelTest method write.

@Test
public void write() {
    String check = UUID.randomUUID().toString();
    ECKey key = new ECKey();
    PingPeerMessage nodeMessage = PingPeerMessage.create("localhost", 80, check, key);
    Channel channel = Mockito.mock(Channel.class);
    PeerExplorer peerExplorer = Mockito.mock(PeerExplorer.class);
    UDPChannel udpChannel = new UDPChannel(channel, peerExplorer);
    udpChannel.write(new DiscoveryEvent(nodeMessage, new InetSocketAddress("localhost", 8080)));
    Mockito.verify(channel, Mockito.times(1)).write(Mockito.any());
    Mockito.verify(channel, Mockito.times(1)).flush();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Channel(io.netty.channel.Channel) PingPeerMessage(co.rsk.net.discovery.message.PingPeerMessage) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 2 with PingPeerMessage

use of co.rsk.net.discovery.message.PingPeerMessage in project rskj by rsksmart.

the class NodeChallengeManager method startChallenge.

public NodeChallenge startChallenge(Node challengedNode, Node challenger, PeerExplorer explorer) {
    PingPeerMessage pingMessage = explorer.sendPing(challengedNode.getAddress(), 1, challengedNode);
    String messageId = pingMessage.getMessageId();
    NodeChallenge challenge = new NodeChallenge(challengedNode, challenger, messageId);
    activeChallenges.put(messageId, challenge);
    return challenge;
}
Also used : PingPeerMessage(co.rsk.net.discovery.message.PingPeerMessage)

Example 3 with PingPeerMessage

use of co.rsk.net.discovery.message.PingPeerMessage in project rskj by rsksmart.

the class PeerDiscoveryRequestTest method create.

@Test
public void create() {
    ECKey key = new ECKey();
    String check = UUID.randomUUID().toString();
    PingPeerMessage pingPeerMessage = PingPeerMessage.create("localhost", 80, check, key);
    PongPeerMessage pongPeerMessage = PongPeerMessage.create("localhost", 80, check, key);
    InetSocketAddress address = new InetSocketAddress("localhost", 8080);
    PeerDiscoveryRequest request = PeerDiscoveryRequestBuilder.builder().messageId(check).message(pingPeerMessage).address(address).expectedResponse(DiscoveryMessageType.PONG).expirationPeriod(1000).attemptNumber(1).build();
    Assert.assertNotNull(request);
    Assert.assertTrue(request.validateMessageResponse(pongPeerMessage));
    Assert.assertFalse(request.validateMessageResponse(pingPeerMessage));
}
Also used : PongPeerMessage(co.rsk.net.discovery.message.PongPeerMessage) InetSocketAddress(java.net.InetSocketAddress) PingPeerMessage(co.rsk.net.discovery.message.PingPeerMessage) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Aggregations

PingPeerMessage (co.rsk.net.discovery.message.PingPeerMessage)3 InetSocketAddress (java.net.InetSocketAddress)2 ECKey (org.ethereum.crypto.ECKey)2 Test (org.junit.Test)2 PongPeerMessage (co.rsk.net.discovery.message.PongPeerMessage)1 Channel (io.netty.channel.Channel)1