Skip to main content

freenet/client_events/
proxy.rs

1use freenet_stdlib::client_api::{ClientError, HostResponse};
2use futures::future::BoxFuture;
3
4use super::types::{ClientId, HostIncomingMsg};
5
6pub(crate) type BoxedClient = Box<dyn ClientEventsProxy + Send + 'static>;
7
8pub trait ClientEventsProxy {
9    /// # Cancellation Safety
10    /// This future must be safe to cancel.
11    fn recv(&mut self) -> BoxFuture<'_, HostIncomingMsg>;
12
13    /// Sends a response from the host to the client application.
14    fn send(
15        &mut self,
16        id: ClientId,
17        response: Result<HostResponse, ClientError>,
18    ) -> BoxFuture<'_, Result<(), ClientError>>;
19
20    /// Wire this proxy's HTTP layer to the live node, so HTTP-only operations
21    /// that must reach the executor (the hosted-mode export endpoint, P3-live of
22    /// #4381) can route through the node's `OpManager`. Called ONCE at node
23    /// startup from `p2p_impl`, where the live `op_manager` first meets the
24    /// client proxies (before the combinator consumes them).
25    ///
26    /// The argument is `&dyn Any` carrying an `Arc<OpManager>` rather than a
27    /// concrete `&Arc<OpManager>` ON PURPOSE: `ClientEventsProxy` is a public
28    /// trait but `OpManager` is `pub(crate)`, so naming it in the signature
29    /// would leak a more-private type. Implementors that care
30    /// (`HttpClientApi`) downcast it; the default no-op ignores it, so external
31    /// implementors (e.g. fdev's `StdInput`) need not know about `OpManager` at
32    /// all. Stored as a `Weak` by the recipient so it does not extend the
33    /// node's lifetime, making this per-node (no process-global singleton that
34    /// concurrent in-process nodes would clobber).
35    fn set_op_manager(&self, _op_manager: &dyn std::any::Any) {}
36}