Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Discovery ENR extension - server part #5571

Merged
merged 10 commits into from
May 6, 2019
Merged

Discovery ENR extension - server part #5571

merged 10 commits into from
May 6, 2019

Conversation

gumb0
Copy link
Member

@gumb0 gumb0 commented Apr 15, 2019

Support ENRRequest / ENRResponse discovery packets.

This doesn't add any change in the Discovery algorithm itself yet, just adds the ability for the node to return its current ENR to peers.

I've decided not to add CLI option to enable this and have it always enabled, as it should be fully backwards-compatible, nodes not supporting ENR extension shouldn't notice any difference.

Also this adds a function to libdevcrypto for converting compressed public key to uncompressed (used only in test for now)

Also renames DiscoveryDatagram::ts => DiscoveryDatagram::expiration

cc @fjl

@codecov-io
Copy link

codecov-io commented Apr 16, 2019

Codecov Report

Merging #5571 into master will increase coverage by <.01%.
The diff coverage is 84.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5571      +/-   ##
==========================================
+ Coverage   62.23%   62.23%   +<.01%     
==========================================
  Files         347      347              
  Lines       29136    29228      +92     
  Branches     3295     3306      +11     
==========================================
+ Hits        18132    18190      +58     
- Misses       9826     9848      +22     
- Partials     1178     1190      +12

auto* ctx = getCtx();

secp256k1_pubkey rawPubkey;
if (!secp256k1_ec_pubkey_parse(
Copy link
Member Author

Choose a reason for hiding this comment

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

libp2p/NodeTable.cpp Outdated Show resolved Hide resolved
@halfalicious
Copy link
Contributor

Not a part of your changes, but all discovery packet types can be constexpr (e.g. PingNode::type, PongNode::type)

@halfalicious
Copy link
Contributor

halfalicious commented Apr 27, 2019

Should we also add tests for unexpected ENRRequests (e.g. we haven't completed the endpoint proof for the node, or the node isn't in our node table)?

Copy link
Contributor

@halfalicious halfalicious left a comment

Choose a reason for hiding this comment

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

Looks great overall, just some minor issues (mostly nits)

libdevcrypto/Common.cpp Outdated Show resolved Hide resolved
libp2p/NodeTable.h Outdated Show resolved Hide resolved
libp2p/NodeTable.h Show resolved Hide resolved
libp2p/NodeTable.h Outdated Show resolved Hide resolved
libp2p/NodeTable.h Outdated Show resolved Hide resolved
test/unittests/libp2p/net.cpp Outdated Show resolved Hide resolved
test/unittests/libp2p/net.cpp Outdated Show resolved Hide resolved
test/unittests/libp2p/net.cpp Outdated Show resolved Hide resolved
test/unittests/libp2p/net.cpp Outdated Show resolved Hide resolved

auto enrResponse = dynamic_cast<ENRResponse const&>(*datagram);
auto const& keyValuePairs = enrResponse.enr->keyValuePairs();
BOOST_REQUIRE_EQUAL(RLP{keyValuePairs.at("id")}.toString(), "v4");
Copy link
Contributor

Choose a reason for hiding this comment

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

(Nit) Instead of hard-coding v4 here should we maybe pull the protocol version from the node table?

Should we also do the same for the key names?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean using the constants from the implementation instead of string literals here?

return sourceNodeEntry;
}

std::shared_ptr<NodeEntry> NodeTable::handleENRResponse(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should verify the hash in the response against the request (or are you planning on doing that in another change)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I planned to add the validation when implementing doing something useful with these responses (the last "ENR Client" part in #5551)
But now I also think there's not much useful we can actually do with them in v4 discovery, so maybe I'll leave it just ignoring ENRResponses

Copy link
Contributor

@halfalicious halfalicious May 3, 2019

Choose a reason for hiding this comment

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

If we listen for responses I think we should validate them so there's 1 less thing to do when we want to actually do something useful with them.

gumb0 added 7 commits May 2, 2019 12:34
The reason is the test vectors there contain RLP-list in place of additional field in Ping and Pong packets, and the parsing code for ENR extension expects an integer sequence number there.
@gumb0
Copy link
Member Author

gumb0 commented May 2, 2019

Should we also add tests for unexpected ENRRequests (e.g. we haven't completed the endpoint proof for the node, or the node isn't in our node table)?

Yeah would be good, but I'm a bit lazy for that 😜

Copy link
Contributor

@halfalicious halfalicious left a comment

Choose a reason for hiding this comment

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

Looks good!

libp2p/NodeTable.h Outdated Show resolved Hide resolved
libp2p/NodeTable.h Outdated Show resolved Hide resolved
@halfalicious
Copy link
Contributor

Also _rlp can be const ref here:

ENR(RLP _rlp, VerifyFunction const& _verifyFunction);

and here:

ENR parseV4ENR(RLP _rlp);

@gumb0 gumb0 merged commit 8e92740 into master May 6, 2019
@gumb0 gumb0 deleted the enr-server branch May 6, 2019 13:23
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.

3 participants