Skip to content

ethnode: Add NewEnodeURI(uri string) (*EnodeURI, error) #76

@shazow

Description

@shazow

I wrote this clunky helper (with some accompanied tests):

vipnode/ethnode/rpc.go

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 a EnodeURI struct with fields like ID, Address, and Port, and possibly helpers like IsWildcard()?

Noting it here so we don't forget.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good First IssueGood for newcomersSomedayGood idea but might not be the right time for it yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions