Fix Sync state

This commit is contained in:
haad 2023-03-26 08:12:27 +03:00
parent 3f138ab98b
commit 2308f01a99

View File

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