Skip to main content

QuicNetworkManager

Struct QuicNetworkManager 

Source
pub struct QuicNetworkManager { /* private fields */ }

Implementations§

Source§

impl QuicNetworkManager

Source

pub fn new() -> QuicNetworkManager

Source

pub fn set_send_hook(&self, hook: Arc<dyn Fn(&[u8], usize) + Sync + Send>)

Installs a callback for successfully queued outbound MPC messages.

Source

pub fn with_node_id(node_id: usize) -> QuicNetworkManager

Source

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.

Source

pub fn public_key_from_certificate_der( cert_der: &[u8], ) -> Result<NodePublicKey, String>

Extract the exact DER-encoded SubjectPublicKeyInfo from a certificate.

Source

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.

Source

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.

Source

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.

Source

pub fn with_nat_traversal() -> QuicNetworkManager

Creates a manager with NAT traversal enabled

Source

pub fn set_expected_parties(&mut self, count: usize)

Sets the expected number of parties for consensus gating.

Source

pub fn set_expected_clients(&mut self, count: usize)

Sets the expected number of clients for consensus gating.

Source

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.

Source

pub fn add_allowed_certificate_public_key(&mut self, key: NodePublicKey)

Adds a DER-encoded SubjectPublicKeyInfo key to the certificate public key allowlist.

Source

pub fn clear_allowed_certificate_public_keys(&mut self)

Clears the certificate public key allowlist, disabling this check.

Source

pub fn has_certificate_public_key_allowlist(&self) -> bool

Returns true when certificate public key allowlisting is enabled.

Source

pub fn add_node(&mut self, node: QuicNode)

Source

pub fn add_node_with_party_id(&mut self, id: usize, address: SocketAddr)

Source

pub async fn ensure_loopback_installed(&self)

Ensures loopback connection exists for self-delivery

Source

pub async fn get_connection( &self, party_id: usize, ) -> Option<Arc<dyn PeerConnection>>

Gets a server connection by party ID

Source

pub fn try_acquire_execution_scanner_receive_owner( &self, ) -> Option<ExecutionScannerReceiveOwnerLease>

Claim this manager clone-set for one execution connection scanner.

Source

pub fn get_all_server_connections( &self, ) -> Vec<(usize, Arc<dyn PeerConnection>)>

Gets all server connections (peer-to-peer MPC party connections)

Source

pub fn get_all_client_connections( &self, ) -> Vec<(usize, Arc<dyn PeerConnection>)>

Gets all client connections (external clients connected to this server)

Source

pub fn get_client_connection( &self, client_id: usize, ) -> Option<Arc<dyn PeerConnection>>

Gets a specific client connection by ID

Source

pub async fn cleanup_dead_connections(&self)

Removes dead connections from both server and client connection maps

Source

pub async fn is_party_connected(&self, party_id: usize) -> bool

Checks connection health for a specific party

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_fully_connected(&self, expected_count: usize) -> bool

Checks if we have public keys from all expected parties.

Source

pub fn get_public_key(&self) -> Option<&NodePublicKey>

Returns a reference to this node’s public key

Source

pub fn local_public_key_bytes(&self) -> Option<Vec<u8>>

Returns this node’s DER-encoded SubjectPublicKeyInfo bytes.

Source

pub fn peer_public_key_bytes(&self, peer_id: usize) -> Option<Vec<u8>>

Returns a connected peer’s DER-encoded SubjectPublicKeyInfo bytes.

Source

pub fn client_public_key_bytes(&self, client_id: usize) -> Option<Vec<u8>>

Returns a connected client’s DER-encoded SubjectPublicKeyInfo bytes.

Source

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.

Source

pub fn get_node_id(&self) -> usize

Returns the node_id (legacy ID, used as fallback)

Source

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.

Source

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 for actor model compatibility.

Source

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 for actor model compatibility.

Source

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.

Source

pub fn is_nat_traversal_enabled(&self) -> bool

Returns whether NAT traversal is enabled

Source

pub fn party_id(&self) -> usize

Returns the local party ID

Source

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.

Source

pub async fn create_ice_candidates_message(&self) -> Result<NetEnvelope, String>

Creates an ICE candidates message for sending to a peer

Source

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:

  1. Gathers local ICE candidates
  2. Sends candidates to the peer via the signaling connection
  3. Receives remote candidates
  4. Runs ICE connectivity checks
  5. Returns the established connection
Source

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.

Source

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:

  1. Direct connection (if address provided)
  2. NAT traversal with hole punching
  3. Relay (future - returns error for now)
Source

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.

Source

pub fn get_sorted_client_keys(&self) -> Vec<NodePublicKey>

Returns a sorted list of all client public keys.

Source

pub fn compute_client_list_digest(&self) -> Vec<u8> ⓘ

Computes BLAKE3 digest of the sorted client public key list.

Source

pub fn compute_node_list_digest(&self) -> Vec<u8> ⓘ

Computes BLAKE3 digest of the sorted node public key list.

Source

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

Source§

fn clone(&self) -> QuicNetworkManager

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QuicNetworkManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for QuicNetworkManager

Source§

fn default() -> QuicNetworkManager

Returns the “default value” for a type. Read more
Source§

impl Network for QuicNetworkManager

Source§

type NodeType = QuicNode

Type of the node in the network.
Source§

type NetworkConfig = QuicNetworkConfig

Configuration of the network.
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,

Send a message through the network to the given party. The function returns the number of bytes sent to the recipient.
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,

Broadcasts a message to all the parties connected to the network. The function returns the number of bytes broadcasted to the network.
Source§

fn parties(&self) -> Vec<&<QuicNetworkManager as Network>::NodeType>

Returns the participants connected to this network.
Source§

fn parties_mut(&mut self) -> Vec<&mut <QuicNetworkManager as Network>::NodeType>

Returns mutable references to the participants connected to this network.
Source§

fn config(&self) -> &<QuicNetworkManager as Network>::NetworkConfig

Returns the configuration of the network.
Source§

fn node(&self, id: usize) -> Option<&<QuicNetworkManager as Network>::NodeType>

Returns the node with the given ID.
Source§

fn node_mut( &mut self, id: usize, ) -> Option<&mut <QuicNetworkManager as Network>::NodeType>

Returns a mutable reference of the node with the given ID.
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,

Send a message to a logical client. When several live physical connections share that client’s authenticated ID, implementations broadcast to all of them and succeed if at least one delivery succeeds.
Source§

fn clients(&self) -> Vec<usize>

Returns distinct logical connected client IDs. Multiple physical connections authenticated as the same client appear once.
Source§

fn is_client_connected(&self, client: usize) -> bool

Checks whether a client is connected.
Source§

fn local_party_id(&self) -> usize

Returns this node’s party ID (0..N-1).
Source§

fn party_count(&self) -> usize

Returns the number of parties in the network (including self).
Source§

fn verified_ordering(&self) -> Option<VerifiedOrdering>

Returns the verified ordering if consensus has completed.
Source§

impl NetworkManager for QuicNetworkManager

Source§

fn connect<'a>( &'a mut self, address: SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn PeerConnection>, String>> + Send + 'a>>

Source§

fn accept<'a>( &'a mut self, ) -> Pin<Box<dyn Future<Output = Result<Arc<dyn PeerConnection>, String>> + Send + 'a>>

Source§

fn listen<'a>( &'a mut self, bind_address: SocketAddr, ) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'a>>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more