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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use exocore_core::cell::NodeId;
use futures::{prelude::*, sink::Sink};
use crate::{Error, InMessage, OutMessage};
pub type TransportHandleOnStart = Box<dyn Future<Output = ()> + Send + Unpin + 'static>;
pub trait TransportServiceHandle: Future<Output = ()> + Send + Unpin + 'static {
type Sink: Sink<OutEvent, Error = Error> + Send + Unpin + 'static;
type Stream: Stream<Item = InEvent> + Send + Unpin + 'static;
fn on_started(&self) -> TransportHandleOnStart;
fn get_sink(&mut self) -> Self::Sink;
fn get_stream(&mut self) -> Self::Stream;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum ServiceType {
None = 0,
Meta = 1,
Common = 2,
Chain = 3,
Store = 4,
Client = 5,
}
impl ServiceType {
pub fn from_code(code: u8) -> Option<ServiceType> {
match code {
0 => Some(ServiceType::None),
1 => Some(ServiceType::Meta),
2 => Some(ServiceType::Common),
3 => Some(ServiceType::Chain),
4 => Some(ServiceType::Store),
5 => Some(ServiceType::Client),
_ => None,
}
}
pub fn to_code(self) -> u8 {
self as u8
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ConnectionStatus {
Connecting,
Connected,
Disconnected,
}
#[derive(Clone, Debug)]
pub enum ConnectionId {
Any,
#[cfg(feature = "p2p-base")]
Libp2p(libp2p::core::connection::ConnectionId),
#[cfg(feature = "http-server")]
HttpServer(crate::http::RequestId),
#[cfg(any(feature = "http-server", feature = "p2p-full"))]
Either(crate::either::Side, Option<Box<ConnectionId>>),
}
pub enum InEvent {
Message(InMessage),
NodeStatus(NodeId, ConnectionStatus),
}
pub enum OutEvent {
Message(OutMessage),
Reset,
}