pub struct QuicNetworkManager { /* private fields */ }Implementations§
Source§impl QuicNetworkManager
impl QuicNetworkManager
pub fn new() -> QuicNetworkManager
Sourcepub fn set_send_hook(&self, hook: Arc<dyn Fn(&[u8], usize) + Sync + Send>)
pub fn set_send_hook(&self, hook: Arc<dyn Fn(&[u8], usize) + Sync + Send>)
Installs a callback for successfully queued outbound MPC messages.
pub fn with_node_id(node_id: usize) -> QuicNetworkManager
Sourcepub fn set_local_certificate_der(
&mut self,
cert_der: Vec<u8>,
key_der: Vec<u8>,
) -> Result<(), String>
pub fn set_local_certificate_der( &mut self, cert_der: Vec<u8>, key_der: Vec<u8>, ) -> Result<(), String>
Install stable local certificate material before listen/connect.
By default the manager generates an ephemeral self-signed certificate on first use. MPC runtimes that persist program-side keys should call this so the authenticated transport identity remains stable across runs.
Sourcepub fn public_key_from_certificate_der(
cert_der: &[u8],
) -> Result<NodePublicKey, String>
pub fn public_key_from_certificate_der( cert_der: &[u8], ) -> Result<NodePublicKey, String>
Extract the exact DER-encoded SubjectPublicKeyInfo from a certificate.
Sourcepub fn install_expected_server_public_keys<I>(
&mut self,
public_keys: I,
) -> Result<(), String>where
I: IntoIterator<Item = NodePublicKey>,
pub fn install_expected_server_public_keys<I>(
&mut self,
public_keys: I,
) -> Result<(), String>where
I: IntoIterator<Item = NodePublicKey>,
Install the immutable full-certificate roster used to admit MPC peers.
Sourcepub fn with_config(config: QuicNetworkConfig) -> QuicNetworkManager
pub fn with_config(config: QuicNetworkConfig) -> QuicNetworkManager
Creates a network manager with the given configuration.
§Panics
In debug builds, panics if the configuration is invalid (e.g., zero timeout,
NAT traversal enabled without STUN servers). Use try_with_config
for fallible construction.
Sourcepub fn try_with_config(
config: QuicNetworkConfig,
) -> Result<QuicNetworkManager, QuicConfigError>
pub fn try_with_config( config: QuicNetworkConfig, ) -> Result<QuicNetworkManager, QuicConfigError>
Creates a network manager with the given configuration, validating it first.
§Errors
Returns an error if the configuration is invalid. See QuicNetworkConfig::validate
for details on validation rules.
Sourcepub fn with_nat_traversal() -> QuicNetworkManager
pub fn with_nat_traversal() -> QuicNetworkManager
Creates a manager with NAT traversal enabled
Sourcepub fn set_expected_parties(&mut self, count: usize)
pub fn set_expected_parties(&mut self, count: usize)
Sets the expected number of parties for consensus gating.
Sourcepub fn set_expected_clients(&mut self, count: usize)
pub fn set_expected_clients(&mut self, count: usize)
Sets the expected number of clients for consensus gating.
Sourcepub fn set_allowed_certificate_public_keys(&mut self, keys: Vec<NodePublicKey>)
pub fn set_allowed_certificate_public_keys(&mut self, keys: Vec<NodePublicKey>)
Replaces the certificate public key allowlist.
Keys must be DER-encoded SubjectPublicKeyInfo bytes, matching
NodePublicKey. When the allowlist is empty, this check is disabled.
Sourcepub fn add_allowed_certificate_public_key(&mut self, key: NodePublicKey)
pub fn add_allowed_certificate_public_key(&mut self, key: NodePublicKey)
Adds a DER-encoded SubjectPublicKeyInfo key to the certificate public key allowlist.
Sourcepub fn clear_allowed_certificate_public_keys(&mut self)
pub fn clear_allowed_certificate_public_keys(&mut self)
Clears the certificate public key allowlist, disabling this check.
Sourcepub fn has_certificate_public_key_allowlist(&self) -> bool
pub fn has_certificate_public_key_allowlist(&self) -> bool
Returns true when certificate public key allowlisting is enabled.
pub fn add_node(&mut self, node: QuicNode)
pub fn add_node_with_party_id(&mut self, id: usize, address: SocketAddr)
Sourcepub async fn ensure_loopback_installed(&self)
pub async fn ensure_loopback_installed(&self)
Ensures loopback connection exists for self-delivery
Sourcepub async fn get_connection(
&self,
party_id: usize,
) -> Option<Arc<dyn PeerConnection>>
pub async fn get_connection( &self, party_id: usize, ) -> Option<Arc<dyn PeerConnection>>
Gets a server connection by party ID
Sourcepub fn try_acquire_execution_scanner_receive_owner(
&self,
) -> Option<ExecutionScannerReceiveOwnerLease>
pub fn try_acquire_execution_scanner_receive_owner( &self, ) -> Option<ExecutionScannerReceiveOwnerLease>
Claim this manager clone-set for one execution connection scanner.
Sourcepub fn get_all_server_connections(
&self,
) -> Vec<(usize, Arc<dyn PeerConnection>)>
pub fn get_all_server_connections( &self, ) -> Vec<(usize, Arc<dyn PeerConnection>)>
Gets all server connections (peer-to-peer MPC party connections)
Sourcepub fn get_all_client_connections(
&self,
) -> Vec<(usize, Arc<dyn PeerConnection>)>
pub fn get_all_client_connections( &self, ) -> Vec<(usize, Arc<dyn PeerConnection>)>
Gets all client connections (external clients connected to this server)
Sourcepub fn get_client_connection(
&self,
client_id: usize,
) -> Option<Arc<dyn PeerConnection>>
pub fn get_client_connection( &self, client_id: usize, ) -> Option<Arc<dyn PeerConnection>>
Gets a specific client connection by ID
Sourcepub async fn cleanup_dead_connections(&self)
pub async fn cleanup_dead_connections(&self)
Removes dead connections from both server and client connection maps
Sourcepub async fn is_party_connected(&self, party_id: usize) -> bool
pub async fn is_party_connected(&self, party_id: usize) -> bool
Checks connection health for a specific party
Sourcepub fn get_sorted_public_keys(&self) -> Vec<NodePublicKey>
pub fn get_sorted_public_keys(&self) -> Vec<NodePublicKey>
Returns a sorted list of all public keys (local + peers). The position in this list corresponds to the sender_id (0..N-1).
Sourcepub fn get_public_key_for_party_id(
&self,
party_id: usize,
) -> Option<NodePublicKey>
pub fn get_public_key_for_party_id( &self, party_id: usize, ) -> Option<NodePublicKey>
Gets the public key for a given party_id (0..N-1). Returns None if party_id is out of range.
Sourcepub fn get_party_id_for_public_key(&self, pk: &NodePublicKey) -> Option<usize>
pub fn get_party_id_for_public_key(&self, pk: &NodePublicKey) -> Option<usize>
Gets the party_id (0..N-1) for a given public key. Returns None if the public key is not known.
Sourcepub fn get_connection_by_party_id(
&self,
party_id: usize,
) -> Option<Arc<dyn PeerConnection>>
pub fn get_connection_by_party_id( &self, party_id: usize, ) -> Option<Arc<dyn PeerConnection>>
Gets the connection for a given party_id (0..N-1). For MPC protocols, use this instead of direct connection lookup.
Sourcepub fn compute_local_party_id(&self) -> Option<usize>
pub fn compute_local_party_id(&self) -> Option<usize>
Computes the local party ID by sorting all public keys (local + peers) lexicographically and returning this node’s position in the sorted list. Returns None if local_public_key is not set.
Sourcepub fn assign_party_ids(&self) -> usize
pub fn assign_party_ids(&self) -> usize
Assigns party IDs to all connections based on the sorted public key list. Call this once all peers are connected to finalize party IDs. Returns the number of connections that were assigned party IDs.
Sourcepub fn is_fully_connected(&self, expected_count: usize) -> bool
pub fn is_fully_connected(&self, expected_count: usize) -> bool
Checks if we have public keys from all expected parties.
Sourcepub fn get_public_key(&self) -> Option<&NodePublicKey>
pub fn get_public_key(&self) -> Option<&NodePublicKey>
Returns a reference to this node’s public key
Sourcepub fn local_public_key_bytes(&self) -> Option<Vec<u8>>
pub fn local_public_key_bytes(&self) -> Option<Vec<u8>>
Returns this node’s DER-encoded SubjectPublicKeyInfo bytes.
Sourcepub fn peer_public_key_bytes(&self, peer_id: usize) -> Option<Vec<u8>>
pub fn peer_public_key_bytes(&self, peer_id: usize) -> Option<Vec<u8>>
Returns a connected peer’s DER-encoded SubjectPublicKeyInfo bytes.
Sourcepub fn client_public_key_bytes(&self, client_id: usize) -> Option<Vec<u8>>
pub fn client_public_key_bytes(&self, client_id: usize) -> Option<Vec<u8>>
Returns a connected client’s DER-encoded SubjectPublicKeyInfo bytes.
Sourcepub fn client_public_key_bytes_by_transport_id(
&self,
client_id: usize,
) -> Option<Vec<u8>>
pub fn client_public_key_bytes_by_transport_id( &self, client_id: usize, ) -> Option<Vec<u8>>
Returns a connected client’s DER-encoded SubjectPublicKeyInfo bytes by TLS-derived transport ID without applying logical client-id mapping.
Sourcepub fn get_node_id(&self) -> usize
pub fn get_node_id(&self) -> usize
Returns the node_id (legacy ID, used as fallback)
Sourcepub fn local_derived_id(&self) -> usize
pub fn local_derived_id(&self) -> usize
Returns the ID derived from this node’s public key. Falls back to node_id if no certificate has been generated yet.
Sourcepub async fn connect_as_client(
&mut self,
address: SocketAddr,
) -> Result<Arc<dyn PeerConnection>, String>
pub async fn connect_as_client( &mut self, address: SocketAddr, ) -> Result<Arc<dyn PeerConnection>, String>
Connects as a CLIENT to a server (role identified via ALPN).
The server’s ID is derived from its public key.
Returns Arc
Sourcepub async fn connect_as_server(
&mut self,
address: SocketAddr,
) -> Result<Arc<dyn PeerConnection>, String>
pub async fn connect_as_server( &mut self, address: SocketAddr, ) -> Result<Arc<dyn PeerConnection>, String>
Connects as a SERVER to another server (role identified via ALPN).
The peer’s ID is derived from its public key.
Returns Arc
Sourcepub async fn connect_as_server_with_expected_public_key(
&mut self,
address: SocketAddr,
expected_public_key: &NodePublicKey,
) -> Result<Arc<dyn PeerConnection>, String>
pub async fn connect_as_server_with_expected_public_key( &mut self, address: SocketAddr, expected_public_key: &NodePublicKey, ) -> Result<Arc<dyn PeerConnection>, String>
Connect to a server and require its TLS certificate to contain the exact expected SubjectPublicKeyInfo before admitting the connection.
Sourcepub fn is_nat_traversal_enabled(&self) -> bool
pub fn is_nat_traversal_enabled(&self) -> bool
Returns whether NAT traversal is enabled
Sourcepub async fn gather_ice_candidates(&self) -> Result<LocalCandidates, String>
pub async fn gather_ice_candidates(&self) -> Result<LocalCandidates, String>
Gathers ICE candidates for NAT traversal
Discovers local host addresses and queries STUN servers for server reflexive (external) addresses.
Sourcepub async fn create_ice_candidates_message(&self) -> Result<NetEnvelope, String>
pub async fn create_ice_candidates_message(&self) -> Result<NetEnvelope, String>
Creates an ICE candidates message for sending to a peer
Sourcepub async fn connect_p2p(
&mut self,
target_party_id: usize,
signaling_connection: Arc<dyn PeerConnection>,
) -> Result<Arc<dyn PeerConnection>, String>
pub async fn connect_p2p( &mut self, target_party_id: usize, signaling_connection: Arc<dyn PeerConnection>, ) -> Result<Arc<dyn PeerConnection>, String>
Initiates a peer-to-peer connection with NAT traversal
This method:
- Gathers local ICE candidates
- Sends candidates to the peer via the signaling connection
- Receives remote candidates
- Runs ICE connectivity checks
- Returns the established connection
Sourcepub async fn handle_p2p_request(
&mut self,
from_party_id: usize,
remote_ufrag: String,
remote_pwd: String,
remote_candidates: Vec<IceCandidate>,
signaling_connection: Arc<dyn PeerConnection>,
) -> Result<Arc<dyn PeerConnection>, String>
pub async fn handle_p2p_request( &mut self, from_party_id: usize, remote_ufrag: String, remote_pwd: String, remote_candidates: Vec<IceCandidate>, signaling_connection: Arc<dyn PeerConnection>, ) -> Result<Arc<dyn PeerConnection>, String>
Handles an incoming P2P connection request with NAT traversal
Called when we receive ICE candidates from a peer wanting to connect.
Sourcepub async fn connect_with_fallback(
&mut self,
target_party_id: usize,
direct_address: Option<SocketAddr>,
signaling_connection: Option<Arc<dyn PeerConnection>>,
) -> Result<Arc<dyn PeerConnection>, String>
pub async fn connect_with_fallback( &mut self, target_party_id: usize, direct_address: Option<SocketAddr>, signaling_connection: Option<Arc<dyn PeerConnection>>, ) -> Result<Arc<dyn PeerConnection>, String>
Connects with automatic fallback strategies
Tries connection methods in order:
- Direct connection (if address provided)
- NAT traversal with hole punching
- Relay (future - returns error for now)
Sourcepub async fn process_signaling_message(
&mut self,
from_party_id: usize,
envelope: NetEnvelope,
signaling_connection: Arc<dyn PeerConnection>,
) -> Result<Option<Arc<dyn PeerConnection>>, String>
pub async fn process_signaling_message( &mut self, from_party_id: usize, envelope: NetEnvelope, signaling_connection: Arc<dyn PeerConnection>, ) -> Result<Option<Arc<dyn PeerConnection>>, String>
Processes an incoming signaling message for NAT traversal
Returns an optional response message to send back.
Sourcepub fn get_sorted_client_keys(&self) -> Vec<NodePublicKey>
pub fn get_sorted_client_keys(&self) -> Vec<NodePublicKey>
Returns a sorted list of all client public keys.
Sourcepub fn compute_client_list_digest(&self) -> Vec<u8> ⓘ
pub fn compute_client_list_digest(&self) -> Vec<u8> ⓘ
Computes BLAKE3 digest of the sorted client public key list.
Sourcepub fn compute_node_list_digest(&self) -> Vec<u8> ⓘ
pub fn compute_node_list_digest(&self) -> Vec<u8> ⓘ
Computes BLAKE3 digest of the sorted node public key list.
Sourcepub async fn verify_node_ordering(
connections: &[Arc<dyn PeerConnection>],
) -> Result<VerifiedOrdering, ConsensusError>
pub async fn verify_node_ordering( connections: &[Arc<dyn PeerConnection>], ) -> Result<VerifiedOrdering, ConsensusError>
Client-side: reads auto-pushed NodeListResponse from each node and verifies consistency.
Trait Implementations§
Source§impl Clone for QuicNetworkManager
impl Clone for QuicNetworkManager
Source§fn clone(&self) -> QuicNetworkManager
fn clone(&self) -> QuicNetworkManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QuicNetworkManager
impl Debug for QuicNetworkManager
Source§impl Default for QuicNetworkManager
impl Default for QuicNetworkManager
Source§fn default() -> QuicNetworkManager
fn default() -> QuicNetworkManager
Source§impl Network for QuicNetworkManager
impl Network for QuicNetworkManager
Source§type NetworkConfig = QuicNetworkConfig
type NetworkConfig = QuicNetworkConfig
Source§fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
recipient: usize,
message: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuicNetworkManager: 'async_trait,
fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
recipient: usize,
message: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuicNetworkManager: 'async_trait,
Source§fn broadcast<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuicNetworkManager: 'async_trait,
fn broadcast<'life0, 'life1, 'async_trait>(
&'life0 self,
message: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuicNetworkManager: 'async_trait,
Source§fn parties(&self) -> Vec<&<QuicNetworkManager as Network>::NodeType>
fn parties(&self) -> Vec<&<QuicNetworkManager as Network>::NodeType>
Source§fn parties_mut(&mut self) -> Vec<&mut <QuicNetworkManager as Network>::NodeType>
fn parties_mut(&mut self) -> Vec<&mut <QuicNetworkManager as Network>::NodeType>
Source§fn config(&self) -> &<QuicNetworkManager as Network>::NetworkConfig
fn config(&self) -> &<QuicNetworkManager as Network>::NetworkConfig
Source§fn node(&self, id: usize) -> Option<&<QuicNetworkManager as Network>::NodeType>
fn node(&self, id: usize) -> Option<&<QuicNetworkManager as Network>::NodeType>
Source§fn node_mut(
&mut self,
id: usize,
) -> Option<&mut <QuicNetworkManager as Network>::NodeType>
fn node_mut( &mut self, id: usize, ) -> Option<&mut <QuicNetworkManager as Network>::NodeType>
Source§fn send_to_client<'life0, 'life1, 'async_trait>(
&'life0 self,
client: usize,
message: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuicNetworkManager: 'async_trait,
fn send_to_client<'life0, 'life1, 'async_trait>(
&'life0 self,
client: usize,
message: &'life1 [u8],
) -> Pin<Box<dyn Future<Output = Result<usize, NetworkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
QuicNetworkManager: 'async_trait,
Source§fn clients(&self) -> Vec<usize>
fn clients(&self) -> Vec<usize>
Source§fn is_client_connected(&self, client: usize) -> bool
fn is_client_connected(&self, client: usize) -> bool
Source§fn local_party_id(&self) -> usize
fn local_party_id(&self) -> usize
Source§fn party_count(&self) -> usize
fn party_count(&self) -> usize
Source§fn verified_ordering(&self) -> Option<VerifiedOrdering>
fn verified_ordering(&self) -> Option<VerifiedOrdering>
Source§impl NetworkManager for QuicNetworkManager
impl NetworkManager for QuicNetworkManager
fn connect<'a>( &'a mut self, address: SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn PeerConnection>, String>> + Send + 'a>>
fn accept<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn PeerConnection>, String>> + Send + 'a>>
fn listen<'a>( &'a mut self, bind_address: SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>>
Auto Trait Implementations§
impl !RefUnwindSafe for QuicNetworkManager
impl !UnwindSafe for QuicNetworkManager
impl Freeze for QuicNetworkManager
impl Send for QuicNetworkManager
impl Sync for QuicNetworkManager
impl Unpin for QuicNetworkManager
impl UnsafeUnpin for QuicNetworkManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more