Skip to content

Commit

Permalink
[PAN-2614] Expand permissioning interface (PegaSysEng#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaxter authored May 22, 2019
1 parent a137742 commit 7521532
Show file tree
Hide file tree
Showing 26 changed files with 1,695 additions and 535 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.TimerUtil;
import tech.pegasys.pantheon.ethereum.p2p.peers.PeerId;
import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.util.NetworkUtility;
import tech.pegasys.pantheon.util.Subscribers;
Expand Down Expand Up @@ -64,7 +63,6 @@ public abstract class PeerDiscoveryAgent {
protected final List<DiscoveryPeer> bootstrapPeers;
private final List<PeerRequirement> peerRequirements = new CopyOnWriteArrayList<>();
private final PeerPermissions peerPermissions;
private final Optional<NodePermissioningController> nodePermissioningController;
private final MetricsSystem metricsSystem;
/* The peer controller, which takes care of the state machine of peers. */
protected Optional<PeerDiscoveryController> controller = Optional.empty();
Expand All @@ -74,8 +72,10 @@ public abstract class PeerDiscoveryAgent {
private final BytesValue id;
protected final DiscoveryConfiguration config;

/* This is the {@link tech.pegasys.pantheon.ethereum.p2p.Peer} object holding who we are. */
private DiscoveryPeer advertisedPeer;
/* This is the {@link tech.pegasys.pantheon.ethereum.p2p.Peer} object representing our local node.
* This value is empty on construction, and is set after the discovery agent is started.
*/
private Optional<DiscoveryPeer> localNode = Optional.empty();

/* Is discovery enabled? */
private boolean isActive = false;
Expand All @@ -85,7 +85,6 @@ public PeerDiscoveryAgent(
final SECP256K1.KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerPermissions peerPermissions,
final Optional<NodePermissioningController> nodePermissioningController,
final MetricsSystem metricsSystem) {
this.metricsSystem = metricsSystem;
checkArgument(keyPair != null, "keypair cannot be null");
Expand All @@ -94,7 +93,6 @@ public PeerDiscoveryAgent(
validateConfiguration(config);

this.peerPermissions = peerPermissions;
this.nodePermissioningController = nodePermissioningController;
this.bootstrapPeers =
config.getBootnodes().stream().map(DiscoveryPeer::fromEnode).collect(Collectors.toList());

Expand Down Expand Up @@ -125,16 +123,17 @@ public CompletableFuture<?> start(final int tcpPort) {
.thenAccept(
(InetSocketAddress localAddress) -> {
// Once listener is set up, finish initializing
advertisedPeer =
final DiscoveryPeer ourNode =
DiscoveryPeer.fromEnode(
EnodeURL.builder()
.nodeId(id)
.ipAddress(config.getAdvertisedHost())
.listeningPort(tcpPort)
.discoveryPort(localAddress.getPort())
.build());
this.localNode = Optional.of(ourNode);
isActive = true;
startController();
startController(ourNode);
});
} else {
this.isActive = false;
Expand All @@ -146,23 +145,22 @@ public void addPeerRequirement(final PeerRequirement peerRequirement) {
this.peerRequirements.add(peerRequirement);
}

private void startController() {
final PeerDiscoveryController controller = createController();
private void startController(final DiscoveryPeer localNode) {
final PeerDiscoveryController controller = createController(localNode);
this.controller = Optional.of(controller);
controller.start();
}

private PeerDiscoveryController createController() {
private PeerDiscoveryController createController(final DiscoveryPeer localNode) {
return PeerDiscoveryController.builder()
.keypair(keyPair)
.localPeer(advertisedPeer)
.localPeer(localNode)
.bootstrapNodes(bootstrapPeers)
.outboundMessageHandler(this::handleOutgoingPacket)
.timerUtil(createTimer())
.workerExecutor(createWorkerExecutor())
.peerRequirement(PeerRequirement.combine(peerRequirements))
.peerPermissions(peerPermissions)
.nodePermissioningController(nodePermissioningController)
.peerBondedObservers(peerBondedObservers)
.metricsSystem(metricsSystem)
.build();
Expand Down Expand Up @@ -232,7 +230,7 @@ public void dropPeer(final PeerId peer) {
}

public Optional<DiscoveryPeer> getAdvertisedPeer() {
return Optional.ofNullable(advertisedPeer);
return localNode;
}

public BytesValue getId() {
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.permissions.PeerPermissions;
import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController;
import tech.pegasys.pantheon.metrics.MetricCategory;
import tech.pegasys.pantheon.metrics.MetricsSystem;
import tech.pegasys.pantheon.util.NetworkUtility;
Expand All @@ -31,7 +30,6 @@
import java.net.BindException;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
Expand Down Expand Up @@ -59,9 +57,8 @@ public VertxPeerDiscoveryAgent(
final KeyPair keyPair,
final DiscoveryConfiguration config,
final PeerPermissions peerPermissions,
final Optional<NodePermissioningController> nodePermissioningController,
final MetricsSystem metricsSystem) {
super(keyPair, config, peerPermissions, nodePermissioningController, metricsSystem);
super(keyPair, config, peerPermissions, metricsSystem);
checkArgument(vertx != null, "vertx instance cannot be null");
this.vertx = vertx;

Expand Down
Loading

0 comments on commit 7521532

Please sign in to comment.