Skip to content

rust: Don't expose websocket service IDs #242

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

Merged
merged 3 commits into from
Feb 26, 2025
Merged

rust: Don't expose websocket service IDs #242

merged 3 commits into from
Feb 26, 2025

Conversation

gasmith
Copy link
Contributor

@gasmith gasmith commented Feb 25, 2025

Websocket service IDs are an implementation detail to accommodate ws-protocol. It's not something that our users need to be aware of. Service names need to be unique, and so that should be the handle by which a service is identified or removed. I realized this as I was trying to implement the python plumbing for remove_services.

Now we need two maps for indexing services: one by name, one by ID. They need to be synchronized, so I introduced a new ServiceMap struct.

/// Removes a service by name.
pub fn remove_by_name(&mut self, name: impl AsRef<str>) -> Option<Arc<Service>> {
if let Some(id) = self.name.remove(name.as_ref()) {
self.id.remove(&id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This don't need locking to coordinate with inserts because IDs are never re-used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the locking, this is rust's classic mutable-xor-shared. Because we hold a &mut self, we know there are no concurrent &self. For the websocket server, that guarantee is provided by an RwLock.

To your other comment, it is true that IDs are not reused. But ServiceId is only 32-bit, so we technically need to worry about overflow. Currently we don't handle that case, we just panic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the explanation.

@gasmith gasmith merged commit c0eab97 into main Feb 26, 2025
29 checks passed
@gasmith gasmith deleted the gasmith/rust-svc-rm branch February 26, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants