Struct qp2p::Connection
source · pub struct Connection { /* private fields */ }
Expand description
The sending API for a connection.
Implementations§
source§impl Connection
impl Connection
sourcepub fn close_reason(&self) -> Option<ConnectionError>
pub fn close_reason(&self) -> Option<ConnectionError>
Returns Some(...)
if the connection is closed.
sourcepub fn id(&self) -> String
pub fn id(&self) -> String
A stable identifier for the connection.
This ID will not change for the lifetime of the connection to a given ip.
The ID pulls the internal conneciton id and concats with the SocketAddr of the peer. So this should be unique per peer (without IP spoofing).
sourcepub fn remote_address(&self) -> SocketAddr
pub fn remote_address(&self) -> SocketAddr
The address of the remote peer.
sourcepub async fn send(&self, user_msg_bytes: UsrMsgBytes) -> Result<(), SendError>
pub async fn send(&self, user_msg_bytes: UsrMsgBytes) -> Result<(), SendError>
Send a message to the peer.
The message will be sent on a unidirectional QUIC stream, meaning the application is responsible for correlating any anticipated responses from incoming streams.
The priority will be 0
.
sourcepub async fn open_uni(&self) -> Result<SendStream, ConnectionError>
pub async fn open_uni(&self) -> Result<SendStream, ConnectionError>
Open a unidirection stream to the peer.
Messages sent over the stream will arrive at the peer in the order they were sent.
sourcepub async fn open_bi(&self) -> Result<(SendStream, RecvStream), ConnectionError>
pub async fn open_bi(&self) -> Result<(SendStream, RecvStream), ConnectionError>
Open a bidirectional stream to the peer.
Bidirectional streams allow messages to be sent in both directions. This can be useful to automatically correlate response messages, for example.
Messages sent over the stream will arrive at the peer in the order they were sent.
sourcepub fn close(&self, reason: Option<String>)
pub fn close(&self, reason: Option<String>)
Close the connection immediately.
This is not a graceful close - pending operations will fail immediately with
ConnectionError::Closed
(
[Close::Local
])
, and data on unfinished streams is not
guaranteed to be delivered.