1use url::Url;
20
21use super::channel::ChannelInfo;
22use crate::util::time::NanoTimestamp;
23
24macro_rules! dnetev {
25 ($self:expr, $event_name:ident, $($code:tt)*) => {
26 {
27 if $self.p2p().dnet_enabled.load(std::sync::atomic::Ordering::SeqCst) {
28 let event = DnetEvent::$event_name(dnet::$event_name $($code)*);
29 $self.p2p().dnet_notify(event).await;
30 }
31 }
32 };
33}
34pub(crate) use dnetev;
35
36#[derive(Clone, Debug)]
37pub struct MessageInfo {
38 pub chan: ChannelInfo,
39 pub cmd: String,
40 pub time: NanoTimestamp,
41}
42
43pub type SendMessage = MessageInfo;
45pub type RecvMessage = MessageInfo;
46
47#[derive(Clone, Debug)]
48pub struct InboundInfo {
49 pub addr: Url,
50 pub channel_id: u32,
51}
52
53pub type InboundConnected = InboundInfo;
54pub type InboundDisconnected = InboundInfo;
55
56#[derive(Clone, Debug)]
57pub struct OutboundSlotSleeping {
58 pub slot: u32,
59}
60
61#[derive(Clone, Debug)]
62pub struct OutboundSlotConnecting {
63 pub slot: u32,
64 pub addr: Url,
65}
66
67#[derive(Clone, Debug)]
68pub struct OutboundSlotConnected {
69 pub slot: u32,
70 pub addr: Url,
71 pub channel_id: u32,
72}
73
74#[derive(Clone, Debug)]
75pub struct OutboundSlotDisconnected {
76 pub slot: u32,
77 pub err: String,
78}
79
80#[derive(Clone, Debug)]
81pub struct OutboundPeerDiscovery {
82 pub attempt: u32,
83 pub state: &'static str,
84}
85
86#[derive(Clone, Debug)]
87pub struct DirectConnecting {
88 pub connect_addr: Url,
89}
90
91#[derive(Clone, Debug)]
92pub struct DirectConnected {
93 pub connect_addr: Url,
94 pub addr: Url,
95 pub channel_id: u32,
96}
97
98#[derive(Clone, Debug)]
99pub struct DirectDisconnected {
100 pub connect_addr: Url,
101 pub err: String,
102}
103
104pub type DirectPeerDiscovery = OutboundPeerDiscovery;
105
106#[derive(Clone, Debug)]
107pub enum DnetEvent {
108 SendMessage(MessageInfo),
109 RecvMessage(MessageInfo),
110 InboundConnected(InboundConnected),
111 InboundDisconnected(InboundDisconnected),
112 OutboundSlotSleeping(OutboundSlotSleeping),
113 OutboundSlotConnecting(OutboundSlotConnecting),
114 OutboundSlotConnected(OutboundSlotConnected),
115 OutboundSlotDisconnected(OutboundSlotDisconnected),
116 OutboundPeerDiscovery(OutboundPeerDiscovery),
117 DirectConnecting(DirectConnecting),
118 DirectConnected(DirectConnected),
119 DirectDisconnected(DirectDisconnected),
120 DirectPeerDiscovery(DirectPeerDiscovery),
121}