Skip to content

p2p: require all addresses come with an ID no matter what#1352

Merged
ebuchman merged 1 commit intodevelopfrom
1228-require-id
Apr 5, 2018
Merged

p2p: require all addresses come with an ID no matter what#1352
ebuchman merged 1 commit intodevelopfrom
1228-require-id

Conversation

@melekes
Copy link
Contributor

@melekes melekes commented Mar 22, 2018

Refs #1228

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG.md

@melekes melekes requested a review from ebuchman as a code owner March 22, 2018 10:30
@melekes melekes changed the base branch from master to develop March 22, 2018 10:30
@melekes melekes force-pushed the 1228-require-id branch 3 times, most recently from 291dd0c to ee3e40d Compare March 22, 2018 10:34
@melekes melekes requested a review from xla March 22, 2018 10:34
@ebuchman
Copy link
Contributor

Looks like #1345 is rearing it's head. Maybe @xla can help work some magic on that one :P

@codecov-io
Copy link

codecov-io commented Mar 23, 2018

Codecov Report

Merging #1352 into develop will increase coverage by 0.13%.
The diff coverage is 100%.

@@             Coverage Diff             @@
##           develop    #1352      +/-   ##
===========================================
+ Coverage    61.66%   61.79%   +0.13%     
===========================================
  Files          114      114              
  Lines        11012    10993      -19     
===========================================
+ Hits          6790     6793       +3     
+ Misses        3574     3564      -10     
+ Partials       648      636      -12
Impacted Files Coverage Δ
p2p/netaddress.go 71.87% <100%> (+2.84%) ⬆️
p2p/listener.go 50% <100%> (ø) ⬆️
types/event_bus.go 0% <0%> (-36.24%) ⬇️
types/events.go 11.11% <0%> (-16.67%) ⬇️
types/part_set.go 63.23% <0%> (-1.16%) ⬇️
rpc/client/httpclient.go 67.53% <0%> (-1.05%) ⬇️
state/txindex/kv/kv.go 73.76% <0%> (-1.02%) ⬇️
p2p/peer.go 63.38% <0%> (-0.91%) ⬇️
types/vote_set.go 49.42% <0%> (-0.77%) ⬇️
node/node.go 63.44% <0%> (-0.2%) ⬇️
... and 17 more

// NewNetAddressStringWithIDRequired returns a new NetAddress using the provided
// address in the form of "ID@IP:Port".
// Also resolves the host if host is not an IP.
func NewNetAddressString(addr string) (*NetAddress, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you forget to change the name or should that name doc be reverted to NewNetAddressString from NewNetAddressStringWithIDRequired?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, thanks

idBytes, err := hex.DecodeString(idStr)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Address (%s) contains invalid ID", addr))
return nil, errors.Wrapf(err, "Address (%s) contains invalid ID", addrWithoutProtocol)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall right, github.com/pkg/errors is no longer recommended in Tendermint /cc @jaekwon @ebuchman. So, perhaps

fmt.Errorf("%v Address (%s) contains invalid ID", err, addrWithoutProtocol)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

new lib is almost ready tendermint/tmlibs#180. but let's not wait here please

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool cool, that was fast with how that new errors package was started and it is almost complete.


func TestNewNetAddressStrings(t *testing.T) {
addrs, errs := NewNetAddressStrings([]string{"127.0.0.1:8080", "127.0.0.2:8080"})
addrs, errs := NewNetAddressStrings([]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we also test some invalid addresses? The current test just confirms the always expected case.

Copy link
Contributor

@odeke-em odeke-em left a comment

Choose a reason for hiding this comment

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

Nice and clean, thank you @melekes! LGTM.

return NewNetAddressStringWithOptionalID(addr)
}

// NewNetAddressStringWithIDRequired returns a new NetAddress using the provided
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit, the name in the doc doesn't match the actual function name:

  • NewNetAddressStringWithIDRequired
  • NewNetAddressStringWithOptionalID

@ebuchman ebuchman merged commit 7cce07b into develop Apr 5, 2018
@ebuchman ebuchman deleted the 1228-require-id branch April 5, 2018 12:57
firelizzard18 pushed a commit to AccumulateNetwork/tendermint that referenced this pull request Feb 1, 2024
…rmint#1352)

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants