pub struct Builder { /* private fields */ }
Expand description
Implementations§
§impl Builder
impl Builder
pub fn set_address(&mut self, address: SocketAddr)
pub fn set_address(&mut self, address: SocketAddr)
Set’s the SocketAddr
to bind to.
Default
[::\]:0
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_address("[::1]:0".parse()?);
pub const fn address(&self) -> &SocketAddr
pub const fn address(&self) -> &SocketAddr
Returns the SocketAddr
to bind to.
See set_address
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
let address = "[::1]:0".parse()?;
builder.set_address(address);
assert_eq!(builder.address(), &address);
pub fn set_reuse_address(&mut self, reuse: bool)
pub fn set_reuse_address(&mut self, reuse: bool)
Enables SO_REUSEADDR
on the underlying UdpSocket
, allowing multiple
Endpoint
s to bind to the same SocketAddr
.
If this is false, attempting to create an Endpoint
to a previously
bound SocketAddr
may result in an address-in-use error.
pub const fn reuse_address(&self) -> bool
pub const fn reuse_address(&self) -> bool
Returns whether the underlying UdpSocket
will enable the
SO_REUSEADDR
option. See
set_reuse_address()
for more information.
pub fn set_server_key_pair(&mut self, key_pair: Option<KeyPair>)
pub fn set_server_key_pair(&mut self, key_pair: Option<KeyPair>)
Set a server certificate KeyPair
, use None
to
remove any server certificate.
Default
None
.
Notes
Endpoint
won’t listen to any incoming
Connection
s without a server certificate.
Examples
use fabruic::{Builder, KeyPair};
let mut builder = Builder::new();
builder.set_server_key_pair(Some(KeyPair::new_self_signed("test")));
pub const fn server_key_pair(&self) -> &Option<KeyPair>
pub const fn server_key_pair(&self) -> &Option<KeyPair>
Returns the server certificate KeyPair
.
See set_server_key_pair
.
Examples
use fabruic::{Builder, KeyPair};
let mut builder = Builder::new();
let key_pair = KeyPair::new_self_signed("test");
builder.set_server_key_pair(Some(key_pair.clone()));
assert_eq!(builder.server_key_pair(), &Some(key_pair))
pub fn set_client_key_pair(&mut self, key_pair: Option<KeyPair>)
pub fn set_client_key_pair(&mut self, key_pair: Option<KeyPair>)
pub const fn client_key_pair(&self) -> &Option<KeyPair>
pub const fn client_key_pair(&self) -> &Option<KeyPair>
Returns the client certificate KeyPair
.
See set_client_key_pair
.
Examples
use fabruic::{Builder, KeyPair};
let mut builder = Builder::new();
let key_pair = KeyPair::new_self_signed("test");
builder.set_client_key_pair(Some(key_pair.clone()));
assert_eq!(builder.client_key_pair(), &Some(key_pair))
pub fn set_protocols<P>(&mut self, protocols: P)where
P: Into<Vec<Vec<u8, Global>, Global>>,
pub fn set_protocols<P>(&mut self, protocols: P)where P: Into<Vec<Vec<u8, Global>, Global>>,
Set the protocols to accept, in order of descending preference. When set, clients which don’t declare support for at least one of the supplied protocols will be rejected.
See Connection::protocol
.
Default
No protocols.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_protocols([b"test".to_vec()]);
pub fn protocols(&self) -> &[Vec<u8, Global>]
pub fn protocols(&self) -> &[Vec<u8, Global>]
Returns the set protocols.
See set_protocols
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
let protocols = [b"test".to_vec()];
builder.set_protocols(protocols.clone());
assert_eq!(builder.protocols(), protocols)
pub fn set_trust_dns(&mut self, enable: bool)
pub fn set_trust_dns(&mut self, enable: bool)
Controls the use of trust-dns
for
Endpoint::connect
.
Default
true
if the crate feature trust-dns
is enabled.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_trust_dns(false);
pub fn disable_trust_dns(&mut self)
pub fn disable_trust_dns(&mut self)
Disables the use of trust-dns
for
Endpoint::connect
despite the activated crate feature.
Default
Not disabled if the crate feature trust-dns
is enabled.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.disable_trust_dns();
pub const fn trust_dns(&self) -> bool
pub const fn trust_dns(&self) -> bool
Returns if trust-dns
is enabled.
See set_trust_dns
or
disable_trust_dns
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_trust_dns(true);
assert_eq!(builder.trust_dns(), true);
builder.disable_trust_dns();
assert_eq!(builder.trust_dns(), false);
pub fn set_dnssec(&mut self, enable: bool)
pub fn set_dnssec(&mut self, enable: bool)
Controls DNSSEC validation for trust-dns
in
Endpoint::connect
. This doesn’t affect the
ToSocketAddrs
resolver.
Default
true
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_dnssec(false);
pub const fn dnssec(&self) -> bool
pub const fn dnssec(&self) -> bool
Returns if DNSSEC is enabled for trust-dns
.
See set_dnssec
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_dnssec(false);
assert_eq!(builder.dnssec(), false);
pub fn set_hosts_file(&mut self, enable: bool)
pub fn set_hosts_file(&mut self, enable: bool)
Controls /etc/hosts
file support for trust-dns
in Endpoint::connect
. This doesn’t affect the
ToSocketAddrs
resolver.
Default
false
. Only affects UNIX like OS’s.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_hosts_file(false);
pub const fn hosts_file(&self) -> bool
pub const fn hosts_file(&self) -> bool
Returns if /etc/hosts
file support is enabled for
trust-dns
.
See set_dnssec
.
Examples
use fabruic::Builder;
let mut builder = Builder::new();
builder.set_hosts_file(true);
assert_eq!(builder.hosts_file(), true);
pub fn set_store(&mut self, store: Store)
pub fn set_store(&mut self, store: Store)
pub const fn store(&self) -> Store
pub const fn store(&self) -> Store
Returns the set Store
.
See set_store
.
Examples
use fabruic::{Builder, Store};
let mut builder = Builder::new();
// default
assert_eq!(builder.store(), Store::Embedded);
builder.set_store(Store::Os);
assert_eq!(builder.store(), Store::Os);
builder.set_store(Store::Empty);
assert_eq!(builder.store(), Store::Empty);
pub fn set_max_idle_timeout(
&mut self,
time: Option<Duration>
) -> Result<(), Config>
pub fn set_max_idle_timeout( &mut self, time: Option<Duration> ) -> Result<(), Config>
Set’s the maximum idle timeout a client can have before getting
automatically disconnected. Set None
to disable automatic
disconnecting completely.
Default
10s
Examples
use std::time::Duration;
use fabruic::{Builder, Store};
let mut builder = Builder::new();
builder.set_max_idle_timeout(Some(Duration::from_millis(1000)));
Errors
Config::MaxIdleTimeout
if time
exceeds 2^62 ms.
pub const fn max_idle_timeout(&self) -> Option<Duration>
pub const fn max_idle_timeout(&self) -> Option<Duration>
Returns the set Duration
specified for idle clients to automatically
get disconnected. None
means clients don’t get automatically
disconnected.
See set_max_idle_timeout
.
Examples
use std::time::Duration;
use fabruic::{Builder, Store};
let mut builder = Builder::new();
// default
assert_eq!(builder.max_idle_timeout(), Some(Duration::from_secs(10)));
builder.set_max_idle_timeout(None);
assert_eq!(builder.max_idle_timeout(), None);
builder.set_max_idle_timeout(Some(Duration::from_secs(30)));
assert_eq!(builder.max_idle_timeout(), Some(Duration::from_secs(30)));
pub fn build(self) -> Result<Endpoint, Builder>
pub fn build(self) -> Result<Endpoint, Builder>
Consumes Builder
to build Endpoint
. Must be called from inside a
Tokio Runtime
.
Errors
error::Builder
if the socket couldn’t be bound to the given
address
.
Panics
- if the given
KeyPair
s orCertificate
s are invalid - can’t happen if they were properly validated throughKeyPair::from_parts
orCertificate::from_der
- if not called from inside a Tokio
Runtime
Examples
use fabruic::Builder;
let endpoint = Builder::new().build()?;
Trait Implementations§
§impl Dangerous for Builder
impl Dangerous for Builder
§fn set_root_certificates<C>(builder: &mut Builder, certificates: C)where
C: Into<Vec<Certificate, Global>>,
fn set_root_certificates<C>(builder: &mut Builder, certificates: C)where C: Into<Vec<Certificate, Global>>,
Certificate
s to be added into the root certificate store for
connect
ing to a server. This is added
additionally to the Store
root certificates and does not replace
them. Read more§fn root_certificates(builder: &Builder) -> &[Certificate]
fn root_certificates(builder: &Builder) -> &[Certificate]
Certificate
s set to be added into the root certificate
store. Read more