mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Remove disconnected peers
This commit is contained in:
parent
3d41ab5d99
commit
8ff138de46
@ -231,6 +231,10 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlePeerDisconnected = async event => {
|
||||||
|
peers.delete(event.detail.toString())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a log entry to the Sync Protocol to be sent to peers.
|
* Add a log entry to the Sync Protocol to be sent to peers.
|
||||||
* @function add
|
* @function add
|
||||||
@ -258,6 +262,7 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
|||||||
pubsub.removeEventListener('message', handleUpdateMessage)
|
pubsub.removeEventListener('message', handleUpdateMessage)
|
||||||
await libp2p.unhandle(headsSyncAddress)
|
await libp2p.unhandle(headsSyncAddress)
|
||||||
await pubsub.unsubscribe(address)
|
await pubsub.unsubscribe(address)
|
||||||
|
libp2p.removeEventListener('peer:disconnect', handlePeerDisconnected);
|
||||||
peers.clear()
|
peers.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -276,6 +281,8 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
|||||||
pubsub.addEventListener('message', handleUpdateMessage)
|
pubsub.addEventListener('message', handleUpdateMessage)
|
||||||
// Subscribe to the pubsub channel for this database through which updates are sent
|
// Subscribe to the pubsub channel for this database through which updates are sent
|
||||||
await pubsub.subscribe(address)
|
await pubsub.subscribe(address)
|
||||||
|
// Remove disconnected peers from `peers`, as otherwise they will not resync heads on reconnection
|
||||||
|
libp2p.addEventListener('peer:disconnect', handlePeerDisconnected);
|
||||||
started = true
|
started = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user