rns_net/common/
callbacks.rs1use crate::{DestHash, IdentityHash, InterfaceId, LinkId, PacketHash, TeardownReason};
4
5pub trait Callbacks: Send {
6 fn on_announce(&mut self, announced: crate::common::destination::AnnouncedIdentity);
7
8 fn on_path_updated(&mut self, dest_hash: DestHash, hops: u8);
9
10 fn on_local_delivery(&mut self, dest_hash: DestHash, raw: Vec<u8>, packet_hash: PacketHash);
11
12 fn on_interface_up(&mut self, _id: InterfaceId) {}
14
15 fn on_interface_down(&mut self, _id: InterfaceId) {}
17
18 fn on_link_established(
20 &mut self,
21 _link_id: LinkId,
22 _dest_hash: DestHash,
23 _rtt: f64,
24 _is_initiator: bool,
25 ) {
26 }
27
28 fn on_link_closed(&mut self, _link_id: LinkId, _reason: Option<TeardownReason>) {}
30
31 fn on_remote_identified(
33 &mut self,
34 _link_id: LinkId,
35 _identity_hash: IdentityHash,
36 _public_key: [u8; 64],
37 ) {
38 }
39
40 fn on_resource_received(
42 &mut self,
43 _link_id: LinkId,
44 _data: Vec<u8>,
45 _metadata: Option<Vec<u8>>,
46 ) {
47 }
48
49 fn on_resource_completed(&mut self, _link_id: LinkId) {}
51
52 fn on_resource_failed(&mut self, _link_id: LinkId, _error: String) {}
54
55 fn on_resource_progress(&mut self, _link_id: LinkId, _received: usize, _total: usize) {}
57
58 fn on_resource_accept_query(
61 &mut self,
62 _link_id: LinkId,
63 _resource_hash: Vec<u8>,
64 _transfer_size: u64,
65 _has_metadata: bool,
66 ) -> bool {
67 false
68 }
69
70 fn on_channel_message(&mut self, _link_id: LinkId, _msgtype: u16, _payload: Vec<u8>) {}
72
73 fn on_link_data(&mut self, _link_id: LinkId, _context: u8, _data: Vec<u8>) {}
75
76 fn on_response(&mut self, _link_id: LinkId, _request_id: [u8; 16], _data: Vec<u8>) {}
78
79 fn on_response_with_metadata(
81 &mut self,
82 link_id: LinkId,
83 request_id: [u8; 16],
84 data: Vec<u8>,
85 _metadata: Option<Vec<u8>>,
86 ) {
87 self.on_response(link_id, request_id, data);
88 }
89
90 fn on_proof(&mut self, _dest_hash: DestHash, _packet_hash: PacketHash, _rtt: f64) {}
93
94 fn on_proof_requested(&mut self, _dest_hash: DestHash, _packet_hash: PacketHash) -> bool {
97 true
98 }
99
100 fn on_direct_connect_proposed(
103 &mut self,
104 _link_id: LinkId,
105 _peer_identity: Option<IdentityHash>,
106 ) -> bool {
107 false
108 }
109
110 fn on_direct_connect_established(&mut self, _link_id: LinkId, _interface_id: InterfaceId) {}
112
113 fn on_direct_connect_failed(&mut self, _link_id: LinkId, _reason: u8) {}
115}