Weave documentation
Rust referenceweave-swarm

weave-swarm · connection

Source declarations, signatures and documentation for connection.

Source: sigil/weave/network/weave-swarm/src/connection.rs. SHA-256: 0a7d4f06055b385ccef73838354bbe757b089abb0e7ec792354f421ec9a54c84.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

connection::PeerId

Peer identifier

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct PeerId(pub [u8; 32]);

Source line: 19.

connection::PeerId::from_public_key

Create from public key

pub fn from_public_key(key: &[u8; 32]) -> Self;

Source line: 23.

connection::PeerId::as_bytes

Get as bytes

pub fn as_bytes(&self) -> &[u8; 32];

Source line: 28.

connection::ConnectionState

Connection state

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionState {
    /// Handshake in progress
    Handshaking,
    /// Connected and ready
    Connected,
    /// Closing
    Closing,
    /// Closed
    Closed,
}

Source line: 41.

connection::ConnectionStats

Connection statistics

#[derive(Debug, Default)]
pub struct ConnectionStats {
/// Bytes sent

pub bytes_sent: AtomicU64,
/// Bytes received

pub bytes_received: AtomicU64,
/// Messages sent

pub messages_sent: AtomicU64,
/// Messages received

pub messages_received: AtomicU64,
/// Connection established time

pub connected_at: Option<Instant>
}

Source line: 54.

connection::ConnectionStats::duration

Get connection duration

pub fn duration(&self) -> Option<Duration>;

Source line: 69.

connection::ConnectionStats::record_sent

Record bytes sent

pub fn record_sent(&self, bytes: usize);

Source line: 74.

connection::ConnectionStats::record_received

Record bytes received

pub fn record_received(&self, bytes: usize);

Source line: 80.

connection::Connection

Active connection to a peer

pub struct Connection {
/// Peer identity

pub peer_id: PeerId,
// No DID in core
/// Encrypted stream

pub stream: Arc<Mutex<Box<dyn ConnectionStream>>>,
/// Topics shared with this peer

pub topics: DashSet<TopicId>,
/// Connection state

pub state: Arc<RwLock<ConnectionState>>,
/// Statistics

pub stats: Arc<ConnectionStats>,
/// Maximum allowed frame size in bytes

pub max_frame_size: usize
}

Source line: 88.

connection::Connection::new

Create new connection

pub fn new<S>(peer_id: PeerId, stream: S, max_frame_size: usize) -> Self
    where
        S: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static,;

Source line: 111.

connection::Connection::is_active

Check if connection is active

pub fn is_active(&self) -> bool;

Source line: 130.

connection::Connection::add_topic

Add a topic to this connection

pub fn add_topic(&self, topic: TopicId);

Source line: 138.

connection::Connection::remove_topic

Remove a topic from this connection

pub fn remove_topic(&self, topic: &TopicId) -> bool;

Source line: 143.

connection::Connection::has_topics

Check if connection has any topics

pub fn has_topics(&self) -> bool;

Source line: 148.

connection::Connection::send

Send data over the connection

pub async fn send(&self, data: &[u8]) -> Result<(), std::io::Error>;

Source line: 153.

connection::Connection::recv

Receive data from the connection

pub async fn recv(&self) -> Result<(ChannelId, Frame), std::io::Error>;

Source line: 168.

connection::ConnectionStream

Trait alias for connection streams

pub trait ConnectionStream: AsyncRead + AsyncWrite + Send + Sync + Unpin {}

Source line: 189.

On this page