1use crate::{DestHash, IdentityHash, InterfaceId, LinkId, PacketHash, TeardownReason};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub struct SendTicket(pub u64);
9
10pub trait Callbacks: Send {
11 fn on_announce(&mut self, announced: crate::common::destination::AnnouncedIdentity);
12
13 fn on_path_updated(&mut self, dest_hash: DestHash, hops: u8);
14
15 fn on_local_delivery(&mut self, dest_hash: DestHash, raw: Vec<u8>, packet_hash: PacketHash);
16
17 fn on_interface_up(&mut self, _id: InterfaceId) {}
19
20 fn on_interface_down(&mut self, _id: InterfaceId) {}
22
23 fn on_link_established(
25 &mut self,
26 _link_id: LinkId,
27 _dest_hash: DestHash,
28 _rtt: f64,
29 _is_initiator: bool,
30 ) {
31 }
32
33 fn on_link_closed(&mut self, _link_id: LinkId, _reason: Option<TeardownReason>) {}
35
36 fn on_remote_identified(
38 &mut self,
39 _link_id: LinkId,
40 _identity_hash: IdentityHash,
41 _public_key: [u8; 64],
42 ) {
43 }
44
45 fn on_resource_received(
47 &mut self,
48 _link_id: LinkId,
49 _data: Vec<u8>,
50 _metadata: Option<Vec<u8>>,
51 ) {
52 }
53
54 fn on_resource_received_with_app_flag(
58 &mut self,
59 link_id: LinkId,
60 data: Vec<u8>,
61 metadata: Option<Vec<u8>>,
62 _app_flag: bool,
63 ) {
64 self.on_resource_received(link_id, data, metadata);
65 }
66
67 fn on_resource_completed(&mut self, _link_id: LinkId) {}
69
70 fn on_resource_failed(&mut self, _link_id: LinkId, _error: String) {}
72
73 fn on_resource_progress(&mut self, _link_id: LinkId, _received: usize, _total: usize) {}
75
76 fn on_resource_stream_completed(
78 &mut self,
79 _link_id: LinkId,
80 _transfer_id: crate::resource::ResourceTransferId,
81 ) {
82 }
83
84 fn on_resource_stream_failed(
86 &mut self,
87 _link_id: LinkId,
88 _transfer_id: crate::resource::ResourceTransferId,
89 _error: crate::resource::ResourceTransferError,
90 ) {
91 }
92
93 fn on_resource_stream_progress(
95 &mut self,
96 _link_id: LinkId,
97 _transfer_id: crate::resource::ResourceTransferId,
98 _transferred: u64,
99 _total: u64,
100 ) {
101 }
102
103 fn on_resource_segment(
107 &mut self,
108 _link_id: LinkId,
109 _original_hash: [u8; 32],
110 _offset: u64,
111 _data: Vec<u8>,
112 ) {
113 }
114
115 fn on_resource_stream_received(
119 &mut self,
120 _link_id: LinkId,
121 _resource: crate::resource::ReceivedResourceStream,
122 ) {
123 }
124
125 fn on_resource_file_received(
127 &mut self,
128 _link_id: LinkId,
129 _resource: crate::resource::ReceivedResourceFile,
130 ) {
131 }
132
133 fn on_resource_accept_query(
136 &mut self,
137 _link_id: LinkId,
138 _resource_hash: Vec<u8>,
139 _transfer_size: u64,
140 _has_metadata: bool,
141 ) -> bool {
142 false
143 }
144
145 fn on_resource_accept_query_with_app_flag(
150 &mut self,
151 link_id: LinkId,
152 resource_hash: Vec<u8>,
153 transfer_size: u64,
154 has_metadata: bool,
155 _app_flag: bool,
156 ) -> bool {
157 self.on_resource_accept_query(link_id, resource_hash, transfer_size, has_metadata)
158 }
159
160 fn on_channel_message(&mut self, _link_id: LinkId, _msgtype: u16, _payload: Vec<u8>) {}
162
163 fn on_link_data(&mut self, _link_id: LinkId, _context: u8, _data: Vec<u8>) {}
165
166 fn on_response(&mut self, _link_id: LinkId, _request_id: [u8; 16], _data: Vec<u8>) {}
168
169 fn on_response_with_metadata(
171 &mut self,
172 link_id: LinkId,
173 request_id: [u8; 16],
174 data: Vec<u8>,
175 _metadata: Option<Vec<u8>>,
176 ) {
177 self.on_response(link_id, request_id, data);
178 }
179
180 fn on_request_failed(
182 &mut self,
183 _link_id: LinkId,
184 _request_id: [u8; 16],
185 _reason: crate::link_manager::RequestFailure,
186 ) {
187 }
188
189 fn on_packet_sent(&mut self, _ticket: SendTicket, _packet_hash: Option<PacketHash>) {}
194
195 fn on_packet_received(
201 &mut self,
202 _dest_hash: DestHash,
203 _data: Vec<u8>,
204 _packet_hash: PacketHash,
205 ) {
206 }
207
208 fn on_proof(&mut self, _dest_hash: DestHash, _packet_hash: PacketHash, _rtt: f64) {}
211
212 fn on_proof_requested(&mut self, _dest_hash: DestHash, _packet_hash: PacketHash) -> bool {
215 true
216 }
217
218 fn on_direct_connect_proposed(
221 &mut self,
222 _link_id: LinkId,
223 _peer_identity: Option<IdentityHash>,
224 ) -> bool {
225 false
226 }
227
228 fn on_direct_connect_established(&mut self, _link_id: LinkId, _interface_id: InterfaceId) {}
230
231 fn on_direct_connect_failed(&mut self, _link_id: LinkId, _reason: u8) {}
233}