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

Share policy prevents fetching document from sync server #346

Open
cklokmose opened this issue May 2, 2024 · 0 comments
Open

Share policy prevents fetching document from sync server #346

cklokmose opened this issue May 2, 2024 · 0 comments

Comments

@cklokmose
Copy link

Requesting a document with repo.find from a peer (e.g., a sync server) will fail if the sharePolicy doesn't return true on the peer id.
The following code reproduces the error as the document here will never load.

import * as AutomergeWasm from "@automerge/automerge-wasm"
import * as Automerge from "@automerge/automerge"
import { Repo } from "@automerge/automerge-repo"
import { IndexedDBStorageAdapter } from "@automerge/automerge-repo-storage-indexeddb"
import { BrowserWebSocketClientAdapter } from "@automerge/automerge-repo-network-websocket"

async function initializeRepo() {
    console.log("Creating repo")
    const repo = new Repo({
        storage: new IndexedDBStorageAdapter(),
        network: [new BrowserWebSocketClientAdapter(`wss://sync.automerge.org`)],
        peerId: "client-" + Math.round(Math.random() * 1000000),
        sharePolicy: async (peerId) => false,
    })

    await AutomergeWasm.promise
    return repo
}

const repo = await initializeRepo()
let handle = repo.find(`automerge:4UJNqDEtH5Eit5cs4uo1inxpMtpW`)
await handle.whenReady();
let doc = await handle.doc();
console.log("doc", doc);
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

No branches or pull requests

1 participant