Refactor handler#1806
Conversation
c3631de to
2dc73fc
Compare
|
an alternative approach (more aligned with the original feedback) would be to allow fn handle_x(
&mut self,
...,
) -> impl std::future::Future<Output = Result<(), Error>> + Send;an implementation would look like this: async fn handle_x(
&mut self,
...,
) -> Result<(), Error> { ... }this would allow alternatively, MSRV v1.75.0 would also allow using the |
The key consideration in both this and our current implementation is whether we want the trait implementor to send messages directly from within the handlers, or whether we expect handlers to return a list of client-specific messages to be sent. In the latter case, handle_message implementor would be responsible for sending those messages based on the handler's response. |
|
@Shourya742 I think we should try to explore the possibility of sending messages inside the handlers, since it was the original request. Maybe we could also consider to provide a double option, with one async trait which can be used to send messages directly there, and one trait which returns |
I was thinking the same both approaches make sense, and we could let the implementors decide what works best for them. However, this would leave us with four possible combinations for the trait implementations:
OR
|
maybe I'm missing something, but wouldn't the caller context already have if that's the case, what would be the value of returning the same message again, instead of a simple |
Yes, It should process the message and return list of new message to be shared or not shared with client. |
|
deleted previous message sorry I'm on mobile... I'll try to follow up later when time allows |
|
@Shourya742 I think we should have:
As pointed out by @plebhash , the caller already has the message in its context (in our current status the caller has the frame), so it makes no sense to return the same message in the sync case. I don't know if returning the Vec would work well for every case we have, especially in |
fa07104 to
3b26df9
Compare
|
We have now moved the handlers into their own crate within the protocol workspace. The handlers now return a unit Result and expect the implementor to manage the message lifecycle deciding how to process and dispatch messages within the handler itself. We now support both sync and async variants of handlers, and we're maintaining MSRV compatibility (thanks @plebhash!). The next step will be to migrate the new tproxy to use the new handlers module as an example implementation demonstrating how the handlers are intended to be used. I'm still exploring ways to improve the trait structure, if nothing significantly better emerges, the current design will be finalized. |
933eb97 to
00c4019
Compare
|
looks great! |
18202de to
df689e2
Compare
Previously, `HandlerError` only supported a fixed set of internal error types. This made it difficult for downstream users implementing library traits to propagate their own custom error types. This commit introduces a new `External(Box<dyn Error + Send + Sync>)` variant to allow wrapping arbitrary error values. This enables implementors to return non-library errors without requiring changes to the core `HandlerError` enum.
…de how to go about authorization of a connection
b709c97 to
52626ca
Compare
|
Thanks for the review, @GitGab19. All suggestions have been addressed. |
This PR aims to relax the strict constraints around handler implementations in the
protocolcrate, particularly concerning synchronicity and return types.Handlers are no longer required to take
Arc<Mutex<Self>>; instead, they now operate with a mutable reference (&mut self) for state mutation. This change simplifies the design and improves ergonomics.We are also moving away from the
SendTo_abstraction in favor of returningOption<Vec<Message>>. The goal is to delegate message routing decisions to the upstream implementor rather than enforcing it within the library.Despite these refactors, users still need to implement the relevant traits and invoke the appropriate
handle_*_messagemethods.We explored exposing a single
handle_messagemethod to unify the interface, but this approach would have forced implementors to implement all handler traits, which is not practical. You can find the associated code changes here: (Shourya742#20)