Browse Source

app/darkirc: wait for SYNC_MIN_PEERS before trying to sync

darkfi 1 ngày trước cách đây
mục cha
commit
437fae42b3
2 tập tin đã thay đổi với 13 bổ sung1 xóa
  1. 0 1
      bin/app/src/app/schema/mod.rs
  2. 13 0
      bin/app/src/plugin/darkirc.rs

+ 0 - 1
bin/app/src/app/schema/mod.rs

@@ -36,7 +36,6 @@ use crate::{
     prop::{PropertyAtomicGuard, PropertyFloat32, Role},
     scene::{SceneNodePtr, Slot},
     sfx, shape,
-    shape,
     ui::{emoji_picker, Button, Layer, Text, TextScramble, VectorArt, VectorShape, Video},
     util::i18n::I18nBabelFish,
 };

+ 13 - 0
bin/app/src/plugin/darkirc.rs

@@ -351,6 +351,19 @@ impl DarkIrc {
                 // Wait until we have enough connections
                 if peers_count < SYNC_MIN_PEERS {
                     i!("Connected to {peers_count} peers. Waiting for more connections.");
+                    let conn_sub = self.p2p.hosts().subscribe_channel().await;
+                    loop {
+                        if let Err(err) = conn_sub.receive().await {
+                            w!("Error while waiting for new connections: {err}");
+                            continue
+                        }
+
+                        if self.p2p.peers_count() >= SYNC_MIN_PEERS {
+                            break
+                        }
+                    }
+
+                    drop(conn_sub);
                     continue
                 }