question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"First shared hypercore must be the same" when trying to replicate via webrtc.

See original GitHub issue

I’m trying to replicate a db over webrtc-swarm and always running into the dreaded “First shared hypercore must be the same” message.

Below is the code I am trying to use. I use the same key for both dbs, and as far as i can tell i am looping both replication streams similarly to the tcp example in #19 .

Does anyone notice anything I’m doing wrong?

const wrtc = require('wrtc')
const swarm = require('webrtc-swarm')

const signalhub = require('signalhub')
const hyperdb = require('hyperdb')

const db1 = init_db('./db1', { valueEncoding: 'utf-8' })

db1.on('ready', () => {
    const db2 = init_db('./db2', db1.key, { valueEncoding: 'utf-8' })
    db2.on('ready', () => {
        db1.put('/hello', 'world', () => {
            init_swarm(db1, (hub) => {
                return swarm(hub, {
                    wrtc: wrtc
                })
            })
            init_swarm(db2, (hub) => {
                return swarm(hub, {
                    wrtc: wrtc
                })
            })
        })

    })
})

function init_swarm(db, swarmfn) {
    const hub = signalhub('freemate', ['https://signalhub.mafintosh.com'])

    const sw = swarmfn(hub)

    sw.on('peer', (peer, id) => {
        console.log('found peer')
        const repstream = db.replicate()
        peer.on('data', (data) => {
            console.log('id: ', id, ' got data: ', data)
        })
        repstream.pipe(peer).pipe(repstream)
        peer.once('finish', (err) => console.log(err))
        peer.once('error', (err) => console.log(err))
    })

    return sw
}

function init_db(location) {
    const db = hyperdb(location, { valueEncoding: 'utf-8' })
    return db
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
micahscopescommented, May 18, 2018

@peacememories once you figure this out, I’d love to see your example!

0reactions
mafintoshcommented, Apr 8, 2018

@peacememories it’s part of the capability system and to have a joint discovery key. the first one to create the db, becomes the source. this simply means that the discoveryKey of the first one is the discovery key for the db forever. the first writer can disappear though without any issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with dat project's hyperdb in browser with webrtc and ...
I'm trying to use hyperdb in browser with swarming via webrtc and signalhub. The code is pretty strait forward, but there is some...
Read more >
Yjs/community - Gitter
Hi all, how is it possible to get a CodeMirror example working using WebRTC instead of WebSockets? This is my first node project...
Read more >
Dripline: Check the specs: final thoughts on p2p options
One metric that's useful to consider when choosing protocols is overall performance. What feels “fast” when a user tries to load data? How...
Read more >
p2p Databases - Hyperbee - workshop
BitTorrent lets you download large files in pieces from different ... WebRTC enables browsers to share video, audio, and data between ...
Read more >
Data Architecture | community - GitHub Pages
How is Hypercore different from BitTorrent, WebTorrent? ... Using Hypercore data structures community produced replicated databases KappaDB and multi- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found