diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelector.java similarity index 91% rename from ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerManager.java rename to ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelector.java index 9424ee0b48..f399963173 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelector.java @@ -28,11 +28,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This is a simple PeerManager implementation that can be used the default implementation in most + * This is a simple PeerSelector implementation that can be used the default implementation in most * situations */ -public class DefaultPeerManager implements PeerManager { - private static final Logger LOG = LoggerFactory.getLogger(DefaultPeerManager.class); +public class DefaultPeerSelector implements PeerSelector { + private static final Logger LOG = LoggerFactory.getLogger(DefaultPeerSelector.class); // use a synchronized map to ensure the map is never modified by multiple threads at once private final Map ethPeersByPeerId = diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerSelector.java similarity index 80% rename from ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerManager.java rename to ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerSelector.java index 14323474a1..73af26ec4c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerSelector.java @@ -20,11 +20,11 @@ import org.hyperledger.besu.ethereum.p2p.peers.PeerId; import java.util.Optional; import java.util.function.Predicate; -/** "Manages" the EthPeers for the PeerTaskExecutor */ -public interface PeerManager { +/** Selects the EthPeers for the PeerTaskExecutor */ +public interface PeerSelector { /** - * Gets the highest reputation peer matching the supplies filter + * Gets the highest reputation peer matching the supplied filter * * @param filter a filter to match prospective peers with * @return the highest reputation peer matching the supplies filter @@ -37,21 +37,21 @@ public interface PeerManager { * * @param peerId the peerId of the desired EthPeer * @return An Optional\ containing the EthPeer identified by peerId if present in the - * PeerManager, or empty otherwise + * PeerSelector, or empty otherwise */ Optional getPeerByPeerId(final PeerId peerId); /** - * Add the supplied EthPeer to the PeerManager + * Add the supplied EthPeer to the PeerSelector * - * @param ethPeer the EthPeer to be added to the PeerManager + * @param ethPeer the EthPeer to be added to the PeerSelector */ void addPeer(final EthPeer ethPeer); /** - * Remove the EthPeer identified by peerId from the PeerManager + * Remove the EthPeer identified by peerId from the PeerSelector * - * @param peerId the PeerId of the EthPeer to be removed from the PeerManager + * @param peerId the PeerId of the EthPeer to be removed from the PeerSelector */ void removePeer(final PeerId peerId); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java index fabf88d05d..ad56987efc 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutor.java @@ -34,17 +34,17 @@ import java.util.function.Supplier; public class PeerTaskExecutor { private static final long[] WAIT_TIME_BEFORE_RETRY = {0, 20000, 5000}; - private final PeerManager peerManager; + private final PeerSelector peerSelector; private final PeerTaskRequestSender requestSender; private final Supplier protocolSpecSupplier; private final LabelledMetric requestTimer; public PeerTaskExecutor( - final PeerManager peerManager, + final PeerSelector peerSelector, final PeerTaskRequestSender requestSender, final Supplier protocolSpecSupplier, final MetricsSystem metricsSystem) { - this.peerManager = peerManager; + this.peerSelector = peerSelector; this.requestSender = requestSender; this.protocolSpecSupplier = protocolSpecSupplier; requestTimer = @@ -61,7 +61,7 @@ public class PeerTaskExecutor { EthPeer peer; try { peer = - peerManager.getPeer( + peerSelector.getPeer( (candidatePeer) -> isPeerUnused(candidatePeer, usedEthPeers) && (protocolSpecSupplier.get().isPoS() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelectorTest.java similarity index 85% rename from ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerManagerTest.java rename to ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelectorTest.java index 5aa04f8f9a..f3b0b27033 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/DefaultPeerSelectorTest.java @@ -28,31 +28,31 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class DefaultPeerManagerTest { +public class DefaultPeerSelectorTest { - public DefaultPeerManager peerManager; + public DefaultPeerSelector peerSelector; @BeforeEach public void beforeTest() { - peerManager = new DefaultPeerManager(); + peerSelector = new DefaultPeerSelector(); } @Test public void testGetPeer() throws NoAvailablePeerException { EthPeer protocol1With5ReputationPeer = createTestPeer(Set.of(Capability.create("capability1", 1)), "protocol1", 5); - peerManager.addPeer(protocol1With5ReputationPeer); + peerSelector.addPeer(protocol1With5ReputationPeer); EthPeer protocol1With4ReputationPeer = createTestPeer(Set.of(Capability.create("capability1", 1)), "protocol1", 4); - peerManager.addPeer(protocol1With4ReputationPeer); + peerSelector.addPeer(protocol1With4ReputationPeer); EthPeer protocol2With50ReputationPeer = createTestPeer(Set.of(Capability.create("capability1", 1)), "protocol2", 50); - peerManager.addPeer(protocol2With50ReputationPeer); + peerSelector.addPeer(protocol2With50ReputationPeer); EthPeer protocol2With4ReputationPeer = createTestPeer(Set.of(Capability.create("capability1", 1)), "protocol2", 4); - peerManager.addPeer(protocol2With4ReputationPeer); + peerSelector.addPeer(protocol2With4ReputationPeer); - EthPeer result = peerManager.getPeer((p) -> p.getProtocolName().equals("protocol1")); + EthPeer result = peerSelector.getPeer((p) -> p.getProtocolName().equals("protocol1")); Assertions.assertSame(protocol1With5ReputationPeer, result); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java index 2c015425f1..930f4325b6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/PeerTaskExecutorTest.java @@ -35,7 +35,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; public class PeerTaskExecutorTest { - private @Mock PeerManager peerManager; + private @Mock PeerSelector peerSelector; private @Mock PeerTaskRequestSender requestSender; private @Mock ProtocolSpec protocolSpec; private @Mock PeerTask peerTask; @@ -51,7 +51,7 @@ public class PeerTaskExecutorTest { mockCloser = MockitoAnnotations.openMocks(this); peerTaskExecutor = new PeerTaskExecutor( - peerManager, requestSender, () -> protocolSpec, new NoOpMetricsSystem()); + peerSelector, requestSender, () -> protocolSpec, new NoOpMetricsSystem()); } @AfterEach @@ -205,7 +205,7 @@ public class PeerTaskExecutorTest { String subprotocol = "subprotocol"; Object responseObject = new Object(); - Mockito.when(peerManager.getPeer(Mockito.any(Predicate.class))).thenReturn(ethPeer); + Mockito.when(peerSelector.getPeer(Mockito.any(Predicate.class))).thenReturn(ethPeer); Mockito.when(peerTask.getRequestMessage()).thenReturn(requestMessageData); Mockito.when(peerTask.getPeerTaskBehaviors()).thenReturn(Collections.emptyList()); @@ -238,7 +238,7 @@ public class PeerTaskExecutorTest { int requestMessageDataCode = 123; EthPeer peer2 = Mockito.mock(EthPeer.class); - Mockito.when(peerManager.getPeer(Mockito.any(Predicate.class))) + Mockito.when(peerSelector.getPeer(Mockito.any(Predicate.class))) .thenReturn(ethPeer) .thenReturn(peer2);