Skip to content
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

Get connection ID in rpc handler #1014

Closed
xlc opened this issue Feb 14, 2023 · 6 comments · Fixed by #1224
Closed

Get connection ID in rpc handler #1014

xlc opened this issue Feb 14, 2023 · 6 comments · Fixed by #1224

Comments

@xlc
Copy link
Contributor

xlc commented Feb 14, 2023

So that it is possible to rate limit message per seconds per connection

@bkchr
Copy link
Member

bkchr commented Feb 15, 2023

@niklasad1 AFAIU @xlc would like to contribute some features like this one, can you make sure he gets the help that he needs?

@niklasad1
Copy link
Member

Like I said before the RPC handler is not exposed by this library by design.

#918 would solve this issue as well as some similar issues raised recently.

@xlc
Copy link
Contributor Author

xlc commented Feb 15, 2023

I am not 100% following. How is TwoerService going to help?

All I need is to make this NOT ignore the connect id parameter

MethodCallback::new_async(Arc::new(move |id, params, _, max_response_size| {

It could be a simple change by adjusting the callback function signature to include connection ID, which will be a breaking change. Or add new register method with callback takes connection ID.

@xlc
Copy link
Contributor Author

xlc commented Feb 15, 2023

I am not very familiar with Tower middleware but I don't think it applies here. It is not compatible with websocket frame data.

@niklasad1
Copy link
Member

niklasad1 commented Feb 15, 2023

It could be a simple change by adjusting the callback function signature to include connection ID, which will be a breaking change.

Ok, I see that could work.

Or add new register method with callback takes connection ID.

This won't work because register_method is done at initialization i.e, before the connection is established.

I am not very familiar with Tower middleware but I don't think it applies here. It is not compatible with websocket frame data.

Ok, I will write down a better issue for it but yeah you are correct after the HTTP upgrade is completed. Then we have no use of tower but you could actually fetch the connection ID there and store somewhere/spawn a task in your proxy for each connection.
Not sure, I haven't really looked at your code.

To elaborate it would useful if you could add an example snippet code what you want to do then it we would understand better and could help out better.

@xlc
Copy link
Contributor Author

xlc commented Feb 15, 2023

I am thinking interface similar to subscription. Have a sink or a connection object as a parameter to the callback that allow me to retrieve the connection ID & related details and close the connection.

The goal is to implement rate limiting feature on RPC methods so I am happy with whatever mechanism that achieves it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants