-
Notifications
You must be signed in to change notification settings - Fork 130
[PAN-2731] Extract connection management from P2PNetwork #1538
[PAN-2731] Extract connection management from P2PNetwork #1538
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments. Happy to discuss if something is unclear.
ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/ConnectCallback.java
Show resolved
Hide resolved
ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/api/MessageCallback.java
Outdated
Show resolved
Hide resolved
ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java
Outdated
Show resolved
Hide resolved
ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java
Show resolved
Hide resolved
ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/network/DefaultP2PNetwork.java
Show resolved
Hide resolved
.forEach(c -> c.disconnect(DisconnectReason.TOO_MANY_PEERS)); | ||
} | ||
|
||
private int prioritizeConnections(final RlpxConnection a, final RlpxConnection b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Optional) Why not using first and second instead of a and b ? In general one letter variable could be confusing.
* @return A negative value if {@code a} should be kept, a positive value is {@code b} should be | ||
* kept | ||
*/ | ||
private int compareDuplicateConnections(final RlpxConnection a, final RlpxConnection b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Optional) Why not using first and second instead of a and b ? In general one letter variable could be confusing.
if (!(o instanceof RemotelyInitiatedRlpxConnection)) { | ||
return false; | ||
} | ||
final RemotelyInitiatedRlpxConnection that = (RemotelyInitiatedRlpxConnection) o; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Optional) I would suggest not to use an intermediate local variable.
@VisibleForTesting | ||
int connectionCount() { | ||
return pendingConnections.size() + rlpxAgent.getConnectionCount(); | ||
private void attemptPeerConnections() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Clear and concise method.
ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/rlpx/RlpxAgent.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have addressed most important comments. Looks good to me.
PR description
This PR extracts connection management logic out of
DefaultP2PNetwork
and into a set of new, more narrowly focused classes.RlpxAgent
manages the set of active and pending connections and enforces connection-related permissions and max peer limits.NettyConnectionInitializer
now contains the netty-specific code for establishing connections. TheDefaultP2PNetwork
is left to delegate actions to the more targeted classes it is composed of and do some coordination between these classes.Other changes include: