Builder

Struct Builder 

Source
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

Source

pub fn new(network: Network) -> Self

Create a new Builder.

Source

pub fn network(&self) -> Network

Fetch the Network for the builder.

Source

pub fn add_peers(self, whitelist: impl IntoIterator<Item = TrustedPeer>) -> Self

Add preferred peers to try to connect to.

Source

pub fn add_peer(self, trusted_peer: impl Into<TrustedPeer>) -> Self

Add a preferred peer to try to connect to.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(&mut self) -> Result<(NodeDefault, Client), SqlInitializationError>

Consume the node builder and receive a Node and Client.

§Errors

Building a node and client will error if a database connection is denied or cannot be found.

Source

pub fn build_with_databases<H: HeaderStore + 'static, P: PeerStore + 'static>( &mut self, peer_store: P, header_store: H, ) -> (Node<H, P>, Client)

Consume the node builder by using custom database implementations, receiving a Node and Client.

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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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