Struct cobalt::Connection [] [src]

pub struct Connection<R: RateLimiter, M: PacketModifier> { /* fields omitted */ }

Implementation of a reliable, virtual socket connection.

Methods

impl<R: RateLimiter, M: PacketModifier> Connection<R, M>
[src]

Creates a new Virtual Connection over the given SocketAddr.

Examples

use std::net::SocketAddr;
use cobalt::{
    BinaryRateLimiter,
    Connection, ConnectionState, Config,
    NoopPacketModifier, PacketModifier, RateLimiter
};

let config = Config::default();
let local_address: SocketAddr = "127.0.0.1:0".parse().unwrap();
let peer_address: SocketAddr = "255.0.0.1:0".parse().unwrap();
let limiter = BinaryRateLimiter::new(config);
let modifier = NoopPacketModifier::new(config);
let conn = Connection::new(config, local_address, peer_address, limiter, modifier);

assert!(conn.state() == ConnectionState::Connecting);
assert_eq!(conn.open(), true);

Extracts a ConnectionID from packet with a valid protocol header.

Examples

use cobalt::{
    BinaryRateLimiter,
    Connection, ConnectionID, Config,
    NoopPacketModifier
};

let config = Config {
    protocol_header: [11, 22, 33, 44],
    ..Config::default()
};

let packet = [
    11, 22, 33, 44,
     1,  2,  3,  4,
     0,
     0,
     0,  0, 0,  0
];

let conn_id = Connection::<BinaryRateLimiter, NoopPacketModifier>::id_from_packet(&config, &packet);

assert!(conn_id == Some(ConnectionID(16909060)));

Returns whether the connection is currently accepting any incoming packets.

Returns whether the connection is currently congested and should be sending less packets per second in order to resolve the congestion.

Returns the id of the connection.

Overrides the id of the connection.

Returns the current state of the connection.

Returns the average roundtrip time for the connection.

Returns the percent of packets that were sent and never acknowledged over the total number of packets that have been send across the connection.

Returns the socket address for the local end of this connection.

Returns the socket address for the remote end of this connection.

Sets the socket address of the remote peer of this connection.

Overrides the connection's existing configuration.

Sends a message of the specified kind along with its payload over the connection.

How exactly the message is send and whether it is guaranteed to be delivered eventually is determined by its MessageKind.

Returns a drain iterator over all queued events from this connection.

Receives a incoming UDP packet.

Send a new outgoing UDP packet.

Resets the connection for re-use with another address.

Closes the connection, no further packets will be received or send.

Trait Implementations

impl<R: Debug + RateLimiter, M: Debug + PacketModifier> Debug for Connection<R, M>
[src]

Formats the value using the given formatter.