Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2386] Report the correct tcp port in PING packets when it differs from the UDP port #1019

Merged
merged 8 commits into from
Mar 4, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected abstract CompletableFuture<Void> sendOutgoingPacket(

public abstract CompletableFuture<?> stop();

public CompletableFuture<?> start() {
public CompletableFuture<?> start(final int tcpPort) {
if (config.isActive()) {
final String host = config.getBindHost();
final int port = config.getBindPort();
Expand All @@ -138,10 +138,7 @@ public CompletableFuture<?> start() {
this.localAddress = localAddress;
advertisedPeer =
new DiscoveryPeer(
id,
config.getAdvertisedHost(),
localAddress.getPort(),
localAddress.getPort());
id, config.getAdvertisedHost(), localAddress.getPort(), tcpPort);
isActive = true;
startController();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public void subscribeDisconnect(final DisconnectCallback callback) {
@Override
public void run() {
try {
peerDiscoveryAgent.start().join();
peerDiscoveryAgent.start(ourPeerInfo.getPort()).join();
peerBondedObserverId =
OptionalLong.of(peerDiscoveryAgent.observePeerBondedEvents(handlePeerBondedEvent()));
peerDroppedObserverId =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.junit.Test;

public class PeerDiscoveryAgentTest {

private static final int BROADCAST_TCP_PORT = 30303;
private final PeerDiscoveryTestHelper helper = new PeerDiscoveryTestHelper();

@Test
Expand Down Expand Up @@ -113,11 +115,11 @@ public void neighborsPacketLimited() {
@Test
public void shouldEvictPeerOnDisconnect() {
final MockPeerDiscoveryAgent peerDiscoveryAgent1 = helper.startDiscoveryAgent();
peerDiscoveryAgent1.start().join();
peerDiscoveryAgent1.start(BROADCAST_TCP_PORT).join();
final DiscoveryPeer peer = peerDiscoveryAgent1.getAdvertisedPeer();

final MockPeerDiscoveryAgent peerDiscoveryAgent2 = helper.startDiscoveryAgent(peer);
peerDiscoveryAgent2.start().join();
peerDiscoveryAgent2.start(BROADCAST_TCP_PORT).join();

assertThat(peerDiscoveryAgent2.getPeers().size()).isEqualTo(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;

public class PeerDiscoveryObserversTest {
private static final Logger LOG = LogManager.getLogger();
private static final int BROADCAST_TCP_PORT = 26422;
private static final int BROADCAST_TCP_PORT = 30303;
private final PeerDiscoveryTestHelper helper = new PeerDiscoveryTestHelper();

@Test
Expand Down Expand Up @@ -106,7 +103,7 @@ public void peerBondedObserverTriggered() throws TimeoutException, InterruptedEx
// A queue for storing peer bonded events.
final List<PeerBondedEvent> events = new ArrayList<>(10);
agent.observePeerBondedEvents(events::add);
agent.start();
agent.start(BROADCAST_TCP_PORT).join();

final HashSet<BytesValue> seenPeers = new HashSet<>();
List<DiscoveryPeer> discoveredPeers =
Expand Down Expand Up @@ -146,7 +143,7 @@ public void multiplePeerBondedObserversTriggered() {
queues.forEach(q -> agent.observePeerBondedEvents(q::add));

// Start the agent and wait until each queue receives one event.
agent.start();
agent.start(BROADCAST_TCP_PORT).join();
for (List<PeerBondedEvent> eventQueue : queues) {
assertThat(eventQueue.size()).isEqualTo(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public MockPeerDiscoveryAgent startDiscoveryAgent(

public MockPeerDiscoveryAgent startDiscoveryAgent(final AgentBuilder agentBuilder) {
final MockPeerDiscoveryAgent agent = createDiscoveryAgent(agentBuilder);
agent.start();
agent.start(nextAvailablePort.incrementAndGet()).join();
return agent;
}

Expand Down