3
3
//! ## Example
4
4
//!
5
5
//! ```no_run
6
- //! # use iroh::{endpoint::{Connection, BindError}, protocol::{ProtocolHandler, Router, ProtocolError }, Endpoint, NodeAddr};
6
+ //! # use iroh::{endpoint::{Connection, BindError}, protocol::{AcceptError, ProtocolHandler, Router }, Endpoint, NodeAddr};
7
7
//! #
8
8
//! # async fn test_compile() -> Result<(), BindError> {
9
9
//! let endpoint = Endpoint::builder().discovery_n0().bind().await?;
19
19
//! struct Echo;
20
20
//!
21
21
//! impl ProtocolHandler for Echo {
22
- //! async fn accept(&self, connection: Connection) -> Result<(), ProtocolError > {
22
+ //! async fn accept(&self, connection: Connection) -> Result<(), AcceptError > {
23
23
//! let (mut send, mut recv) = connection.accept_bi().await?;
24
24
//!
25
25
//! // Echo any bytes received back directly.
@@ -98,16 +98,16 @@ pub struct RouterBuilder {
98
98
#[ allow( missing_docs) ]
99
99
#[ derive( Debug , Snafu ) ]
100
100
#[ non_exhaustive]
101
- pub enum ProtocolError {
101
+ pub enum AcceptError {
102
102
#[ snafu( transparent) ]
103
- Connect {
103
+ Connection {
104
104
source : crate :: endpoint:: ConnectionError ,
105
105
backtrace : Option < Backtrace > ,
106
106
#[ snafu( implicit) ]
107
107
span_trace : n0_snafu:: SpanTrace ,
108
108
} ,
109
109
#[ snafu( transparent) ]
110
- RemoteNodeId { source : RemoteNodeIdError } ,
110
+ MissingRemoteNodeId { source : RemoteNodeIdError } ,
111
111
#[ snafu( display( "Not allowed." ) ) ]
112
112
NotAllowed { } ,
113
113
@@ -117,7 +117,7 @@ pub enum ProtocolError {
117
117
} ,
118
118
}
119
119
120
- impl ProtocolError {
120
+ impl AcceptError {
121
121
/// Creates a new user error from an arbitrary error type.
122
122
pub fn from_err < T : std:: error:: Error + Send + Sync + ' static > ( value : T ) -> Self {
123
123
Self :: User {
@@ -126,13 +126,13 @@ impl ProtocolError {
126
126
}
127
127
}
128
128
129
- impl From < std:: io:: Error > for ProtocolError {
129
+ impl From < std:: io:: Error > for AcceptError {
130
130
fn from ( err : std:: io:: Error ) -> Self {
131
131
Self :: from_err ( err)
132
132
}
133
133
}
134
134
135
- impl From < quinn:: ClosedStream > for ProtocolError {
135
+ impl From < quinn:: ClosedStream > for AcceptError {
136
136
fn from ( err : quinn:: ClosedStream ) -> Self {
137
137
Self :: from_err ( err)
138
138
}
@@ -158,7 +158,7 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
158
158
fn on_connecting (
159
159
& self ,
160
160
connecting : Connecting ,
161
- ) -> impl Future < Output = Result < Connection , ProtocolError > > + Send {
161
+ ) -> impl Future < Output = Result < Connection , AcceptError > > + Send {
162
162
async move {
163
163
let conn = connecting. await ?;
164
164
Ok ( conn)
@@ -177,7 +177,7 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
177
177
fn accept (
178
178
& self ,
179
179
connection : Connection ,
180
- ) -> impl Future < Output = Result < ( ) , ProtocolError > > + Send ;
180
+ ) -> impl Future < Output = Result < ( ) , AcceptError > > + Send ;
181
181
182
182
/// Called when the router shuts down.
183
183
///
@@ -191,11 +191,11 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
191
191
}
192
192
193
193
impl < T : ProtocolHandler > ProtocolHandler for Arc < T > {
194
- async fn on_connecting ( & self , conn : Connecting ) -> Result < Connection , ProtocolError > {
194
+ async fn on_connecting ( & self , conn : Connecting ) -> Result < Connection , AcceptError > {
195
195
self . as_ref ( ) . on_connecting ( conn) . await
196
196
}
197
197
198
- async fn accept ( & self , conn : Connection ) -> Result < ( ) , ProtocolError > {
198
+ async fn accept ( & self , conn : Connection ) -> Result < ( ) , AcceptError > {
199
199
self . as_ref ( ) . accept ( conn) . await
200
200
}
201
201
@@ -205,11 +205,11 @@ impl<T: ProtocolHandler> ProtocolHandler for Arc<T> {
205
205
}
206
206
207
207
impl < T : ProtocolHandler > ProtocolHandler for Box < T > {
208
- async fn on_connecting ( & self , conn : Connecting ) -> Result < Connection , ProtocolError > {
208
+ async fn on_connecting ( & self , conn : Connecting ) -> Result < Connection , AcceptError > {
209
209
self . as_ref ( ) . on_connecting ( conn) . await
210
210
}
211
211
212
- async fn accept ( & self , conn : Connection ) -> Result < ( ) , ProtocolError > {
212
+ async fn accept ( & self , conn : Connection ) -> Result < ( ) , AcceptError > {
213
213
self . as_ref ( ) . accept ( conn) . await
214
214
}
215
215
@@ -227,7 +227,7 @@ pub(crate) trait DynProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
227
227
fn on_connecting (
228
228
& self ,
229
229
connecting : Connecting ,
230
- ) -> Pin < Box < dyn Future < Output = Result < Connection , ProtocolError > > + Send + ' _ > > {
230
+ ) -> Pin < Box < dyn Future < Output = Result < Connection , AcceptError > > + Send + ' _ > > {
231
231
Box :: pin ( async move {
232
232
let conn = connecting. await ?;
233
233
Ok ( conn)
@@ -238,7 +238,7 @@ pub(crate) trait DynProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
238
238
fn accept (
239
239
& self ,
240
240
connection : Connection ,
241
- ) -> Pin < Box < dyn Future < Output = Result < ( ) , ProtocolError > > + Send + ' _ > > ;
241
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) , AcceptError > > + Send + ' _ > > ;
242
242
243
243
/// See [`ProtocolHandler::shutdown`].
244
244
fn shutdown ( & self ) -> Pin < Box < dyn Future < Output = ( ) > + Send + ' _ > > {
@@ -250,14 +250,14 @@ impl<P: ProtocolHandler> DynProtocolHandler for P {
250
250
fn accept (
251
251
& self ,
252
252
connection : Connection ,
253
- ) -> Pin < Box < dyn Future < Output = Result < ( ) , ProtocolError > > + Send + ' _ > > {
253
+ ) -> Pin < Box < dyn Future < Output = Result < ( ) , AcceptError > > + Send + ' _ > > {
254
254
Box :: pin ( <Self as ProtocolHandler >:: accept ( self , connection) )
255
255
}
256
256
257
257
fn on_connecting (
258
258
& self ,
259
259
connecting : Connecting ,
260
- ) -> Pin < Box < dyn Future < Output = Result < Connection , ProtocolError > > + Send + ' _ > > {
260
+ ) -> Pin < Box < dyn Future < Output = Result < Connection , AcceptError > > + Send + ' _ > > {
261
261
Box :: pin ( <Self as ProtocolHandler >:: on_connecting ( self , connecting) )
262
262
}
263
263
@@ -519,11 +519,11 @@ impl<P: ProtocolHandler + Clone> ProtocolHandler for AccessLimit<P> {
519
519
fn on_connecting (
520
520
& self ,
521
521
conn : Connecting ,
522
- ) -> impl Future < Output = Result < Connection , ProtocolError > > + Send {
522
+ ) -> impl Future < Output = Result < Connection , AcceptError > > + Send {
523
523
self . proto . on_connecting ( conn)
524
524
}
525
525
526
- async fn accept ( & self , conn : Connection ) -> Result < ( ) , ProtocolError > {
526
+ async fn accept ( & self , conn : Connection ) -> Result < ( ) , AcceptError > {
527
527
let remote = conn. remote_node_id ( ) ?;
528
528
let is_allowed = ( self . limiter ) ( remote) ;
529
529
if !is_allowed {
@@ -572,7 +572,7 @@ mod tests {
572
572
const ECHO_ALPN : & [ u8 ] = b"/iroh/echo/1" ;
573
573
574
574
impl ProtocolHandler for Echo {
575
- async fn accept ( & self , connection : Connection ) -> Result < ( ) , ProtocolError > {
575
+ async fn accept ( & self , connection : Connection ) -> Result < ( ) , AcceptError > {
576
576
println ! ( "accepting echo" ) ;
577
577
let ( mut send, mut recv) = connection. accept_bi ( ) . await ?;
578
578
@@ -619,7 +619,7 @@ mod tests {
619
619
const TEST_ALPN : & [ u8 ] = b"/iroh/test/1" ;
620
620
621
621
impl ProtocolHandler for TestProtocol {
622
- async fn accept ( & self , connection : Connection ) -> Result < ( ) , ProtocolError > {
622
+ async fn accept ( & self , connection : Connection ) -> Result < ( ) , AcceptError > {
623
623
self . connections . lock ( ) . expect ( "poisoned" ) . push ( connection) ;
624
624
Ok ( ( ) )
625
625
}
0 commit comments