-
Notifications
You must be signed in to change notification settings - Fork 31
Description
The docs suggest that corestore can replicate to an existing stream, e.g. a connection stream from Hyperswarm like so:
const swarm = new Hyperswarm()
// join the relevant topic
swarm.join(...)
// simply pass the connection stream to corestore
swarm.on('connection', (connection) => store.replicate(connection))This does work, however if you try to replicate any other corestore or hypercore to the stream before this, then the discovery key hook in corestore does not work, meaning that un-opened cores which exist on the peer are not replicated.
This seems to be because the Protomux stream is only created once, when the first hypercore or corestore is replicated to the stream, and the ondiscoverykey hook only works on that first replication.
I have created a failing test for this (#44) which replicates a third (unrelated) corestore to the connection stream. Removing the line results in the test passing.
This may be intended behaviour, in which case it would be helpful if the docs clarify that if you replicate to an existing stream, you can only replicate one corestore to that stream, and it must be replicated to that stream before any other hypercores.