|
|
@@ -117,14 +117,6 @@ struct Args {
|
|
|
#[structopt(long)]
|
|
|
skip_dag_sync: bool,
|
|
|
|
|
|
- /// Number of attempts to sync the DAG.
|
|
|
- #[structopt(long, default_value = "5")]
|
|
|
- sync_attempts: u8,
|
|
|
-
|
|
|
- /// Number of seconds to wait before trying again if sync fails.
|
|
|
- #[structopt(long, default_value = "10")]
|
|
|
- sync_timeout: u8,
|
|
|
-
|
|
|
/// IRC Password (Encrypted with bcrypt-2b)
|
|
|
#[structopt(long)]
|
|
|
pub password: Option<String>,
|
|
|
@@ -400,31 +392,31 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
|
|
|
info!("Starting P2P network");
|
|
|
p2p.clone().start().await?;
|
|
|
|
|
|
- info!("Waiting for some P2P connections...");
|
|
|
- sleep(5).await;
|
|
|
-
|
|
|
- // We'll attempt to sync {sync_attempts} times
|
|
|
- if !args.skip_dag_sync {
|
|
|
- for i in 1..=args.sync_attempts {
|
|
|
- info!("Syncing event DAG (attempt #{})", i);
|
|
|
- match event_graph.dag_sync().await {
|
|
|
- Ok(()) => break,
|
|
|
- Err(e) => {
|
|
|
- if i == args.sync_attempts {
|
|
|
- error!("Failed syncing DAG. Exiting.");
|
|
|
- p2p.stop().await;
|
|
|
- return Err(Error::DagSyncFailed)
|
|
|
- } else {
|
|
|
+ let comms_timeout = p2p.settings().read().await.outbound_connect_timeout;
|
|
|
+
|
|
|
+ loop {
|
|
|
+ if p2p.is_connected() {
|
|
|
+ info!("Got peer connection");
|
|
|
+ // We'll attempt to sync for ever
|
|
|
+ if !args.skip_dag_sync {
|
|
|
+ info!("Syncing event DAG");
|
|
|
+ match event_graph.dag_sync().await {
|
|
|
+ Ok(()) => break,
|
|
|
+ Err(e) => {
|
|
|
// TODO: Maybe at this point we should prune or something?
|
|
|
// TODO: Or maybe just tell the user to delete the DAG from FS.
|
|
|
- error!("Failed syncing DAG ({}), retrying in {}s...", e, args.sync_timeout);
|
|
|
- sleep(args.sync_timeout.into()).await;
|
|
|
+ error!("Failed syncing DAG ({}), retrying in {}s...", e, comms_timeout);
|
|
|
+ sleep(comms_timeout).await;
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ *event_graph.synced.write().await = true;
|
|
|
+ break
|
|
|
}
|
|
|
+ } else {
|
|
|
+ info!("Waiting for some P2P connections...");
|
|
|
+ sleep(comms_timeout).await;
|
|
|
}
|
|
|
- } else {
|
|
|
- *event_graph.synced.write().await = true;
|
|
|
}
|
|
|
|
|
|
// Signal handling for graceful termination.
|