|
1 | 1 | use futures::prelude::*; |
2 | 2 |
|
| 3 | +use std::fmt::Debug; |
3 | 4 | use std::sync::{atomic::Ordering, Arc}; |
4 | 5 | use std::time::Duration; |
5 | 6 |
|
6 | 7 | use crate::{ |
7 | 8 | channel::mpsc, |
8 | 9 | error::SendErrorKind, |
9 | 10 | multiaddr::Multiaddr, |
10 | | - service::{event::ServiceTask, TargetProtocol, TargetSession}, |
| 11 | + service::{ |
| 12 | + event::{RawSessionInfo, ServiceTask}, |
| 13 | + TargetProtocol, TargetSession, |
| 14 | + }, |
11 | 15 | ProtocolId, SessionId, |
12 | 16 | }; |
13 | 17 | use bytes::Bytes; |
@@ -72,6 +76,25 @@ impl ServiceControl { |
72 | 76 | self.quick_send(ServiceTask::Dial { address, target }) |
73 | 77 | } |
74 | 78 |
|
| 79 | + /// Receive an established connection session |
| 80 | + /// and build the tentacle protocol on top of it. |
| 81 | + #[inline] |
| 82 | + pub fn raw_session<T>( |
| 83 | + &self, |
| 84 | + raw_session: T, |
| 85 | + remote_address: Multiaddr, |
| 86 | + info: RawSessionInfo, |
| 87 | + ) -> Result |
| 88 | + where |
| 89 | + T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + Unpin + 'static, |
| 90 | + { |
| 91 | + self.quick_send(ServiceTask::RawSession { |
| 92 | + raw_session: Box::new(raw_session), |
| 93 | + remote_address, |
| 94 | + session_info: info, |
| 95 | + }) |
| 96 | + } |
| 97 | + |
75 | 98 | /// Disconnect a connection |
76 | 99 | #[inline] |
77 | 100 | pub fn disconnect(&self, session_id: SessionId) -> Result { |
@@ -255,6 +278,18 @@ impl From<ServiceAsyncControl> for ServiceControl { |
255 | 278 | } |
256 | 279 | } |
257 | 280 |
|
| 281 | +impl Debug for ServiceControl { |
| 282 | + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 283 | + write!(f, "ServiceControl") |
| 284 | + } |
| 285 | +} |
| 286 | + |
| 287 | +impl Debug for ServiceAsyncControl { |
| 288 | + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
| 289 | + write!(f, "ServiceAsyncControl") |
| 290 | + } |
| 291 | +} |
| 292 | + |
258 | 293 | /// Service control, used to send commands externally at runtime, All interfaces are async methods |
259 | 294 | #[derive(Clone)] |
260 | 295 | pub struct ServiceAsyncControl { |
@@ -301,6 +336,26 @@ impl ServiceAsyncControl { |
301 | 336 | self.quick_send(ServiceTask::Dial { address, target }).await |
302 | 337 | } |
303 | 338 |
|
| 339 | + /// Receive an established connection session |
| 340 | + /// and build the tentacle protocol on top of it. |
| 341 | + #[inline] |
| 342 | + pub async fn raw_session<T>( |
| 343 | + &self, |
| 344 | + raw_session: T, |
| 345 | + remote_address: Multiaddr, |
| 346 | + info: RawSessionInfo, |
| 347 | + ) -> Result |
| 348 | + where |
| 349 | + T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + Unpin + 'static, |
| 350 | + { |
| 351 | + self.quick_send(ServiceTask::RawSession { |
| 352 | + raw_session: Box::new(raw_session), |
| 353 | + remote_address, |
| 354 | + session_info: info, |
| 355 | + }) |
| 356 | + .await |
| 357 | + } |
| 358 | + |
304 | 359 | /// Disconnect a connection |
305 | 360 | #[inline] |
306 | 361 | pub async fn disconnect(&self, session_id: SessionId) -> Result { |
|
0 commit comments