pub struct ClientConfig { /* private fields */ }
Expand description
Client configuration struct
See library documentation for usage example.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new(id: String, coord: String) -> Self
pub fn new(id: String, coord: String) -> Self
Construct new ClientConfig
id
is the Client’s name, which will be used to identify it to other clients.coord
is the hostname of the coordinator. The coordinator’s TLS certificate must match this name.
By default, Client will attempt to resolve the hostname coord
and connect
on the default port. Use set_port to change the port number, or use
set_addr to specify a SocketAddr rather than
relying on name resolution.
In all cases, the Client will ensure that the Coordinator’s TLS certificate
matches the hostname specified as coord
.
Sourcepub fn set_addr(&mut self, addr: SocketAddr) -> &mut Self
pub fn set_addr(&mut self, addr: SocketAddr) -> &mut Self
Set the Coordinator’s address to addr
, disabling name resolution
Note that Client will still ensure that Coordinator’s TLS certificate matches the name specified to ClientConfig::new.
Sourcepub fn enable_keylog(&mut self) -> &mut Self
pub fn enable_keylog(&mut self) -> &mut Self
Enable logging key material to the file specified by the environment variable SSLKEYLOGFILE
.
Sourcepub fn set_ca(&mut self, ca: Certificate) -> &mut Self
pub fn set_ca(&mut self, ca: Certificate) -> &mut Self
Add a trusted certificate authority
This certificate authority is used to validate the Coordinator’s certificate.
Sourcepub fn set_ca_from_file(
&mut self,
cert_path: &Path,
) -> Result<&mut Self, CertReadError>
pub fn set_ca_from_file( &mut self, cert_path: &Path, ) -> Result<&mut Self, CertReadError>
Add a trusted certificate authority from a file
This is a convenience wrapper around ClientConfig::set_ca. Both PEM and DER formats are supported.
Sourcepub fn set_client_ca(&mut self, ca: Certificate) -> &mut Self
pub fn set_client_ca(&mut self, ca: Certificate) -> &mut Self
Add a trusted certificate authority for checking Client certs
If no trusted CA is provided, self-signed Client certificates are required.
Sourcepub fn set_client_ca_from_file(
&mut self,
cert_path: &Path,
) -> Result<&mut Self, CertReadError>
pub fn set_client_ca_from_file( &mut self, cert_path: &Path, ) -> Result<&mut Self, CertReadError>
Add a trusted certificate authority for checking Client certs from a file
This is a convenience wrapper around ClientConfig::set_client_ca. Both PEM and DER formats are supported.
Sourcepub fn set_srcaddr(&mut self, src: SocketAddr) -> &mut Self
pub fn set_srcaddr(&mut self, src: SocketAddr) -> &mut Self
Set the Client’s source address explicitly
By default, the source address is set to 0.0.0.0:0
. To bind to a host-assigned
IPv6 port instead, one might call
client_cfg.set_srcaddr(SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 0));
Sourcepub fn enable_stateless_retry(&mut self) -> &mut Self
pub fn enable_stateless_retry(&mut self) -> &mut Self
Enable QUIC stateless retry.
Per QUIC spec, stateless retry defends against client address spoofing. The downside is that this adds another round-trip to new connections.
Sourcepub fn disable_listen(&mut self) -> &mut Self
pub fn disable_listen(&mut self) -> &mut Self
Disable Client listening for incoming direct connections
This means that all streams must be proxed through Coordinator
Sourcepub fn disable_keepalive(&mut self) -> &mut Self
pub fn disable_keepalive(&mut self) -> &mut Self
Disable Client keepalive messages
By default, Clients send a short keepalive message every 5 seconds. This setting disables that.
Note that when keepalive is disabled, the underlying transport will close idle connections after 10 seconds.
Sourcepub fn disable_holepunch(&mut self) -> &mut Self
pub fn disable_holepunch(&mut self) -> &mut Self
Disable holepunching
By default, Clients that are listening for incoming channels will attempt to set up a UDP Holepunch when alerted by the Coordinator that a new channel is incoming. This setting disables that.
Sourcepub fn set_cert(
&mut self,
cert: CertificateChain,
key: PrivateKey,
key_der: Vec<u8>,
) -> &mut Self
pub fn set_cert( &mut self, cert: CertificateChain, key: PrivateKey, key_der: Vec<u8>, ) -> &mut Self
Set a certificate and key for Client
This certificate is used to authenticate to the Coordinator and when accepting direct connections from other clients.
To be usable, a certificate must meet two criteria:
-
It must be valid for the Client
id
provided to ClientConfig::new, otherwise the coordinator will reject the connection. -
If the Coordinator is configured to accept self-signed certificates (which is the default), this certificate must be self-signed. Otherwise, if the coordinator is configured to accept certificates signed by a particular CA (via CoordConfig::set_client_ca), this certificate must be signed by that CA.
Sourcepub fn set_cert_from_file(
&mut self,
cert_path: &Path,
key_path: &Path,
) -> Result<&mut Self, CertReadError>
pub fn set_cert_from_file( &mut self, cert_path: &Path, key_path: &Path, ) -> Result<&mut Self, CertReadError>
Set a certificate and key for Client from file
This is a convenience wrapper around ClientConfig::set_cert. Both PEM and DER formats are supported.
Trait Implementations§
Source§impl Clone for ClientConfig
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more