The definitive replication and authorization guide
See original GitHub issueI think we need to hash out and clarify the replication and authorization processes a bit. I have been struggling with this for many days now and based on issues here I’m not alone, so I’m hoping we can use this issue to clear things up.
After reading the documentation, reading the tests, going over the code and issues, I still can’t get this right, so I think I’m not far off if I say that the whole replication process is not intuitive to implement. There are so many details to grok so let’s go over it one step at a time. The biggest issue seems to be that it’s not clear how the hyperdbs need to be set up for replication to work.
Here are two scenarios that I want to figure out, but it seems I can’t.
Scenario 1: I have hyperdb 1 that I want to read & write with hyperdb 2
My logic:
- Create 2nd hyperdb with 1st hyperdb’s
local.key
- Authorize 2nd hyperdb to write 1st hyperdb
- Create
replicate()
streams from both hyperdbs - Create socket connection between machines and do
stream1st.pipe(socket)
andsocket.pipe(stream_2nd)
That’s the structure I got from the docs etc. but it doesn’t seem to work. There’s the issue with “first hypercore must be the same” which I guess means I have to create 2nd hyperdb with hyperdb(storage, hyperdb_1st.local.key)
. With that, I can see the connection happening, but nothing gets replicated. What steps are missing here?
Scenario 2: I want to replicate another hyperdb without writing
My logic:
- Create own hyperdb with remote hyperdb’s
local.key
? - Create
replicate({ live: true })
stream for my hyperdb - Connect to remote hyperdb’s socket
- Do
socket.pipe(my_hyperdb_stream)
With this I don’t get any errors, I see data going over the socket, and I can see the data in the remote hyperdb, but nothing shows up in my hyperdb. It’s a bit like the replication doesn’t start for some reason.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8
Top GitHub Comments
Hey folks, I wrote a pretty detailed guide about authorization & replication in hyperdb. Hope it’s useful!
@0fork Your broader point about needing a guide is on point. I debugged your script and was only able to do so because I know about some gotchas.
I made a few changes but there were only two that mattered:
@hyperswarm/network
to only have one side announce and the other side lookup. That’s because hyperswarm doesn’t yet have connection deduplication builtin, and so you were getting more connections than you need. We’re either going to have dedup builtin to the code, or we’ll put that pattern in the readme once we’ve got one written.Here’s the fixed snippet: