-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Use randomized subscription ids for PubSub #5756
Conversation
pub struct Subscribers<T> { | ||
next_id: u64, | ||
subscriptions: HashMap<u64, T>, | ||
rand: StdRng, |
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.
why use random IDs? is it a reason that's defeated by not using cryptographic-strength randomness?
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.
When you run public node it would be possible to cancel other peoples subscriptions. We could instead have an id per session, but I think it would be a bit more complicated.
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 see, but you could still guess and get lucky and cancel others'?
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.
Yes, you could even try to fire milions of requests and cancel all of them. But that should be that should be handled by some rate limiting (that is needed anyway).
rpc/src/v1/helpers/subscribers.rs
Outdated
Err(_) => { | ||
self.next_id -= 1; | ||
}, | ||
Err(_) => {}, |
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.
if let
is more idiomatic
No description provided.