-
Notifications
You must be signed in to change notification settings - Fork 20.9k
p2p/discover: pass node instead of node ID to TALKREQ handler #31075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
52c7b8c
to
cd9f1b7
Compare
fix #31094 |
p2p/discover/v5_udp.go
Outdated
func (t *UDPv5) getNode(id enode.ID) *enode.Node { | ||
if n := t.tab.getNode(id); n != nil { | ||
return n | ||
func (t *UDPv5) GetNode(id enode.ID) (n *enode.Node) { |
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.
Should we consider thread-safe if the method is public?
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.
Each method called within GetNode already has locks, so there is no need to add additional locks to ensure thread safety.
We discussed this in a meeting with Shisui developers, and the need for calling So we should change talk handling to pass the node to the handler function. Doing this will require changing the discv5 session cache to include the node alongside the keys. |
7c9bb00
to
4770320
Compare
I think the approach you chose is too complicated, and the message flag should not be exposed. I might be wrong since I didn't try to implement myself, but here is my suggestion: In
In both of these places, the node is available:
So we could just add the node as a parameter in |
Seems make sense, however how to get node from session cache, session cache is only available in |
Yeah, an accessor method has to be added to the |
Oh, I missed a place to call storeNewSession. And you mentioned the necessity of exposing the Flag. I've also been struggling with this. The codec field in UDPv5 is an interface type, it only provides the Encode and Decode methods. In UDPv5, its cannot directly use So I tried to make the codec's Decode method return the node most of the time, rather than only returning the node after a successful handshake.
func (t *UDPv5) handlePacket(rawpacket []byte, fromAddr netip.AddrPort) error {
addr := fromAddr.String()
fromID, fromNode, packet, err := t.codec.Decode(rawpacket, addr)
if err != nil {
// handle invalid packet and return...
}
if fromNode != nil {
// Handshake succeeded, add to table.
t.tab.addInboundNode(fromNode)
}
// ignoring...
return nil
} Here got a problem, which is that now fromNode is almost always not nil, causing addInboundNode to be called every time. I need a new Flag to indicate whether it is the successful handshake. And I have other two alternative options:
fromID, fromNode, packet, handshakeSuccess, err := t.codec.Decode(rawpacket, addr)
// blabla...
if fromNode != nil && handshakeSuccess {
// Handshake succeeded, add to table.
t.tab.addInboundNode(fromNode)
}
fromID, fromNode, packet, isHandShake, err := t.codec.Decode(rawpacket, addr, func(node *enode.Node) {
// Handshake succeeded, add to table.
t.tab.addInboundNode(fromNode)
}) Or if there are other ways. |
I considered it as well, but I feel that adding a new method to the Codec to get the Session seems a bit out of place for its functionality. |
750bc55
to
d1c3505
Compare
Signed-off-by: thinkAfCod <q315xia@163.com>
…um#31075) This is for the implementation of Portal Network in the Shisui client. Their handler needs access to the node object in order to send further calls to the requesting node. This is a breaking API change but it should be fine, since there are basically no known users of TALKREQ outside of Portal network. --------- Signed-off-by: thinkAfCod <q315xia@163.com> Co-authored-by: Felix Lange <fjl@twurst.com>
…um#31075) This is for the implementation of Portal Network in the Shisui client. Their handler needs access to the node object in order to send further calls to the requesting node. This is a breaking API change but it should be fine, since there are basically no known users of TALKREQ outside of Portal network. --------- Signed-off-by: thinkAfCod <q315xia@163.com> Co-authored-by: Felix Lange <fjl@twurst.com>
This is for the implementation of Portal Network in the Shisui client. Their handler needs access to the node object in order to send further calls to the requesting node. This is a breaking API change but it should be fine, since there are basically no known users of TALKREQ outside of Portal network.