diff --git a/pr/3921/docs/iroh_relay/server/client/enum.HandleFrameError.html b/pr/3921/docs/iroh_relay/server/client/enum.HandleFrameError.html index 9b6e2e70f2..cb2a0cf38b 100644 --- a/pr/3921/docs/iroh_relay/server/client/enum.HandleFrameError.html +++ b/pr/3921/docs/iroh_relay/server/client/enum.HandleFrameError.html @@ -1,4 +1,4 @@ -HandleFrameError in iroh_relay::server::client - Rust

HandleFrameError

Enum HandleFrameError 

Source
#[non_exhaustive]
pub enum HandleFrameError { +HandleFrameError in iroh_relay::server::client - Rust

HandleFrameError

Enum HandleFrameError 

Source
#[non_exhaustive]
pub enum HandleFrameError { ForwardPacket { source: ForwardPacketError, meta: Meta, @@ -19,7 +19,7 @@
§

StreamTerminated

Fields

§meta: Meta

Captured call-site metadata

§

Recv

Fields

§source: RecvError
§meta: Meta

Captured call-site metadata

§

Send

Fields

§meta: Meta

Captured call-site metadata

-

Trait Implementations§

Source§

impl Debug for HandleFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for HandleFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for HandleFrameError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ForwardPacketError> for HandleFrameError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl From<HandleFrameError> for AnyError

Source§

fn from(value: HandleFrameError) -> AnyError

Converts to this type from the input type.
Source§

impl From<HandleFrameError> for RunError

Source§

fn from(source: HandleFrameError) -> Self

Converts to this type from the input type.
Source§

impl From<RecvError> for HandleFrameError

Source§

fn from(source: RelayRecvError) -> Self

Converts to this type from the input type.
Source§

impl From<WriteFrameError> for HandleFrameError

Source§

fn from(source: WriteFrameError) -> Self

Converts to this type from the input type.
Source§

impl StackError for HandleFrameError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

§

impl Freeze for HandleFrameError

§

impl !RefUnwindSafe for HandleFrameError

§

impl Send for HandleFrameError

§

impl Sync for HandleFrameError

§

impl Unpin for HandleFrameError

§

impl !UnwindSafe for HandleFrameError

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Debug for HandleFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for HandleFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for HandleFrameError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ForwardPacketError> for HandleFrameError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl From<HandleFrameError> for AnyError

Source§

fn from(value: HandleFrameError) -> AnyError

Converts to this type from the input type.
Source§

impl From<HandleFrameError> for RunError

Source§

fn from(source: HandleFrameError) -> Self

Converts to this type from the input type.
Source§

impl From<RecvError> for HandleFrameError

Source§

fn from(source: RelayRecvError) -> Self

Converts to this type from the input type.
Source§

impl From<WriteFrameError> for HandleFrameError

Source§

fn from(source: WriteFrameError) -> Self

Converts to this type from the input type.
Source§

impl StackError for HandleFrameError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

§

impl Freeze for HandleFrameError

§

impl !RefUnwindSafe for HandleFrameError

§

impl Send for HandleFrameError

§

impl Sync for HandleFrameError

§

impl Unpin for HandleFrameError

§

impl !UnwindSafe for HandleFrameError

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/3921/docs/iroh_relay/server/client/enum.RunError.html b/pr/3921/docs/iroh_relay/server/client/enum.RunError.html index 5030d10bd5..94cf610245 100644 --- a/pr/3921/docs/iroh_relay/server/client/enum.RunError.html +++ b/pr/3921/docs/iroh_relay/server/client/enum.RunError.html @@ -1,4 +1,4 @@ -RunError in iroh_relay::server::client - Rust

RunError

Enum RunError 

Source
#[non_exhaustive]
pub enum RunError { +RunError in iroh_relay::server::client - Rust

RunError

Enum RunError 

Source
#[non_exhaustive]
pub enum RunError { ForwardPacket { source: ForwardPacketError, meta: Meta, @@ -36,7 +36,7 @@

§

EndpointGoneDrop

Fields

§meta: Meta

Captured call-site metadata

§

WriteFrame

Fields

§meta: Meta

Captured call-site metadata

§

TickFlush

Fields

§meta: Meta

Captured call-site metadata

-

Trait Implementations§

Source§

impl Debug for RunError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RunError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for RunError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ForwardPacketError> for RunError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl From<HandleFrameError> for RunError

Source§

fn from(source: HandleFrameError) -> Self

Converts to this type from the input type.
Source§

impl From<RunError> for AnyError

Source§

fn from(value: RunError) -> AnyError

Converts to this type from the input type.
Source§

impl StackError for RunError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

§

impl Freeze for RunError

§

impl !RefUnwindSafe for RunError

§

impl Send for RunError

§

impl Sync for RunError

§

impl Unpin for RunError

§

impl !UnwindSafe for RunError

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Debug for RunError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RunError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for RunError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ForwardPacketError> for RunError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl From<HandleFrameError> for RunError

Source§

fn from(source: HandleFrameError) -> Self

Converts to this type from the input type.
Source§

impl From<RunError> for AnyError

Source§

fn from(value: RunError) -> AnyError

Converts to this type from the input type.
Source§

impl StackError for RunError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

§

impl Freeze for RunError

§

impl !RefUnwindSafe for RunError

§

impl Send for RunError

§

impl Sync for RunError

§

impl Unpin for RunError

§

impl !UnwindSafe for RunError

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/3921/docs/iroh_relay/server/client/enum.WriteFrameError.html b/pr/3921/docs/iroh_relay/server/client/enum.WriteFrameError.html index d68324efa4..c3de2e3db1 100644 --- a/pr/3921/docs/iroh_relay/server/client/enum.WriteFrameError.html +++ b/pr/3921/docs/iroh_relay/server/client/enum.WriteFrameError.html @@ -1,4 +1,4 @@ -WriteFrameError in iroh_relay::server::client - Rust

WriteFrameError

Enum WriteFrameError 

Source
#[non_exhaustive]
pub enum WriteFrameError { +WriteFrameError in iroh_relay::server::client - Rust

WriteFrameError

Enum WriteFrameError 

Source
#[non_exhaustive]
pub enum WriteFrameError { Stream { source: SendError, meta: Meta, @@ -10,7 +10,7 @@ }
Available on crate feature server only.
Expand description

Error when writing a frame to a client.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Stream

Fields

§source: SendError
§meta: Meta

Captured call-site metadata

§

Timeout

Fields

§source: Elapsed
§meta: Meta

Captured call-site metadata

-

Trait Implementations§

Source§

impl Debug for WriteFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for WriteFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for WriteFrameError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Elapsed> for WriteFrameError

Source§

fn from(source: Elapsed) -> Self

Converts to this type from the input type.
Source§

impl From<SendError> for WriteFrameError

Source§

fn from(source: RelaySendError) -> Self

Converts to this type from the input type.
Source§

impl From<WriteFrameError> for AnyError

Source§

fn from(value: WriteFrameError) -> AnyError

Converts to this type from the input type.
Source§

impl From<WriteFrameError> for HandleFrameError

Source§

fn from(source: WriteFrameError) -> Self

Converts to this type from the input type.
Source§

impl StackError for WriteFrameError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Debug for WriteFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for WriteFrameError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for WriteFrameError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Elapsed> for WriteFrameError

Source§

fn from(source: Elapsed) -> Self

Converts to this type from the input type.
Source§

impl From<SendError> for WriteFrameError

Source§

fn from(source: RelaySendError) -> Self

Converts to this type from the input type.
Source§

impl From<WriteFrameError> for AnyError

Source§

fn from(value: WriteFrameError) -> AnyError

Converts to this type from the input type.
Source§

impl From<WriteFrameError> for HandleFrameError

Source§

fn from(source: WriteFrameError) -> Self

Converts to this type from the input type.
Source§

impl StackError for WriteFrameError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/3921/docs/iroh_relay/server/client/index.html b/pr/3921/docs/iroh_relay/server/client/index.html index 71d2135c97..420c1afc77 100644 --- a/pr/3921/docs/iroh_relay/server/client/index.html +++ b/pr/3921/docs/iroh_relay/server/client/index.html @@ -1,2 +1,2 @@ -iroh_relay::server::client - Rust

Module client

Module client 

Source
Available on crate feature server only.
Expand description

The server-side representation of an ongoing client relaying connection.

+iroh_relay::server::client - Rust

Module client

Module client 

Source
Available on crate feature server only.
Expand description

The server-side representation of an ongoing client relaying connection.

Structs§

Client
The Server side representation of a Client’s connection.
Config
Configuration for a Client.
ForwardPacketError
Error returned when forwarding a packet to a client fails.

Enums§

HandleFrameError
Error when handling an incoming frame from a client.
RunError
Run error
WriteFrameError
Error when writing a frame to a client.
\ No newline at end of file diff --git a/pr/3921/docs/iroh_relay/server/client/struct.ForwardPacketError.html b/pr/3921/docs/iroh_relay/server/client/struct.ForwardPacketError.html index 2a3d97fa2a..0e06d2660d 100644 --- a/pr/3921/docs/iroh_relay/server/client/struct.ForwardPacketError.html +++ b/pr/3921/docs/iroh_relay/server/client/struct.ForwardPacketError.html @@ -1,9 +1,9 @@ -ForwardPacketError in iroh_relay::server::client - Rust

ForwardPacketError

Struct ForwardPacketError 

Source
pub struct ForwardPacketError { /* private fields */ }
Available on crate feature server only.
Expand description

Error returned when forwarding a packet to a client fails.

+ForwardPacketError in iroh_relay::server::client - Rust

ForwardPacketError

Struct ForwardPacketError 

Source
pub struct ForwardPacketError { /* private fields */ }
Available on crate feature server only.
Expand description

Error returned when forwarding a packet to a client fails.

This error occurs when the relay server cannot deliver a packet to its intended recipient, typically due to the client’s send queue being full or the client disconnecting.

-

Implementations§

Source§

impl ForwardPacketError

Source

pub fn new(reason: SendError) -> Self

Creates a new ForwardPacketError error.

-

Trait Implementations§

Source§

impl Debug for ForwardPacketError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ForwardPacketError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ForwardPacketError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ForwardPacketError> for AnyError

Source§

fn from(value: ForwardPacketError) -> AnyError

Converts to this type from the input type.
Source§

impl From<ForwardPacketError> for HandleFrameError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl From<ForwardPacketError> for RunError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl StackError for ForwardPacketError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where +

Implementations§

Source§

impl ForwardPacketError

Source

pub fn new(reason: SendError) -> Self

Creates a new ForwardPacketError error.

+

Trait Implementations§

Source§

impl Debug for ForwardPacketError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ForwardPacketError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ForwardPacketError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ForwardPacketError> for AnyError

Source§

fn from(value: ForwardPacketError) -> AnyError

Converts to this type from the input type.
Source§

impl From<ForwardPacketError> for HandleFrameError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl From<ForwardPacketError> for RunError

Source§

fn from(source: ForwardPacketError) -> Self

Converts to this type from the input type.
Source§

impl StackError for ForwardPacketError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/3921/docs/iroh_relay/server/streams/enum.RecvError.html b/pr/3921/docs/iroh_relay/server/streams/enum.RecvError.html index b0d9bc287f..019c5aaa10 100644 --- a/pr/3921/docs/iroh_relay/server/streams/enum.RecvError.html +++ b/pr/3921/docs/iroh_relay/server/streams/enum.RecvError.html @@ -14,7 +14,7 @@

§

StreamError

Error from the underlying WebSocket stream

Fields

§source: StreamError

The underlying stream error

§meta: Meta

Captured call-site metadata

-

Trait Implementations§

Source§

impl Debug for RecvError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RecvError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for RecvError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for RecvError

Source§

fn from(source: ProtoError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for RecvError

Source§

fn from(source: StreamError) -> Self

Converts to this type from the input type.
Source§

impl From<RecvError> for AnyError

Source§

fn from(value: RecvError) -> AnyError

Converts to this type from the input type.
Source§

impl From<RecvError> for HandleFrameError

Source§

fn from(source: RelayRecvError) -> Self

Converts to this type from the input type.
Source§

impl StackError for RecvError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Debug for RecvError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for RecvError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for RecvError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for RecvError

Source§

fn from(source: ProtoError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for RecvError

Source§

fn from(source: StreamError) -> Self

Converts to this type from the input type.
Source§

impl From<RecvError> for AnyError

Source§

fn from(value: RecvError) -> AnyError

Converts to this type from the input type.
Source§

impl From<RecvError> for HandleFrameError

Source§

fn from(source: RelayRecvError) -> Self

Converts to this type from the input type.
Source§

impl StackError for RecvError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/3921/docs/iroh_relay/server/streams/enum.SendError.html b/pr/3921/docs/iroh_relay/server/streams/enum.SendError.html index 802a5d721f..538357142a 100644 --- a/pr/3921/docs/iroh_relay/server/streams/enum.SendError.html +++ b/pr/3921/docs/iroh_relay/server/streams/enum.SendError.html @@ -19,7 +19,7 @@

§meta: Meta

Captured call-site metadata

§

EmptyPacket

Attempted to send an empty packet

Fields

§meta: Meta

Captured call-site metadata

-

Trait Implementations§

Source§

impl Debug for SendError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SendError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for SendError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for SendError

Source§

fn from(source: StreamError) -> Self

Converts to this type from the input type.
Source§

impl From<SendError> for AnyError

Source§

fn from(value: SendError) -> AnyError

Converts to this type from the input type.
Source§

impl From<SendError> for WriteFrameError

Source§

fn from(source: RelaySendError) -> Self

Converts to this type from the input type.
Source§

impl StackError for SendError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where +

Trait Implementations§

Source§

impl Debug for SendError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SendError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for SendError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for SendError

Source§

fn from(source: StreamError) -> Self

Converts to this type from the input type.
Source§

impl From<SendError> for AnyError

Source§

fn from(value: SendError) -> AnyError

Converts to this type from the input type.
Source§

impl From<SendError> for WriteFrameError

Source§

fn from(source: RelaySendError) -> Self

Converts to this type from the input type.
Source§

impl StackError for SendError

Source§

fn as_std(&self) -> &(dyn Error + Send + Sync + 'static)

Returns this error as a std error reference.
Source§

fn into_std(self: Box<Self>) -> Box<dyn Error + Send + Sync>

Returns this error as a std error.
Source§

fn as_dyn(&self) -> &dyn StackError

Returns this error as a dyn StackError.
Source§

fn fmt_message(&self, f: &mut Formatter<'_>) -> Result

Returns the next source in the chain, if any.
Source§

fn meta(&self) -> Option<&Meta>

Returns metadata captured at creation time, if available.
Source§

fn source(&self) -> Option<ErrorRef<'_>>

Returns the next source in the chain, if any.
Source§

fn is_transparent(&self) -> bool

Returns whether this error is transparent and should be skipped in reports.
§

fn as_ref(&self) -> ErrorRef<'_>

Returns this error as an [ErrorRef]. Read more
§

fn stack(&self) -> Chain<'_>

Returns an iterator over this error followed by its sources.
§

fn sources(&self) -> Chain<'_>

Returns an iterator over sources of this error (skipping self).
§

fn report(&self) -> Report<'_>

Returns a [Report] to output the error with configurable formatting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( diff --git a/pr/3921/docs/src/iroh/socket/transports/relay/actor.rs.html b/pr/3921/docs/src/iroh/socket/transports/relay/actor.rs.html index f2529acbb7..b366195703 100644 --- a/pr/3921/docs/src/iroh/socket/transports/relay/actor.rs.html +++ b/pr/3921/docs/src/iroh/socket/transports/relay/actor.rs.html @@ -349,7 +349,7 @@ 349 // If the relay disconnected us because another endpoint with the same secret key connected afterwards, 350 // we don't fight our successor and instead give up. 351 // If we would `break` here, the relay actor would very likely be restarted again right away. -352 // The home relay actor is restarted regularily if dropped in `RelayActor::reap_active_relays`. +352 // The home relay actor is restarted regularly if dropped in `RelayActor::reap_active_relays`. 353 // Other relay actors are restarted on-demand. 354 std::future::pending::<()>().await; 355 } diff --git a/pr/3921/docs/src/iroh_relay/server/client.rs.html b/pr/3921/docs/src/iroh_relay/server/client.rs.html index 4d57ea832e..4426bbaf2f 100644 --- a/pr/3921/docs/src/iroh_relay/server/client.rs.html +++ b/pr/3921/docs/src/iroh_relay/server/client.rs.html @@ -152,549 +152,548 @@ 152 /// Starts the process of shutdown. 153 pub(super) fn start_shutdown(&self, reason: Option<CloseReason>) { 154 if let Some(sender) = self.done_s.lock().expect("poisoned").take() { -155 trace!("SEND SHUTDOWN"); -156 sender.send(reason).ok(); -157 } -158 } -159 -160 pub(super) fn try_send_packet( -161 &self, -162 src: EndpointId, -163 data: Datagrams, -164 ) -> Result<(), TrySendError<Packet>> { -165 self.send_queue.try_send(Packet { src, data }) -166 } -167 -168 pub(super) fn try_send_peer_gone( -169 &self, -170 key: EndpointId, -171 ) -> Result<(), TrySendError<EndpointId>> { -172 self.peer_gone.try_send(key) -173 } -174} -175 -176/// Error when handling an incoming frame from a client. -177#[stack_error(derive, add_meta, from_sources)] -178#[allow(missing_docs)] -179#[non_exhaustive] -180pub enum HandleFrameError { -181 #[error(transparent)] -182 ForwardPacket { source: ForwardPacketError }, -183 #[error("Stream terminated")] -184 StreamTerminated {}, -185 #[error(transparent)] -186 Recv { source: RelayRecvError }, -187 #[error(transparent)] -188 Send { source: WriteFrameError }, -189} -190 -191/// Error when writing a frame to a client. -192#[stack_error(derive, add_meta, from_sources)] -193#[allow(missing_docs)] -194#[non_exhaustive] -195pub enum WriteFrameError { -196 #[error(transparent)] -197 Stream { source: RelaySendError }, -198 #[error(transparent)] -199 Timeout { -200 #[error(std_err)] -201 source: tokio::time::error::Elapsed, -202 }, -203} -204 -205/// Run error -206#[stack_error(derive, add_meta)] -207#[allow(missing_docs)] -208#[non_exhaustive] -209pub enum RunError { -210 #[error(transparent)] -211 ForwardPacket { -212 #[error(from)] -213 source: ForwardPacketError, -214 }, -215 #[error("Flush")] -216 CloseFlush {}, -217 #[error(transparent)] -218 HandleFrame { -219 #[error(from)] -220 source: HandleFrameError, -221 }, -222 #[error("Server.send_queue dropped")] -223 SendQueuePacketDrop {}, -224 #[error("Failed to send packet")] -225 PacketSend { source: WriteFrameError }, -226 #[error("Server.endpoint_gone dropped")] -227 EndpointGoneDrop {}, -228 #[error("Writing frame failed")] -229 WriteFrame { source: WriteFrameError }, -230 #[error("Tick flush")] -231 TickFlush {}, -232} -233 -234/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE` -235/// message to the client to keep the connection alive. -236/// -237/// Call `run` to manage the input and output to and from the connection and the server. -238/// Once it hits its first write error or error receiving off a channel, -239/// it errors on return. -240/// If writes do not complete in the given `timeout`, it will also error. -241/// -242/// On the "write" side, the [`Actor`] can send the client: -243/// - a KEEP_ALIVE frame -244/// - a PEER_GONE frame to inform the client that a peer they have previously sent messages to -245/// is gone from the network -246/// - packets from other peers -247/// -248/// On the "read" side, it can: -249/// - receive a ping and write a pong back -250/// to speak to the endpoint ID associated with that client. -251#[derive(Debug)] -252struct Actor<S> { -253 /// IO Stream to talk to the client -254 stream: RelayedStream<S>, -255 /// Maximum time we wait to complete a write to the client -256 timeout: Duration, -257 /// Packets queued to send to the client -258 send_queue: mpsc::Receiver<Packet>, -259 /// Notify the client that a previous sender has disconnected -260 endpoint_gone: mpsc::Receiver<EndpointId>, -261 /// [`EndpointId`] of this client -262 endpoint_id: EndpointId, -263 /// Connection identifier. -264 connection_id: u64, -265 /// Reference to the other connected clients. -266 clients: Clients, -267 /// Statistics about the connected clients -268 client_counter: ClientCounter, -269 ping_tracker: PingTracker, -270 metrics: Arc<Metrics>, -271} -272 -273impl<S> Actor<S> -274where -275 S: BytesStreamSink, -276{ -277 async fn run(mut self, done_r: oneshot::Receiver<Option<CloseReason>>) { -278 // Note the accept and disconnects metrics must be in a pair. Technically the -279 // connection is accepted long before this in the HTTP server, but it is clearer to -280 // handle the metric here. -281 self.metrics.accepts.inc(); -282 if self.client_counter.update(self.endpoint_id) { -283 self.metrics.unique_client_keys.inc(); -284 } -285 match self.run_inner(done_r).await { -286 Err(e) => { -287 warn!("actor errored {e:#}, exiting"); -288 } -289 Ok(()) => { -290 debug!("actor finished, exiting"); -291 } -292 } -293 -294 self.clients -295 .unregister(self.connection_id, self.endpoint_id); -296 self.metrics.disconnects.inc(); -297 } -298 -299 async fn run_inner( -300 &mut self, -301 mut done_r: oneshot::Receiver<Option<CloseReason>>, -302 ) -> Result<(), RunError> { -303 // Add some jitter to ping pong interactions, to avoid all pings being sent at the same time -304 let next_interval = || { -305 let random_secs = rand::rng().random_range(1..=5); -306 Duration::from_secs(random_secs) + PING_INTERVAL -307 }; -308 -309 let mut ping_interval = tokio::time::interval(next_interval()); -310 // ticks immediately -311 ping_interval.set_missed_tick_behavior(MissedTickBehavior::Delay); -312 ping_interval.tick().await; -313 -314 loop { -315 tokio::select! { -316 biased; -317 -318 reason = &mut done_r => { -319 trace!("actor loop cancelled, exiting (reason: {reason:?})"); -320 if let Ok(Some(reason)) = reason { -321 self.write_frame(RelayToClientMsg::Close { reason }).await -322 .map_err(|err| e!(RunError::WriteFrame, err))?; -323 } -324 self.stream -325 .flush() -326 .await -327 .map_err(|_| e!(RunError::CloseFlush))?; -328 break; -329 } -330 maybe_frame = self.stream.next() => { -331 self -332 .handle_frame(maybe_frame) -333 .await?; -334 // reset the ping interval, we just received a message -335 ping_interval.reset(); -336 } -337 // Second priority, sending regular packets -338 packet = self.send_queue.recv() => { -339 let packet = packet.ok_or_else(|| e!(RunError::SendQueuePacketDrop))?; -340 self.send_packet(packet) -341 .await -342 .map_err(|err| e!(RunError::PacketSend, err))?; -343 } -344 // Last priority, sending left endpoints -345 endpoint_id = self.endpoint_gone.recv() => { -346 let endpoint_id = endpoint_id.ok_or_else(|| e!(RunError::EndpointGoneDrop))?; -347 trace!("endpoint_id gone: {:?}", endpoint_id); -348 self.write_frame(RelayToClientMsg::EndpointGone(endpoint_id)) -349 .await -350 .map_err(|err| e!(RunError::WriteFrame, err))?; -351 } -352 _ = self.ping_tracker.timeout() => { -353 trace!("pong timed out"); -354 break; -355 } -356 _ = ping_interval.tick() => { -357 trace!("keep alive ping"); -358 // new interval -359 ping_interval.reset_after(next_interval()); -360 let data = self.ping_tracker.new_ping(); -361 self.write_frame(RelayToClientMsg::Ping(data)) -362 .await -363 .map_err(|err| e!(RunError::WriteFrame, err))?; -364 } -365 } -366 -367 self.stream -368 .flush() -369 .await -370 .map_err(|_| e!(RunError::TickFlush))?; -371 } -372 Ok(()) -373 } -374 -375 /// Writes the given frame to the connection. -376 /// -377 /// Errors if the send does not happen within the `timeout` duration -378 async fn write_frame(&mut self, frame: RelayToClientMsg) -> Result<(), WriteFrameError> { -379 tokio::time::timeout(self.timeout, self.stream.send(frame)).await??; -380 Ok(()) -381 } -382 -383 /// Writes contents to the client in a `RECV_PACKET` frame. -384 /// -385 /// Errors if the send does not happen within the `timeout` duration -386 /// Does not flush. -387 async fn send_raw(&mut self, packet: Packet) -> Result<(), WriteFrameError> { -388 let remote_endpoint_id = packet.src; -389 let datagrams = packet.data; -390 -391 if let Ok(len) = datagrams.contents.len().try_into() { -392 self.metrics.bytes_sent.inc_by(len); -393 } -394 self.write_frame(RelayToClientMsg::Datagrams { -395 remote_endpoint_id, -396 datagrams, -397 }) -398 .await -399 } -400 -401 async fn send_packet(&mut self, packet: Packet) -> Result<(), WriteFrameError> { -402 trace!("send packet"); -403 match self.send_raw(packet).await { -404 Ok(()) => { -405 self.metrics.send_packets_sent.inc(); -406 Ok(()) -407 } -408 Err(err) => { -409 self.metrics.send_packets_dropped.inc(); -410 Err(err) -411 } -412 } -413 } -414 -415 /// Handles frame read results. -416 async fn handle_frame( -417 &mut self, -418 maybe_frame: Option<Result<ClientToRelayMsg, RelayRecvError>>, -419 ) -> Result<(), HandleFrameError> { -420 trace!(?maybe_frame, "handle incoming frame"); -421 let frame = match maybe_frame { -422 Some(frame) => frame?, -423 None => return Err(e!(HandleFrameError::StreamTerminated)), -424 }; -425 -426 match frame { -427 ClientToRelayMsg::Datagrams { -428 dst_endpoint_id: dst_key, -429 datagrams, -430 } => { -431 let packet_len = datagrams.contents.len(); -432 if let Err(err @ ForwardPacketError { .. }) = -433 self.handle_frame_send_packet(dst_key, datagrams) -434 { -435 warn!("failed to handle send packet frame: {err:#}"); -436 } -437 self.metrics.bytes_recv.inc_by(packet_len as u64); -438 } -439 ClientToRelayMsg::Ping(data) => { -440 self.metrics.got_ping.inc(); -441 // TODO: add rate limiter -442 self.write_frame(RelayToClientMsg::Pong(data)).await?; -443 self.metrics.sent_pong.inc(); -444 } -445 ClientToRelayMsg::Pong(data) => { -446 self.ping_tracker.pong_received(data); -447 } -448 } -449 Ok(()) -450 } -451 -452 fn handle_frame_send_packet( -453 &self, -454 dst: EndpointId, -455 data: Datagrams, -456 ) -> Result<(), ForwardPacketError> { -457 self.metrics.send_packets_recv.inc(); -458 self.clients -459 .send_packet(dst, data, self.endpoint_id, &self.metrics)?; -460 -461 Ok(()) -462 } -463} -464 -465#[derive(Debug)] -466pub(crate) enum SendError { -467 Full, -468 Closed, -469} -470 -471/// Error returned when forwarding a packet to a client fails. -472/// -473/// This error occurs when the relay server cannot deliver a packet to its intended -474/// recipient, typically due to the client's send queue being full or the client -475/// disconnecting. -476#[stack_error(derive, add_meta)] -477#[error("failed to forward packet: {reason:?}")] -478pub struct ForwardPacketError { -479 reason: SendError, -480} -481 -482/// Tracks how many unique endpoints have been seen during the last day. -483#[derive(Debug)] -484struct ClientCounter { -485 clients: HashSet<EndpointId>, -486 last_clear_date: Date, -487} -488 -489impl Default for ClientCounter { -490 fn default() -> Self { -491 Self { -492 clients: HashSet::new(), -493 last_clear_date: OffsetDateTime::now_utc().date(), -494 } -495 } -496} -497 -498impl ClientCounter { -499 fn check_and_clear(&mut self) { -500 let today = OffsetDateTime::now_utc().date(); -501 if today != self.last_clear_date { -502 self.clients.clear(); -503 self.last_clear_date = today; -504 } -505 } -506 -507 /// Marks this endpoint as seen, returns whether it is new today or not. -508 fn update(&mut self, client: EndpointId) -> bool { -509 self.check_and_clear(); -510 self.clients.insert(client) -511 } -512} -513 -514#[cfg(test)] -515mod tests { -516 use iroh_base::SecretKey; -517 use n0_error::{Result, StdResultExt, bail_any}; -518 use n0_future::Stream; -519 use n0_tracing_test::traced_test; -520 use rand::SeedableRng; -521 use tracing::info; -522 -523 use super::*; -524 use crate::{client::conn::Conn, protos::common::FrameType}; -525 -526 async fn recv_frame< -527 E: std::error::Error + Sync + Send + 'static, -528 S: Stream<Item = Result<RelayToClientMsg, E>> + Unpin, -529 >( -530 frame_type: FrameType, -531 mut stream: S, -532 ) -> Result<RelayToClientMsg> { -533 match stream.next().await { -534 Some(Ok(frame)) => { -535 if frame_type != frame.typ() { -536 bail_any!( -537 "Unexpected frame, got {:?}, but expected {:?}", -538 frame.typ(), -539 frame_type -540 ); -541 } -542 Ok(frame) -543 } -544 Some(Err(err)) => Err(err).anyerr(), -545 None => bail_any!("Unexpected EOF, expected frame {frame_type:?}"), -546 } -547 } -548 -549 #[tokio::test] -550 #[traced_test] -551 async fn test_client_actor_basic() -> Result { -552 let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64); -553 -554 let (send_queue_s, send_queue_r) = mpsc::channel(10); -555 let (peer_gone_s, peer_gone_r) = mpsc::channel(10); -556 let (done_s, done_r) = oneshot::channel(); -557 -558 let endpoint_id = SecretKey::generate(&mut rng).public(); -559 let (io, io_rw) = tokio::io::duplex(1024); -560 let mut io_rw = Conn::test(io_rw); -561 let stream = RelayedStream::test(io); -562 -563 let clients = Clients::default(); -564 let metrics = Arc::new(Metrics::default()); -565 let actor = Actor { -566 stream, -567 timeout: Duration::from_secs(1), -568 send_queue: send_queue_r, -569 endpoint_gone: peer_gone_r, -570 connection_id: 0, -571 endpoint_id, -572 clients: clients.clone(), -573 client_counter: ClientCounter::default(), -574 ping_tracker: PingTracker::default(), -575 metrics, -576 }; -577 -578 let handle = tokio::task::spawn(async move { actor.run(done_r).await }); -579 -580 // Write tests -581 println!("-- write"); -582 let data = b"hello world!"; -583 -584 // send packet -585 println!(" send packet"); -586 let packet = Packet { -587 src: endpoint_id, -588 data: Datagrams::from(&data[..]), -589 }; -590 send_queue_s -591 .send(packet.clone()) -592 .await -593 .std_context("send")?; -594 let frame = recv_frame(FrameType::RelayToClientDatagram, &mut io_rw) -595 .await -596 .anyerr()?; -597 assert_eq!( -598 frame, -599 RelayToClientMsg::Datagrams { -600 remote_endpoint_id: endpoint_id, -601 datagrams: data.to_vec().into() -602 } -603 ); -604 -605 // send peer_gone -606 println!("send peer gone"); -607 peer_gone_s.send(endpoint_id).await.std_context("send")?; -608 let frame = recv_frame(FrameType::EndpointGone, &mut io_rw) -609 .await -610 .anyerr()?; -611 assert_eq!(frame, RelayToClientMsg::EndpointGone(endpoint_id)); -612 -613 // Read tests -614 println!("--read"); -615 -616 // send ping, expect pong -617 let data = b"pingpong"; -618 io_rw.send(ClientToRelayMsg::Ping(*data)).await?; -619 -620 // recv pong -621 println!(" recv pong"); -622 let frame = recv_frame(FrameType::Pong, &mut io_rw).await?; -623 assert_eq!(frame, RelayToClientMsg::Pong(*data)); -624 -625 let target = SecretKey::generate(&mut rng).public(); -626 -627 // send packet -628 println!(" send packet"); -629 let data = b"hello world!"; -630 io_rw -631 .send(ClientToRelayMsg::Datagrams { -632 dst_endpoint_id: target, -633 datagrams: Datagrams::from(data), -634 }) -635 .await -636 .std_context("send")?; -637 -638 done_s.send(None).ok(); -639 handle.await.std_context("join")?; -640 Ok(()) -641 } -642 -643 #[tokio::test(start_paused = true)] -644 #[traced_test] -645 async fn test_rate_limit() -> Result { -646 const LIMIT: u32 = 50; -647 const MAX_FRAMES: u32 = 100; -648 -649 let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64); -650 -651 // Build the rate limited stream. -652 let (io_read, io_write) = tokio::io::duplex((LIMIT * MAX_FRAMES) as _); -653 let mut frame_writer = Conn::test(io_write); -654 // Rate limiter allowing LIMIT bytes/s -655 let mut stream = RelayedStream::test_limited(io_read, LIMIT / 10, LIMIT)?; -656 -657 // Prepare a frame to send, assert its size. -658 let data = Datagrams::from(b"hello world!!!!!"); -659 let target = SecretKey::generate(&mut rng).public(); -660 let frame = ClientToRelayMsg::Datagrams { -661 dst_endpoint_id: target, -662 datagrams: data.clone(), -663 }; -664 let frame_len = frame.to_bytes().len(); -665 assert_eq!(frame_len, LIMIT as usize); -666 -667 // Send a frame, it should arrive. -668 info!("-- send packet"); -669 frame_writer.send(frame.clone()).await.std_context("send")?; -670 frame_writer.flush().await.std_context("flush")?; -671 let recv_frame = tokio::time::timeout(Duration::from_millis(500), stream.next()) -672 .await -673 .expect("timeout") -674 .expect("option") -675 .expect("ok"); -676 assert_eq!(recv_frame, frame); -677 -678 // Next frame does not arrive. -679 info!("-- send packet"); -680 frame_writer.send(frame.clone()).await.std_context("send")?; -681 frame_writer.flush().await.std_context("flush")?; -682 let res = tokio::time::timeout(Duration::from_millis(100), stream.next()).await; -683 assert!(res.is_err(), "expecting a timeout"); -684 info!("-- timeout happened"); -685 -686 // Wait long enough. -687 info!("-- sleep"); -688 tokio::time::sleep(Duration::from_secs(1)).await; -689 -690 // Frame arrives. -691 let recv_frame = tokio::time::timeout(Duration::from_millis(500), stream.next()) -692 .await -693 .expect("timeout") -694 .expect("option") -695 .expect("ok"); -696 assert_eq!(recv_frame, frame); -697 -698 Ok(()) -699 } -700}

\ No newline at end of file +155 sender.send(reason).ok(); +156 } +157 } +158 +159 pub(super) fn try_send_packet( +160 &self, +161 src: EndpointId, +162 data: Datagrams, +163 ) -> Result<(), TrySendError<Packet>> { +164 self.send_queue.try_send(Packet { src, data }) +165 } +166 +167 pub(super) fn try_send_peer_gone( +168 &self, +169 key: EndpointId, +170 ) -> Result<(), TrySendError<EndpointId>> { +171 self.peer_gone.try_send(key) +172 } +173} +174 +175/// Error when handling an incoming frame from a client. +176#[stack_error(derive, add_meta, from_sources)] +177#[allow(missing_docs)] +178#[non_exhaustive] +179pub enum HandleFrameError { +180 #[error(transparent)] +181 ForwardPacket { source: ForwardPacketError }, +182 #[error("Stream terminated")] +183 StreamTerminated {}, +184 #[error(transparent)] +185 Recv { source: RelayRecvError }, +186 #[error(transparent)] +187 Send { source: WriteFrameError }, +188} +189 +190/// Error when writing a frame to a client. +191#[stack_error(derive, add_meta, from_sources)] +192#[allow(missing_docs)] +193#[non_exhaustive] +194pub enum WriteFrameError { +195 #[error(transparent)] +196 Stream { source: RelaySendError }, +197 #[error(transparent)] +198 Timeout { +199 #[error(std_err)] +200 source: tokio::time::error::Elapsed, +201 }, +202} +203 +204/// Run error +205#[stack_error(derive, add_meta)] +206#[allow(missing_docs)] +207#[non_exhaustive] +208pub enum RunError { +209 #[error(transparent)] +210 ForwardPacket { +211 #[error(from)] +212 source: ForwardPacketError, +213 }, +214 #[error("Flush")] +215 CloseFlush {}, +216 #[error(transparent)] +217 HandleFrame { +218 #[error(from)] +219 source: HandleFrameError, +220 }, +221 #[error("Server.send_queue dropped")] +222 SendQueuePacketDrop {}, +223 #[error("Failed to send packet")] +224 PacketSend { source: WriteFrameError }, +225 #[error("Server.endpoint_gone dropped")] +226 EndpointGoneDrop {}, +227 #[error("Writing frame failed")] +228 WriteFrame { source: WriteFrameError }, +229 #[error("Tick flush")] +230 TickFlush {}, +231} +232 +233/// Manages all the reads and writes to this client. It periodically sends a `KEEP_ALIVE` +234/// message to the client to keep the connection alive. +235/// +236/// Call `run` to manage the input and output to and from the connection and the server. +237/// Once it hits its first write error or error receiving off a channel, +238/// it errors on return. +239/// If writes do not complete in the given `timeout`, it will also error. +240/// +241/// On the "write" side, the [`Actor`] can send the client: +242/// - a KEEP_ALIVE frame +243/// - a PEER_GONE frame to inform the client that a peer they have previously sent messages to +244/// is gone from the network +245/// - packets from other peers +246/// +247/// On the "read" side, it can: +248/// - receive a ping and write a pong back +249/// to speak to the endpoint ID associated with that client. +250#[derive(Debug)] +251struct Actor<S> { +252 /// IO Stream to talk to the client +253 stream: RelayedStream<S>, +254 /// Maximum time we wait to complete a write to the client +255 timeout: Duration, +256 /// Packets queued to send to the client +257 send_queue: mpsc::Receiver<Packet>, +258 /// Notify the client that a previous sender has disconnected +259 endpoint_gone: mpsc::Receiver<EndpointId>, +260 /// [`EndpointId`] of this client +261 endpoint_id: EndpointId, +262 /// Connection identifier. +263 connection_id: u64, +264 /// Reference to the other connected clients. +265 clients: Clients, +266 /// Statistics about the connected clients +267 client_counter: ClientCounter, +268 ping_tracker: PingTracker, +269 metrics: Arc<Metrics>, +270} +271 +272impl<S> Actor<S> +273where +274 S: BytesStreamSink, +275{ +276 async fn run(mut self, done_r: oneshot::Receiver<Option<CloseReason>>) { +277 // Note the accept and disconnects metrics must be in a pair. Technically the +278 // connection is accepted long before this in the HTTP server, but it is clearer to +279 // handle the metric here. +280 self.metrics.accepts.inc(); +281 if self.client_counter.update(self.endpoint_id) { +282 self.metrics.unique_client_keys.inc(); +283 } +284 match self.run_inner(done_r).await { +285 Err(e) => { +286 warn!("actor errored {e:#}, exiting"); +287 } +288 Ok(()) => { +289 debug!("actor finished, exiting"); +290 } +291 } +292 +293 self.clients +294 .unregister(self.connection_id, self.endpoint_id); +295 self.metrics.disconnects.inc(); +296 } +297 +298 async fn run_inner( +299 &mut self, +300 mut done_r: oneshot::Receiver<Option<CloseReason>>, +301 ) -> Result<(), RunError> { +302 // Add some jitter to ping pong interactions, to avoid all pings being sent at the same time +303 let next_interval = || { +304 let random_secs = rand::rng().random_range(1..=5); +305 Duration::from_secs(random_secs) + PING_INTERVAL +306 }; +307 +308 let mut ping_interval = tokio::time::interval(next_interval()); +309 // ticks immediately +310 ping_interval.set_missed_tick_behavior(MissedTickBehavior::Delay); +311 ping_interval.tick().await; +312 +313 loop { +314 tokio::select! { +315 biased; +316 +317 reason = &mut done_r => { +318 trace!("actor loop cancelled, exiting (reason: {reason:?})"); +319 if let Ok(Some(reason)) = reason { +320 self.write_frame(RelayToClientMsg::Close { reason }).await +321 .map_err(|err| e!(RunError::WriteFrame, err))?; +322 } +323 self.stream +324 .flush() +325 .await +326 .map_err(|_| e!(RunError::CloseFlush))?; +327 break; +328 } +329 maybe_frame = self.stream.next() => { +330 self +331 .handle_frame(maybe_frame) +332 .await?; +333 // reset the ping interval, we just received a message +334 ping_interval.reset(); +335 } +336 // Second priority, sending regular packets +337 packet = self.send_queue.recv() => { +338 let packet = packet.ok_or_else(|| e!(RunError::SendQueuePacketDrop))?; +339 self.send_packet(packet) +340 .await +341 .map_err(|err| e!(RunError::PacketSend, err))?; +342 } +343 // Last priority, sending left endpoints +344 endpoint_id = self.endpoint_gone.recv() => { +345 let endpoint_id = endpoint_id.ok_or_else(|| e!(RunError::EndpointGoneDrop))?; +346 trace!("endpoint_id gone: {:?}", endpoint_id); +347 self.write_frame(RelayToClientMsg::EndpointGone(endpoint_id)) +348 .await +349 .map_err(|err| e!(RunError::WriteFrame, err))?; +350 } +351 _ = self.ping_tracker.timeout() => { +352 trace!("pong timed out"); +353 break; +354 } +355 _ = ping_interval.tick() => { +356 trace!("keep alive ping"); +357 // new interval +358 ping_interval.reset_after(next_interval()); +359 let data = self.ping_tracker.new_ping(); +360 self.write_frame(RelayToClientMsg::Ping(data)) +361 .await +362 .map_err(|err| e!(RunError::WriteFrame, err))?; +363 } +364 } +365 +366 self.stream +367 .flush() +368 .await +369 .map_err(|_| e!(RunError::TickFlush))?; +370 } +371 Ok(()) +372 } +373 +374 /// Writes the given frame to the connection. +375 /// +376 /// Errors if the send does not happen within the `timeout` duration +377 async fn write_frame(&mut self, frame: RelayToClientMsg) -> Result<(), WriteFrameError> { +378 tokio::time::timeout(self.timeout, self.stream.send(frame)).await??; +379 Ok(()) +380 } +381 +382 /// Writes contents to the client in a `RECV_PACKET` frame. +383 /// +384 /// Errors if the send does not happen within the `timeout` duration +385 /// Does not flush. +386 async fn send_raw(&mut self, packet: Packet) -> Result<(), WriteFrameError> { +387 let remote_endpoint_id = packet.src; +388 let datagrams = packet.data; +389 +390 if let Ok(len) = datagrams.contents.len().try_into() { +391 self.metrics.bytes_sent.inc_by(len); +392 } +393 self.write_frame(RelayToClientMsg::Datagrams { +394 remote_endpoint_id, +395 datagrams, +396 }) +397 .await +398 } +399 +400 async fn send_packet(&mut self, packet: Packet) -> Result<(), WriteFrameError> { +401 trace!("send packet"); +402 match self.send_raw(packet).await { +403 Ok(()) => { +404 self.metrics.send_packets_sent.inc(); +405 Ok(()) +406 } +407 Err(err) => { +408 self.metrics.send_packets_dropped.inc(); +409 Err(err) +410 } +411 } +412 } +413 +414 /// Handles frame read results. +415 async fn handle_frame( +416 &mut self, +417 maybe_frame: Option<Result<ClientToRelayMsg, RelayRecvError>>, +418 ) -> Result<(), HandleFrameError> { +419 trace!(?maybe_frame, "handle incoming frame"); +420 let frame = match maybe_frame { +421 Some(frame) => frame?, +422 None => return Err(e!(HandleFrameError::StreamTerminated)), +423 }; +424 +425 match frame { +426 ClientToRelayMsg::Datagrams { +427 dst_endpoint_id: dst_key, +428 datagrams, +429 } => { +430 let packet_len = datagrams.contents.len(); +431 if let Err(err @ ForwardPacketError { .. }) = +432 self.handle_frame_send_packet(dst_key, datagrams) +433 { +434 warn!("failed to handle send packet frame: {err:#}"); +435 } +436 self.metrics.bytes_recv.inc_by(packet_len as u64); +437 } +438 ClientToRelayMsg::Ping(data) => { +439 self.metrics.got_ping.inc(); +440 // TODO: add rate limiter +441 self.write_frame(RelayToClientMsg::Pong(data)).await?; +442 self.metrics.sent_pong.inc(); +443 } +444 ClientToRelayMsg::Pong(data) => { +445 self.ping_tracker.pong_received(data); +446 } +447 } +448 Ok(()) +449 } +450 +451 fn handle_frame_send_packet( +452 &self, +453 dst: EndpointId, +454 data: Datagrams, +455 ) -> Result<(), ForwardPacketError> { +456 self.metrics.send_packets_recv.inc(); +457 self.clients +458 .send_packet(dst, data, self.endpoint_id, &self.metrics)?; +459 +460 Ok(()) +461 } +462} +463 +464#[derive(Debug)] +465pub(crate) enum SendError { +466 Full, +467 Closed, +468} +469 +470/// Error returned when forwarding a packet to a client fails. +471/// +472/// This error occurs when the relay server cannot deliver a packet to its intended +473/// recipient, typically due to the client's send queue being full or the client +474/// disconnecting. +475#[stack_error(derive, add_meta)] +476#[error("failed to forward packet: {reason:?}")] +477pub struct ForwardPacketError { +478 reason: SendError, +479} +480 +481/// Tracks how many unique endpoints have been seen during the last day. +482#[derive(Debug)] +483struct ClientCounter { +484 clients: HashSet<EndpointId>, +485 last_clear_date: Date, +486} +487 +488impl Default for ClientCounter { +489 fn default() -> Self { +490 Self { +491 clients: HashSet::new(), +492 last_clear_date: OffsetDateTime::now_utc().date(), +493 } +494 } +495} +496 +497impl ClientCounter { +498 fn check_and_clear(&mut self) { +499 let today = OffsetDateTime::now_utc().date(); +500 if today != self.last_clear_date { +501 self.clients.clear(); +502 self.last_clear_date = today; +503 } +504 } +505 +506 /// Marks this endpoint as seen, returns whether it is new today or not. +507 fn update(&mut self, client: EndpointId) -> bool { +508 self.check_and_clear(); +509 self.clients.insert(client) +510 } +511} +512 +513#[cfg(test)] +514mod tests { +515 use iroh_base::SecretKey; +516 use n0_error::{Result, StdResultExt, bail_any}; +517 use n0_future::Stream; +518 use n0_tracing_test::traced_test; +519 use rand::SeedableRng; +520 use tracing::info; +521 +522 use super::*; +523 use crate::{client::conn::Conn, protos::common::FrameType}; +524 +525 async fn recv_frame< +526 E: std::error::Error + Sync + Send + 'static, +527 S: Stream<Item = Result<RelayToClientMsg, E>> + Unpin, +528 >( +529 frame_type: FrameType, +530 mut stream: S, +531 ) -> Result<RelayToClientMsg> { +532 match stream.next().await { +533 Some(Ok(frame)) => { +534 if frame_type != frame.typ() { +535 bail_any!( +536 "Unexpected frame, got {:?}, but expected {:?}", +537 frame.typ(), +538 frame_type +539 ); +540 } +541 Ok(frame) +542 } +543 Some(Err(err)) => Err(err).anyerr(), +544 None => bail_any!("Unexpected EOF, expected frame {frame_type:?}"), +545 } +546 } +547 +548 #[tokio::test] +549 #[traced_test] +550 async fn test_client_actor_basic() -> Result { +551 let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64); +552 +553 let (send_queue_s, send_queue_r) = mpsc::channel(10); +554 let (peer_gone_s, peer_gone_r) = mpsc::channel(10); +555 let (done_s, done_r) = oneshot::channel(); +556 +557 let endpoint_id = SecretKey::generate(&mut rng).public(); +558 let (io, io_rw) = tokio::io::duplex(1024); +559 let mut io_rw = Conn::test(io_rw); +560 let stream = RelayedStream::test(io); +561 +562 let clients = Clients::default(); +563 let metrics = Arc::new(Metrics::default()); +564 let actor = Actor { +565 stream, +566 timeout: Duration::from_secs(1), +567 send_queue: send_queue_r, +568 endpoint_gone: peer_gone_r, +569 connection_id: 0, +570 endpoint_id, +571 clients: clients.clone(), +572 client_counter: ClientCounter::default(), +573 ping_tracker: PingTracker::default(), +574 metrics, +575 }; +576 +577 let handle = tokio::task::spawn(async move { actor.run(done_r).await }); +578 +579 // Write tests +580 println!("-- write"); +581 let data = b"hello world!"; +582 +583 // send packet +584 println!(" send packet"); +585 let packet = Packet { +586 src: endpoint_id, +587 data: Datagrams::from(&data[..]), +588 }; +589 send_queue_s +590 .send(packet.clone()) +591 .await +592 .std_context("send")?; +593 let frame = recv_frame(FrameType::RelayToClientDatagram, &mut io_rw) +594 .await +595 .anyerr()?; +596 assert_eq!( +597 frame, +598 RelayToClientMsg::Datagrams { +599 remote_endpoint_id: endpoint_id, +600 datagrams: data.to_vec().into() +601 } +602 ); +603 +604 // send peer_gone +605 println!("send peer gone"); +606 peer_gone_s.send(endpoint_id).await.std_context("send")?; +607 let frame = recv_frame(FrameType::EndpointGone, &mut io_rw) +608 .await +609 .anyerr()?; +610 assert_eq!(frame, RelayToClientMsg::EndpointGone(endpoint_id)); +611 +612 // Read tests +613 println!("--read"); +614 +615 // send ping, expect pong +616 let data = b"pingpong"; +617 io_rw.send(ClientToRelayMsg::Ping(*data)).await?; +618 +619 // recv pong +620 println!(" recv pong"); +621 let frame = recv_frame(FrameType::Pong, &mut io_rw).await?; +622 assert_eq!(frame, RelayToClientMsg::Pong(*data)); +623 +624 let target = SecretKey::generate(&mut rng).public(); +625 +626 // send packet +627 println!(" send packet"); +628 let data = b"hello world!"; +629 io_rw +630 .send(ClientToRelayMsg::Datagrams { +631 dst_endpoint_id: target, +632 datagrams: Datagrams::from(data), +633 }) +634 .await +635 .std_context("send")?; +636 +637 done_s.send(None).ok(); +638 handle.await.std_context("join")?; +639 Ok(()) +640 } +641 +642 #[tokio::test(start_paused = true)] +643 #[traced_test] +644 async fn test_rate_limit() -> Result { +645 const LIMIT: u32 = 50; +646 const MAX_FRAMES: u32 = 100; +647 +648 let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64); +649 +650 // Build the rate limited stream. +651 let (io_read, io_write) = tokio::io::duplex((LIMIT * MAX_FRAMES) as _); +652 let mut frame_writer = Conn::test(io_write); +653 // Rate limiter allowing LIMIT bytes/s +654 let mut stream = RelayedStream::test_limited(io_read, LIMIT / 10, LIMIT)?; +655 +656 // Prepare a frame to send, assert its size. +657 let data = Datagrams::from(b"hello world!!!!!"); +658 let target = SecretKey::generate(&mut rng).public(); +659 let frame = ClientToRelayMsg::Datagrams { +660 dst_endpoint_id: target, +661 datagrams: data.clone(), +662 }; +663 let frame_len = frame.to_bytes().len(); +664 assert_eq!(frame_len, LIMIT as usize); +665 +666 // Send a frame, it should arrive. +667 info!("-- send packet"); +668 frame_writer.send(frame.clone()).await.std_context("send")?; +669 frame_writer.flush().await.std_context("flush")?; +670 let recv_frame = tokio::time::timeout(Duration::from_millis(500), stream.next()) +671 .await +672 .expect("timeout") +673 .expect("option") +674 .expect("ok"); +675 assert_eq!(recv_frame, frame); +676 +677 // Next frame does not arrive. +678 info!("-- send packet"); +679 frame_writer.send(frame.clone()).await.std_context("send")?; +680 frame_writer.flush().await.std_context("flush")?; +681 let res = tokio::time::timeout(Duration::from_millis(100), stream.next()).await; +682 assert!(res.is_err(), "expecting a timeout"); +683 info!("-- timeout happened"); +684 +685 // Wait long enough. +686 info!("-- sleep"); +687 tokio::time::sleep(Duration::from_secs(1)).await; +688 +689 // Frame arrives. +690 let recv_frame = tokio::time::timeout(Duration::from_millis(500), stream.next()) +691 .await +692 .expect("timeout") +693 .expect("option") +694 .expect("ok"); +695 assert_eq!(recv_frame, frame); +696 +697 Ok(()) +698 } +699} \ No newline at end of file