Search in sources :

Example 1 with PingMessage

use of org.ethereum.net.p2p.PingMessage in project rskj by rsksmart.

the class PingPongMessageTest method testPing.

/* PING_MESSAGE & PONG_MESSAGE */
@Test
public /* PingMessage */
void testPing() {
    PingMessage pingMessage = new PingMessage();
    System.out.println(pingMessage);
    assertEquals(PongMessage.class, pingMessage.getAnswerMessage());
    assertEquals(P2pMessageCodes.PING, pingMessage.getCommand());
}
Also used : PingMessage(org.ethereum.net.p2p.PingMessage) Test(org.junit.Test)

Example 2 with PingMessage

use of org.ethereum.net.p2p.PingMessage in project rskj by rsksmart.

the class MessageQueue method receivedMessage.

public void receivedMessage(Message msg) throws InterruptedException {
    MessageRoundtrip messageRoundtrip = requestQueue.peek();
    if (messageRoundtrip != null) {
        Message waitingMessage = messageRoundtrip.getMsg();
        if (waitingMessage instanceof PingMessage) {
            hasPing = false;
        }
        if (waitingMessage.getAnswerMessage() != null && msg.getClass() == waitingMessage.getAnswerMessage()) {
            messageRoundtrip.answer();
            if (waitingMessage instanceof EthMessage) {
                channel.getPeerStats().pong(messageRoundtrip.lastTimestamp);
            }
            logger.trace("Message round trip covered: [{}] ", messageRoundtrip.getMsg().getClass());
        }
    }
}
Also used : Message(org.ethereum.net.message.Message) DisconnectMessage(org.ethereum.net.p2p.DisconnectMessage) PingMessage(org.ethereum.net.p2p.PingMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) EthMessage(org.ethereum.net.eth.message.EthMessage) PingMessage(org.ethereum.net.p2p.PingMessage)

Aggregations

PingMessage (org.ethereum.net.p2p.PingMessage)2 EthMessage (org.ethereum.net.eth.message.EthMessage)1 Message (org.ethereum.net.message.Message)1 DisconnectMessage (org.ethereum.net.p2p.DisconnectMessage)1 Test (org.junit.Test)1