@@ -206,6 +206,7 @@ import { createHelia } from 'helia'
206206import { createOrbitDB , IPFSAccessController } from ' @orbitdb/core'
207207import { LevelBlockstore } from ' blockstore-level'
208208import { Libp2pOptions } from ' ./config/libp2p.js'
209+ import { multiaddr } from ' @multiformats/multiaddr'
209210
210211const main = async () => {
211212 // create a random directory to avoid OrbitDB conflicts.
@@ -219,7 +220,9 @@ const main = async () => {
219220
220221 let db
221222
222- if (process .argv [2 ]) {
223+ if (process .argv [2 ] && process .argv [3 ]) {
224+ await orbitdb .ipfs .libp2p .dial (multiaddr (process .argv [3 ]))
225+ console .log (' opening db' , process .argv [2 ])
223226 db = await orbitdb .open (process .argv [2 ])
224227 } else {
225228 // When we open a new database, write access is only available to the
@@ -230,6 +233,8 @@ const main = async () => {
230233 // access using grant and revoke.
231234 db = await orbitdb .open (' my-db' , { AccessController: IPFSAccessController ({ write: [' *' ]}) })
232235
236+ console .log (' libp2p address' , ' (copy one of these addresses then dial into this node from the second node)' , orbitdb .ipfs .libp2p .getMultiaddrs ())
237+
233238 // Copy this output if you want to connect a peer to another.
234239 console .log (' my-db address' , ' (copy my db address and use when launching peer 2)' , db .address )
235240 }
@@ -263,27 +268,33 @@ const main = async () => {
263268main ()
264269```
265270
266- Open two consoles in your command line terminal.
267-
268- In terminal 1, run the first peer:
271+ Launch peer 1 from the terminal:
269272
270- ``` sh
271- node index .js
273+ ``` bash
274+ node test .js
272275```
273276
274- When running, you should see the address of the database, for example :
277+ Once launched you will see some output which may look something like this :
275278
276- ``` sh
279+ ```
280+ libp2p address (copy one of these addresses then dial into this node from the second node) [
281+ Multiaddr(/ip4/127.0.0.1/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF),
282+ Multiaddr(/ip4/192.168.1.22/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF),
283+ Multiaddr(/ip4/100.64.100.6/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF)
284+ ]
277285my-db address (copy my db address and use when launching peer 2) /orbitdb/zdpuB2aYUCnZ7YUBrDkCWpRLQ8ieUbqJEVRZEd5aDhJBDpBqj
278286```
279287
280- Copy the database's address from terminal 1 and, in terminal 2, run:
288+ It contains the libp2p address and db address. You will need both of these when connecting from peer 2.
281289
282- ``` sh
283- node index.js /orbitdb/zdpuB2aYUCnZ7YUBrDkCWpRLQ8ieUbqJEVRZEd5aDhJBDpBqj
290+ Open another terminal and launch peer 2. The command takes the form ` node test.js <orbitdb-address> <libp2p-address> `
291+
292+ ``` bash
293+ node test.js /orbitdb/zdpuB2aYUCnZ7YUBrDkCWpRLQ8ieUbqJEVRZEd5aDhJBDpBqj /ip4/127.0.0.1/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF
284294```
285295
286- Both peers will print new records to the terminal as the log is updated. When you stop each peer using ctrl+c, the final state of the database will be printed to the terminal. They should match.
296+ What is happening is the second peer is dialing the first peer on the /ip4/ address then opens the database.
297+
287298
288299** PLEASE NOTE:**
289300
0 commit comments