33//! ## Example
44//!
55//! ```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};
77//! #
88//! # async fn test_compile() -> Result<(), BindError> {
99//! let endpoint = Endpoint::builder().discovery_n0().bind().await?;
1919//! struct Echo;
2020//!
2121//! impl ProtocolHandler for Echo {
22- //! async fn accept(&self, connection: Connection) -> Result<(), ProtocolError > {
22+ //! async fn accept(&self, connection: Connection) -> Result<(), AcceptError > {
2323//! let (mut send, mut recv) = connection.accept_bi().await?;
2424//!
2525//! // Echo any bytes received back directly.
@@ -98,16 +98,16 @@ pub struct RouterBuilder {
9898#[ allow( missing_docs) ]
9999#[ derive( Debug , Snafu ) ]
100100#[ non_exhaustive]
101- pub enum ProtocolError {
101+ pub enum AcceptError {
102102 #[ snafu( transparent) ]
103- Connect {
103+ Connection {
104104 source : crate :: endpoint:: ConnectionError ,
105105 backtrace : Option < Backtrace > ,
106106 #[ snafu( implicit) ]
107107 span_trace : n0_snafu:: SpanTrace ,
108108 } ,
109109 #[ snafu( transparent) ]
110- RemoteNodeId { source : RemoteNodeIdError } ,
110+ MissingRemoteNodeId { source : RemoteNodeIdError } ,
111111 #[ snafu( display( "Not allowed." ) ) ]
112112 NotAllowed { } ,
113113
@@ -117,7 +117,7 @@ pub enum ProtocolError {
117117 } ,
118118}
119119
120- impl ProtocolError {
120+ impl AcceptError {
121121 /// Creates a new user error from an arbitrary error type.
122122 pub fn from_err < T : std:: error:: Error + Send + Sync + ' static > ( value : T ) -> Self {
123123 Self :: User {
@@ -126,13 +126,13 @@ impl ProtocolError {
126126 }
127127}
128128
129- impl From < std:: io:: Error > for ProtocolError {
129+ impl From < std:: io:: Error > for AcceptError {
130130 fn from ( err : std:: io:: Error ) -> Self {
131131 Self :: from_err ( err)
132132 }
133133}
134134
135- impl From < quinn:: ClosedStream > for ProtocolError {
135+ impl From < quinn:: ClosedStream > for AcceptError {
136136 fn from ( err : quinn:: ClosedStream ) -> Self {
137137 Self :: from_err ( err)
138138 }
@@ -158,7 +158,7 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
158158 fn on_connecting (
159159 & self ,
160160 connecting : Connecting ,
161- ) -> impl Future < Output = Result < Connection , ProtocolError > > + Send {
161+ ) -> impl Future < Output = Result < Connection , AcceptError > > + Send {
162162 async move {
163163 let conn = connecting. await ?;
164164 Ok ( conn)
@@ -177,7 +177,7 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
177177 fn accept (
178178 & self ,
179179 connection : Connection ,
180- ) -> impl Future < Output = Result < ( ) , ProtocolError > > + Send ;
180+ ) -> impl Future < Output = Result < ( ) , AcceptError > > + Send ;
181181
182182 /// Called when the router shuts down.
183183 ///
@@ -191,11 +191,11 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
191191}
192192
193193impl < 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 > {
195195 self . as_ref ( ) . on_connecting ( conn) . await
196196 }
197197
198- async fn accept ( & self , conn : Connection ) -> Result < ( ) , ProtocolError > {
198+ async fn accept ( & self , conn : Connection ) -> Result < ( ) , AcceptError > {
199199 self . as_ref ( ) . accept ( conn) . await
200200 }
201201
@@ -205,11 +205,11 @@ impl<T: ProtocolHandler> ProtocolHandler for Arc<T> {
205205}
206206
207207impl < 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 > {
209209 self . as_ref ( ) . on_connecting ( conn) . await
210210 }
211211
212- async fn accept ( & self , conn : Connection ) -> Result < ( ) , ProtocolError > {
212+ async fn accept ( & self , conn : Connection ) -> Result < ( ) , AcceptError > {
213213 self . as_ref ( ) . accept ( conn) . await
214214 }
215215
@@ -227,7 +227,7 @@ pub(crate) trait DynProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
227227 fn on_connecting (
228228 & self ,
229229 connecting : Connecting ,
230- ) -> Pin < Box < dyn Future < Output = Result < Connection , ProtocolError > > + Send + ' _ > > {
230+ ) -> Pin < Box < dyn Future < Output = Result < Connection , AcceptError > > + Send + ' _ > > {
231231 Box :: pin ( async move {
232232 let conn = connecting. await ?;
233233 Ok ( conn)
@@ -238,7 +238,7 @@ pub(crate) trait DynProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
238238 fn accept (
239239 & self ,
240240 connection : Connection ,
241- ) -> Pin < Box < dyn Future < Output = Result < ( ) , ProtocolError > > + Send + ' _ > > ;
241+ ) -> Pin < Box < dyn Future < Output = Result < ( ) , AcceptError > > + Send + ' _ > > ;
242242
243243 /// See [`ProtocolHandler::shutdown`].
244244 fn shutdown ( & self ) -> Pin < Box < dyn Future < Output = ( ) > + Send + ' _ > > {
@@ -250,14 +250,14 @@ impl<P: ProtocolHandler> DynProtocolHandler for P {
250250 fn accept (
251251 & self ,
252252 connection : Connection ,
253- ) -> Pin < Box < dyn Future < Output = Result < ( ) , ProtocolError > > + Send + ' _ > > {
253+ ) -> Pin < Box < dyn Future < Output = Result < ( ) , AcceptError > > + Send + ' _ > > {
254254 Box :: pin ( <Self as ProtocolHandler >:: accept ( self , connection) )
255255 }
256256
257257 fn on_connecting (
258258 & self ,
259259 connecting : Connecting ,
260- ) -> Pin < Box < dyn Future < Output = Result < Connection , ProtocolError > > + Send + ' _ > > {
260+ ) -> Pin < Box < dyn Future < Output = Result < Connection , AcceptError > > + Send + ' _ > > {
261261 Box :: pin ( <Self as ProtocolHandler >:: on_connecting ( self , connecting) )
262262 }
263263
@@ -519,11 +519,11 @@ impl<P: ProtocolHandler + Clone> ProtocolHandler for AccessLimit<P> {
519519 fn on_connecting (
520520 & self ,
521521 conn : Connecting ,
522- ) -> impl Future < Output = Result < Connection , ProtocolError > > + Send {
522+ ) -> impl Future < Output = Result < Connection , AcceptError > > + Send {
523523 self . proto . on_connecting ( conn)
524524 }
525525
526- async fn accept ( & self , conn : Connection ) -> Result < ( ) , ProtocolError > {
526+ async fn accept ( & self , conn : Connection ) -> Result < ( ) , AcceptError > {
527527 let remote = conn. remote_node_id ( ) ?;
528528 let is_allowed = ( self . limiter ) ( remote) ;
529529 if !is_allowed {
@@ -572,7 +572,7 @@ mod tests {
572572 const ECHO_ALPN : & [ u8 ] = b"/iroh/echo/1" ;
573573
574574 impl ProtocolHandler for Echo {
575- async fn accept ( & self , connection : Connection ) -> Result < ( ) , ProtocolError > {
575+ async fn accept ( & self , connection : Connection ) -> Result < ( ) , AcceptError > {
576576 println ! ( "accepting echo" ) ;
577577 let ( mut send, mut recv) = connection. accept_bi ( ) . await ?;
578578
@@ -619,7 +619,7 @@ mod tests {
619619 const TEST_ALPN : & [ u8 ] = b"/iroh/test/1" ;
620620
621621 impl ProtocolHandler for TestProtocol {
622- async fn accept ( & self , connection : Connection ) -> Result < ( ) , ProtocolError > {
622+ async fn accept ( & self , connection : Connection ) -> Result < ( ) , AcceptError > {
623623 self . connections . lock ( ) . expect ( "poisoned" ) . push ( connection) ;
624624 Ok ( ( ) )
625625 }
0 commit comments