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

Commit

Permalink
bootstrappingPeersListUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
smatthewenglish committed Dec 15, 2018
1 parent 2a8487c commit 15a7c0b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public PeerDiscoveryAgent(
nodeWhitelistController);
}

PeerDiscoveryController getPeerDiscoveryController() {
return this.controller;
}

public CompletableFuture<?> start(final int tcpPort) {
final CompletableFuture<?> completion = new CompletableFuture<>();
if (config.isActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ public boolean removePeerDroppedObserver(final long observerId) {
*
* @return Associated RecursivePeerRefreshState.
*/
RecursivePeerRefreshState getRecursivePeerRefreshState() {
@VisibleForTesting
public RecursivePeerRefreshState getRecursivePeerRefreshState() {
return this.recursivePeerRefreshState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static java.util.stream.Collectors.toList;
import static tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerDistanceCalculator.distance;

import com.google.common.annotations.VisibleForTesting;
import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
Expand All @@ -25,7 +26,7 @@
import java.util.List;
import java.util.Objects;

class RecursivePeerRefreshState {
public class RecursivePeerRefreshState {
private final int CONCURRENT_REQUEST_LIMIT = 3;
private final BytesValue target;
private final BondingAgent bondingAgent;
Expand All @@ -38,7 +39,7 @@ class RecursivePeerRefreshState {
private NodeWhitelistController nodeWhitelist;
private PeerBlacklist peerBlacklist;

RecursivePeerRefreshState(
public RecursivePeerRefreshState(
final BytesValue target,
final NodeWhitelistController nodeWhitelist,
final PeerBlacklist peerBlacklist,
Expand Down Expand Up @@ -107,19 +108,23 @@ private void executeFindNodeRequest(final DiscoveryPeer peer) {
*/
private void initiatePeerRefreshCycle(final List<DiscoveryPeer> peers) {
for (DiscoveryPeer peer : peers) {
if (!dispatchedFindNeighbours.contains(peer.getId())) {
if (!dispatchedFindNeighbours.contains(peer.getId()) && !dispatchedBond.contains(peer.getId())) {
executeFindNodeRequest(peer);
}
}
}

void onNeighboursPacketReceived(final NeighborsPacketData neighboursPacket, final Peer peer) {

if (outstandingRequestList.contains(new OutstandingRequest(peer))) {

final List<DiscoveryPeer> receivedPeerList = neighboursPacket.getNodes();
for (DiscoveryPeer receivedPeer : receivedPeerList) {

if (!dispatchedBond.contains(receivedPeer.getId())
&& !peerBlacklist.contains(receivedPeer)
&& nodeWhitelist.contains(receivedPeer)) {

bondingAgent.performBonding(receivedPeer, false);
dispatchedBond.add(receivedPeer.getId());
anteList.add(new PeerDistance(receivedPeer, distance(target, receivedPeer.getId())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.Packet;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PacketType;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PingPacketData;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.RecursivePeerRefreshState;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController;
Expand Down Expand Up @@ -106,7 +107,7 @@ public void bootstrappingPingsSentMultipleBootstrapPeers() {
}
}

@Ignore
@Test
public void bootstrappingPeersListUpdated() {
// Start an agent.
final PeerDiscoveryAgent bootstrapAgent = startDiscoveryAgent(emptyList());
Expand Down Expand Up @@ -144,7 +145,7 @@ public void bootstrappingPeersListUpdated() {
}

@Test
public void deconstructed() {
public void deconstructedBootstrappingPeersListUpdated() {
final int BROADCAST_TCP_PORT = 12356;
final Vertx vertx = vertx();

Expand All @@ -167,7 +168,6 @@ public void deconstructed() {
throw new AssertionError("Could not initialize discovery agent", ex);
}


// Start other five agents, pointing to the one above as a bootstrap peer.
final DiscoveryConfiguration agentConfig = new DiscoveryConfiguration();
agentConfig.setBootstrapPeers(singletonList(bootstrapAgent.getAdvertisedPeer()));
Expand Down Expand Up @@ -283,7 +283,8 @@ public void deconstructed() {
}

await()
.atMost(5, TimeUnit.SECONDS)
.atMost(30, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(testAgent.getPeers()).hasSize(6));
vertx.close();
}
}

0 comments on commit 15a7c0b

Please sign in to comment.