I wrote this clunky helper (with some accompanied tests):
|
// 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 a EnodeURI struct with fields like ID, Address, and Port, and possibly helpers like IsWildcard()?
Noting it here so we don't forget.
I wrote this clunky helper (with some accompanied tests):
vipnode/ethnode/rpc.go
Lines 316 to 339 in aaabebc
@ryanschneider had a good idea: https://github.com/vipnode/vipnode/pull/73/files#r327756689
Noting it here so we don't forget.