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

Commit

Permalink
PAN-2449: Remove NodePermissioningLocalConfig external references (#1406
Browse files Browse the repository at this point in the history
)

* Removing local config controller reference

* Removing permissioning whitelist references in p2p

* Removing whitelist updated listener from DiscoveryController
  • Loading branch information
lucassaldanha authored and macfarla committed May 8, 2019
1 parent 6451d28 commit b9c54d7
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.util.NetworkUtility;
Expand Down Expand Up @@ -74,7 +73,6 @@ public abstract class PeerDiscoveryAgent implements DisconnectCallback {
protected final List<DiscoveryPeer> bootstrapPeers;
private final List<PeerRequirement> peerRequirements = new CopyOnWriteArrayList<>();
private final PeerBlacklist peerBlacklist;
private final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController;
private final Optional<NodePermissioningController> nodePermissioningController;
private final MetricsSystem metricsSystem;
/* The peer controller, which takes care of the state machine of peers. */
Expand All @@ -98,7 +96,6 @@ public PeerDiscoveryAgent(
final SECP256K1.KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController,
final MetricsSystem metricsSystem) {
this.metricsSystem = metricsSystem;
Expand All @@ -108,7 +105,6 @@ public PeerDiscoveryAgent(
validateConfiguration(config);

this.peerBlacklist = peerBlacklist;
this.nodeWhitelistController = nodeWhitelistController;
this.nodePermissioningController = nodePermissioningController;
this.bootstrapPeers =
config.getBootstrapPeers().stream()
Expand Down Expand Up @@ -183,7 +179,6 @@ private PeerDiscoveryController createController() {
PEER_REFRESH_INTERVAL_MS,
PeerRequirement.combine(peerRequirements),
peerBlacklist,
nodeWhitelistController,
nodePermissioningController,
peerBondedObservers,
peerDroppedObservers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.TimerUtil;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.VertxTimerUtil;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.metrics.MetricCategory;
import tech.pegasys.pantheon.metrics.MetricsSystem;
Expand Down Expand Up @@ -61,16 +60,9 @@ public VertxPeerDiscoveryAgent(
final KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController,
final MetricsSystem metricsSystem) {
super(
keyPair,
config,
peerBlacklist,
nodeWhitelistController,
nodePermissioningController,
metricsSystem);
super(keyPair, config, peerBlacklist, nodePermissioningController, metricsSystem);
checkArgument(vertx != null, "vertx instance cannot be null");
this.vertx = vertx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerTable.EvictResult.EvictOutcome;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent;
import tech.pegasys.pantheon.metrics.Counter;
import tech.pegasys.pantheon.metrics.LabelledMetric;
import tech.pegasys.pantheon.metrics.MetricCategory;
Expand Down Expand Up @@ -121,7 +119,6 @@ public class PeerDiscoveryController {
private final DiscoveryPeer localPeer;
private final OutboundMessageHandler outboundMessageHandler;
private final PeerBlacklist peerBlacklist;
private final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController;
private final Optional<NodePermissioningController> nodePermissioningController;
private final DiscoveryProtocolLogger discoveryProtocolLogger;
private final LabelledMetric<Counter> interactionCounter;
Expand Down Expand Up @@ -155,7 +152,6 @@ public PeerDiscoveryController(
final long tableRefreshIntervalMs,
final PeerRequirement peerRequirement,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController,
final Subscribers<Consumer<PeerBondedEvent>> peerBondedObservers,
final Subscribers<Consumer<PeerDroppedEvent>> peerDroppedObservers,
Expand All @@ -169,7 +165,6 @@ public PeerDiscoveryController(
this.tableRefreshIntervalMs = tableRefreshIntervalMs;
this.peerRequirement = peerRequirement;
this.peerBlacklist = peerBlacklist;
this.nodeWhitelistController = nodeWhitelistController;
this.nodePermissioningController = nodePermissioningController;
this.outboundMessageHandler = outboundMessageHandler;
this.peerBondedObservers = peerBondedObservers;
Expand Down Expand Up @@ -243,9 +238,6 @@ public void start() {
Math.min(REFRESH_CHECK_INTERVAL_MILLIS, tableRefreshIntervalMs),
this::refreshTableIfRequired);
tableRefreshTimerId = OptionalLong.of(timerId);

nodeWhitelistController.ifPresent(
c -> c.subscribeToListUpdatedEvent(this::handleNodeWhitelistUpdatedEvent));
}

public CompletableFuture<?> stop() {
Expand Down Expand Up @@ -375,10 +367,6 @@ private boolean addToPeerTable(final DiscoveryPeer peer) {
return true;
}

private void handleNodeWhitelistUpdatedEvent(final NodeWhitelistUpdatedEvent event) {
event.getRemovedNodes().stream().map(DiscoveryPeer::fromEnode).forEach(this::dropFromPeerTable);
}

@VisibleForTesting
boolean dropFromPeerTable(final DiscoveryPeer peer) {
final EvictResult evictResult = peerTable.tryEvict(peer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo;
import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol;
import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.metrics.Counter;
import tech.pegasys.pantheon.metrics.LabelledMetric;
Expand Down Expand Up @@ -733,8 +732,6 @@ public static class Builder {
private Optional<NodePermissioningController> nodePermissioningController = Optional.empty();
private Blockchain blockchain = null;
private Vertx vertx;
private Optional<NodeLocalConfigPermissioningController>
nodeLocalConfigPermissioningController = Optional.empty();

public P2PNetwork build() {
validate();
Expand Down Expand Up @@ -767,9 +764,6 @@ private void validate() {
!nodePermissioningController.isPresent() || blockchain != null,
"Network permissioning needs to listen to BlockAddedEvents. Blockchain can't be null.");
checkState(vertx != null, "Vertx must be set.");
checkState(
nodeLocalConfigPermissioningController != null,
"NodeLocalConfigPermissioningController must be set.");
}

private PeerDiscoveryAgent createDiscoveryAgent() {
Expand All @@ -779,7 +773,6 @@ private PeerDiscoveryAgent createDiscoveryAgent() {
keyPair,
config.getDiscovery(),
peerBlacklist,
nodeLocalConfigPermissioningController,
nodePermissioningController,
metricsSystem);
}
Expand All @@ -790,21 +783,6 @@ public Builder vertx(final Vertx vertx) {
return this;
}

public Builder nodeLocalConfigPermissioningController(
final Optional<NodeLocalConfigPermissioningController>
nodeLocalConfigPermissioningController) {
checkNotNull(nodeLocalConfigPermissioningController);
this.nodeLocalConfigPermissioningController = nodeLocalConfigPermissioningController;
return this;
}

public Builder nodeLocalConfigPermissioningController(
final NodeLocalConfigPermissioningController nodeLocalConfigPermissioningController) {
this.nodeLocalConfigPermissioningController =
Optional.ofNullable(nodeLocalConfigPermissioningController);
return this;
}

public Builder keyPair(final KeyPair keyPair) {
checkNotNull(keyPair);
this.keyPair = keyPair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PingPacketData;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.enode.EnodeURL;
Expand Down Expand Up @@ -176,7 +175,6 @@ public static class AgentBuilder {
private final AtomicInteger nextAvailablePort;

private PeerBlacklist blacklist = new PeerBlacklist();
private Optional<NodeLocalConfigPermissioningController> whitelist = Optional.empty();
private Optional<NodePermissioningController> nodePermissioningController = Optional.empty();
private List<URI> bootstrapPeers = Collections.emptyList();
private boolean active = true;
Expand Down Expand Up @@ -204,12 +202,6 @@ private List<URI> asEnodes(final List<DiscoveryPeer> peers) {
.collect(Collectors.toList());
}

public AgentBuilder whiteList(
final Optional<NodeLocalConfigPermissioningController> whitelist) {
this.whitelist = whitelist;
return this;
}

public AgentBuilder nodePermissioningController(final NodePermissioningController controller) {
this.nodePermissioningController = Optional.ofNullable(controller);
return this;
Expand All @@ -232,12 +224,7 @@ public MockPeerDiscoveryAgent build() {
config.setActive(active);

return new MockPeerDiscoveryAgent(
SECP256K1.KeyPair.generate(),
config,
blacklist,
whitelist,
nodePermissioningController,
agents);
SECP256K1.KeyPair.generate(), config, blacklist, nodePermissioningController, agents);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public void lastSeenAndFirstDiscoveredTimestampsUpdatedOnMessage() {
() -> true,
new PeerBlacklist(),
Optional.empty(),
Optional.empty(),
new Subscribers<>(),
new Subscribers<>(),
new NoOpMetricsSystem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryAgent;
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerDiscoveryController.AsyncExecutor;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerBlacklist;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem;
import tech.pegasys.pantheon.util.bytes.BytesValue;
Expand All @@ -41,16 +40,9 @@ public MockPeerDiscoveryAgent(
final KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerBlacklist peerBlacklist,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<NodePermissioningController> nodePermissioningController,
final Map<BytesValue, MockPeerDiscoveryAgent> agentNetwork) {
super(
keyPair,
config,
peerBlacklist,
nodeWhitelistController,
nodePermissioningController,
new NoOpMetricsSystem());
super(keyPair, config, peerBlacklist, nodePermissioningController, new NoOpMetricsSystem());
this.agentNetwork = agentNetwork;
}

Expand Down
Loading

0 comments on commit b9c54d7

Please sign in to comment.