WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Muxing multiple corestores in the same stream breaks discovery key hook #45

@gmaclennan

Description

@gmaclennan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions