Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negentropy + DHT Sync #19

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open

Negentropy + DHT Sync #19

wants to merge 42 commits into from

Conversation

illuzen
Copy link
Collaborator

@illuzen illuzen commented Jul 14, 2024

This PR creates a new lib subdirectory "sync" which handles the negentropy syncing between hosts and methods for putting and getting records about relays from the mainline DHT. There are new tests for both of these functions as well.

Mutable inputs "targets" to the DHT are required to be sha1(pubkey + salt), where the salt is optional and arbitrary. For our purposes we leave it empty.

We use the DHT to broadcast user's relay lists to other relays. This is triggered by kind11011 events and we periodically (every 2 hours) re-upload because that's about how long the dht will store data for us. This mostly happens in kind11011handler.go and relay-store.go. We also store the uploadables, the relays and the authors of kind11011 events in a sql database called sync_store.db.

When we are missing events in a kind1 reply, if there is a dht_key tag, then we use that to look up the relay list and try to sync with those relays on the missing-author to find the missing event. We also add those discovered relays and author to the periodic-sync list in the RelayStore object.

The negentropy code closely mirrors that of str-fry, but not exactly, since we add a couple methods for uploading and downloading missing events. Basically it takes a libp2p host and initiates a protocol like this one: https://github.com/hoytech/strfry/blob/master/docs/negentropy.md

There are several unit tests in two files, test/event_test.go which tests the negentropy syncing on a random collection of events and test/dht_test.go which tests putting and getting objects from the mainline dht. All tests should pass, although we test against the real mainline DHT so it takes a couple minutes and may fail if bit-torrent is blocked. Using a VPN seems to work.

@f7f376a1fcd0d0e11a10ed1b6577c9
Copy link
Contributor

@illuzen
Do you mind explaining what you mean by "I feel like there's something weird with the versioning" as I'm not sure what you're referring to.

I see what you mean with the deserialize event method and making graviton conform to the storage interface for negentropy, realistically we can add some additional functions for taking the event into the database as raw bytes but verifying that the event is correct is important so we are probably going to end up deserializing it and verifying them all anyway. If more data is required to be stored for the negentropy sync then it's probably best we cache it as I would think this additional data is always generated from the event data itself anyway.

Let me know if I have misunderstood anything.

@illuzen
Copy link
Collaborator Author

illuzen commented Jul 15, 2024

the go.mod has this line

github.com/illuzen/go-negentropy v0.0.0-20240505133407-a298222fce41

it just looks kind weird, the other imports don't have long hex strings after the semver

@f7f376a1fcd0d0e11a10ed1b6577c9
Copy link
Contributor

Ah yeah I wouldn't worry about that at the moment, probably a way to specify the actual version so it doesn't just v0.0.0 with the time stamp and potentially the commit id?

It's been on my list of things to look into.

@illuzen
Copy link
Collaborator Author

illuzen commented Jul 19, 2024

ok @f7f376a1fcd0d0e11a10ed1b6577c9 , made some serious progress, the main thing left to do is upload and download raw events that are identified as being missing. There are two TODOs in the code for this. Can you advise on how to do this using existing machinery if possible? Probably should use the same mechanism clients use to upload events...

also, I was thinking, should we make git commits a special kind of event? create a NIP for it? maybe you've already discussed this

@illuzen
Copy link
Collaborator Author

illuzen commented Jul 23, 2024

Ok @f7f376a1fcd0d0e11a10ed1b6577c9 I think this is done, the test passes.

@illuzen
Copy link
Collaborator Author

illuzen commented Jul 28, 2024

I'm adding dht code + tests, fyi

@illuzen
Copy link
Collaborator Author

illuzen commented Aug 6, 2024

waiting for review from @f7f376a1fcd0d0e11a10ed1b6577c9

@illuzen illuzen changed the title Negentropy [WIP] Negentropy + DHT Sync Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants