pub struct HqEndpoint { /* private fields */ }
Expand description
A harlequinn client or server endpoint.
Implementations§
Source§impl HqEndpoint
impl HqEndpoint
Sourcepub fn new_client(protocol: &str) -> Self
pub fn new_client(protocol: &str) -> Self
Creates a new client endpoint.
Doesn’t listen for incoming connections, use connect
to start a connection to a server.
Sourcepub fn new_server(
protocol: &str,
socket_addr: SocketAddr,
certificate: Certificate,
private_key: PrivateKey,
) -> Self
pub fn new_server( protocol: &str, socket_addr: SocketAddr, certificate: Certificate, private_key: PrivateKey, ) -> Self
Creates a new server endpoint.
Listens for incoming connections.
Sourcepub fn connect<S: ToString>(
&mut self,
server_addr: SocketAddr,
server_name: S,
certificate: Certificate,
) -> PeerId
pub fn connect<S: ToString>( &mut self, server_addr: SocketAddr, server_name: S, certificate: Certificate, ) -> PeerId
Initiate a connection to a server endpoint.
Raises ConnectionFailed
on failure, and ConnectionRequested
on success.
Sourcepub fn disconnect(&mut self, peer_id: PeerId, reason: String)
pub fn disconnect(&mut self, peer_id: PeerId, reason: String)
Disconnects a peer, ending the connection.
reason
is not preserved intact, and will be mangled on the other side, but can be used to
provide human-readable reasons.
Sourcepub fn send_datagram(&mut self, peer_id: PeerId, bytes: Bytes)
pub fn send_datagram(&mut self, peer_id: PeerId, bytes: Bytes)
Send an unreliable datagram to a peer.
If the peer is taking too long to respond to messages, this may disconnect the peer.
Sourcepub fn send_message(
&mut self,
peer_id: PeerId,
bytes: Bytes,
order: MessageOrder,
)
pub fn send_message( &mut self, peer_id: PeerId, bytes: Bytes, order: MessageOrder, )
Send a reliable message over the main stream to a peer.
Messages with ordered
set to true will arrive in order at the peer.
If the peer is taking too long to respond to messages, this may disconnect the peer.
Sourcepub fn poll_events(&mut self, events: &mut Vec<EndpointEvent>)
pub fn poll_events(&mut self, events: &mut Vec<EndpointEvent>)
Polls for events and stores them in the given events buffer.
This must be called frequently, or the endpoint will run out of space in the events channel and stall.