From 037a6e85272be461beb92a4a5b1a47c2f6470a92 Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 14 Jun 2019 11:19:39 -0400 Subject: [PATCH] [PAN-2783] Invert dependency between permissioning and p2p (#1557) Signed-off-by: Adrian Sutton --- .../dsl/node/ThreadPantheonNodeRunner.java | 2 +- ...ractPermissioningAllowNodeTransaction.java | 2 +- ...sioningConnectionIsAllowedTransaction.java | 2 +- ...actPermissioningForbidNodeTransaction.java | 2 +- ...ractPermissioningIsAllowedTransaction.java | 2 +- .../eth/manager/MockPeerConnection.java | 2 +- .../internal/methods/AdminAddPeer.java | 2 +- .../internal/methods/AdminNodeInfo.java | 2 +- .../internal/methods/AdminRemovePeer.java | 2 +- .../jsonrpc/internal/methods/NetEnode.java | 2 +- .../internal/methods/AdminNodeInfoTest.java | 2 +- .../internal/methods/NetEnodeTest.java | 2 +- .../ethereum/p2p/testing/MockNetwork.java | 2 +- .../ethereum/p2p/testing/MockNetworkTest.java | 2 +- ethereum/p2p/build.gradle | 1 - .../pantheon/ethereum/p2p/NoopP2PNetwork.java | 2 +- .../pantheon/ethereum/p2p/api/P2PNetwork.java | 2 +- .../ethereum/p2p/api/PeerConnection.java | 2 +- .../p2p/config/DiscoveryConfiguration.java | 2 +- .../ethereum/p2p/discovery/DiscoveryPeer.java | 2 +- .../ethereum/p2p/discovery/Endpoint.java | 2 +- .../p2p/discovery/PeerDiscoveryAgent.java | 2 +- .../p2p/network/DefaultP2PNetwork.java | 33 +------ .../ethereum/p2p/peers/DefaultLocalNode.java | 1 - .../ethereum/p2p/peers/DefaultPeer.java | 2 - .../ethereum/p2p/peers}/EnodeURL.java | 2 +- .../ethereum/p2p/peers/LocalNode.java | 1 - .../ethereum/p2p/peers/MutableLocalNode.java | 1 - .../pantheon/ethereum/p2p/peers/Peer.java | 1 - .../ethereum/p2p/peers/StaticNodesParser.java | 2 - .../pantheon/ethereum/p2p/rlpx/RlpxAgent.java | 2 +- .../p2p/rlpx/connections/netty/DeFramer.java | 2 +- .../netty/NettyConnectionInitializer.java | 2 +- .../config/DiscoveryConfigurationTest.java | 2 +- .../p2p/discovery/PeerDiscoveryAgentTest.java | 2 +- .../discovery/PeerDiscoveryTestHelper.java | 2 +- .../internal/PeerDiscoveryControllerTest.java | 2 +- .../p2p/discovery/internal/PeerTableTest.java | 2 +- .../RecursivePeerRefreshStateTest.java | 2 +- .../p2p/network/DefaultP2PNetworkTest.java | 58 ++---------- .../NetworkingServiceLifecycleTest.java | 2 +- .../ethereum/p2p/network/P2PNetworkTest.java | 90 +------------------ .../network/PeerReputationManagerTest.java | 2 +- .../p2p/peers/DefaultLocalNodeTest.java | 1 - .../ethereum/p2p/peers}/EnodeURLTest.java | 2 +- .../p2p/peers/MaintainedPeersTest.java | 2 - .../pantheon/ethereum/p2p/peers/PeerTest.java | 1 - .../ethereum/p2p/peers/PeerTestHelper.java | 1 - .../p2p/peers/StaticNodesParserTest.java | 2 - .../PeerPermissionsBlacklistTest.java | 2 +- .../p2p/permissions/PeerPermissionsTest.java | 2 +- .../ethereum/p2p/rlpx/RlpxAgentTest.java | 2 +- .../rlpx/connections/netty/DeFramerTest.java | 2 +- ethereum/permissioning/build.gradle | 1 + ...odeLocalConfigPermissioningController.java | 2 +- .../NodePermissioningControllerFactory.java | 2 +- ...eSmartContractPermissioningController.java | 2 +- .../PermissioningConfigurationBuilder.java | 2 +- .../ContextualNodePermissioningProvider.java | 2 +- ...nsufficientPeersPermissioningProvider.java | 5 +- .../node/NodePermissioningController.java | 2 +- .../node/NodePermissioningProvider.java | 2 +- .../node/NodeWhitelistUpdatedEvent.java | 2 +- .../node/PeerPermissionsAdapter.java} | 9 +- .../SyncStatusNodePermissioningProvider.java | 2 +- ...ocalConfigPermissioningControllerTest.java | 2 +- ...rtContractPermissioningControllerTest.java | 2 +- ...ficientPeersPermissioningProviderTest.java | 4 +- ...odePermissioningControllerFactoryTest.java | 2 +- .../node/NodePermissioningControllerTest.java | 2 +- .../node/PeerPermissionsAdapterTest.java} | 30 ++++--- ...ncStatusNodePermissioningProviderTest.java | 2 +- .../java/tech/pegasys/pantheon/Runner.java | 2 +- .../tech/pegasys/pantheon/RunnerBuilder.java | 22 +++-- .../pantheon/cli/EthNetworkConfig.java | 2 +- .../pegasys/pantheon/cli/PantheonCommand.java | 2 +- .../custom/EnodeToURIPropertyConverter.java | 2 +- .../tech/pegasys/pantheon/RunnerTest.java | 2 +- .../pantheon/cli/PantheonCommandTest.java | 2 +- ...rmissioningConfigurationValidatorTest.java | 2 +- 80 files changed, 114 insertions(+), 272 deletions(-) rename {util/src/main/java/tech/pegasys/pantheon/util/enode => ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers}/EnodeURL.java (99%) rename {util/src/test/java/tech/pegasys/pantheon/util/enode => ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers}/EnodeURLTest.java (99%) rename ethereum/{p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p => permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node}/InsufficientPeersPermissioningProvider.java (95%) rename ethereum/{p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapter.java => permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapter.java} (94%) rename ethereum/{p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p => permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node}/InsufficientPeersPermissioningProviderTest.java (98%) rename ethereum/{p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapterTest.java => permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapterTest.java} (94%) diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java index 0ab75f9a00..1597ad1c87 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/ThreadPantheonNodeRunner.java @@ -24,6 +24,7 @@ import tech.pegasys.pantheon.ethereum.eth.EthereumWireProtocolConfiguration; import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.ethereum.eth.transactions.PendingTransactions; import tech.pegasys.pantheon.ethereum.graphql.GraphQLConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; @@ -33,7 +34,6 @@ import tech.pegasys.pantheon.services.PantheonEventsImpl; import tech.pegasys.pantheon.services.PantheonPluginContextImpl; import tech.pegasys.pantheon.services.PicoCLIOptionsImpl; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.File; import java.io.IOException; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningAllowNodeTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningAllowNodeTransaction.java index ac02d23ac5..bef2d8578f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningAllowNodeTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningAllowNodeTransaction.java @@ -17,6 +17,7 @@ import static org.web3j.utils.Numeric.toHexString; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController; import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; @@ -24,7 +25,6 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.math.BigInteger; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningConnectionIsAllowedTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningConnectionIsAllowedTransaction.java index f574197384..f59e76de76 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningConnectionIsAllowedTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningConnectionIsAllowedTransaction.java @@ -16,13 +16,13 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController.checkTransactionResult; import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningForbidNodeTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningForbidNodeTransaction.java index d55a5a9315..adb23696d2 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningForbidNodeTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningForbidNodeTransaction.java @@ -17,6 +17,7 @@ import static org.web3j.utils.Numeric.toHexString; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Hash; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController; import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; @@ -24,7 +25,6 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.math.BigInteger; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningIsAllowedTransaction.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningIsAllowedTransaction.java index 471572b018..e5f2ae6c93 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningIsAllowedTransaction.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/perm/NodeSmartContractPermissioningIsAllowedTransaction.java @@ -15,13 +15,13 @@ package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm; import static java.nio.charset.StandardCharsets.UTF_8; import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.NodeSmartContractPermissioningController; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; import tech.pegasys.pantheon.tests.acceptance.dsl.node.RunnableNode; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.NodeRequests; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; diff --git a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/MockPeerConnection.java b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/MockPeerConnection.java index 886165b00b..fb31606aa3 100644 --- a/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/MockPeerConnection.java +++ b/ethereum/eth/src/test/java/tech/pegasys/pantheon/ethereum/eth/manager/MockPeerConnection.java @@ -15,12 +15,12 @@ package tech.pegasys.pantheon.ethereum.eth.manager; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetSocketAddress; import java.util.ArrayList; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java index 0ea3f390f7..bde3203a42 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java @@ -18,8 +18,8 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; -import tech.pegasys.pantheon.util.enode.EnodeURL; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfo.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfo.java index 924115675d..07471e4888 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfo.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfo.java @@ -22,8 +22,8 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResp import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.HashMap; import java.util.Map; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java index 6e81764792..c14d90155b 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminRemovePeer.java @@ -18,7 +18,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnode.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnode.java index dae31cf847..d9f497d2f6 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnode.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnode.java @@ -19,7 +19,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResp import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.util.Optional; diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfoTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfoTest.java index cb980c32e8..c693ae0d9c 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfoTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminNodeInfoTest.java @@ -29,8 +29,8 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import tech.pegasys.pantheon.util.uint.UInt256; import java.math.BigInteger; diff --git a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnodeTest.java b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnodeTest.java index d0b561d1af..4320afbec8 100644 --- a/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnodeTest.java +++ b/ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/NetEnodeTest.java @@ -23,8 +23,8 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Optional; diff --git a/ethereum/mock-p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetwork.java b/ethereum/mock-p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetwork.java index cac516bb34..d8b970d578 100644 --- a/ethereum/mock-p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetwork.java +++ b/ethereum/mock-p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetwork.java @@ -20,13 +20,13 @@ import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.DefaultMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.util.Subscribers; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetSocketAddress; import java.util.ArrayList; diff --git a/ethereum/mock-p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetworkTest.java b/ethereum/mock-p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetworkTest.java index 37b2a7410f..aa3d55b550 100644 --- a/ethereum/mock-p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetworkTest.java +++ b/ethereum/mock-p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/testing/MockNetworkTest.java @@ -17,12 +17,12 @@ import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.RawMessage; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Arrays; import java.util.Optional; diff --git a/ethereum/p2p/build.gradle b/ethereum/p2p/build.gradle index 910761cf7e..97052ea8e5 100644 --- a/ethereum/p2p/build.gradle +++ b/ethereum/p2p/build.gradle @@ -28,7 +28,6 @@ jar { dependencies { implementation project(':crypto') implementation project(':ethereum:core') - implementation project(':ethereum:permissioning') implementation project(':ethereum:rlp') implementation project(':metrics:core') diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NoopP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NoopP2PNetwork.java index d102370e05..76d5fd6280 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NoopP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/NoopP2PNetwork.java @@ -18,9 +18,9 @@ import tech.pegasys.pantheon.ethereum.p2p.api.MessageCallback; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.util.Collection; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/P2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/P2PNetwork.java index 622db8c110..d2e3e6dcfa 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/P2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/P2PNetwork.java @@ -13,9 +13,9 @@ package tech.pegasys.pantheon.ethereum.p2p.api; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.Closeable; import java.util.Collection; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/PeerConnection.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/PeerConnection.java index 68ad776ed9..ecc8852b7c 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/PeerConnection.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/PeerConnection.java @@ -12,11 +12,11 @@ */ package tech.pegasys.pantheon.ethereum.p2p.api; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.net.InetSocketAddress; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java index cec4adc9b4..c7a6141ef6 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfiguration.java @@ -14,7 +14,7 @@ package tech.pegasys.pantheon.ethereum.p2p.config; import static java.util.stream.Collectors.toList; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.util.ArrayList; import java.util.Collections; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/DiscoveryPeer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/DiscoveryPeer.java index 8185449b64..a5e9a7778a 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/DiscoveryPeer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/DiscoveryPeer.java @@ -13,11 +13,11 @@ package tech.pegasys.pantheon.ethereum.p2p.discovery; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerId; import tech.pegasys.pantheon.ethereum.rlp.RLPInput; import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; /** * Represents an Ethereum node that we interacting with through the discovery and wire protocols. diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/Endpoint.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/Endpoint.java index ff8e7389ff..5008152ddd 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/Endpoint.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/Endpoint.java @@ -15,11 +15,11 @@ package tech.pegasys.pantheon.ethereum.p2p.discovery; import static com.google.common.base.Preconditions.checkArgument; import static tech.pegasys.pantheon.util.Preconditions.checkGuard; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.rlp.RLPInput; import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; import tech.pegasys.pantheon.util.NetworkUtility; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetAddress; import java.util.Objects; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgent.java index 948ca55bfa..dd2656da7b 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgent.java @@ -24,13 +24,13 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerDiscoveryContro import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerRequirement; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PingPacketData; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.TimerUtil; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerId; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.NetworkUtility; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetSocketAddress; import java.net.SocketException; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java index 6eb594674d..bccbe5b424 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java @@ -17,7 +17,6 @@ import static com.google.common.base.Preconditions.checkState; import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; -import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.p2p.api.ConnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.DisconnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.MessageCallback; @@ -30,6 +29,7 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryEvent.PeerBonde import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryStatus; import tech.pegasys.pantheon.ethereum.p2p.discovery.VertxPeerDiscoveryAgent; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeerProperties; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.LocalNode; import tech.pegasys.pantheon.ethereum.p2p.peers.MaintainedPeers; import tech.pegasys.pantheon.ethereum.p2p.peers.MutableLocalNode; @@ -40,10 +40,8 @@ import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissionsBlacklist; import tech.pegasys.pantheon.ethereum.p2p.rlpx.RlpxAgent; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.time.Duration; import java.util.Arrays; @@ -351,8 +349,6 @@ public class DefaultP2PNetwork implements P2PNetwork { private MaintainedPeers maintainedPeers = new MaintainedPeers(); private PeerPermissions peerPermissions = PeerPermissions.noop(); - private Optional nodePermissioningController = Optional.empty(); - private Blockchain blockchain = null; private MetricsSystem metricsSystem; @@ -363,13 +359,6 @@ public class DefaultP2PNetwork implements P2PNetwork { private P2PNetwork doBuild() { // Set up permissions - // Fold NodePermissioningController into peerPermissions - if (nodePermissioningController.isPresent()) { - final List bootnodes = config.getDiscovery().getBootnodes(); - final PeerPermissions nodePermissions = - new NodePermissioningAdapter(nodePermissioningController.get(), bootnodes, blockchain); - peerPermissions = PeerPermissions.combine(peerPermissions, nodePermissions); - } // Fold peer reputation into permissions final PeerPermissionsBlacklist misbehavingPeers = PeerPermissionsBlacklist.create(500); final PeerReputationManager reputationManager = new PeerReputationManager(misbehavingPeers); @@ -399,9 +388,6 @@ public class DefaultP2PNetwork implements P2PNetwork { supportedCapabilities != null && supportedCapabilities.size() > 0, "Supported capabilities must be set and non-empty."); checkState(metricsSystem != null, "MetricsSystem must be set."); - checkState( - !nodePermissioningController.isPresent() || blockchain != null, - "Network permissioning needs to listen to BlockAddedEvents. Blockchain can't be null."); checkState(peerDiscoveryAgent != null || vertx != null, "Vertx must be set."); } @@ -476,23 +462,6 @@ public class DefaultP2PNetwork implements P2PNetwork { return this; } - public Builder nodePermissioningController( - final NodePermissioningController nodePermissioningController) { - this.nodePermissioningController = Optional.ofNullable(nodePermissioningController); - return this; - } - - public Builder nodePermissioningController( - final Optional nodePermissioningController) { - this.nodePermissioningController = nodePermissioningController; - return this; - } - - public Builder blockchain(final Blockchain blockchain) { - this.blockchain = blockchain; - return this; - } - public Builder maintainedPeers(final MaintainedPeers maintainedPeers) { checkNotNull(maintainedPeers); this.maintainedPeers = maintainedPeers; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNode.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNode.java index 90e221294c..a7537a8e34 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNode.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNode.java @@ -14,7 +14,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.List; import java.util.Optional; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultPeer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultPeer.java index 72f2420a62..c32a50d113 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultPeer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultPeer.java @@ -12,8 +12,6 @@ */ package tech.pegasys.pantheon.ethereum.p2p.peers; -import tech.pegasys.pantheon.util.enode.EnodeURL; - import java.net.URI; import java.util.Objects; diff --git a/util/src/main/java/tech/pegasys/pantheon/util/enode/EnodeURL.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java similarity index 99% rename from util/src/main/java/tech/pegasys/pantheon/util/enode/EnodeURL.java rename to ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java index f1b55898f5..0ca0c4be4b 100644 --- a/util/src/main/java/tech/pegasys/pantheon/util/enode/EnodeURL.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURL.java @@ -10,7 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.util.enode; +package tech.pegasys.pantheon.ethereum.p2p.peers; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/LocalNode.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/LocalNode.java index 2b0fcf87ac..e779cba93e 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/LocalNode.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/LocalNode.java @@ -14,7 +14,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.List; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/MutableLocalNode.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/MutableLocalNode.java index 4596def6a8..569ce02e6b 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/MutableLocalNode.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/MutableLocalNode.java @@ -13,7 +13,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.List; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/Peer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/Peer.java index fda98361e7..e61ddacc3a 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/Peer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/Peer.java @@ -14,7 +14,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import tech.pegasys.pantheon.crypto.SecureRandomProvider; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; public interface Peer extends PeerId { diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParser.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParser.java index e2aaf98f96..7c0172126d 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParser.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParser.java @@ -16,8 +16,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.emptySet; -import tech.pegasys.pantheon.util.enode.EnodeURL; - import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgent.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgent.java index ca177fc47b..a4f6d7169c 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgent.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgent.java @@ -23,6 +23,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.MessageCallback; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.config.RlpxConfiguration; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.LocalNode; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerProperties; @@ -40,7 +41,6 @@ import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.FutureUtils; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; import java.util.List; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramer.java index 084dd9c577..4c23721c79 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramer.java @@ -19,6 +19,7 @@ import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.IncompatiblePeerExc import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.PeerDisconnectedException; import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.UnexpectedPeerConnectionException; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.LocalNode; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.rlpx.connections.PeerConnectionEventDispatcher; @@ -36,7 +37,6 @@ import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.LabelledMetric; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.net.InetSocketAddress; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/NettyConnectionInitializer.java b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/NettyConnectionInitializer.java index 3c8bc94dfc..d32fe1756d 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/NettyConnectionInitializer.java +++ b/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/NettyConnectionInitializer.java @@ -19,6 +19,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.ConnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.config.RlpxConfiguration; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.LocalNode; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.rlpx.connections.ConnectionInitializer; @@ -26,7 +27,6 @@ import tech.pegasys.pantheon.ethereum.p2p.rlpx.connections.PeerConnectionEventDi import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.Subscribers; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfigurationTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfigurationTest.java index 6d10ed0ef1..398b79f59e 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfigurationTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/config/DiscoveryConfigurationTest.java @@ -14,8 +14,8 @@ package tech.pegasys.pantheon.ethereum.p2p.config; import static org.assertj.core.api.Java6Assertions.assertThatThrownBy; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collections; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java index c3f8634024..f3f9a8de68 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryAgentTest.java @@ -27,11 +27,11 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.MockPeerDiscoveryAg import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.NeighborsPacketData; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.Packet; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PacketType; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissionsBlacklist; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collections; import java.util.List; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java index 95cff654d6..7840ef1942 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/PeerDiscoveryTestHelper.java @@ -21,10 +21,10 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.MockPeerDiscoveryAg 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.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Arrays; import java.util.Collections; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java index 594caa274e..59e0653699 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerDiscoveryControllerTest.java @@ -35,6 +35,7 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.Endpoint; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerBondedObserver; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryStatus; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryTestHelper; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; @@ -44,7 +45,6 @@ import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.Bytes32; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.MutableBytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import tech.pegasys.pantheon.util.uint.UInt256; import tech.pegasys.pantheon.util.uint.UInt256Value; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerTableTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerTableTest.java index 28045eaaf9..b2986f479d 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerTableTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/PeerTableTest.java @@ -19,8 +19,8 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryTestHelper; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerTable.AddResult.AddOutcome; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerTable.EvictResult; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.PeerTable.EvictResult.EvictOutcome; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.List; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java index 0af649ccba..7c09a6e6cc 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/discovery/internal/RecursivePeerRefreshStateTest.java @@ -27,8 +27,8 @@ import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryStatus; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.RecursivePeerRefreshState.BondingAgent; import tech.pegasys.pantheon.ethereum.p2p.discovery.internal.RecursivePeerRefreshState.FindNeighbourDispatcher; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collections; import java.util.List; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetworkTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetworkTest.java index 4b66581b22..dffcf3e066 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetworkTest.java @@ -13,12 +13,8 @@ package tech.pegasys.pantheon.ethereum.p2p.network; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -26,8 +22,6 @@ import static tech.pegasys.pantheon.ethereum.p2p.peers.PeerTestHelper.createPeer import static tech.pegasys.pantheon.ethereum.p2p.peers.PeerTestHelper.enode; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; -import tech.pegasys.pantheon.ethereum.chain.BlockAddedObserver; -import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; @@ -46,7 +40,6 @@ import tech.pegasys.pantheon.ethereum.p2p.rlpx.connections.MockPeerConnection; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.MockSubProtocol; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import java.util.ArrayList; @@ -68,15 +61,10 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.StrictStubs.class) public final class DefaultP2PNetworkTest { - @Mock private NodePermissioningController nodePermissioningController; final MaintainedPeers maintainedPeers = new MaintainedPeers(); - - @Mock private Blockchain blockchain; @Mock PeerDiscoveryAgent discoveryAgent; @Mock RlpxAgent rlpxAgent; - private final ArgumentCaptor observerCaptor = - ArgumentCaptor.forClass(BlockAddedObserver.class); private final ArgumentCaptor discoverySubscriberCaptor = ArgumentCaptor.forClass(PeerBondedObserver.class); @@ -92,16 +80,15 @@ public final class DefaultP2PNetworkTest { @Before public void before() { - when(rlpxAgent.start()).thenReturn(CompletableFuture.completedFuture(30303)); - when(rlpxAgent.stop()).thenReturn(CompletableFuture.completedFuture(null)); - when(discoveryAgent.start(anyInt())).thenReturn(CompletableFuture.completedFuture(30303)); - when(discoveryAgent.stop()).thenReturn(CompletableFuture.completedFuture(null)); - when(discoveryAgent.observePeerBondedEvents(discoverySubscriberCaptor.capture())) + lenient().when(rlpxAgent.start()).thenReturn(CompletableFuture.completedFuture(30303)); + lenient().when(rlpxAgent.stop()).thenReturn(CompletableFuture.completedFuture(null)); + lenient() + .when(discoveryAgent.start(anyInt())) + .thenReturn(CompletableFuture.completedFuture(30303)); + lenient().when(discoveryAgent.stop()).thenReturn(CompletableFuture.completedFuture(null)); + lenient() + .when(discoveryAgent.observePeerBondedEvents(discoverySubscriberCaptor.capture())) .thenReturn(1L); - - when(blockchain.observeBlockAdded(observerCaptor.capture())).thenReturn(1L); - // Make permissions lenient by default - lenient().when(nodePermissioningController.isPermitted(any(), any())).thenReturn(true); } @Test @@ -201,31 +188,6 @@ public final class DefaultP2PNetworkTest { verify(rlpxAgent, times(0)).connect(peer); } - @Test - public void whenBuildingNetworkWithNodePermissioningWithoutBlockchainShouldThrowIllegalState() { - blockchain = null; - final Throwable throwable = catchThrowable(this::network); - assertThat(throwable) - .isInstanceOf(IllegalStateException.class) - .hasMessage( - "Network permissioning needs to listen to BlockAddedEvents. Blockchain can't be null."); - } - - @Test - public void stop_removesListeners() { - final P2PNetwork network = network(); - - network.start(); - verify(blockchain, never()).removeObserver(anyLong()); - verify(nodePermissioningController, never()).unsubscribeFromUpdates(anyLong()); - - network.stop(); - network.awaitStop(); - - verify(blockchain, times(1)).removeObserver(anyLong()); - verify(nodePermissioningController, times(1)).unsubscribeFromUpdates(anyLong()); - } - @Test public void beforeStartingNetworkEnodeURLShouldNotBePresent() { final P2PNetwork network = network(); @@ -334,8 +296,6 @@ public final class DefaultP2PNetworkTest { .keyPair(keyPair) .maintainedPeers(maintainedPeers) .metricsSystem(new NoOpMetricsSystem()) - .supportedCapabilities(Capability.create("eth", 63)) - .nodePermissioningController(nodePermissioningController) - .blockchain(blockchain); + .supportedCapabilities(Capability.create("eth", 63)); } } diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NetworkingServiceLifecycleTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NetworkingServiceLifecycleTest.java index bfe3b1615f..d9523ca5d0 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NetworkingServiceLifecycleTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NetworkingServiceLifecycleTest.java @@ -23,9 +23,9 @@ import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryServiceException; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.util.Arrays; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/P2PNetworkTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/P2PNetworkTest.java index c836d57bad..f324dfa834 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/P2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/P2PNetworkTest.java @@ -21,8 +21,6 @@ import static org.mockito.Mockito.when; import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; -import tech.pegasys.pantheon.ethereum.chain.BlockAddedObserver; -import tech.pegasys.pantheon.ethereum.chain.Blockchain; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; @@ -30,6 +28,7 @@ import tech.pegasys.pantheon.ethereum.p2p.config.NetworkingConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.RlpxConfiguration; import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.IncompatiblePeerException; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; @@ -37,54 +36,28 @@ import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissionsBlacklist; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; -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; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetAddress; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Arrays; -import java.util.Collections; -import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import io.vertx.core.Vertx; import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class P2PNetworkTest { - - @Mock private Blockchain blockchain; - - private ArgumentCaptor observerCaptor = - ArgumentCaptor.forClass(BlockAddedObserver.class); - private final Vertx vertx = Vertx.vertx(); private final NetworkingConfiguration config = NetworkingConfiguration.create() .setDiscovery(DiscoveryConfiguration.create().setActive(false)) .setRlpx(RlpxConfiguration.create().setBindPort(0).setSupportedProtocols(subProtocol())); - private final String selfEnodeString = - "enode://5f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:1111"; - private final EnodeURL selfEnode = EnodeURL.fromString(selfEnodeString); - - @Before - public void before() { - when(blockchain.observeBlockAdded(observerCaptor.capture())).thenReturn(1L); - } - @After public void closeVertx() { vertx.close(); @@ -269,71 +242,12 @@ public class P2PNetworkTest { } } - @Test - public void rejectIncomingConnectionFromNonWhitelistedPeer() throws Exception { - final LocalPermissioningConfiguration config = LocalPermissioningConfiguration.createDefault(); - final Path tempFile = Files.createTempFile("test", "test"); - tempFile.toFile().deleteOnExit(); - config.setNodePermissioningConfigFilePath(tempFile.toAbsolutePath().toString()); - - final NodeLocalConfigPermissioningController localWhitelistController = - new NodeLocalConfigPermissioningController( - config, Collections.emptyList(), selfEnode.getNodeId(), new NoOpMetricsSystem()); - // turn on whitelisting by adding a different node NOT remote node - localWhitelistController.addNode( - EnodeURL.builder() - .ipAddress("127.0.0.1") - .useDefaultPorts() - .nodeId(Peer.randomId()) - .build()); - final NodePermissioningController nodePermissioningController = - new NodePermissioningController( - Optional.empty(), Collections.singletonList(localWhitelistController)); - - try (final P2PNetwork localNetwork = - builder() - .nodePermissioningController(nodePermissioningController) - .blockchain(blockchain) - .build(); - final P2PNetwork remoteNetwork = builder().build()) { - - localNetwork.start(); - remoteNetwork.start(); - - final EnodeURL localEnode = localNetwork.getLocalEnode().get(); - final BytesValue localId = localEnode.getNodeId(); - final int localPort = localEnode.getListeningPort().getAsInt(); - - final Peer localPeer = createPeer(localId, localPort); - - // Setup disconnect listener - final CompletableFuture peerFuture = new CompletableFuture<>(); - final CompletableFuture reasonFuture = new CompletableFuture<>(); - remoteNetwork.subscribeDisconnect( - (peerConnection, reason, initiatedByPeer) -> { - peerFuture.complete(peerConnection); - reasonFuture.complete(reason); - }); - - // Remote connect to local - final CompletableFuture connectFuture = remoteNetwork.connect(localPeer); - - // Check connection is made, and then a disconnect is registered at remote - assertThat(connectFuture.get(5L, TimeUnit.SECONDS).getPeerInfo().getNodeId()) - .isEqualTo(localId); - assertThat(peerFuture.get(5L, TimeUnit.SECONDS).getPeerInfo().getNodeId()).isEqualTo(localId); - assertThat(reasonFuture.get(5L, TimeUnit.SECONDS)) - .isEqualByComparingTo(DisconnectReason.UNKNOWN); - } - } - @Test public void rejectIncomingConnectionFromDisallowedPeer() throws Exception { final PeerPermissions peerPermissions = mock(PeerPermissions.class); when(peerPermissions.isPermitted(any(), any(), any())).thenReturn(true); - try (final P2PNetwork localNetwork = - builder().peerPermissions(peerPermissions).blockchain(blockchain).build(); + try (final P2PNetwork localNetwork = builder().peerPermissions(peerPermissions).build(); final P2PNetwork remoteNetwork = builder().build()) { localNetwork.start(); diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/PeerReputationManagerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/PeerReputationManagerTest.java index 87c9bf4e8f..610664c515 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/PeerReputationManagerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/PeerReputationManagerTest.java @@ -18,13 +18,13 @@ import static org.mockito.Mockito.when; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissionsBlacklist; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import org.junit.Test; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNodeTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNodeTest.java index 53ae060f59..5bb637233f 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNodeTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/DefaultLocalNodeTest.java @@ -20,7 +20,6 @@ import tech.pegasys.pantheon.ethereum.p2p.peers.MutableLocalNode.NodeAlreadySetE import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Arrays; import java.util.List; diff --git a/util/src/test/java/tech/pegasys/pantheon/util/enode/EnodeURLTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURLTest.java similarity index 99% rename from util/src/test/java/tech/pegasys/pantheon/util/enode/EnodeURLTest.java rename to ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURLTest.java index 41251eed19..14dc256c84 100644 --- a/util/src/test/java/tech/pegasys/pantheon/util/enode/EnodeURLTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/EnodeURLTest.java @@ -10,7 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.util.enode; +package tech.pegasys.pantheon.ethereum.p2p.peers; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/MaintainedPeersTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/MaintainedPeersTest.java index 7c223fe4c0..e589d736f9 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/MaintainedPeersTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/MaintainedPeersTest.java @@ -15,8 +15,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import tech.pegasys.pantheon.util.enode.EnodeURL; - import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTest.java index a2f09f34f5..392b76512c 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTest.java @@ -20,7 +20,6 @@ import static tech.pegasys.pantheon.util.bytes.BytesValue.fromHexString; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; import tech.pegasys.pantheon.ethereum.p2p.discovery.PeerDiscoveryStatus; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import com.google.common.net.InetAddresses; import org.junit.Test; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTestHelper.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTestHelper.java index 2d5072fc04..fbf1e26561 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTestHelper.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/PeerTestHelper.java @@ -14,7 +14,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Arrays; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParserTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParserTest.java index c433a0f4fb..ba61b9cc64 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParserTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/peers/StaticNodesParserTest.java @@ -15,8 +15,6 @@ package tech.pegasys.pantheon.ethereum.p2p.peers; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import tech.pegasys.pantheon.util.enode.EnodeURL; - import java.io.File; import java.io.IOException; import java.net.URISyntaxException; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsBlacklistTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsBlacklistTest.java index 830dfa1cc0..c03550894f 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsBlacklistTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsBlacklistTest.java @@ -15,9 +15,9 @@ package tech.pegasys.pantheon.ethereum.p2p.permissions; import static org.assertj.core.api.Assertions.assertThat; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collections; import java.util.List; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsTest.java index 9d6770134f..4c6538a40a 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/permissions/PeerPermissionsTest.java @@ -19,9 +19,9 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgentTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgentTest.java index 515b35d755..956f7c2877 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgentTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgentTest.java @@ -33,6 +33,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection.PeerNotConnected; import tech.pegasys.pantheon.ethereum.p2p.config.RlpxConfiguration; import tech.pegasys.pantheon.ethereum.p2p.discovery.DiscoveryPeer; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.MutableLocalNode; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.peers.PeerProperties; @@ -49,7 +50,6 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.PingMessage; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Arrays; import java.util.List; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramerTest.java b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramerTest.java index 9521a1a959..4b339df33e 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramerTest.java +++ b/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/connections/netty/DeFramerTest.java @@ -29,6 +29,7 @@ import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.IncompatiblePeerExc import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.PeerDisconnectedException; import tech.pegasys.pantheon.ethereum.p2p.network.exceptions.UnexpectedPeerConnectionException; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.LocalNode; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.rlpx.connections.PeerConnectionEvents; @@ -47,7 +48,6 @@ import tech.pegasys.pantheon.ethereum.p2p.wire.messages.WireMessageCodes; import tech.pegasys.pantheon.ethereum.rlp.RLPException; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetSocketAddress; import java.util.ArrayList; diff --git a/ethereum/permissioning/build.gradle b/ethereum/permissioning/build.gradle index 54bfe7e19c..2d67fe461b 100644 --- a/ethereum/permissioning/build.gradle +++ b/ethereum/permissioning/build.gradle @@ -28,6 +28,7 @@ jar { dependencies { implementation project(':util') implementation project(':ethereum:core') + implementation project(':ethereum:p2p') implementation project(':crypto') implementation project(':metrics:core') diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java index 20427ca6a4..3a4bf90ce7 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningController.java @@ -12,6 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.permissioning; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent; import tech.pegasys.pantheon.metrics.Counter; @@ -19,7 +20,6 @@ import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.Subscribers; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.net.URI; diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodePermissioningControllerFactory.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodePermissioningControllerFactory.java index 1acf07ef30..3eaf082b90 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodePermissioningControllerFactory.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodePermissioningControllerFactory.java @@ -13,13 +13,13 @@ package tech.pegasys.pantheon.ethereum.permissioning; import tech.pegasys.pantheon.ethereum.core.Synchronizer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.ethereum.permissioning.node.provider.SyncStatusNodePermissioningProvider; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; import java.util.Collection; diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java index 34187d88b2..8d2c0546cd 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningController.java @@ -16,6 +16,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import tech.pegasys.pantheon.crypto.Hash; import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.ethereum.transaction.CallParameter; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; @@ -25,7 +26,6 @@ import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValues; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.InetAddress; import java.util.Optional; diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilder.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilder.java index a39f2d20fe..805d17c94c 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilder.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationBuilder.java @@ -13,7 +13,7 @@ package tech.pegasys.pantheon.ethereum.permissioning; import tech.pegasys.pantheon.ethereum.core.Address; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.net.URI; import java.util.List; diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/ContextualNodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/ContextualNodePermissioningProvider.java index 505f3d01e8..598164c97e 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/ContextualNodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/ContextualNodePermissioningProvider.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.permissioning.node; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.util.Optional; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/InsufficientPeersPermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/InsufficientPeersPermissioningProvider.java similarity index 95% rename from ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/InsufficientPeersPermissioningProvider.java rename to ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/InsufficientPeersPermissioningProvider.java index a35e536c08..ca46c57116 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/InsufficientPeersPermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/InsufficientPeersPermissioningProvider.java @@ -10,14 +10,13 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.ethereum.p2p; +package tech.pegasys.pantheon.ethereum.permissioning.node; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.wire.messages.DisconnectMessage.DisconnectReason; -import tech.pegasys.pantheon.ethereum.permissioning.node.ContextualNodePermissioningProvider; import tech.pegasys.pantheon.util.Subscribers; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collection; import java.util.Optional; diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningController.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningController.java index 909ce25fd0..74d9fc78e0 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningController.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningController.java @@ -12,10 +12,10 @@ */ package tech.pegasys.pantheon.ethereum.permissioning.node; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.node.provider.SyncStatusNodePermissioningProvider; import tech.pegasys.pantheon.util.Subscribers; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.List; import java.util.Optional; diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningProvider.java index b8f7cf5806..9acd5336de 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningProvider.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.permissioning.node; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; @FunctionalInterface public interface NodePermissioningProvider { diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodeWhitelistUpdatedEvent.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodeWhitelistUpdatedEvent.java index c59b8a915e..1f8741f60e 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodeWhitelistUpdatedEvent.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodeWhitelistUpdatedEvent.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.ethereum.permissioning.node; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.util.Collections; import java.util.List; diff --git a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapter.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapter.java similarity index 94% rename from ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapter.java rename to ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapter.java index bce0850c34..b66349aca2 100644 --- a/ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapter.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapter.java @@ -10,16 +10,15 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.ethereum.p2p.network; +package tech.pegasys.pantheon.ethereum.permissioning.node; import static com.google.common.base.Preconditions.checkNotNull; import tech.pegasys.pantheon.ethereum.chain.Blockchain; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; -import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.node.provider.SyncStatusNodePermissioningProvider; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.List; import java.util.Optional; @@ -27,7 +26,7 @@ import java.util.Optional; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -class NodePermissioningAdapter extends PeerPermissions { +public class PeerPermissionsAdapter extends PeerPermissions { private static final Logger LOG = LogManager.getLogger(); private final NodePermissioningController nodePermissioningController; @@ -36,7 +35,7 @@ class NodePermissioningAdapter extends PeerPermissions { private final long blockchainListenId; private final long nodePermissioningListenId; - public NodePermissioningAdapter( + public PeerPermissionsAdapter( final NodePermissioningController nodePermissioningController, final List bootnodes, final Blockchain blockchain) { diff --git a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java index 8019aa8392..4034b0dfd3 100644 --- a/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java +++ b/ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProvider.java @@ -16,11 +16,11 @@ import static com.google.common.base.Preconditions.checkNotNull; import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningProvider; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collection; import java.util.HashSet; diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java index 568d762a2b..98389c4406 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java @@ -26,11 +26,11 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import static tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController.NodesWhitelistResult; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.node.NodeWhitelistUpdatedEvent; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.net.URI; diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java index 2883c4022c..366cfda343 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/NodeSmartContractPermissioningControllerTest.java @@ -27,12 +27,12 @@ import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.mainnet.MainnetProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/InsufficientPeersPermissioningProviderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/InsufficientPeersPermissioningProviderTest.java similarity index 98% rename from ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/InsufficientPeersPermissioningProviderTest.java rename to ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/InsufficientPeersPermissioningProviderTest.java index f907865209..f8bd52abc9 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/InsufficientPeersPermissioningProviderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/InsufficientPeersPermissioningProviderTest.java @@ -10,7 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.ethereum.p2p; +package tech.pegasys.pantheon.ethereum.permissioning.node; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -22,7 +22,7 @@ import tech.pegasys.pantheon.ethereum.p2p.api.ConnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.DisconnectCallback; import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.util.Arrays; import java.util.Collection; diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerFactoryTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerFactoryTest.java index 95ce33d531..8f4ff6178b 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerFactoryTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerFactoryTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Synchronizer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.NodePermissioningControllerFactory; @@ -24,7 +25,6 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.Collection; import java.util.Collections; diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerTest.java index 40339f87e1..f922f8fce8 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/NodePermissioningControllerTest.java @@ -21,9 +21,9 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.node.provider.SyncStatusNodePermissioningProvider; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; import java.util.List; diff --git a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapterTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapterTest.java similarity index 94% rename from ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapterTest.java rename to ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapterTest.java index c5d772b226..307058dc68 100644 --- a/ethereum/p2p/src/test/java/tech/pegasys/pantheon/ethereum/p2p/network/NodePermissioningAdapterTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/PeerPermissionsAdapterTest.java @@ -10,23 +10,21 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.ethereum.p2p.network; +package tech.pegasys.pantheon.ethereum.permissioning.node; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static tech.pegasys.pantheon.ethereum.p2p.peers.PeerTestHelper.createPeer; import tech.pegasys.pantheon.ethereum.chain.MutableBlockchain; import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.BlockDataGenerator; import tech.pegasys.pantheon.ethereum.core.InMemoryStorageProvider; +import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions.Action; -import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.node.provider.SyncStatusNodePermissioningProvider; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; import java.util.List; @@ -34,8 +32,9 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; +import org.mockito.ArgumentMatchers; -public class NodePermissioningAdapterTest { +public class PeerPermissionsAdapterTest { private final Peer localNode = createPeer(); private final Peer remoteNode = createPeer(); @@ -45,8 +44,8 @@ public class NodePermissioningAdapterTest { private final MutableBlockchain blockchain = InMemoryStorageProvider.createInMemoryBlockchain(gen.genesisBlock()); private final List bootNodes = new ArrayList<>(); - private final NodePermissioningAdapter adapter = - new NodePermissioningAdapter(nodePermissioningController, bootNodes, blockchain); + private final PeerPermissionsAdapter adapter = + new PeerPermissionsAdapter(nodePermissioningController, bootNodes, blockchain); @Test public void allowInPeerTable() { @@ -386,10 +385,21 @@ public class NodePermissioningAdapterTest { private void mockControllerPermissions( final boolean allowLocalToRemote, final boolean allowRemoteToLocal) { when(nodePermissioningController.isPermitted( - eq(localNode.getEnodeURL()), eq(remoteNode.getEnodeURL()))) + ArgumentMatchers.eq(localNode.getEnodeURL()), + ArgumentMatchers.eq(remoteNode.getEnodeURL()))) .thenReturn(allowLocalToRemote); when(nodePermissioningController.isPermitted( - eq(remoteNode.getEnodeURL()), eq(localNode.getEnodeURL()))) + ArgumentMatchers.eq(remoteNode.getEnodeURL()), + ArgumentMatchers.eq(localNode.getEnodeURL()))) .thenReturn(allowRemoteToLocal); } + + private Peer createPeer() { + return DefaultPeer.fromEnodeURL( + EnodeURL.builder() + .ipAddress("127.0.0.1") + .nodeId(Peer.randomId()) + .useDefaultPorts() + .build()); + } } diff --git a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java index 07aa00b16c..fd3b119536 100644 --- a/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java +++ b/ethereum/permissioning/src/test/java/tech/pegasys/pantheon/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java @@ -22,10 +22,10 @@ import static org.mockito.Mockito.when; import tech.pegasys.pantheon.ethereum.core.SyncStatus; import tech.pegasys.pantheon.ethereum.core.Synchronizer; import tech.pegasys.pantheon.ethereum.core.Synchronizer.SyncStatusListener; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.metrics.Counter; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.MetricsSystem; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.util.ArrayList; import java.util.Collection; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Runner.java b/pantheon/src/main/java/tech/pegasys/pantheon/Runner.java index cf26c58a77..b246233564 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Runner.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Runner.java @@ -17,8 +17,8 @@ import tech.pegasys.pantheon.ethereum.graphql.GraphQLHttpService; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcHttpService; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketService; import tech.pegasys.pantheon.ethereum.p2p.NetworkRunner; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.metrics.prometheus.MetricsService; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.File; import java.io.FileOutputStream; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java index 54e253d7fa..4997cb30f1 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/RunnerBuilder.java @@ -49,7 +49,6 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.pending.Pen import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.pending.PendingTransactionSubscriptionService; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.syncing.SyncingSubscriptionService; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; -import tech.pegasys.pantheon.ethereum.p2p.InsufficientPeersPermissioningProvider; import tech.pegasys.pantheon.ethereum.p2p.NetworkRunner; import tech.pegasys.pantheon.ethereum.p2p.NetworkRunner.NetworkBuilder; import tech.pegasys.pantheon.ethereum.p2p.NoopP2PNetwork; @@ -61,6 +60,8 @@ import tech.pegasys.pantheon.ethereum.p2p.config.RlpxConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.SubProtocolConfiguration; import tech.pegasys.pantheon.ethereum.p2p.network.DefaultP2PNetwork; import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissions; import tech.pegasys.pantheon.ethereum.p2p.permissions.PeerPermissionsBlacklist; import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; import tech.pegasys.pantheon.ethereum.p2p.wire.SubProtocol; @@ -72,14 +73,15 @@ import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.TransactionSmartContractPermissioningController; import tech.pegasys.pantheon.ethereum.permissioning.account.AccountPermissioningController; +import tech.pegasys.pantheon.ethereum.permissioning.node.InsufficientPeersPermissioningProvider; import tech.pegasys.pantheon.ethereum.permissioning.node.NodePermissioningController; +import tech.pegasys.pantheon.ethereum.permissioning.node.PeerPermissionsAdapter; import tech.pegasys.pantheon.ethereum.transaction.TransactionSimulator; import tech.pegasys.pantheon.ethereum.worldstate.WorldStateArchive; import tech.pegasys.pantheon.metrics.MetricsSystem; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsService; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.IOException; import java.nio.file.Path; @@ -266,9 +268,11 @@ public class RunnerBuilder { buildNodePermissioningController( bootnodes, synchronizer, transactionSimulator, localNodeId); - final Optional accountPermissioningController = - buildAccountPermissioningController( - permissioningConfiguration, pantheonController, transactionSimulator); + final PeerPermissions peerPermissions = + nodePermissioningController + .map(nodePC -> new PeerPermissionsAdapter(nodePC, bootnodes, context.getBlockchain())) + .map(nodePerms -> PeerPermissions.combine(nodePerms, bannedNodes)) + .orElse(bannedNodes); NetworkBuilder inactiveNetwork = (caps) -> new NoopP2PNetwork(); NetworkBuilder activeNetwork = @@ -277,11 +281,9 @@ public class RunnerBuilder { .vertx(vertx) .keyPair(keyPair) .config(networkConfig) - .peerPermissions(bannedNodes) + .peerPermissions(peerPermissions) .metricsSystem(metricsSystem) .supportedCapabilities(caps) - .nodePermissioningController(nodePermissioningController) - .blockchain(context.getBlockchain()) .build(); final NetworkRunner networkRunner = @@ -313,6 +315,10 @@ public class RunnerBuilder { final Optional nodeLocalConfigPermissioningController = nodePermissioningController.flatMap(NodePermissioningController::localConfigController); + final Optional accountPermissioningController = + buildAccountPermissioningController( + permissioningConfiguration, pantheonController, transactionSimulator); + final Optional accountLocalConfigPermissioningController = accountPermissioningController.flatMap( diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java index eea27f2165..7e74a764b3 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/EthNetworkConfig.java @@ -18,7 +18,7 @@ import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.M import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.RINKEBY_BOOTSTRAP_NODES; import static tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration.ROPSTEN_BOOTSTRAP_NODES; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.io.IOException; import java.net.URI; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 56d0d4b113..ffa08493a2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -56,6 +56,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.p2p.peers.StaticNodesParser; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; @@ -76,7 +77,6 @@ import tech.pegasys.pantheon.util.BlockImporter; import tech.pegasys.pantheon.util.InvalidConfigurationException; import tech.pegasys.pantheon.util.PermissioningConfigurationValidator; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import tech.pegasys.pantheon.util.number.PositiveNumber; import tech.pegasys.pantheon.util.uint.UInt256; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/custom/EnodeToURIPropertyConverter.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/custom/EnodeToURIPropertyConverter.java index 936007ca0c..f0659a00e9 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/custom/EnodeToURIPropertyConverter.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/custom/EnodeToURIPropertyConverter.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.cli.custom; -import tech.pegasys.pantheon.util.enode.EnodeURL; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import java.net.URI; import java.util.function.Function; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java index d190d254b9..373068bacb 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/RunnerTest.java @@ -40,6 +40,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.mainnet.HeaderValidationMode; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSchedule; import tech.pegasys.pantheon.ethereum.mainnet.ProtocolSpec; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.storage.StorageProvider; import tech.pegasys.pantheon.ethereum.storage.keyvalue.RocksDbStorageProvider; import tech.pegasys.pantheon.metrics.MetricsSystem; @@ -47,7 +48,6 @@ import tech.pegasys.pantheon.metrics.noop.NoOpMetricsSystem; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.testutil.TestClock; -import tech.pegasys.pantheon.util.enode.EnodeURL; import tech.pegasys.pantheon.util.uint.UInt256; import java.io.IOException; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index e8966fa0fb..fc8a3d854c 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -45,13 +45,13 @@ import tech.pegasys.pantheon.ethereum.graphql.GraphQLConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningConfiguration; import tech.pegasys.pantheon.metrics.MetricCategory; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.util.bytes.BytesValue; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.io.File; import java.io.IOException; diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java index 90d183364e..b04b9d7e17 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/util/LocalPermissioningConfigurationValidatorTest.java @@ -17,9 +17,9 @@ import static org.assertj.core.api.Assertions.fail; import tech.pegasys.pantheon.cli.EthNetworkConfig; import tech.pegasys.pantheon.cli.NetworkName; +import tech.pegasys.pantheon.ethereum.p2p.peers.EnodeURL; import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfigurationBuilder; -import tech.pegasys.pantheon.util.enode.EnodeURL; import java.net.URI; import java.net.URL;