-
Notifications
You must be signed in to change notification settings - Fork 12
ethnode: Add NewEnodeURI(uri string) (*EnodeURI, error) #76
Copy link
Copy link
Closed
Labels
Good First IssueGood for newcomersGood for newcomersSomedayGood idea but might not be the right time for it yetGood idea but might not be the right time for it yet
Description
I wrote this clunky helper (with some accompanied tests):
Lines 316 to 339 in aaabebc
| // EnodeEqual returns whether two enode:// strings are equivalent after | |
| // normalization, comparing only the enodeID and remote address. | |
| // Failure to parse returns false. Remote address "[::]" acts as a wildcard. | |
| func EnodeEqual(a, b string) bool { | |
| uriA, err := url.Parse(a) | |
| if err != nil || uriA.User == nil { | |
| return false | |
| } | |
| uriB, err := url.Parse(b) | |
| if err != nil || uriB.User == nil { | |
| return false | |
| } | |
| if uriA.User.Username() != uriB.User.Username() { | |
| return false | |
| } | |
| if uriA.Hostname() == "::" || uriB.Hostname() == "::" { | |
| if uriA.Port() != uriB.Port() { | |
| return false | |
| } | |
| return true | |
| } | |
| return uriA.Host == uriB.Host | |
| } |
@ryanschneider had a good idea: https://github.com/vipnode/vipnode/pull/73/files#r327756689
maybe we should have a
NewEnodeURI(uri string) (*EnodeURI, error)method that returns aEnodeURIstruct with fields likeID,Address, andPort, and possibly helpers likeIsWildcard()?
Noting it here so we don't forget.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Good First IssueGood for newcomersGood for newcomersSomedayGood idea but might not be the right time for it yetGood idea but might not be the right time for it yet