summaryrefslogtreecommitdiff
path: root/crates/arti-rpcserver/src/mgr.rs
blob: 37fe307506b0accd5b28a6e5e61fb6607c2a737c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Top-level `RpcMgr` to launch sessions.

use std::sync::Arc;

use arti_client::TorClient;
use tor_rpcbase as rpc;
use tor_rtcompat::Runtime;

use crate::connection::Connection;

/// Shared state, configuration, and data for all RPC sessions.
///
/// An RpcMgr knows how to listen for incoming RPC connections, and launch sessions based on them.
///
/// TODO RPC: Actually not all of the above functionality is implemented yet. But it should be.
pub struct RpcMgr {
    /// Our reference to the dispatch table used to look up the functions that
    /// implement each object on each
    dispatch_table: Arc<rpc::DispatchTable>,
}

impl RpcMgr {
    /// Create a new RpcMgr.
    #[allow(clippy::new_without_default)]
    pub fn new() -> Self {
        RpcMgr {
            dispatch_table: Arc::new(rpc::DispatchTable::from_inventory()),
        }
    }

    /// Start a new session based on this RpcMgr, with a given TorClient.
    ///
    /// TODO RPC: If `client` is not a `TorClient<PreferredRuntime>`, it won't
    /// be possible to invoke any of its methods. See #837.
    pub fn new_session<R: Runtime>(&self, client: TorClient<R>) -> Connection {
        let client_obj = Arc::new(client);
        Connection::new(self.dispatch_table.clone(), client_obj)
    }
}