-
Notifications
You must be signed in to change notification settings - Fork 51
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
fix: Enable sync with all peers for not local documents #292
base: main
Are you sure you want to change the base?
fix: Enable sync with all peers for not local documents #292
Conversation
This is a really interesting case, and one which needs consideration. A "request" for a document is essentially performed by creating an empty document and then attempting to sync that empty doc with connected peers. As a share policy of false instructs repo not to explicitly sync with other peers unless they request it, that "request" won't ever be sent. That should be a relatively simple case to fix. However, let's say you have 2 unconnected peers which both connect to a central server. This server would typically have a share policy of While I imagine receiving an explicitly requested a document from one peer might be expected behaviour, I would imagine that being able to essentially request any document from a peer anywhere on your network might not be. |
Added test with MessageChannelNetworkAdapter |
Looks like there is an |
I added it intentionally, just not to run all tests on CI for now but I can remove it if you insist |
CI won't run the tests at all if there is an |
false
false
false
@@ -90,6 +91,7 @@ export class Repo extends EventEmitter<RepoEvents> { | |||
// Try to load from disk | |||
const loadedDoc = await storageSubsystem.loadDoc(handle.documentId) | |||
if (loadedDoc) { | |||
isLocal = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is another side effect here. Let's say that we have a peer with a sharePolicy of false. If it boots up for the first time and tries to find
a document, will this now be immediately synced with all peers?
|
||
await bobDoc.whenReady() | ||
|
||
assert.equal(bobDoc.isReady(), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a test here for a 3rd peer, to show it can't find a document from across the network.
eg. alice --> bob --> charlie
Alice creates a document.
Charlie requests it. Show that it doesn't resolve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
I think this is a relatively significant problem -- we're rather cavalier with how we broadcast documentIds at the moment. If we ask someone who doesn't have a documentId if they've got it... they could make a note and just turn around and request it back. This is a problem solved by the dat / hypercore project with the idea of a discoveryKey (a hash of the document ID which is used to find peers which claim to have a document before challenging them to prove it.) We should definitely consider this in the next round of sync & auth{n,z} thinking as we upgrade the network protocol. I don't think there's going to be a great solution in the meantime. |
await eventPromise(charlieHandle, "unavailable") | ||
}) | ||
|
||
it("peers continue replicating existing documents after reload with `sharePolicy` false", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is currently failing
e61f8e3
to
d3d1a7d
Compare
Added a test with two peers (Alice, Bob)
false
for all requests.find
Fixed behavior of method
.addDocument
on synchronizer to send requests for documents we do not create