pub struct Peer<S: Socket>(/* private fields */);
Expand description
A peer, associated with a Host
, which may or may not be connected.
To check on the connectivity of a peer, see Peer::state
.
Implementations§
Source§impl<S: Socket> Peer<S>
impl<S: Socket> Peer<S>
Sourcepub fn ping(&mut self)
pub fn ping(&mut self)
Sends a ping request to a peer.
Ping requests factor into the mean round trip time as acquired by
Peer::round_trip_time
. ENet automatically pings all connected peers at regular
intervals, however, this function may be called to ensure more frequent ping requests.
The ping interval can be changed with Self::set_ping_interval
.
Sourcepub fn send(
&mut self,
channel_id: u8,
packet: &Packet,
) -> Result<(), PeerSendError>
pub fn send( &mut self, channel_id: u8, packet: &Packet, ) -> Result<(), PeerSendError>
Queues a packet to be sent to this peer on the specified channel.
§Errors
May return any of the PeerSendError
variants on failure.
Sourcepub fn disconnect(&mut self, data: u32)
pub fn disconnect(&mut self, data: u32)
Request a disconnection from a peer.
An Event::Disconnect
event will be generated by
Host::service
once the disconnection is complete.
Sourcepub fn disconnect_now(&mut self, data: u32)
pub fn disconnect_now(&mut self, data: u32)
Force an immediate disconnection from a peer.
No Event::Disconnect
event will be generated. The foreign
peer is not guaranteed to receive the disconnect notification, and is reset immediately upon
return from this function.
Sourcepub fn disconnect_later(&mut self, data: u32)
pub fn disconnect_later(&mut self, data: u32)
Request a disconnection from a peer, but only after all queued outgoing packets are sent.
An Event::Disconnect
event will be generated by
Host::service
once the disconnection is complete.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forcefully disconnects a peer.
The foreign host represented by the peer is not notified of the disconnection and will timeout on its connection to the local host.
Sourcepub fn set_timeout(&mut self, limit: u32, minimum: u32, maximum: u32)
pub fn set_timeout(&mut self, limit: u32, minimum: u32, maximum: u32)
Timeout parameters to control how and when a peer will timeout from a failure to acknowledge reliable traffic.
Timeout values use an exponential backoff mechanism, where if a reliable packet is not acknowledge within some multiple of the average RTT plus a variance tolerance, the timeout will be doubled until it reaches a set limit. If the timeout is thus at this limit and reliable packets have been sent but not acknowledged within a certain minimum time period, the peer will be disconnected. Alternatively, if reliable packets have been sent but not acknowledged for a certain maximum time period, the peer will be disconnected regardless of the current timeout limit value.
limit
- the timeout limit; defaults toPEER_TIMEOUT_LIMIT
if 0minimum
- the timeout minimum; defaults toPEER_TIMEOUT_MINIMUM
if 0maximum
- the timeout maximum; defaults toPEER_TIMEOUT_MAXIMUM
if 0
Sourcepub fn set_ping_interval(&mut self, ping_interval: u32)
pub fn set_ping_interval(&mut self, ping_interval: u32)
Sets the interval at which pings will be sent to a peer in milliseconds.
Pings are used both to monitor the liveness of the connection and also to dynamically adjust the throttle during periods of low traffic so that the throttle has reasonable responsiveness during traffic spikes.
See Peer::ping
.
Sourcepub fn set_throttle(
&mut self,
interval: u32,
acceleration: u32,
deceleration: u32,
)
pub fn set_throttle( &mut self, interval: u32, acceleration: u32, deceleration: u32, )
Configure the peer’s throttle parameters.
Unreliable packets are dropped by ENet in response to the varying conditions of the
Internet connection to the peer. The throttle represents a probability that an unreliable
packet should not be dropped and thus sent by ENet to the peer. The lowest mean round trip
time from the sending of a reliable packet to the receipt of its acknowledgement is measured
over an amount of time specified by the interval parameter in milliseconds. If a measured
round trip time happens to be significantly less than the mean round trip time measured over
the interval, then the throttle probability is increased to allow more traffic by an amount
specified in the acceleration parameter, which is a ratio to the
PEER_PACKET_THROTTLE_SCALE
constant. If a measured round trip time happens to be significantly greater than the mean
round trip time measured over the interval, then the throttle probability is decreased to
limit traffic by an amount specified in the deceleration parameter, which is a ratio to the
ENET_PEER_PACKET_THROTTLE_SCALE
When
the throttle has a value of
PEER_PACKET_THROTTLE_SCALE
When
no unreliable packets are dropped by ENet, and so 100% of all unreliable packets will be
sent. When the throttle has a value of 0, all unreliable packets are dropped by ENet, and so
0% of all unreliable packets will be sent. Intermediate values for the throttle represent
intermediate probabilities between 0% and 100% of unreliable packets being sent. The
bandwidth limits of the local and foreign hosts are taken into account to determine a
sensible limit for the throttle probability above which it should not raise even in the best
of conditions.
interval
- interval, in milliseconds, over which to measure lowest mean RTT; the default value isPEER_PACKET_THROTTLE_INTERVAL
acceleration
- rate at which to increase the throttle probability as mean RTT declinesdeceleration
- rate at which to decrease the throttle probability as mean RTT increases
Sourcepub fn set_mtu(&mut self, mtu: u16) -> Result<(), BadParameter>
pub fn set_mtu(&mut self, mtu: u16) -> Result<(), BadParameter>
Set the maximum transmission unit for this peer. See
Host::set_mtu
.
§Errors
Returns BadParameter
if mtu
is greater than PROTOCOL_MAXIMUM_MTU
or less than
PROTOCOL_MINIMUM_MTU
.
Sourcepub fn connected(&self) -> bool
pub fn connected(&self) -> bool
Check if this peer’s state is PeerState::Connected
.
Sourcepub fn channel_count(&self) -> usize
pub fn channel_count(&self) -> usize
Number of channels allocated for communication with peer.
Sourcepub fn incoming_bandwidth(&self) -> u32
pub fn incoming_bandwidth(&self) -> u32
Downstream bandwidth of the client in bytes/second.
Sourcepub fn outgoing_bandwidth(&self) -> u32
pub fn outgoing_bandwidth(&self) -> u32
Upstream bandwidth of the client in bytes/second.
Sourcepub fn incoming_data_total(&self) -> u32
pub fn incoming_data_total(&self) -> u32
Total amount of downstream data received.
Sourcepub fn outgoing_data_total(&self) -> u32
pub fn outgoing_data_total(&self) -> u32
Total amount of upstream data sent.
Sourcepub fn packets_sent(&self) -> u32
pub fn packets_sent(&self) -> u32
Total number of packets sent.
Sourcepub fn packets_lost(&self) -> u32
pub fn packets_lost(&self) -> u32
Total number of packets lost.
Sourcepub fn packet_loss(&self) -> u32
pub fn packet_loss(&self) -> u32
Mean packet loss of reliable packets as a ratio with respect to the constant
PEER_PACKET_LOSS_SCALE
.
Sourcepub fn packet_loss_variance(&self) -> u32
pub fn packet_loss_variance(&self) -> u32
Variance of the mean packet loss.
Sourcepub fn ping_interval(&self) -> Duration
pub fn ping_interval(&self) -> Duration
Ping interval. See Peer::set_ping_interval
.
Sourcepub fn round_trip_time(&self) -> Duration
pub fn round_trip_time(&self) -> Duration
Mean round trip time (RTT), between sending a reliable packet and receiving its acknowledgement.
Sourcepub fn round_trip_time_variance(&self) -> Duration
pub fn round_trip_time_variance(&self) -> Duration
Round trip time (RTT) variance. See Peer::round_trip_time
.