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

[PAN-2585] Prefer EnodeURL over Endpoint #1378

Merged
merged 23 commits into from
May 1, 2019

Conversation

mbaxter
Copy link
Contributor

@mbaxter mbaxter commented May 1, 2019

PR description

EnodeURL is a more complete representation of a node's address than Endpoint and many API's are being built around EnodeURL. To simplify the code base, this PR tries to remove and contain the use of Endpoint in favor of EnodeURL by:

  • Moving Endpoint into the discovery package, as it is really an object that is specific to discovery message parsing.
  • Move discovery-specific serialization logic from various Peer classes to DiscoveryPeer
  • Removing getEndpoint() from Peer interface.
  • Try to build peers from EnodeURL objects so we can leverage the EnodeURL.Builder rather than duplicating logic across many constructors (removed a lot of DefaultPeer constructors).

A few tangential changes are included as well:

  • URI parsing was moved from DefaultPeer to EnodeURL and replaces the existing String-based URI parsing code.
  • EnodeURL.getIp() returns an InetAddress and getIpAsString() was added to support the cases where a string is required.
  • EnodeURL.getListeningPort() returns a primitive int rather than an Integer.
  • The default P2P_PORT constant was moved to DefaultCommandValues as there's really no case where the p2p logic should assume a default port.
  • Update PeerDiscoveryController to extract and deduplicate peers from neighbors packets before passing those peers on to RecursivePeerRefreshState.

@mbaxter mbaxter marked this pull request as ready for review May 1, 2019 02:24
Copy link
Contributor

@ajsutton ajsutton left a comment

Choose a reason for hiding this comment

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

LGTM.

verify(controller, times(0)).bond(otherPeer);
verify(controller, times(1)).bond(otherPeer2);
verify(controller, times(0)).bond(eq(otherPeer));
verify(controller, times(1)).bond(eq(otherPeer2));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't think we need the eq here. The default is equals comparison so you typically only use eq if you need to use other matchers for some params (because all params must use matchers if any do).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

+ "(\\?discport=(?<discovery>\\d+))?$";
private static final int NODE_ID_SIZE = 64;
private static final Pattern DISCPORT_QUERY_STRING_REGEX =
Pattern.compile("discport=([0-9]{1,5})");
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're being really strict this should probably be "(^|&)discport=([0-9]{1,4})" I think. So discport should either be the first arg or after a & to prevent matching enode://...@...:30303?notthediscport=1234

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this check stricter and added more tests. For now, I have the parsing fail if there are any additional params outside of a singular discport param. It's simpler to implement this way and if we need additional params for some reason we can add that later.

public InetAddress getIp() {
return ip;
}

public InetAddress getInetAddress() {
return ip;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably shouldn't have both getIp and getInetAddress both returning the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call - not sure how I missed this since the method is right below the one I added 😂

@mbaxter mbaxter merged commit 3437b1b into PegaSysEng:master May 1, 2019
notlesh pushed a commit to notlesh/pantheon that referenced this pull request May 4, 2019
notlesh pushed a commit to notlesh/pantheon that referenced this pull request May 14, 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