fixed method name and some 'finals' (#3370)

Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
pull/3386/head
Stefan Pingel 3 years ago committed by GitHub
parent 33b8b872ff
commit cd281946c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
  2. 2
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminAddPeer.java
  3. 6
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminAddPeerTest.java
  4. 2
      ethereum/mock-p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/testing/MockNetwork.java
  5. 14
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java
  6. 2
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NoopP2PNetwork.java
  7. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetwork.java
  8. 16
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/DefaultPeer.java
  9. 8
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java
  10. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/MaintainedPeers.java
  11. 10
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java
  12. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/DeFramer.java
  13. 10
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java
  14. 2
      util/src/main/java/org/hyperledger/besu/util/Subscribers.java

@ -534,7 +534,7 @@ public class RunnerBuilder {
sanitizePeers(network, staticNodes)
.map(DefaultPeer::fromEnodeURL)
.forEach(peerNetwork::addMaintainConnectionPeer);
.forEach(peerNetwork::addMaintainedConnectionPeer);
final Optional<NodeLocalConfigPermissioningController> nodeLocalConfigPermissioningController =
nodePermissioningController.flatMap(NodePermissioningController::localConfigController);

@ -44,7 +44,7 @@ public class AdminAddPeer extends AdminModifyPeer {
LOG.debug("Adding ({}) to peers", enode);
final EnodeURL enodeURL = EnodeURLImpl.fromString(enode);
final Peer peer = DefaultPeer.fromEnodeURL(enodeURL);
final boolean addedToNetwork = peerNetwork.addMaintainConnectionPeer(peer);
final boolean addedToNetwork = peerNetwork.addMaintainedConnectionPeer(peer);
return new JsonRpcSuccessResponse(id, addedToNetwork);
}
}

@ -128,7 +128,7 @@ public class AdminAddPeerTest {
@Test
public void requestAddsValidEnode() {
when(p2pNetwork.addMaintainConnectionPeer(any())).thenReturn(true);
when(p2pNetwork.addMaintainedConnectionPeer(any())).thenReturn(true);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(validRequest.getRequest().getId(), true);
@ -154,7 +154,7 @@ public class AdminAddPeerTest {
@Test
public void requestReturnsFalseIfAddFails() {
when(p2pNetwork.addMaintainConnectionPeer(any())).thenReturn(false);
when(p2pNetwork.addMaintainedConnectionPeer(any())).thenReturn(false);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(validRequest.getRequest().getId(), false);
@ -166,7 +166,7 @@ public class AdminAddPeerTest {
@Test
public void requestReturnsErrorWhenP2pDisabled() {
when(p2pNetwork.addMaintainConnectionPeer(any()))
when(p2pNetwork.addMaintainedConnectionPeer(any()))
.thenThrow(
new P2PDisabledException("P2P networking disabled. Unable to connect to add peer."));

@ -174,7 +174,7 @@ public final class MockNetwork {
}
@Override
public boolean addMaintainConnectionPeer(final Peer peer) {
public boolean addMaintainedConnectionPeer(final Peer peer) {
return true;
}

@ -240,7 +240,7 @@ public class DefaultP2PNetwork implements P2PNetwork {
final Consumer<? super NatManager> natAction =
natManager -> {
UpnpNatManager upnpNatManager = (UpnpNatManager) natManager;
final UpnpNatManager upnpNatManager = (UpnpNatManager) natManager;
upnpNatManager.requestPortForward(
discoveryPort, NetworkProtocol.UDP, NatServiceType.DISCOVERY);
upnpNatManager.requestPortForward(
@ -302,7 +302,7 @@ public class DefaultP2PNetwork implements P2PNetwork {
}
@Override
public boolean addMaintainConnectionPeer(final Peer peer) {
public boolean addMaintainedConnectionPeer(final Peer peer) {
if (localNode.isReady()
&& localNode.getPeer() != null
&& localNode.getPeer().getEnodeURL() != null
@ -332,16 +332,16 @@ public class DefaultP2PNetwork implements P2PNetwork {
@VisibleForTesting
DNSDaemonListener createDaemonListener() {
return (seq, records) -> {
List<DiscoveryPeer> peers = new ArrayList<>();
for (EthereumNodeRecord enr : records) {
EnodeURL enodeURL =
final List<DiscoveryPeer> peers = new ArrayList<>();
for (final EthereumNodeRecord enr : records) {
final EnodeURL enodeURL =
EnodeURLImpl.builder()
.ipAddress(enr.ip())
.nodeId(enr.publicKey().bytes())
.discoveryPort(Optional.ofNullable(enr.udp()))
.listeningPort(Optional.ofNullable(enr.tcp()))
.build();
DiscoveryPeer peer = DiscoveryPeer.fromEnode(enodeURL);
final DiscoveryPeer peer = DiscoveryPeer.fromEnode(enodeURL);
peers.add(peer);
rlpxAgent.connect(peer);
}
@ -379,7 +379,7 @@ public class DefaultP2PNetwork implements P2PNetwork {
@Override
public Stream<DiscoveryPeer> streamDiscoveredPeers() {
List<DiscoveryPeer> peers = dnsPeers.get();
final List<DiscoveryPeer> peers = dnsPeers.get();
if (peers != null) {
Collections.shuffle(peers);
return Stream.concat(peerDiscoveryAgent.streamDiscoveredPeers(), peers.stream());

@ -56,7 +56,7 @@ public class NoopP2PNetwork implements P2PNetwork {
public void subscribeDisconnect(final DisconnectCallback callback) {}
@Override
public boolean addMaintainConnectionPeer(final Peer peer) {
public boolean addMaintainedConnectionPeer(final Peer peer) {
throw new P2PDisabledException("P2P networking disabled. Unable to connect to add peer.");
}

@ -101,12 +101,12 @@ public interface P2PNetwork extends Closeable {
* @return boolean representing whether or not the peer has been added to the list, false is
* returned if the peer was already on the list
*/
boolean addMaintainConnectionPeer(final Peer peer);
boolean addMaintainedConnectionPeer(final Peer peer);
/**
* Disconnect and remove the given {@link Peer} from the maintained peer list. Peer is
* disconnected even if it is not in the maintained peer list. See {@link
* #addMaintainConnectionPeer(Peer)} for details on the maintained peer list.
* #addMaintainedConnectionPeer(Peer)} for details on the maintained peer list.
*
* @param peer The peer to which connections are not longer required
* @return boolean representing whether the peer was removed from the maintained peer list

@ -22,11 +22,11 @@ import java.util.Objects;
/** The default, basic representation of an Ethereum {@link Peer}. */
public class DefaultPeer extends DefaultPeerId implements Peer {
private final EnodeURL enode;
private final EnodeURL enodeURL;
protected DefaultPeer(final EnodeURL enode) {
super(enode.getNodeId());
this.enode = enode;
protected DefaultPeer(final EnodeURL enodeURL) {
super(enodeURL.getNodeId());
this.enodeURL = enodeURL;
}
public static DefaultPeer fromEnodeURL(final EnodeURL enodeURL) {
@ -57,7 +57,7 @@ public class DefaultPeer extends DefaultPeerId implements Peer {
@Override
public EnodeURL getEnodeURL() {
return enode;
return enodeURL;
}
@Override
@ -72,19 +72,19 @@ public class DefaultPeer extends DefaultPeerId implements Peer {
return false;
}
final DefaultPeer other = (DefaultPeer) obj;
return id.equals(other.id) && enode.equals(other.enode);
return id.equals(other.id) && enodeURL.equals(other.enodeURL);
}
@Override
public int hashCode() {
return Objects.hash(id, enode);
return Objects.hash(id, enodeURL);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DefaultPeer{");
sb.append("id=").append(id);
sb.append(", enode=").append(enode);
sb.append(", enode=").append(enodeURL);
sb.append('}');
return sb.toString();
}

@ -79,7 +79,7 @@ public class EnodeURLImpl implements EnodeURL {
try {
checkStringArgumentNotEmpty(value, "Invalid empty value.");
return fromURI(URI.create(value), enodeDnsConfiguration);
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
String message =
String.format(
"Invalid enode URL syntax '%s'. Enode URL should have the following format 'enode://<node_id>@<ip>:<listening_port>[?discport=<discovery_port>]'.",
@ -237,7 +237,7 @@ public class EnodeURLImpl implements EnodeURL {
hostname -> {
try {
return InetAddress.getByName(hostname);
} catch (UnknownHostException e) {
} catch (final UnknownHostException e) {
return ip;
}
})
@ -283,7 +283,7 @@ public class EnodeURLImpl implements EnodeURL {
if (o == null || getClass() != o.getClass()) {
return false;
}
EnodeURL enodeURL = (EnodeURL) o;
final EnodeURL enodeURL = (EnodeURL) o;
return Objects.equals(getNodeId(), enodeURL.getNodeId())
&& Objects.equals(getIp(), enodeURL.getIp())
&& Objects.equals(getListeningPort(), enodeURL.getListeningPort())
@ -364,7 +364,7 @@ public class EnodeURLImpl implements EnodeURL {
this.maybeHostname = Optional.of(ip);
}
this.ip = InetAddress.getByName(ip);
} catch (UnknownHostException e) {
} catch (final UnknownHostException e) {
if (!enodeDnsConfiguration.updateEnabled()) {
throw new IllegalArgumentException("Invalid ip address or hostname.");
} else {

@ -33,13 +33,13 @@ public class MaintainedPeers {
checkArgument(
peer.getEnodeURL().isListening(),
"Invalid enode url. Enode url must contain a non-zero listening port.");
boolean wasAdded = maintainedPeers.add(peer);
final boolean wasAdded = maintainedPeers.add(peer);
addedSubscribers.forEach(s -> s.onPeerAdded(peer, wasAdded));
return wasAdded;
}
public boolean remove(final Peer peer) {
boolean wasRemoved = maintainedPeers.remove(peer);
final boolean wasRemoved = maintainedPeers.remove(peer);
removedCallbackSubscribers.forEach(s -> s.onPeerRemoved(peer, wasRemoved));
return wasRemoved;
}

@ -54,7 +54,6 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.annotations.VisibleForTesting;
import org.apache.tuweni.bytes.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -76,7 +75,7 @@ public class RlpxAgent {
// without allowing the counterparty to play nodeId farming games
private final Bytes nodeIdMask = Bytes.random(SECPPublicKey.BYTE_LENGTH);
@VisibleForTesting final Map<Bytes, RlpxConnection> connectionsById = new ConcurrentHashMap<>();
final Map<Bytes, RlpxConnection> connectionsById = new ConcurrentHashMap<>();
private final AtomicBoolean started = new AtomicBoolean(false);
private final AtomicBoolean stopped = new AtomicBoolean(false);
@ -182,7 +181,7 @@ public class RlpxAgent {
}
public void disconnect(final Bytes peerId, final DisconnectReason reason) {
RlpxConnection connection = connectionsById.remove(peerId);
final RlpxConnection connection = connectionsById.remove(peerId);
if (connection != null) {
connection.disconnect(reason);
}
@ -240,7 +239,8 @@ public class RlpxAgent {
}
// Initiate connection or return existing connection
AtomicReference<CompletableFuture<PeerConnection>> connectionFuture = new AtomicReference<>();
final AtomicReference<CompletableFuture<PeerConnection>> connectionFuture =
new AtomicReference<>();
connectionsById.compute(
peer.getId(),
(id, existingConnection) -> {
@ -252,7 +252,7 @@ public class RlpxAgent {
// We're initiating a new connection
final CompletableFuture<PeerConnection> future = initiateOutboundConnection(peer);
connectionFuture.set(future);
RlpxConnection newConnection = RlpxConnection.outboundConnection(peer, future);
final RlpxConnection newConnection = RlpxConnection.outboundConnection(peer, future);
newConnection.subscribeConnectionEstablished(
(conn) -> {
this.dispatchConnect(conn.getPeerConnection());

@ -138,7 +138,7 @@ final class DeFramer extends ByteToMessageDecoder {
// Check peer is who we expected
if (expectedPeer.isPresent()
&& !Objects.equals(expectedPeer.get().getId(), peerInfo.getNodeId())) {
String unexpectedMsg =
final String unexpectedMsg =
String.format(
"Expected id %s, but got %s", expectedPeer.get().getId(), peerInfo.getNodeId());
connectFuture.completeExceptionally(new UnexpectedPeerConnectionException(unexpectedMsg));
@ -166,7 +166,7 @@ final class DeFramer extends ByteToMessageDecoder {
new MessageFramer(capabilityMultiplexer, framer));
connectFuture.complete(connection);
} else if (message.getCode() == WireMessageCodes.DISCONNECT) {
DisconnectMessage disconnectMessage = DisconnectMessage.readFrom(message);
final DisconnectMessage disconnectMessage = DisconnectMessage.readFrom(message);
LOG.debug(
"Peer {} disconnected before sending HELLO. Reason: {}",
expectedPeer.map(Peer::getEnodeURLString).orElse("unknown"),

@ -120,7 +120,7 @@ public final class DefaultP2PNetworkTest {
network.start();
final Peer peer = PeerTestHelper.createPeer();
assertThat(network.addMaintainConnectionPeer(peer)).isTrue();
assertThat(network.addMaintainedConnectionPeer(peer)).isTrue();
assertThat(maintainedPeers.contains(peer)).isTrue();
verify(rlpxAgent).connect(peer);
@ -133,8 +133,8 @@ public final class DefaultP2PNetworkTest {
network.start();
final Peer peer = PeerTestHelper.createPeer();
assertThat(network.addMaintainConnectionPeer(peer)).isTrue();
assertThat(network.addMaintainConnectionPeer(peer)).isFalse();
assertThat(network.addMaintainedConnectionPeer(peer)).isTrue();
assertThat(network.addMaintainedConnectionPeer(peer)).isFalse();
verify(rlpxAgent, times(2)).connect(peer);
verify(discoveryAgent, times(2)).bond(peer);
assertThat(maintainedPeers.contains(peer)).isTrue();
@ -146,7 +146,7 @@ public final class DefaultP2PNetworkTest {
network.start();
final Peer peer = PeerTestHelper.createPeer();
assertThat(network.addMaintainConnectionPeer(peer)).isTrue();
assertThat(network.addMaintainedConnectionPeer(peer)).isTrue();
assertThat(network.removeMaintainedConnectionPeer(peer)).isTrue();
assertThat(maintainedPeers.contains(peer)).isFalse();
@ -363,7 +363,7 @@ public final class DefaultP2PNetworkTest {
network.start();
assertThat(network.getLocalEnode()).isPresent();
final Peer peer = PeerTestHelper.createPeer(network.getLocalEnode().get().getNodeId());
assertThat(network.addMaintainConnectionPeer(peer)).isFalse();
assertThat(network.addMaintainedConnectionPeer(peer)).isFalse();
}
@Test

@ -110,7 +110,7 @@ public class Subscribers<T> {
subscriber -> {
try {
action.accept(subscriber);
} catch (Exception e) {
} catch (final Exception e) {
if (suppressCallbackExceptions) {
LOG.error("Error in callback: ", e);
} else {

Loading…
Cancel
Save