A hyperswarm replacement modeled for corestore that allows
resource tracking and garbage collection.
const Corestore = require('corestore')
const Replicator = require('hyperjoin')
const store = new Corestore('./storage')
const rep = new Replicator(store, { slots: 8, maxPeers: 40 })
await rep.ready()
const session = store.session() // or namespace()
const core = session.get({ name: 'example' })
await core.ready()
const topic = Buffer.alloc(32, 0x1)
// ReplicatorSession
const rs = rep.join(session, topic, { pin: true })
await rep.refresh() // apply auto-rotation & launch topics
await store.close() // leaves topic
await rep.close()Create a topic replicator for a root corestore.
opts:
General
autoswarm: enables active topic rotation (default:true)suspended: start suspendedseed: derive the replicator keypair from a seedmaxPeers: drop connections aboveminPeers: minimum connections to keepmaxParallel: max parallel outbound dialsslots: auto-rotation slotsgcIdleTime: Evict idle sessions exceeding timedefaultDiscoveryTimeout: initial discovery lifetimeupdatedDiscoveryTimeout: shortened discovery lifetime aftersession.bump()discoveryStartupDelay: delay before discovery lookupsautoStartupDelay: delay before autoswarm announcementsminActiveTime: minimum time an autoswarmed session stays activemanual: don't launch internalrefresh()interval (default:false)interval: Auto-refresh interval (default:5000)gcDisabled: prevent garbage collection onrefresh()
Transport
keyPair: provide an explicit keypair (default: store.createKeypair)bootstrap: DHT bootstrap nodesnodes: explicit DHT nodesdht: reuse an existing HyperDHT instance, note: replicator does not close/suspend/resume borrowed dht instances.port: bind the DHT socket to a fixed portfirewall: filter inbound and outbound peersrelayThrough: relay selector for outbound connections
Fired when a session becomes active.
Fired when a session becomes inactive a.k.a idle.
Fired when a session is removed from the replicator.
Fired after GC evicts idle sessions. count is the number removed.
Can be used as signal to add more sessions through rep.join()
and update all priorities:
for (const [topic, session] of rep.sessions) {
session.priority = appTimestampOf(topic)
}
Fired after GC drops connections. count is the number dropped.
Total amount of active connections.
Amount of outbound connections in-flight.
Returns iterator over all established connections.
Returns list of active sessions.
Returns list of announced sessions that are required to be un-announced on teardown.
Resolves after dht.server port is bound and store is ready.
Join topic, returns ReplicatorSession.
opts:
priority: autoswarm prioritynumberpin: same assession.pin()discover: same assession.discover()limit: maximum peers emitted per discovery query (default:Infinity)server: whether the session can announce on the dht (default:true).
Invokes topic-rotation, applies state transitions, then finally runs garbage-collector.
Manual replicators take no actions unless refresh is called.
Wait until current discovery and dial work settles.
Enable or disable autoswarm topic rotation. Disabling un-announces all autostarted topics
Begins unannouncing all topics.
Suspend and resume discovery, server, and connection activity.
Close the replicator and all joined sessions.
Fired when a session changes state.
States:
inactivepinnedautostarteddiscoveringdestroyed
Fired when the session becomes active.
Fired when the session becomes inactive a.k.a idle.
Fired when a remote discovery bump is observed.
Fired when the session exits discovery mode.
Pin topic to announce itself on dht - bypasses priority, auto-rotation and
forces the session to be active until manual call to unpin().
Launch a dht lookup for the topic to discover peers and update version seen. (announce: false / client only)
On pinned sessions, forces a discovery refresh without unpinning.
Announce local version on topic.
If bump is called while in discovery mode, the discovery timeout is reset to
updatedDiscoveryTimeout as the discovery operation can be considered 'sucessful'
Priority used by autoswarm auto-selection.
Wait until this topic's current dht query settles
Apache-2.0