-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Conversation
libp2p/ENR.cpp
Outdated
|
||
return ENR{0 /* sequence number */, keyValuePairs, signFunction}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to start the sequence number at 1.
8771c9a
to
b49f1fc
Compare
Codecov Report
@@ Coverage Diff @@
## master #5593 +/- ##
==========================================
+ Coverage 62.33% 62.42% +0.08%
==========================================
Files 350 350
Lines 29428 29531 +103
Branches 3322 3327 +5
==========================================
+ Hits 18344 18434 +90
- Misses 9886 9893 +7
- Partials 1198 1204 +6 |
Currently ENR is updated too often - every time we receive Pong with different destination port (this is how we always updated our knowledge of UDP external port). I'll try to investigate geth code for a better approach, like updating it only when certain number of packets with specific port is received, it seems it shouldn't be too difficult to implement something like this. |
I plan to rebase this after #5602 is merged |
For context what is the downside of updating a node’s ENR this frequently? |
@halfalicious Well discv5 nodes should keep ENRs of their peers up-to-date, so changing it all the time would make it necessary to re-request it from us all the time. (I suspect putting different endpoint values into our Pings all the time might negatively affect simple v4 discovery, too, somehow) Also I think signing ENR is pretty costly operation (now it happens sometimes several times a second) |
geth implementation ignores ENRs with seq=0
Also make ENR output in log more readable.
also move ip, tcp and udp reading to ENR class, as they're not specific to the v4 Identity Scheme. Rename ENR::m_map to m_keyValuePairs.
@@ -825,10 +842,12 @@ void Host::startedWorking() | |||
else | |||
m_listenPort = m_netConfig.listenPort; | |||
|
|||
determinePublic(); | |||
m_tcpPublic = determinePublic(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made determinePublic
return tcp::endpoint
as result, instead of assigning it inside, to make more explicit that it's the only result of this function.
I tried it with geth, and it look to be working, geth doesn't complain about our ENR. The logs look like this:
|
libp2p/ENR.cpp
Outdated
std::array<byte, N> bytesToAddress(bytesConstRef _bytes) | ||
{ | ||
std::array<byte, N> address; | ||
std::copy(_bytes.begin(), _bytes.begin() + N, address.begin()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use std::copy_n()
libp2p/ENR.cpp
Outdated
// The resulting 64-byte signature is encoded as the concatenation of the r and s signature values. | ||
return bytes(&s[0], &s[64]); | ||
}; | ||
return ENR(m_seq + 1, _keyValuePairs, _signFunction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ENR(m_seq + 1, _keyValuePairs, _signFunction); | |
return ENR{m_seq + 1, _keyValuePairs, _signFunction}; |
or
return ENR(m_seq + 1, _keyValuePairs, _signFunction); | |
return {m_seq + 1, _keyValuePairs, _signFunction}; |
libp2p/ENR.cpp
Outdated
{ | ||
_out << keyValue.first << "="; | ||
_out << toHexPrefixed(RLP{keyValue.second}.toBytes()) << " "; | ||
_out << "key=" << IdentitySchemeV4::publicKey(_enr).abridged() << " ip=" << _enr.ip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can partly output something.
Also fix operator<< to handle incorrect tcp and udp.
Implements part 3 of #5551
New host ENR is generated:
Host
contains new public address / listen portEndpointTracker
inNodeTable
detects new public UDP endpoint