Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2731] Extract connection management from P2PNetwork #1538

Merged
merged 27 commits into from
Jun 11, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented Jun 7, 2019

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. The DefaultP2PNetwork is left to delegate actions to the more targeted classes it is composed of and do some coordination between these classes.

Other changes include:

  • Update Subscribers to optionally suppress callback exceptions.
  • Update IBFT connection handling to account for duplicate connections.
  • Simplify p2p configuration objects and delete dead code.
  • Add functional interfaces for various p2p callbacks.
  • Some reorganization of classes and tests.

@mbaxter mbaxter marked this pull request as ready for review June 11, 2019 15:44
Copy link
Contributor

@AbdelStark AbdelStark left a 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.

.forEach(c -> c.disconnect(DisconnectReason.TOO_MANY_PEERS));
}

private int prioritizeConnections(final RlpxConnection a, final RlpxConnection b) {
Copy link
Contributor

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) {
Copy link
Contributor

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;
Copy link
Contributor

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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Clear and concise method.

Copy link
Contributor

@AbdelStark AbdelStark left a 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.

@mbaxter mbaxter merged commit 15fb741 into PegaSysEng:master Jun 11, 2019
@mbaxter mbaxter mentioned this pull request Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants