-
Notifications
You must be signed in to change notification settings - Fork 130
[PAN-2588] Create P2PNetwork Builder #1343
[PAN-2588] Create P2PNetwork Builder #1343
Conversation
cc7baab
to
049ed1c
Compare
* | ||
* @return A stream of discovered peers on the network. | ||
*/ | ||
Stream<DiscoveryPeer> getDiscoveredPeers(); |
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.
I'm not sure a Stream
should be returned as a property. Streams are single use and have transient state, and mutations are not propagated back into the returning object. Could this be renamed streamDiscoveredPeers
? This may need another PR to push this getFoo
-> streamFoo
done properly, but the name would then reflect reality.
Another option is to return the backing collection, but that looks to be an even deeper refactor to do properly.
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.
Up to now, we haven't used any special naming for streams. But we can discuss offline and maybe create a follow-up PR.
@@ -70,7 +71,7 @@ | |||
private static final long PEER_REFRESH_INTERVAL_MS = MILLISECONDS.convert(30, TimeUnit.MINUTES); | |||
|
|||
protected final List<DiscoveryPeer> bootstrapPeers; | |||
private final PeerRequirement peerRequirement; | |||
private final List<PeerRequirement> peerRequirements = new CopyOnWriteArrayList<>(); |
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.
😄 CopyOnWriteArray
is very concurrent friendly.
peerBlacklist, | ||
nodeWhitelistController, | ||
nodePermissioningController, | ||
metricsSystem); | ||
checkArgument(vertx != null, "vertx instance cannot be null"); | ||
this.vertx = vertx; | ||
|
||
metricsSystem.createIntegerGauge( |
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.
Just to clarify, is the VertxPeerDiscoveryAgent created once and only once per server? If not the createIntegerGauge
call will result in errors on the second and subsequent calls. Not sure there is any way to hedge this.
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.
Yes, currently only created once.
@@ -741,4 +716,140 @@ private void onConnectionEstablished(final PeerConnection connection) { | |||
connections.registerConnection(connection); | |||
connectCallbacks.forEach(callback -> callback.accept(connection)); | |||
} | |||
|
|||
public static class Builder { |
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.
Not for this PR, but we should consider using a Builder library for these in the future to cut down on busy-work code. Lombok and Guava autoValues both have support for the builder pattern like we use it. Guava has the advantage we use part of it in our code already.
PR description
Create a
P2PNetwork
builder. Using this builder pattern simplifies tests and should make it simpler to update theP2PNetwork
in the future.This PR also:
network
packagenetty
package tonetwork.netty
NettyP2PNetworkTest
into two tests: one that depends on the concrete implementation details of the network and one that doesn'tNettyP2PNetwork
toDefaultP2PNework
PeerRequirement
's on thePeerDiscoveryAgent
instance rather than passing the requirements to the constructor - this allows us to construct the discovery agent outside of theP2PNetwork
and pass it in as a dependencyReviewer's Notes
To review, it may be easier to look through individual commits in order to view changes without the noise of the file reorganization.