Skip to content

Share policy prevents fetching document from sync server #346

Open
@cklokmose

Description

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);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions