-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Change sc_network::protocol::generic_proto::behaviour to occupy inbound peerset slots for substreams and not connections #7074
Comments
I've been trying to tackle this issue for around two weeks now, and I've been having a lot of troubles redesigning the Opening a notifications protocol substream is done by opening a substream, sending a handshake, then waiting for the remote to accept or reject that handshake. Assuming the handshake is accepted, it is then possible to send notifications. The remote might at some point close their writing side of the substream, which is a hint that we should close the substream as soon as possible. In other words, each substream thus has four possible states:
Each notifications protocol allows up to two substreams active at a time: one outbound and one inbound. The state transitions that a node is allowed to perform are:
It should be possible to design a communication layer where the This however looks very complicated to implement in |
I believe it should be possible to model the interactions like that:
The reason why the handler needs to confirm the closing is so that the behaviour knows whether a "remote has opened the substream" message has taken into account the close message it has potentially sent earlier. |
Wouldn't allowing unlimited incoming TCP connections open the door for DOS attacks? |
Yes, we need a hard limit on the number of incoming TCP connections. This issue is mostly about making sure that TCP connections used only for discovery or for collation don't use the peerset slots that are supposed to be only for relay chain full nodes. |
At the moment, receiving an incoming connection results in
behaviour.rs
requesting an inbound slot from the peerset.If the peerset refuses the node, any incoming substream is immediately shut down.
If the peerset accepts the node, incoming notification substreams are expected. If no such substream arrives, the connection is killed after a 60 seconds timeout. During these 60 seconds, the peerset slot is reserved.
The problem with that scheme is that if a node connects for example only for Kademlia-related purposes and has a no intention of opening notification substreams, a peerset slot will also get reserved.
Instead, a slot should be queried from the peerset only after the remote has attempt to open notification substreams.
This change requires a lot of tweaking in
group.rs
as well in order for theNotifsHandler
struct to signal that the remote desires the substreams to be open.As such, this issue is blocked upon some parts of #5670. See #5670 for details about how this issue integrates with the rest of the changes.
The text was updated successfully, but these errors were encountered: