pub struct Builder { /* private fields */ }
Expand description
Builder for Endpoint
.
By default the endpoint will generate a new random SecretKey
, which will result in a
new NodeId
.
To create the Endpoint
call Builder::bind
.
Implementations§
Source§impl Builder
impl Builder
Sourcepub fn bind_addr_v4(self, addr: SocketAddrV4) -> Self
pub fn bind_addr_v4(self, addr: SocketAddrV4) -> Self
Sets the IPv4 bind address.
Setting the port to 0
will use a random port.
If the port specified is already in use, it will fallback to choosing a random port.
By default will use 0.0.0.0:0
to bind to.
Sourcepub fn bind_addr_v6(self, addr: SocketAddrV6) -> Self
pub fn bind_addr_v6(self, addr: SocketAddrV6) -> Self
Sets the IPv6 bind address.
Setting the port to 0
will use a random port.
If the port specified is already in use, it will fallback to choosing a random port.
By default will use [::]:0
to bind to.
Sourcepub fn secret_key(self, secret_key: SecretKey) -> Self
pub fn secret_key(self, secret_key: SecretKey) -> Self
Sourcepub fn relay_mode(self, relay_mode: RelayMode) -> Self
pub fn relay_mode(self, relay_mode: RelayMode) -> Self
Sets the relay servers to assist in establishing connectivity.
Relay servers are used to establish initial connection with another iroh-net node. They also perform various functions related to hole punching, see the crate docs for more details.
By default the number 0 relay servers are used, see RelayMode::Default
.
When using RelayMode::Custom, the provided relay_map
must contain at least one
configured relay node. If an invalid RelayMap is provided bind
will result in an error.
Sourcepub fn clear_discovery(self) -> Self
pub fn clear_discovery(self) -> Self
Removes all discovery services from the builder.
Sourcepub fn discovery(self, discovery: Box<dyn Discovery>) -> Self
pub fn discovery(self, discovery: Box<dyn Discovery>) -> Self
Optionally sets a discovery mechanism for this endpoint.
If you want to combine multiple discovery services, you can use
Builder::add_discovery
instead. This will internally create a
crate::discovery::ConcurrentDiscovery
.
If no discovery service is set, connecting to a node without providing its direct addresses or relay URLs will fail.
See the documentation of the Discovery
trait for details.
Sourcepub fn add_discovery<F, D>(self, discovery: F) -> Self
pub fn add_discovery<F, D>(self, discovery: F) -> Self
Adds a discovery mechanism for this endpoint.
The function discovery
will be called on endpoint creation with the configured secret key of
the endpoint. Discovery services that need to publish information need
to use this secret key to sign the information.
If you add multiple discovery services, they will be combined using a
crate::discovery::ConcurrentDiscovery
.
If no discovery service is set, connecting to a node without providing its direct addresses or relay URLs will fail.
To clear all discovery services, use Builder::clear_discovery
.
See the documentation of the Discovery
trait for details.
Sourcepub fn discovery_n0(self) -> Self
pub fn discovery_n0(self) -> Self
Configures the endpoint to use the default n0 DNS discovery service.
The default discovery service publishes to and resolves from the
n0.computer dns server iroh.link
.
This is equivalent to adding both a crate::discovery::pkarr::PkarrPublisher
and a crate::discovery::dns::DnsDiscovery
, both configured to use the
n0.computer dns server.
This will by default use N0_DNS_PKARR_RELAY_PROD
.
When in tests, or when the test-utils
feature is enabled, this will use the
N0_DNS_PKARR_RELAY_STAGING
.
Sourcepub fn discovery_dht(self) -> Self
pub fn discovery_dht(self) -> Self
Configures the endpoint to also use the mainline DHT with default settings.
This is equivalent to adding a crate::discovery::pkarr::dht::DhtDiscovery
with default settings. Note that DhtDiscovery has various more advanced
configuration options. If you need any of those, you should manually
create a DhtDiscovery and add it with Builder::add_discovery
.
Sourcepub fn discovery_local_network(self) -> Self
pub fn discovery_local_network(self) -> Self
Configures the endpoint to also use local network discovery.
This is equivalent to adding a crate::discovery::local_swarm_discovery::LocalSwarmDiscovery
with default settings. Note that LocalSwarmDiscovery has various more advanced
configuration options. If you need any of those, you should manually
create a LocalSwarmDiscovery and add it with Builder::add_discovery
.
Sourcepub fn known_nodes(self, nodes: Vec<NodeAddr>) -> Self
pub fn known_nodes(self, nodes: Vec<NodeAddr>) -> Self
Optionally set a list of known nodes.
Sourcepub fn transport_config(self, transport_config: TransportConfig) -> Self
pub fn transport_config(self, transport_config: TransportConfig) -> Self
Sets a custom quinn::TransportConfig
for this endpoint.
The transport config contains parameters governing the QUIC state machine.
If unset, the default config is used. Default values should be suitable for most
internet applications. Applications protocols which forbid remotely-initiated
streams should set max_concurrent_bidi_streams
and max_concurrent_uni_streams
to
zero.
Sourcepub fn dns_resolver(self, dns_resolver: DnsResolver) -> Self
pub fn dns_resolver(self, dns_resolver: DnsResolver) -> Self
Optionally sets a custom DNS resolver to use for this endpoint.
The DNS resolver is used to resolve relay hostnames, and node addresses if
crate::discovery::dns::DnsDiscovery
is configured.
By default, all endpoints share a DNS resolver, which is configured to use the
host system’s DNS configuration. You can pass a custom instance of DnsResolver
here to use a differently configured DNS resolver for this endpoint.
Sourcepub fn proxy_url(self, url: Url) -> Self
pub fn proxy_url(self, url: Url) -> Self
Sets an explicit proxy url to proxy all HTTP(S) traffic through.
Sourcepub fn proxy_from_env(self) -> Self
pub fn proxy_from_env(self) -> Self
Sets the proxy url from the environment, in this order:
HTTP_PROXY
http_proxy
HTTPS_PROXY
https_proxy
Sourcepub fn keylog(self, keylog: bool) -> Self
pub fn keylog(self, keylog: bool) -> Self
Enables saving the TLS pre-master key for connections.
This key should normally remain secret but can be useful to debug networking issues by decrypting captured traffic.
If keylog is true
then setting the SSLKEYLOGFILE
environment variable to a
filename will result in this file being used to log the TLS pre-master keys.
Sourcepub fn insecure_skip_relay_cert_verify(self, skip_verify: bool) -> Self
Available on test
or crate feature test-utils
only.
pub fn insecure_skip_relay_cert_verify(self, skip_verify: bool) -> Self
test
or crate feature test-utils
only.Skip verification of SSL certificates from relay servers
May only be used in tests.