pub struct Client { /* private fields */ }Expand description
An HTTP Relay client.
Cheaply clonable.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn recv(&mut self) -> Result<Option<Result<ReceivedMessage>>, Elapsed>
pub async fn recv(&mut self) -> Result<Option<Result<ReceivedMessage>>, Elapsed>
Reads a message from the server.
Any ReceivedMessage::Pong messages which are in response to a pong we sent will
wake up the future returned by Client::send_ping and not be returned here. Any
unknown ping messages are returned.
§Cancel safety
This method is cancel safe. If the future is dropped before completion it is guaranteed that no message is lost.
Sourcepub async fn connect(&mut self) -> Result<(), ClientError>
pub async fn connect(&mut self) -> Result<(), ClientError>
Connects to a relay Server.
If there already is a connection it is returned rather than re-establishing it.
Sourcepub fn local_addr(&self) -> Option<SocketAddr>
pub fn local_addr(&self) -> Option<SocketAddr>
Returns the local addr of the connection.
If there is no current underlying relay connection, None is returned.
Sourcepub async fn send_ping(
&mut self,
) -> Result<impl Future<Output = Result<Duration, ClientError>> + Send + Sync + 'static, ClientError>
pub async fn send_ping( &mut self, ) -> Result<impl Future<Output = Result<Duration, ClientError>> + Send + Sync + 'static, ClientError>
Send a ping to the server.
The returned future will complete once we get an expected pong.
Client::recv must be called for any reads to occur and thus to process the pong
reply.
This has a built-in timeout crate::defaults::timeouts::PING_TIMEOUT.
Sourcepub async fn send(
&mut self,
remote_node: NodeId,
payload: Bytes,
) -> Result<(), ClientError>
pub async fn send( &mut self, remote_node: NodeId, payload: Bytes, ) -> Result<(), ClientError>
Sends a packet for a remote node to the server.
If there is no underlying active relay connection, it creates one before attempting to send the message.
If there is an error sending the packet, it closes the underlying relay connection before returning.
Sourcepub async fn send_pong(&mut self, data: [u8; 8]) -> Result<(), ClientError>
pub async fn send_pong(&mut self, data: [u8; 8]) -> Result<(), ClientError>
Send a pong back to the server.
If there is no underlying active relay connection, it creates one before attempting to send the pong message.
If there is an error sending pong, it closes the underlying relay connection before returning.
Sourcepub async fn close(&mut self)
pub async fn close(&mut self)
Disconnects the http relay connection.
Closes the underlying relay connection. The next time the client takes some action
that requires a connection, it will call Client::connect.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if the underlying relay connection is established.