nakamoto_node/
lib.rs

1//! Stand-alone light-client daemon. Runs the light-client as a background process.
2#![deny(missing_docs, unsafe_code)]
3
4use std::net;
5use std::path::PathBuf;
6
7pub use nakamoto_client::{Client, Config, Error, Network};
8pub use nakamoto_client::{Domain, LoadingHandler};
9
10pub mod logger;
11
12/// The network reactor we're going to use.
13type Reactor = nakamoto_net_poll::Reactor<net::TcpStream>;
14
15/// Run the light-client. Takes an initial list of peers to connect to, a list of listen addresses,
16/// the client root and the Bitcoin network to connect to.
17pub fn run(
18    connect: &[net::SocketAddr],
19    listen: &[net::SocketAddr],
20    root: Option<PathBuf>,
21    domains: &[Domain],
22    network: Network,
23) -> Result<(), Error> {
24    let mut cfg = Config {
25        network,
26        connect: connect.to_vec(),
27        domains: domains.to_vec(),
28        listen: if listen.is_empty() {
29            vec![([0, 0, 0, 0], 0).into()]
30        } else {
31            listen.to_vec()
32        },
33        ..Config::default()
34    };
35    if let Some(path) = root {
36        cfg.root = path;
37    }
38    if !connect.is_empty() {
39        cfg.limits.max_outbound_peers = connect.len();
40    }
41
42    Client::<Reactor>::new()?.run(cfg)
43}