Browse Source

darkirc: DAG sync loops for ever instead of exiting with error after {sync_attempts} times

dasman 1 year ago
parent
commit
e417fe914d
2 changed files with 19 additions and 33 deletions
  1. 0 6
      bin/darkirc/darkirc_config.toml
  2. 19 27
      bin/darkirc/src/main.rs

+ 0 - 6
bin/darkirc/darkirc_config.toml

@@ -38,12 +38,6 @@ autojoin = [
 ## (optional, but once configured, it is required from the IRC client side)
 #password = "CHANGE_ME"
 
-## Number of attempts to sync the DAG.
-#sync_attempts = 5
-
-## Number of seconds to wait before trying again if sync fails.
-#sync_timeout = 10
-
 # Log to file. Off by default.
 #log = "/tmp/darkirc.log"
 # Set log level. 1 is info (default), 2 is debug, 3 is trace

+ 19 - 27
bin/darkirc/src/main.rs

@@ -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.