From 6501ec6fa74c2eada255eff3b1b5c18ee90d355e Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Fri, 15 Dec 2023 23:10:24 +0000 Subject: [PATCH] docs: Remove references "lazy loading" during replication. All values are now replicated when entries are replicated via joinEntry. --- docs/ACCESS_CONTROLLERS.md | 32 +++-- docs/CONNECTING_PEERS.md | 246 ++++++++++++++++++++++++++++++------- docs/DATABASES.md | 29 +++-- docs/GETTING_STARTED.md | 37 +++--- docs/IDENTITIES.md | 8 +- docs/REPLICATION.md | 49 ++------ src/sync.js | 16 +-- 7 files changed, 280 insertions(+), 137 deletions(-) diff --git a/docs/ACCESS_CONTROLLERS.md b/docs/ACCESS_CONTROLLERS.md index 68ca9a4..1059403 100644 --- a/docs/ACCESS_CONTROLLERS.md +++ b/docs/ACCESS_CONTROLLERS.md @@ -7,11 +7,13 @@ An access controller is passed when a database is opened for the first time. Onc Different access controllers can be assigned to the database using the `AccessController` param and passing it to OrbitDB's `open` function. ```js -import { create } from 'ipfs-core' -import { createOrbitDB } from '@orbitdb/core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { createOrbitDB, DefaultLibp2pOptions } from '@orbitdb/core' import * as SomeAccessController from 'some-access-controller.js' -const ipfs = create({ options }) +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) const orbitdb = await createOrbitDB({ ipfs }) @@ -34,10 +36,12 @@ await db.add('hello world') // only orbitdb.identity.id can write to the db. To change write access, pass the IPFSAccessController with the `write` parameter and an array of one or more Identity ids: ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB, Identities, IPFSAccessController } from '@orbitdb/core' -const ipfs = create({ options }) +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) const identities = await Identities() const anotherIdentity = identities.createIdentity('userB') @@ -52,10 +56,12 @@ const db = orbitdb.open('my-db', { AccessController: IPFSAccessController({ writ To allow anyone to write to the database, specify the wildcard '*': ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB, Identities, IPFSAccessController } from '@orbitdb/core' -const ipfs = create({ options }) +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) const orbitdb = await createOrbitDB({ ipfs }) @@ -69,10 +75,12 @@ const db = orbitdb.open('my-db', { AccessController: IPFSAccessController({ writ The OrbitDB access controller provides configurable write access using grant and revoke. ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB, Identities, OrbitDBAccessController } from '@orbitdb/core' -const ipfs = create({ options }) +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) const orbitdb = await createOrbitDB({ ipfs }) @@ -155,9 +163,13 @@ In the above example, the `entry.identity` will be the hash of the identity. Usi Before passing the custom access controller to the `open` function, it must be added to OrbitDB's AccessControllers: ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB, useAccessController } from '@orbitdb/core' +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) + useAccessController(CustomAccessController) const orbitdb = await createOrbitDB({ ipfs }) const db = await orbitdb.open('my-db', { AccessController: CustomAccessController(params) }) diff --git a/docs/CONNECTING_PEERS.md b/docs/CONNECTING_PEERS.md index eec8216..05d36db 100644 --- a/docs/CONNECTING_PEERS.md +++ b/docs/CONNECTING_PEERS.md @@ -7,10 +7,16 @@ OrbitDB peers connect to one another using js-libp2p. Connection settings will v Node.js allows libp2p to open connections with other Node.js daemons. ```javascript -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' -const ipfs1 = await create({ repo: './ipfs1' }) -const ipfs2 = await create({ repo: './ipfs2' }) +const initIPFSInstance = () => { + const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) + return createHelia({ libp2p }) +} + +const ipfs1 = await initIPFSInstance() +const ipfs2 = await initIPFSInstance() const cid = await ipfs1.block.put('here is some data') const block = await ipfs2.block.get(cid) @@ -18,15 +24,22 @@ const block = await ipfs2.block.get(cid) On localhost or a local network, both ipfs nodes should discover each other quickly enough so that ipfs2 will retrieve the block added to ipfs1. -In remote networks, retrieval of content across peers may take significantly longer. To speed up communication between the two peers, one peer can be directly connected to another using the swarm API and a peer's publicly accessible address. For example, assuming ipfs1 is listening on the address /ip4/1.2.3.4/tcp/12345/p2p/ipfs1-peer-hash: +In remote networks, retrieval of content across peers may take significantly longer. To speed up communication between the two peers, one peer can be directly connected to another using libp2p's dial function: ```javascript -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' -const ipfs1 = await create({ repo: './ipfs1' }) -const ipfs2 = await create({ repo: './ipfs2' }) +const initIPFSInstance = () => { + const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) + return createHelia({ libp2p }) +} -await ipfs2.swarm.connect('/ip4/1.2.3.4/tcp/12345/p2p/ipfs1-peer-hash') +const ipfs1 = await initIPFSInstance() +const ipfs2 = await initIPFSInstance() + +await ipfs2.libp2p.save(ipfs1.libp2p.peerId, { multiaddr: ipfs1.libp2p.getMultiaddrs() }) +await ipfs2.libp2p.dial(ipfs1.libp2p.peerId) const cid = await ipfs1.block.put('here is some data') const block = await ipfs2.block.get(cid) @@ -39,40 +52,83 @@ For various security reasons, a browser cannot dial another peer over a raw TCP On the server, listen for incoming websocket connections: ```javascript +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { yamux } from '@chainsafe/libp2p-yamux' +import { noise } from '@chainsafe/libp2p-noise' +import { identifyService } from 'libp2p/identify' +import { circuitRelayServer} from 'libp2p/circuit-relay' import { webSockets } from '@libp2p/websockets' -import { create } from 'ipfs-core' +import * as filters from '@libp2p/websockets/filters' -ipfs1 = await create({ - libp2p: { - addresses: { - listen: [ - '/ip4/0.0.0.0/tcp/0/wss' - ] - }, - transports: [webSockets()] +const options = { + addresses: { + listen: ['/ip4/0.0.0.0/tcp/12345/ws'] }, - repo: './ipfs1' -}) + transports: [ + webSockets({ + filter: filters.all + }) + ], + connectionEncryption: [noise()], + streamMuxers: [yamux()], + services: { + identify: identifyService(), + relay: circuitRelayServer() + } +} + +const libp2p = createLibp2p(options) +const ipfs1 = await createHelia({ libp2p }) ``` Within the browser, dial into the server using the server's exposed web socket: ```javascript // import the following libraries if using a build environment such as vite. +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { yamux } from '@chainsafe/libp2p-yamux' +import { identifyService } from 'libp2p/identify' import { webSockets } from '@libp2p/websockets' -import { create } from 'ipfs-core' +import { webRTC } from '@libp2p/webrtc' +import { noise } from '@chainsafe/libp2p-noise' +import { circuitRelayTransport } from 'libp2p/circuit-relay' const ws = new webSockets() -ipfs1 = await create({ - libp2p: { - transports: [ws] - }}, - repo: './ipfs1' -}) +const options = { + addresses: { + listen: [ + '/webrtc' + ] + }, + transports: [ + webSockets({ + filter: all + }), + webRTC(), + circuitRelayTransport({ + discoverRelays: 1 + }) + ], + connectionEncryption: [noise()], + streamMuxers: [yamux()], + connectionGater: { + denyDialMultiaddr: () => { + return false + } + }, + services: { + identify: identifyService() + } +} + +const libp2p = createLibp2p(options) +const ipfs1 = await createHelia({ libp2p }) ``` -You may find IPFS is unable to connect to a local WebRTC Star server. This will likely to due to the local WebSockets transport being insecure (ws instead of wss). To solve this issue, pass the `all` filter to the `webSockets` function: +You may find IPFS is unable to connect to a local WebRTC relay. This is likely due to the local WebSockets transport being insecure (ws instead of wss). This issue should be solvable by passing the `all` filter to the `webSockets` function (remove this in production environments): ``` import { all } from '@libp2p/websockets/filters' @@ -84,42 +140,142 @@ const ws = webSockets({ filter: all }) A connection cannot be made directly to a browser node. Browsers do not listen for incoming connections, they operate in a server/client environment where the server address is known and the browser connects to the server using the known address. Therefore, for a browser to respond to an incoming connection a relay is required to "listen" on the browser's behalf. The relay assigns and advertises multi addresses on behalf of the browser nodes, allowing the nodes to create a direct connection between each other. -Peer to peer connections where another peer connects to a browser node can use WebRTC as the transport protocol. A signalling server is required to facilitate the discovery of a node and establish a direct connection to another node. +Peer to peer connections where another peer connects to a browser node can use WebRTC as the transport protocol. A relay server is required to facilitate the discovery of a node and establish a direct connection to another node. -Details on how to [deploy a WebRTC signalling server](https://github.com/libp2p/js-libp2p-webrtc-star/tree/master/packages/webrtc-star-signalling-server) are provided by the libp2p project. +Details on how to [deploy a relay server](https://github.com/libp2p/js-libp2p-examples/tree/main/examples/js-libp2p-example-circuit-relay) are provided by the libp2p-examples project. -To connect two nodes via a relay, the IPFS swarm address should match the address of the signalling server. +To connect two nodes via a relay, dial the relay from the first browser node. Once the first browser node's address is known, use this to dial the first browser node from the second browser node. -In the first browser peer, configure +In the first browser peer, dial the relay to discover the browser peer's address: ```javascript -import { create } from 'ipfs-core' -import { multiaddr } from 'multiaddr' +// import the following libraries if using a build environment such as vite. +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { yamux } from '@chainsafe/libp2p-yamux' +import { identifyService } from 'libp2p/identify' +import { webSockets } from '@libp2p/websockets' +import { webRTC } from '@libp2p/webrtc' +import { noise } from '@chainsafe/libp2p-noise' +import { circuitRelayTransport } from 'libp2p/circuit-relay' +import { multiaddr } from '@multiformats/multiaddr' +import { WebRTC as WebRTCMatcher } from '@multiformats/multiaddr-matcher' +import pRetry from 'p-retry' +import delay from 'delay' -ipfs = await create({ - config: { - Addresses: { - Swarm: ['/ip4/0.0.0.0/tcp/12345/ws/p2p-webrtc-star'] +const options = { + addresses: { + listen: [ + '/webrtc' + ] + }, + transports: [ + webSockets({ + filter: all + }), + webRTC(), + circuitRelayTransport({ + discoverRelays: 1 + }) + ], + connectionEncryption: [noise()], + streamMuxers: [yamux()], + connectionGater: { + denyDialMultiaddr: () => { + return false } + }, + services: { + identify: identifyService() } +} + +const libp2p = createLibp2p(options) +const ipfs1 = await createHelia({ libp2p }) + +/*The creation and deployment of a circuit relay is not covered in this documentation. However, you can use the one bundled with the OrbitDB unit tests by cloning the OrbitDB repository, installing the dependencies and then running `npm run webrtc` from the OrbitDB project's root dir. Once running, the webrtc relay server will print a number of addresses it is listening on. Use the address /ip4/127.0.0.1/tcp/12345/ws/p2p when specifying the relay for browser 1. +*/ +const relay = '/ip4/127.0.0.1/tcp/12345/ws/p2p' // the address of the relay server. Change this if you are not using the OrbitDB-bundled webrtc relay. + +await ipfs1.libp2p.dial(multiaddr(relay)) + +const a1 = await pRetry(async () => { + const addr = ipfs1.libp2p.getMultiaddrs().filter(ma => WebRTCMatcher.matches(ma)).pop() + + if (addr == null) { + await delay(10) + throw new Error('No WebRTC address found') + } + + return addr }) + +console.log('ipfs1 address discovered: ', a1) ``` -Configure the second browser node in the same way as the first, then dial in to the first browser peer using its multiaddress: +Configure the second browser node in the same way as the first, then dial in to the first browser peer using the "ipfs1 address discovered": ```javascript -import { create } from 'ipfs-core' -import { multiaddr } from 'multiaddr' +// import the following libraries if using a build environment such as vite. +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { yamux } from '@chainsafe/libp2p-yamux' +import { identifyService } from 'libp2p/identify' +import { webSockets } from '@libp2p/websockets' +import { webRTC } from '@libp2p/webrtc' +import { noise } from '@chainsafe/libp2p-noise' +import { circuitRelayTransport } from 'libp2p/circuit-relay' +import { multiaddr } from '@multiformats/multiaddr' +import { WebRTC as WebRTCMatcher } from '@multiformats/multiaddr-matcher' +import pRetry from 'p-retry' +import delay from 'delay' -ipfs = await create({ - config: { - Addresses: { - Swarm: ['/ip4/0.0.0.0/tcp/12345/ws/p2p-webrtc-star'] +const options = { + addresses: { + listen: [ + '/webrtc' + ] + }, + transports: [ + webSockets({ + filter: all + }), + webRTC(), + circuitRelayTransport({ + discoverRelays: 1 + }) + ], + connectionEncryption: [noise()], + streamMuxers: [yamux()], + connectionGater: { + denyDialMultiaddr: () => { + return false } + }, + services: { + identify: identifyService() } +} + +const libp2p = createLibp2p(options) +const ipfs1 = await createHelia({ libp2p }) + +const ipfs1Address = '' // paste the "ipfs1 address discovered:" value here. + +await ipfs1.libp2p.dial(multiaddr(ipfs1Address)) + +const a2 = await pRetry(async () => { + const addr = ipfs2.libp2p.getMultiaddrs().filter(ma => WebRTCMatcher.matches(ma)).pop() + + if (addr == null) { + await delay(10) + throw new Error('No WebRTC address found') + } + + return addr }) -await ipfs.swarm.connect('/multiaddr/of/first-peer') +console.log('ipfs2 address discovered: ', a2) ``` ## Further Reading diff --git a/docs/DATABASES.md b/docs/DATABASES.md index 2900fc3..ff19b87 100644 --- a/docs/DATABASES.md +++ b/docs/DATABASES.md @@ -35,10 +35,13 @@ The second part, an IPFS multihash `zdpuAmrcSRUhkQcnRQ6p4bphs7DJWGBkqczSGFYynX6m In order to replicate the database with peers, the address is what you need to give to other peers in order for them to start replicating the database. ```js -import IPFS from 'ipfs-core' -import { createOrbitDB } from '@orbitdb/core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { createOrbitDB, DefaultLibp2pOptions } from '@orbitdb/core' + +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) -const ipfs = await IPFS.create() const orbitdb = await createOrbitDB({ ipfs }) const db = await orbitdb.open('my-db') console.log(db.address) @@ -62,15 +65,17 @@ An example of a manifest is given below: The manifest is an [IPLD data structure](https://ipld.io/docs/) which can be retrived from IPFS using the manifest's hash: ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import * as Block from 'multiformats/block' -import { createOrbitDB, OrbitDBAddress } from '@orbitdb/core' +import { createOrbitDB, OrbitDBAddress, DefaultLibp2pOptions } from '@orbitdb/core' import * as dagCbor from '@ipld/dag-cbor' import { sha256 } from 'multiformats/hashes/sha2' import { base58btc } from 'multiformats/bases/base58' import { CID } from 'multiformats/cid' -const ipfs = await create() +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) // Create the db then close. const orbitdb = await createOrbitDB({ ipfs }) @@ -172,11 +177,17 @@ The power of OrbitDB lies in its ability to replicate databases across distribut A simple way to replicate a database between peers can be accomplished by opening a database, listening for updates and iterating over the records as those updates occur. ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB } from '@orbitdb/core' -const ipfs1 = await create({ config1, repo: './ipfs1' }) -const ipfs2 = await create({ config2, repo: './ipfs2' }) +const initIPFSInstance = () => { + const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) + return createHelia({ libp2p }) +} + +const ipfs1 = await initIPFSInstance() +const ipfs2 = await initIPFSInstance() orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) diff --git a/docs/GETTING_STARTED.md b/docs/GETTING_STARTED.md index ac9bd53..37725f8 100644 --- a/docs/GETTING_STARTED.md +++ b/docs/GETTING_STARTED.md @@ -10,10 +10,10 @@ Install OrbitDB: npm i @orbitdb/core ``` -You will also need IPFS for replication: +You will also need Helia for replication: ```sh -npm i ipfs-core +npm i helia ``` ## Creating a standalone database @@ -31,11 +31,13 @@ npm init Create a file in your project called index.js and add the following code to it: ```js +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB } from '@orbitdb/core' -import { create } from 'ipfs-core' // Create an IPFS instance with defaults. -const ipfs = await create() +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) const orbitdb = await createOrbitDB({ ipfs }) @@ -117,27 +119,18 @@ npm init Create a new file called index.js and paste in the following code: ```js -import { OrbitDB, IPFSAccessController } from '@orbitdb/core' -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' +import { OrbitDB, IPFSAccessController, DefaultLibp2pBrowserOptions } from '@orbitdb/core' -const main = async () => { - // create a random directory to avoid IPFS and OrbitDB conflicts. +const main = async () => { + const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) + const ipfs = await createHelia({ libp2p }) + + // create a random directory to avoid OrbitDB conflicts. let randDir = (Math.random() + 1).toString(36).substring(2) - const config = { - Addresses: { - API: '/ip4/127.0.0.1/tcp/0', - Swarm: ['/ip4/0.0.0.0/tcp/0'], - Gateway: '/ip4/0.0.0.0/tcp/0' - } - } - - // This will create an IPFS repo in ./[randDir]/ipfs. - const ipfs = await create({ config, repo: './' + randDir + '/ipfs'}) - - // This will create all OrbitDB-related databases (keystore, my-db, etc) in - // ./[randDir]/ipfs. - const orbitdb = await createOrbitDB({ ipfs, directory: './' + randDir + '/orbitdb' }) + const orbitdb = await createOrbitDB({ ipfs, directory: `./${randDir}/orbitdb` }) let db diff --git a/docs/IDENTITIES.md b/docs/IDENTITIES.md index 7ddfb14..365fde4 100644 --- a/docs/IDENTITIES.md +++ b/docs/IDENTITIES.md @@ -88,15 +88,17 @@ const identities = await Identities({ path }) The identity object is stored like any other [IPLD data structure](https://ipld.io/docs/) and can therefore be retrieved from IPFS using the identity's hash: ```js -import { create } from 'ipfs-core' +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' from 'ipfs-core' import * as Block from 'multiformats/block' -import { Identities } from '@orbitdb/core' +import { Identities, DefaultLibp2pOptions } from '@orbitdb/core' import * as dagCbor from '@ipld/dag-cbor' import { sha256 } from 'multiformats/hashes/sha2' import { base58btc } from 'multiformats/bases/base58' import { CID } from 'multiformats/cid' -const ipfs = await create() +const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) +const ipfs = await createHelia({ libp2p }) const identities = await Identities({ ipfs }) const identity = await identities.createIdentity({ id: 'me' }) diff --git a/docs/REPLICATION.md b/docs/REPLICATION.md index 8f53212..d2bf023 100644 --- a/docs/REPLICATION.md +++ b/docs/REPLICATION.md @@ -3,49 +3,27 @@ Below is a simple replication example. Both peers run within the same Nodejs process. ```js +import { createLibp2p } from 'libp2p' +import { createHelia } from 'helia' import { createOrbitDB } from '@orbitdb/core' -import { create } from 'ipfs-core' -// The config will set up a TCP connection when dialling other node.js peers. -// You can find out more about peer connectivity at https://connectivity.libp2p.io/. -const config1 = { - Addresses: { - API: '/ip4/127.0.0.1/tcp/0', - Swarm: ['/ip4/0.0.0.0/tcp/0'], - Gateway: '/ip4/0.0.0.0/tcp/0' - }, - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: true, - Interval: 0 - } - } +// Our ipfs instances will be connecting over websockets. However, you could achieve the same here using tcp. You can find out more about peer connectivity at https://connectivity.libp2p.io/. + +const initIPFSInstance = () => { + const libp2p = await createLibp2p({ ...DefaultLibp2pOptions }) + return createHelia({ libp2p }) } -const config2 = { - Addresses: { - API: '/ip4/127.0.0.1/tcp/0', - Swarm: ['/ip4/0.0.0.0/tcp/0'], - Gateway: '/ip4/0.0.0.0/tcp/0' - }, - Bootstrap: [], - Discovery: { - MDNS: { - Enabled: true, - Interval: 0 - } - } -} - -const ipfs1 = await create({ config: config1, repo: './ipfs/1' }) -const ipfs2 = await create({ config: config2, repo: './ipfs/2' }) +const ipfs1 = await initIPFSInstance() +const ipfs2 = await initIPFSInstance() // The decentralized nature if IPFS can make it slow for peers to find one // another. You can speed up a connection between two peers by "dialling-in" // to one peer from another. -// const ipfs1PeerId = await ipfs1.id() -// await ipfs2.swarm.connect(ipfs1PeerId.id) +/* +await ipfs2.libp2p.save(ipfs1.libp2p.peerId, { multiaddr: ipfs1.libp2p.getMultiaddrs() }) +await ipfs2.libp2p.dial(ipfs1.libp2p.peerId) +*/ const orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'userA', directory: './orbitdb/1' }) const orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'userB', directory: './orbitdb/2' }) @@ -79,7 +57,6 @@ db2.events.on('join', async (peerId, heads) => { // new heads that are available on db1. // If we want to listen for new data on db2, add an "update" listener to db1. db2.events.on('update', async (entry) => { - // Full replication is achieved by explicitly retrieving all records from db1. console.log(await db2.all()) db2Updated = true }) diff --git a/src/sync.js b/src/sync.js index 9d9faa8..7fd9d56 100644 --- a/src/sync.js +++ b/src/sync.js @@ -23,12 +23,10 @@ const DefaultTimeout = 30000 // 30 seconds * * Once the initial sync has completed, peers notify one another of updates to * the log, ie. updates to the database, using the initially opened pubsub - * topic subscription. - * A peer with new heads broadcasts changes to other peers by publishing the - * updated heads - * to the pubsub topic. Peers subscribed to the same topic will then receive - * the update and - * will update their log's state, the heads, accordingly. + * topic subscription. A peer with new heads broadcasts changes to other peers + * by publishing the updated heads to the pubsub topic. Peers subscribed to the + * same topic will then receive the update and will update their log's state, + * the heads, accordingly. * * The Sync Protocol is eventually consistent. It guarantees that once all * messages have been sent and received, peers will observe the same log state @@ -36,12 +34,6 @@ const DefaultTimeout = 30000 // 30 seconds * are received or even that a message is recieved at all, nor any timing on * when messages are received. * - * Note that the Sync Protocol does not retrieve the full log when - * synchronizing the heads. Rather only the "latest entries" in the log, the - * heads, are exchanged. In order to retrieve the full log and each entry, the - * user would call the log.traverse() or log.iterator() functions, which go - * through the log and retrieve each missing log entry from IPFS. - * * @example * // Using defaults * const sync = await Sync({ ipfs, log, onSynced: (peerId, heads) => ... })