pub struct Builder { /* private fields */ }Expand description
Build a Node in an additive way.
§Examples
Nodes may be built with minimal configuration.
use std::net::{IpAddr, Ipv4Addr};
use std::collections::HashSet;
use kyoto::{Builder, Network};
let host = (IpAddr::from(Ipv4Addr::new(0, 0, 0, 0)), None);
let builder = Builder::new(Network::Regtest);
let (node, client) = builder
.add_peers(vec![host.into()])
.build()
.unwrap();Implementations§
Source§impl Builder
impl Builder
Sourcepub fn add_peers(self, whitelist: impl IntoIterator<Item = TrustedPeer>) -> Self
pub fn add_peers(self, whitelist: impl IntoIterator<Item = TrustedPeer>) -> Self
Add preferred peers to try to connect to.
Sourcepub fn add_peer(self, trusted_peer: impl Into<TrustedPeer>) -> Self
pub fn add_peer(self, trusted_peer: impl Into<TrustedPeer>) -> Self
Add a preferred peer to try to connect to.
Sourcepub fn data_dir(self, path: impl Into<PathBuf>) -> Self
pub fn data_dir(self, path: impl Into<PathBuf>) -> Self
Add a path to the directory where data should be stored. If none is provided, the current working directory will be used.
Sourcepub fn required_peers(self, num_peers: u8) -> Self
pub fn required_peers(self, num_peers: u8) -> Self
Add the minimum number of peer connections that should be maintained by the node. Adding more connections increases the node’s anonymity, but requires waiting for more responses, higher bandwidth, and higher memory requirements. If none is provided, a single connection will be maintained. The number of connections will be clamped to a range of 1 to 15.
Sourcepub fn peer_db_size(self, target: PeerStoreSizeConfig) -> Self
pub fn peer_db_size(self, target: PeerStoreSizeConfig) -> Self
Set the desired number of peers for the database to keep track of. For limited or in-memory peer storage, this number may be small, however a sufficient margin of peers should be set so the node can try many options when downloading compact block filters. For nodes that store peers on disk, more peers will typically result in fewer errors. If none is provided, no limit to the size of the store will be introduced.
Sourcepub fn after_checkpoint(self, checkpoint: impl Into<HeaderCheckpoint>) -> Self
pub fn after_checkpoint(self, checkpoint: impl Into<HeaderCheckpoint>) -> Self
Add a checkpoint for the node to look for relevant blocks strictly after the given height.
This may be from the same HeaderCheckpoint every time the node is ran, or from the last known sync height.
In the case of a block reorganization, the node may scan for blocks below the given block height
to accurately reflect which relevant blocks are in the best chain.
If none is provided, the most recent checkpoint will be used.
Sourcepub fn handshake_timeout(self, handshake_timeout: impl Into<Duration>) -> Self
pub fn handshake_timeout(self, handshake_timeout: impl Into<Duration>) -> Self
Set the time a peer has to complete the initial TCP handshake. Even on unstable connections this may be fast.
If none is provided, a timeout of two seconds will be used.
Sourcepub fn response_timeout(self, response_timeout: impl Into<Duration>) -> Self
pub fn response_timeout(self, response_timeout: impl Into<Duration>) -> Self
Set the time duration a peer has to respond to a message from the local node.
§Note
Both bandwidth and computing time should be considered when configuring this timeout. On test networks, this value may be quite short, however on the Bitcoin network, nodes may be slower to respond while processing blocks and transactions.
If none is provided, a timeout of 5 seconds will be used.
Sourcepub fn maximum_connection_time(
self,
max_connection_time: impl Into<Duration>,
) -> Self
pub fn maximum_connection_time( self, max_connection_time: impl Into<Duration>, ) -> Self
The maximum connection time that will be maintained with a remote peer, regardless of the quality of the peer.
§Note
This value is configurable as some developers may be satisfied with a peer as long as the peer responds promptly. Other implementations may value finding new and reliable peers faster, so the maximum connection time may be shorter.
If none is provided, a maximum connection time of two hours will be used.
Sourcepub fn dns_resolver(self, resolver: impl Into<IpAddr>) -> Self
pub fn dns_resolver(self, resolver: impl Into<IpAddr>) -> Self
Configure the DNS resolver to use when querying DNS seeds.
Default is 1.1.1.1:53.
Sourcepub fn socks5_proxy(self, proxy: impl Into<SocketAddr>) -> Self
pub fn socks5_proxy(self, proxy: impl Into<SocketAddr>) -> Self
Route network traffic through a Tor daemon using a Socks5 proxy. Currently, proxies must be reachable by IP address.