Skip to main content

sfo_cmd_server/server/
mod.rs

1mod peer_manager;
2mod server;
3
4use crate::errors::CmdResult;
5use crate::{CmdBody, CmdHandler, PeerId, TunnelId};
6use bucky_raw_codec::{RawDecode, RawEncode, RawFixedBytes};
7use num::{FromPrimitive, ToPrimitive};
8pub use server::*;
9use std::hash::Hash;
10use std::time::Duration;
11
12#[async_trait::async_trait]
13pub trait CmdServer<
14    LEN: RawEncode
15        + for<'a> RawDecode<'a>
16        + Copy
17        + RawFixedBytes
18        + Sync
19        + Send
20        + 'static
21        + FromPrimitive
22        + ToPrimitive,
23    CMD: RawEncode + for<'a> RawDecode<'a> + Copy + RawFixedBytes + Sync + Send + 'static + Eq + Hash,
24>: 'static + Send + Sync
25{
26    fn register_cmd_handler(&self, cmd: CMD, handler: impl CmdHandler<LEN, CMD>);
27    async fn send(&self, peer_id: &PeerId, cmd: CMD, version: u8, body: &[u8]) -> CmdResult<()>;
28    async fn send_with_resp(
29        &self,
30        peer_id: &PeerId,
31        cmd: CMD,
32        version: u8,
33        body: &[u8],
34        timeout: Duration,
35    ) -> CmdResult<CmdBody>;
36    async fn send_parts(
37        &self,
38        peer_id: &PeerId,
39        cmd: CMD,
40        version: u8,
41        body: &[&[u8]],
42    ) -> CmdResult<()>;
43    async fn send_parts_with_resp(
44        &self,
45        peer_id: &PeerId,
46        cmd: CMD,
47        version: u8,
48        body: &[&[u8]],
49        timeout: Duration,
50    ) -> CmdResult<CmdBody>;
51    #[deprecated(note = "use send_parts instead")]
52    async fn send2(
53        &self,
54        peer_id: &PeerId,
55        cmd: CMD,
56        version: u8,
57        body: &[&[u8]],
58    ) -> CmdResult<()> {
59        self.send_parts(peer_id, cmd, version, body).await
60    }
61    #[deprecated(note = "use send_parts_with_resp instead")]
62    async fn send2_with_resp(
63        &self,
64        peer_id: &PeerId,
65        cmd: CMD,
66        version: u8,
67        body: &[&[u8]],
68        timeout: Duration,
69    ) -> CmdResult<CmdBody> {
70        self.send_parts_with_resp(peer_id, cmd, version, body, timeout)
71            .await
72    }
73    async fn send_cmd(
74        &self,
75        peer_id: &PeerId,
76        cmd: CMD,
77        version: u8,
78        body: CmdBody,
79    ) -> CmdResult<()>;
80    async fn send_cmd_with_resp(
81        &self,
82        peer_id: &PeerId,
83        cmd: CMD,
84        version: u8,
85        body: CmdBody,
86        timeout: Duration,
87    ) -> CmdResult<CmdBody>;
88    async fn send_by_specify_tunnel(
89        &self,
90        peer_id: &PeerId,
91        tunnel_id: TunnelId,
92        cmd: CMD,
93        version: u8,
94        body: &[u8],
95    ) -> CmdResult<()>;
96    async fn send_by_specify_tunnel_with_resp(
97        &self,
98        peer_id: &PeerId,
99        tunnel_id: TunnelId,
100        cmd: CMD,
101        version: u8,
102        body: &[u8],
103        timeout: Duration,
104    ) -> CmdResult<CmdBody>;
105    async fn send_parts_by_specify_tunnel(
106        &self,
107        peer_id: &PeerId,
108        tunnel_id: TunnelId,
109        cmd: CMD,
110        version: u8,
111        body: &[&[u8]],
112    ) -> CmdResult<()>;
113    async fn send_parts_by_specify_tunnel_with_resp(
114        &self,
115        peer_id: &PeerId,
116        tunnel_id: TunnelId,
117        cmd: CMD,
118        version: u8,
119        body: &[&[u8]],
120        timeout: Duration,
121    ) -> CmdResult<CmdBody>;
122    #[deprecated(note = "use send_parts_by_specify_tunnel instead")]
123    async fn send2_by_specify_tunnel(
124        &self,
125        peer_id: &PeerId,
126        tunnel_id: TunnelId,
127        cmd: CMD,
128        version: u8,
129        body: &[&[u8]],
130    ) -> CmdResult<()> {
131        self.send_parts_by_specify_tunnel(peer_id, tunnel_id, cmd, version, body)
132            .await
133    }
134    #[deprecated(note = "use send_parts_by_specify_tunnel_with_resp instead")]
135    async fn send2_by_specify_tunnel_with_resp(
136        &self,
137        peer_id: &PeerId,
138        tunnel_id: TunnelId,
139        cmd: CMD,
140        version: u8,
141        body: &[&[u8]],
142        timeout: Duration,
143    ) -> CmdResult<CmdBody> {
144        self.send_parts_by_specify_tunnel_with_resp(peer_id, tunnel_id, cmd, version, body, timeout)
145            .await
146    }
147    async fn send_cmd_by_specify_tunnel(
148        &self,
149        peer_id: &PeerId,
150        tunnel_id: TunnelId,
151        cmd: CMD,
152        version: u8,
153        body: CmdBody,
154    ) -> CmdResult<()>;
155    async fn send_cmd_by_specify_tunnel_with_resp(
156        &self,
157        peer_id: &PeerId,
158        tunnel_id: TunnelId,
159        cmd: CMD,
160        version: u8,
161        body: CmdBody,
162        timeout: Duration,
163    ) -> CmdResult<CmdBody>;
164    async fn send_by_all_tunnels(
165        &self,
166        peer_id: &PeerId,
167        cmd: CMD,
168        version: u8,
169        body: &[u8],
170    ) -> CmdResult<()>;
171    async fn send_parts_by_all_tunnels(
172        &self,
173        peer_id: &PeerId,
174        cmd: CMD,
175        version: u8,
176        body: &[&[u8]],
177    ) -> CmdResult<()>;
178    #[deprecated(note = "use send_parts_by_all_tunnels instead")]
179    async fn send2_by_all_tunnels(
180        &self,
181        peer_id: &PeerId,
182        cmd: CMD,
183        version: u8,
184        body: &[&[u8]],
185    ) -> CmdResult<()> {
186        self.send_parts_by_all_tunnels(peer_id, cmd, version, body)
187            .await
188    }
189}