Skip to content

Commit

Permalink
Introduce EndpointStats
Browse files Browse the repository at this point in the history
  • Loading branch information
ryleung-solana authored Jul 28, 2024
1 parent 9dbaff0 commit a385630
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,12 @@ impl Endpoint {
self.connections.len()
}

/// Counter for the number of bytes currently used
/// in the buffers for Initial and 0-RTT messages for pending incoming connections
pub fn incoming_buffer_bytes(&self) -> u64 {
self.all_incoming_buffers_total_bytes
}

#[cfg(test)]
pub(crate) fn known_connections(&self) -> usize {
let x = self.connections.len();
Expand Down
46 changes: 45 additions & 1 deletion quinn/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ impl Endpoint {
)
}

/// Returns relevant stats from this Endpoint
pub fn stats(&self) -> EndpointStats {
let state = self.inner.state.lock().unwrap();
EndpointStats {
open_connections: state.inner.open_connections() as u64,
accepted_handshakes: state.accepted_handshakes,
outgoing_handshakes: state.outgoing_handshakes,
refused_handshakes: state.refused_handshakes,
ignored_handshakes: state.ignored_handshakes,
incoming_buffer_bytes: state.inner.incoming_buffer_bytes(),
}
}

/// Helper to construct an endpoint for use with both incoming and outgoing connections
///
/// Platform defaults for dual-stack sockets vary. For example, any socket bound to a wildcard
Expand Down Expand Up @@ -219,6 +232,7 @@ impl Endpoint {
.connect(self.runtime.now(), config, addr, server_name)?;

let socket = endpoint.socket.clone();
endpoint.outgoing_handshakes += 1;
Ok(endpoint
.recv_state
.connections
Expand Down Expand Up @@ -319,6 +333,24 @@ impl Endpoint {
}
}

/// Statistics on [Endpoint] activity
#[non_exhaustive]
#[derive(Debug, Default, Copy, Clone)]
pub struct EndpointStats {
/// Number of open connecctions on this [Endpoint]
pub open_connections: u64,
/// Cummulative number of Quic handshakes accepted by this [Endpoint]
pub accepted_handshakes: u64,
/// Cummulative number of Quic handshakees sent from this [Endpoint]
pub outgoing_handshakes: u64,
/// Cummulative number of Quic handshakes refused on this [Endpoint]
pub refused_handshakes: u64,
/// Cummulative number of Quic handshakes ignored on this [Endpoint]
pub ignored_handshakes: u64,
/// Number of bytes used in all incoming buffers on this [Endpoint]
pub incoming_buffer_bytes: u64,
}

/// A future that drives IO on an endpoint
///
/// This task functions as the switch point between the UDP socket object and the
Expand Down Expand Up @@ -398,6 +430,7 @@ impl EndpointInner {
.accept(incoming, now, &mut response_buffer, server_config)
{
Ok((handle, conn)) => {
state.accepted_handshakes += 1;
let socket = state.socket.clone();
let runtime = state.runtime.clone();
Ok(state
Expand All @@ -416,6 +449,7 @@ impl EndpointInner {

pub(crate) fn refuse(&self, incoming: proto::Incoming) {
let mut state = self.state.lock().unwrap();
state.refused_handshakes += 1;
let mut response_buffer = Vec::new();
let transmit = state.inner.refuse(incoming, &mut response_buffer);
respond(transmit, &response_buffer, &*state.socket);
Expand All @@ -430,7 +464,9 @@ impl EndpointInner {
}

pub(crate) fn ignore(&self, incoming: proto::Incoming) {
self.state.lock().unwrap().inner.ignore(incoming);
let mut state = self.state.lock().unwrap();
state.ignored_handshakes += 1;
state.inner.ignore(incoming);
}
}

Expand All @@ -449,6 +485,10 @@ pub(crate) struct State {
ref_count: usize,
driver_lost: bool,
runtime: Arc<dyn Runtime>,
accepted_handshakes: u64,
outgoing_handshakes: u64,
refused_handshakes: u64,
ignored_handshakes: u64,
}

#[derive(Debug)]
Expand Down Expand Up @@ -666,6 +706,10 @@ impl EndpointRef {
driver_lost: false,
recv_state,
runtime,
accepted_handshakes: 0,
outgoing_handshakes: 0,
refused_handshakes: 0,
ignored_handshakes: 0,
}),
}))
}
Expand Down

0 comments on commit a385630

Please sign in to comment.