-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: all unverified inbound sessions #180
feat: all unverified inbound sessions #180
Conversation
b5bcf75
to
d5a0e50
Compare
@@ -13,7 +13,7 @@ | |||
"lint": "eslint --color --ext .ts src/", | |||
"test": "yarn test:unit && yarn test:e2e", | |||
"test:unit": "mocha 'test/unit/**/*.test.ts'", | |||
"test:e2e": "mocha 'test/unit/**/*.test.ts'" | |||
"test:e2e": "mocha 'test/e2e/**/*.test.ts'" |
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.
🙏
d5a0e50
to
413ce5c
Compare
This should be ready for review. |
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.
Does it make sense to also also allow outbound unverified sessions?
They seem less useful, but you could dial a peer via a full multiaddr, and currently, if they respond with 'unverified' ENR (wrong or no IP+port), the session is dropped.
If we allowed unverified outbound sessions, we'd be able to use them for TALKREQ/RESP at least.
Potentially, though at least in a Portal Network context, we have no inbuilt way to obtain a full |
And now that I think about it, another way to approach this might be to have the sessionService "established" event include the observed socket address along with the ENR as well as a "verified" flag and then update the routing table to only if the verified is set. Then, Portal Network can listen for that and update our own ENR cache (since we are already also maintaining our own routing tables) with the ENRs and multiaddrs and then we can call |
Disregard my previous feedback, I think this is now ready for review again. |
I went ahead and added this in as I think I now can see where it can be useful down the line. I can't think of a use case where we'll be able to make use of it within Portal Network in our current code base unless we set up an ENR/socket address cache since we wouldn't have any other way to know the correct socket address to send a TALKREQ to but as I noted above, we do have one use case where we might want to still send outbound messages to a node with an invalid ENR so this will be a useful stepping stone to that use case. |
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.
And now that I think about it, another way to approach this might be to have the sessionService "established" event include the observed socket address along with the ENR as well as a "verified" flag and then update the routing table to only if the verified is set. Then, Portal Network can listen for that and update our own ENR cache (since we are already also maintaining our own routing tables) with the ENRs and multiaddrs and then we can call
TALKREQ/TALKRESP
with ENR or multiaddr. Thoughts?
I think thats a good idea. We can update the established
event type to:
established: (nodeAddr: INodeAddress, enr: ENR, connectionDirection: ConnectionDirection, verified: boolean) => void;
and filter out unverified sessions as a first step in onEstablished
.
This also wouldn't effect performance/behavior in the default configuration, since only verified sessions will emit established
events.
|
||
// Drop session if invalid ENR and session service not configured to allow unverified sessions | ||
if (!verified && !this.config.allowUnverifiedSessions) { | ||
log("ENR contains invalid socket address. Dropping session with %o", nodeAddr); |
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 think there should be a this.failSession(nodeAddr, RequestErrorType.InvalidRemoteENR, true)
after this log and the similar log below.
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.
Added.
I've made these updates. Can we also bubble up this |
Looks like I have a broken test now so will look at that too. |
Maybe we can just make the |
That works for me though it is another event emitter for me and any other consumer to keep track of. Doesn't seem like there are any other undue risks since even if somebody sends random messages, it seems like the worst that could happen is a session gets invalidated by the receiving node if somebody starts sending garbage data. |
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.
Awesome! this will be a nice feature
Features
sessionConfig
parameter to allow inbound sessions with invalid ENRs (i.e. where observed socket address doesn't match socket address reported in ENR - to allow nodes reporting local IP/port combinations to receivediscv5
PONG messages in order to update ENRs).discv5
routing table so the discv5 service will never send outbound messages to them to ensure we aren't propagating DDoS attackssendTalkResp
to specify a target node via session key (nodeId + socketAddr
) to allow responding to nodes with unverified sessions (so will not have an ENR in the routing table)service.sendPing
public so it can be triggered by portal network layer to triggerenrUpdate
logic via PONG messages.Fixes