mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
bin/tau: add the option to run tau locally & add net::Setting to Args struct
This commit is contained in:
@@ -11,7 +11,6 @@ use structopt_toml::StructOptToml;
|
||||
|
||||
use darkfi::{
|
||||
async_daemonize,
|
||||
net::Settings as P2pSettings,
|
||||
raft::Raft,
|
||||
rpc::rpcserver::{listen_and_serve, RpcServerConfig},
|
||||
util::{
|
||||
@@ -32,33 +31,14 @@ use crate::{
|
||||
error::TaudResult,
|
||||
jsonrpc::JsonRpcInterface,
|
||||
month_tasks::MonthTasks,
|
||||
settings::{Args, CONFIG_FILE, CONFIG_FILE_CONTENTS},
|
||||
settings::{Args, Command, CONFIG_FILE, CONFIG_FILE_CONTENTS},
|
||||
task_info::TaskInfo,
|
||||
};
|
||||
|
||||
async_daemonize!(realmain);
|
||||
async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
let p2p_settings = P2pSettings {
|
||||
inbound: settings.accept,
|
||||
outbound_connections: settings.slots,
|
||||
external_addr: settings.accept,
|
||||
peers: settings.connect.clone(),
|
||||
seeds: settings.seeds.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let datastore_path = PathBuf::from(&settings.datastore);
|
||||
|
||||
//
|
||||
//Raft
|
||||
//
|
||||
let datastore_raft = datastore_path.join("tau.db");
|
||||
let mut raft = Raft::<TaskInfo>::new(settings.accept, datastore_raft)?;
|
||||
|
||||
let raft_sender = raft.get_broadcast();
|
||||
let commits = raft.get_commits();
|
||||
let initial_sync_raft_sender = raft_sender.clone();
|
||||
|
||||
//
|
||||
// RPC
|
||||
//
|
||||
@@ -74,6 +54,29 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
|
||||
let rpc_interface = Arc::new(JsonRpcInterface::new(rpc_snd, datastore_path.clone()));
|
||||
|
||||
let executor_cloned = executor.clone();
|
||||
let rpc_listener_taks =
|
||||
executor_cloned.spawn(listen_and_serve(server_config, rpc_interface, executor.clone()));
|
||||
|
||||
let net_settings = match settings.command {
|
||||
Some(Command::Net(s)) => s,
|
||||
None => {
|
||||
warn!("run without connecting to raft and p2p network");
|
||||
rpc_listener_taks.await?;
|
||||
return Ok(())
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
//Raft
|
||||
//
|
||||
let datastore_raft = datastore_path.join("tau.db");
|
||||
let mut raft = Raft::<TaskInfo>::new(net_settings.inbound, datastore_raft)?;
|
||||
|
||||
let raft_sender = raft.get_broadcast();
|
||||
let commits = raft.get_commits();
|
||||
let initial_sync_raft_sender = raft_sender.clone();
|
||||
|
||||
let datastore_path_cloned = datastore_path.clone();
|
||||
let recv_update: smol::Task<TaudResult<()>> = executor.spawn(async move {
|
||||
info!(target: "tau", "Start initial sync");
|
||||
@@ -105,10 +108,6 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
}
|
||||
});
|
||||
|
||||
let executor_cloned = executor.clone();
|
||||
let rpc_listener_taks =
|
||||
executor_cloned.spawn(listen_and_serve(server_config, rpc_interface, executor.clone()));
|
||||
|
||||
let (signal, shutdown) = async_channel::bounded::<()>(1);
|
||||
ctrlc_async::set_async_handler(async move {
|
||||
warn!(target: "tau", "taud start() Exit Signal");
|
||||
@@ -120,7 +119,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
|
||||
.unwrap();
|
||||
|
||||
// blocking
|
||||
raft.start(p2p_settings.clone(), executor.clone(), shutdown.clone()).await?;
|
||||
raft.start(net_settings, executor.clone(), shutdown.clone()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use darkfi::net;
|
||||
use serde::Deserialize;
|
||||
use structopt::StructOpt;
|
||||
use structopt_toml::StructOptToml;
|
||||
@@ -21,19 +22,17 @@ pub struct Args {
|
||||
/// Sets Datastore Path
|
||||
#[structopt(long, default_value = "~/.config/tau")]
|
||||
pub datastore: String,
|
||||
/// Raft Accept address
|
||||
#[structopt(short, long)]
|
||||
pub accept: Option<SocketAddr>,
|
||||
/// Raft Seed nodes (repeatable)
|
||||
#[structopt(short, long)]
|
||||
pub seeds: Vec<SocketAddr>,
|
||||
/// Raft Manual connection (repeatable)
|
||||
#[structopt(short, long)]
|
||||
pub connect: Vec<SocketAddr>,
|
||||
/// Raft Connection slots
|
||||
#[structopt(long, default_value = "0")]
|
||||
pub slots: u32,
|
||||
#[structopt(subcommand)]
|
||||
pub command: Option<Command>,
|
||||
/// Increase verbosity
|
||||
#[structopt(short, parse(from_occurrences))]
|
||||
pub verbose: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, StructOpt)]
|
||||
#[serde(tag = "type", content = "args")]
|
||||
pub enum Command {
|
||||
/// Raft net settings
|
||||
/// Note: Wihtout passing this flag, tau will work locally
|
||||
Net(net::Settings),
|
||||
}
|
||||
|
||||
@@ -1 +1,19 @@
|
||||
# JSON-RPC listen URL
|
||||
rpc_listen="127.0.0.1:8857"
|
||||
# Sets Datastore Path
|
||||
datastore="~/.config/tau"
|
||||
|
||||
# Raft net settings
|
||||
[command]
|
||||
type="Net"
|
||||
[args]
|
||||
inbound="127.0.0.1:11002"
|
||||
outbound_connections=0
|
||||
manual_attempt_limit=0
|
||||
seed_query_timeout_seconds=8
|
||||
connect_timeout_seconds=10
|
||||
channel_handshake_seconds=4
|
||||
channel_heartbeat_seconds=10
|
||||
external_addr="127.0.0.1:11002"
|
||||
peers=["127.0.0.1:11003"]
|
||||
seeds=["127.0.0.1:11001"]
|
||||
|
||||
Reference in New Issue
Block a user