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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//! Application callback trait for driver events.
use crate::{DestHash, IdentityHash, InterfaceId, LinkId, PacketHash, TeardownReason};
pub trait Callbacks: Send {
fn on_announce(&mut self, announced: crate::common::destination::AnnouncedIdentity);
fn on_path_updated(&mut self, dest_hash: DestHash, hops: u8);
fn on_local_delivery(&mut self, dest_hash: DestHash, raw: Vec<u8>, packet_hash: PacketHash);
/// Called when an interface comes online.
fn on_interface_up(&mut self, _id: InterfaceId) {}
/// Called when an interface goes offline.
fn on_interface_down(&mut self, _id: InterfaceId) {}
/// Called when a link is fully established.
fn on_link_established(
&mut self,
_link_id: LinkId,
_dest_hash: DestHash,
_rtt: f64,
_is_initiator: bool,
) {
}
/// Called when a link is closed.
fn on_link_closed(&mut self, _link_id: LinkId, _reason: Option<TeardownReason>) {}
/// Called when a remote peer identifies on a link.
fn on_remote_identified(
&mut self,
_link_id: LinkId,
_identity_hash: IdentityHash,
_public_key: [u8; 64],
) {
}
/// Called when a resource transfer delivers data.
fn on_resource_received(
&mut self,
_link_id: LinkId,
_data: Vec<u8>,
_metadata: Option<Vec<u8>>,
) {
}
/// Called when a resource transfer completes (sender-side proof validated).
fn on_resource_completed(&mut self, _link_id: LinkId) {}
/// Called when a resource transfer fails.
fn on_resource_failed(&mut self, _link_id: LinkId, _error: String) {}
/// Called with resource transfer progress updates.
fn on_resource_progress(&mut self, _link_id: LinkId, _received: usize, _total: usize) {}
/// Called when a streaming Resource completes on the sender side.
fn on_resource_stream_completed(
&mut self,
_link_id: LinkId,
_transfer_id: crate::resource::ResourceTransferId,
) {
}
/// Called when a streaming Resource fails.
fn on_resource_stream_failed(
&mut self,
_link_id: LinkId,
_transfer_id: crate::resource::ResourceTransferId,
_error: crate::resource::ResourceTransferError,
) {
}
/// Called with logical-byte progress for a streaming Resource.
fn on_resource_stream_progress(
&mut self,
_link_id: LinkId,
_transfer_id: crate::resource::ResourceTransferId,
_transferred: u64,
_total: u64,
) {
}
/// Called when a disk-backed incoming Resource is ready.
fn on_resource_file_received(
&mut self,
_link_id: LinkId,
_resource: crate::resource::ReceivedResourceFile,
) {
}
/// Called to ask whether to accept an incoming resource (for AcceptApp strategy).
/// Return true to accept, false to reject.
fn on_resource_accept_query(
&mut self,
_link_id: LinkId,
_resource_hash: Vec<u8>,
_transfer_size: u64,
_has_metadata: bool,
) -> bool {
false
}
/// Called when a channel message is received on a link.
fn on_channel_message(&mut self, _link_id: LinkId, _msgtype: u16, _payload: Vec<u8>) {}
/// Called when generic link data is received.
fn on_link_data(&mut self, _link_id: LinkId, _context: u8, _data: Vec<u8>) {}
/// Called when a response is received on a link.
fn on_response(&mut self, _link_id: LinkId, _request_id: [u8; 16], _data: Vec<u8>) {}
/// Called when a response is received on a link, including resource metadata when present.
fn on_response_with_metadata(
&mut self,
link_id: LinkId,
request_id: [u8; 16],
data: Vec<u8>,
_metadata: Option<Vec<u8>>,
) {
self.on_response(link_id, request_id, data);
}
/// Called when a request response is rejected.
fn on_request_failed(
&mut self,
_link_id: LinkId,
_request_id: [u8; 16],
_reason: crate::link_manager::RequestFailure,
) {
}
/// Called when a delivery proof is received for a packet we sent.
/// `rtt` is the round-trip time in seconds.
fn on_proof(&mut self, _dest_hash: DestHash, _packet_hash: PacketHash, _rtt: f64) {}
/// Called for ProveApp strategy: should we prove this incoming packet?
/// Return true to generate and send a proof, false to skip.
fn on_proof_requested(&mut self, _dest_hash: DestHash, _packet_hash: PacketHash) -> bool {
true
}
/// Called when a direct connection is proposed by a peer (for AskApp policy).
/// Return true to accept, false to reject.
fn on_direct_connect_proposed(
&mut self,
_link_id: LinkId,
_peer_identity: Option<IdentityHash>,
) -> bool {
false
}
/// Called when a direct P2P connection is established via hole punching.
fn on_direct_connect_established(&mut self, _link_id: LinkId, _interface_id: InterfaceId) {}
/// Called when a direct connection attempt fails.
fn on_direct_connect_failed(&mut self, _link_id: LinkId, _reason: u8) {}
}