From 2308f01a99fd5b7789b8fa363f3fa63d2677603a Mon Sep 17 00:00:00 2001 From: haad Date: Sun, 26 Mar 2023 08:12:27 +0300 Subject: [PATCH] Fix Sync state --- src/sync.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sync.js b/src/sync.js index 9418c57..8d9add4 100644 --- a/src/sync.js +++ b/src/sync.js @@ -153,12 +153,14 @@ const Sync = async ({ ipfs, log, events, onSynced, start }) => { } const startSync = async () => { - // Exchange head entries with peers when connected - await ipfs.libp2p.handle(headsSyncAddress, handleReceiveHeads) - ipfs.libp2p.pubsub.addEventListener('subscription-change', handlePeerSubscribed) - // Subscribe to the pubsub channel for this database through which updates are sent - await ipfs.pubsub.subscribe(address, handleUpdateMessage) - started = true + if (!started) { + // Exchange head entries with peers when connected + await ipfs.libp2p.handle(headsSyncAddress, handleReceiveHeads) + ipfs.libp2p.pubsub.addEventListener('subscription-change', handlePeerSubscribed) + // Subscribe to the pubsub channel for this database through which updates are sent + await ipfs.pubsub.subscribe(address, handleUpdateMessage) + started = true + } } // Start Sync automatically