Skip to content

Commit

Permalink
fix(discovery): makes pong send only IP
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajpiar committed Apr 1, 2024
1 parent 71b5f5b commit c7b58f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private void handlePong(InetSocketAddress pongAddress, PongPeerMessage message)
this.pendingPingRequests.remove(message.getMessageId());
NodeChallenge challenge = this.challengeManager.removeChallenge(message.getMessageId());
if (challenge == null) {
this.addConnection(message, request.getAddress().getHostString(), request.getAddress().getPort());
this.addConnection(message, request.getAddress().getAddress().getHostAddress(), request.getAddress().getPort());
}
} else {
logger.debug("handlePong - Peer discovery request with id [{}] is either null or invalid", message.getMessageId());
Expand Down
17 changes: 13 additions & 4 deletions rskj-core/src/test/java/co/rsk/net/discovery/PeerExplorerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
import java.net.UnknownHostException;
import java.util.*;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -235,7 +234,7 @@ void handlePongMessage() throws Exception {

peerExplorer.start(false);

//A incoming pong for a Ping we did not sent.
//An incoming pong for a Ping we did not sent.
String check = UUID.randomUUID().toString();
PongPeerMessage incomingPongMessage = PongPeerMessage.create(HOST_1, PORT_1, check, key1, NETWORK_ID1);
DiscoveryEvent incomingPongEvent = new DiscoveryEvent(incomingPongMessage, new InetSocketAddress(HOST_1, PORT_1));
Expand All @@ -258,13 +257,18 @@ void handlePongMessage() throws Exception {
addedNodes = peerExplorer.getNodes();
assertEquals(1, addedNodes.size());

//A incoming pong for a ping we sent but from a different address
//An incoming pong for a ping we sent but from a different address
incomingPongMessage = PongPeerMessage.create(HOST_4, PORT_4, ((PingPeerMessage) initialPingMessages.get(1).getMessage()).getMessageId(), key4, NETWORK_ID1);
incomingPongEvent = new DiscoveryEvent(incomingPongMessage, new InetSocketAddress(HOST_1, PORT_1));
channel.clearEvents();
channel.channelRead0(ctx, incomingPongEvent);
assertEquals(1, peerExplorer.getNodes().size());

// Verify that only IP is being sent, not hostname
for (Node discoveredNode : peerExplorer.getNodes()) {
assertNotEquals(HOST_1, discoveredNode.getHost());
}

peerExplorer.dispose();
}

Expand Down Expand Up @@ -427,6 +431,11 @@ void handleFindNodeMessage() throws Exception {
NeighborsPeerMessage neighborsPeerMessage = (NeighborsPeerMessage) sentEvents.get(0).getMessage();
assertEquals(1, neighborsPeerMessage.getNodes().size());

// Verify that only IP is being sent, not hostname
for (Node discoveredNode : neighborsPeerMessage.getNodes()) {
assertNotEquals(HOST_1, discoveredNode.getHost());
}

peerExplorer.dispose();
}

Expand Down

0 comments on commit c7b58f0

Please sign in to comment.