mafintosh / mafintosh/hyperdb

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

Open
#93 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
748
Forks
56
PR merge metrics
No merged PRs in 30d

Description

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?

```javascript
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
}
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided hyperdb, webrtc-swarm, signalhub, and wrtc setup, then compare the replication stream wiring with the TCP example referenced in #19. Trace why the two databases are rejected despite using the same key; done means the same-key databases replicate without the “First shared hypercore must be the same” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
databases, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.