mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-03-30 15:08:28 +00:00
Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2aab9667c4 | ||
![]() |
a66c4e01bb | ||
![]() |
da1a0873fd | ||
![]() |
b5926cb972 | ||
![]() |
11c11ffe61 | ||
![]() |
494dfdb1ef | ||
![]() |
1b470fdb68 | ||
![]() |
35bf38d8d8 | ||
![]() |
c5898dd58a | ||
![]() |
8ff138de46 | ||
![]() |
3d41ab5d99 | ||
![]() |
d504e0f7ba | ||
![]() |
28b3e807de | ||
![]() |
41f015cb13 | ||
![]() |
d290032ebf | ||
![]() |
9612a61c6f | ||
![]() |
4fccfda975 | ||
![]() |
adb8d77aa2 | ||
![]() |
ed12f2b2cf | ||
![]() |
c3be1d2fac | ||
![]() |
af79cb8235 | ||
![]() |
0f062cb38d | ||
![]() |
497cf43cc7 | ||
![]() |
ff8b736ad9 | ||
![]() |
90dc85077c | ||
![]() |
4a5822c4a1 | ||
![]() |
bef35b013c | ||
![]() |
89ff328325 | ||
![]() |
d1ddc2ec98 | ||
![]() |
830902ed3d | ||
![]() |
a9dcdfdc5c | ||
![]() |
2f7a6270a8 |
4
.github/workflows/api-publish.yml
vendored
4
.github/workflows/api-publish.yml
vendored
@ -25,7 +25,7 @@ jobs:
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- run: npm ci
|
||||
- run: npm run build:docs
|
||||
- uses: actions/upload-pages-artifact@v2
|
||||
- uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: ./docs/api/
|
||||
|
||||
@ -37,5 +37,5 @@ jobs:
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v2 # or the latest "vX.X.X" version tag for this action
|
||||
uses: actions/deploy-pages@v4 # or the latest "vX.X.X" version tag for this action
|
||||
|
36
.github/workflows/run-test-node-min-ver.yml
vendored
Normal file
36
.github/workflows/run-test-node-min-ver.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
---
|
||||
name: Run Tests (Node Minimum Version)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 20
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Run linter
|
||||
run: npm run lint
|
||||
- name: Run tests
|
||||
run: npm run test:ci
|
||||
test-browser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 20
|
||||
registry-url: https://registry.npmjs.org/
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Run linter
|
||||
run: npm run lint
|
||||
- name: Run a webrtc relay in the background
|
||||
run: npm run webrtc:background
|
||||
- name: Run browser tests
|
||||
run: npm run test:browser
|
1
.well-known/funding-manifest-urls
Normal file
1
.well-known/funding-manifest-urls
Normal file
@ -0,0 +1 @@
|
||||
https://orbitdb.org/funding.json
|
@ -2,4 +2,10 @@
|
||||
|
||||
For now, please refer to our Git commit history for a list of changes.
|
||||
|
||||
https://github.com/orbitdb/orbitdb/commits/v2.4.0
|
||||
https://github.com/orbitdb/orbitdb/compare/v2.4.3...v2.5.0
|
||||
|
||||
You can also use the following git command to generate a log of changes:
|
||||
|
||||
```
|
||||
git log v2.4.3..v2.5.0 --oneline
|
||||
```
|
||||
|
@ -206,6 +206,7 @@ import { createHelia } from 'helia'
|
||||
import { createOrbitDB, IPFSAccessController } from '@orbitdb/core'
|
||||
import { LevelBlockstore } from 'blockstore-level'
|
||||
import { Libp2pOptions } from './config/libp2p.js'
|
||||
import { multiaddr } from '@multiformats/multiaddr'
|
||||
|
||||
const main = async () => {
|
||||
// create a random directory to avoid OrbitDB conflicts.
|
||||
@ -219,7 +220,9 @@ const main = async () => {
|
||||
|
||||
let db
|
||||
|
||||
if (process.argv[2]) {
|
||||
if (process.argv[2] && process.argv[3]) {
|
||||
await orbitdb.ipfs.libp2p.dial(multiaddr(process.argv[3]))
|
||||
console.log('opening db', process.argv[2])
|
||||
db = await orbitdb.open(process.argv[2])
|
||||
} else {
|
||||
// When we open a new database, write access is only available to the
|
||||
@ -230,6 +233,8 @@ const main = async () => {
|
||||
// access using grant and revoke.
|
||||
db = await orbitdb.open('my-db', { AccessController: IPFSAccessController({ write: ['*']}) })
|
||||
|
||||
console.log('libp2p address', '(copy one of these addresses then dial into this node from the second node)', orbitdb.ipfs.libp2p.getMultiaddrs())
|
||||
|
||||
// Copy this output if you want to connect a peer to another.
|
||||
console.log('my-db address', '(copy my db address and use when launching peer 2)', db.address)
|
||||
}
|
||||
@ -263,27 +268,33 @@ const main = async () => {
|
||||
main()
|
||||
```
|
||||
|
||||
Open two consoles in your command line terminal.
|
||||
Launch peer 1 from the terminal:
|
||||
|
||||
In terminal 1, run the first peer:
|
||||
|
||||
```sh
|
||||
node index.js
|
||||
```bash
|
||||
node test.js
|
||||
```
|
||||
|
||||
When running, you should see the address of the database, for example:
|
||||
Once launched you will see some output which may look something like this:
|
||||
|
||||
```sh
|
||||
```
|
||||
libp2p address (copy one of these addresses then dial into this node from the second node) [
|
||||
Multiaddr(/ip4/127.0.0.1/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF),
|
||||
Multiaddr(/ip4/192.168.1.22/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF),
|
||||
Multiaddr(/ip4/100.64.100.6/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF)
|
||||
]
|
||||
my-db address (copy my db address and use when launching peer 2) /orbitdb/zdpuB2aYUCnZ7YUBrDkCWpRLQ8ieUbqJEVRZEd5aDhJBDpBqj
|
||||
```
|
||||
|
||||
Copy the database's address from terminal 1 and, in terminal 2, run:
|
||||
It contains the libp2p address and db address. You will need both of these when connecting from peer 2.
|
||||
|
||||
```sh
|
||||
node index.js /orbitdb/zdpuB2aYUCnZ7YUBrDkCWpRLQ8ieUbqJEVRZEd5aDhJBDpBqj
|
||||
Open another terminal and launch peer 2. The command takes the form `node test.js <orbitdb-address> <libp2p-address>`
|
||||
|
||||
```bash
|
||||
node test.js /orbitdb/zdpuB2aYUCnZ7YUBrDkCWpRLQ8ieUbqJEVRZEd5aDhJBDpBqj /ip4/127.0.0.1/tcp/36161/p2p/12D3KooWKFWB78Hka2uPVNYYoXfucWp6rDLsQzr5CFiP67NAo7YF
|
||||
```
|
||||
|
||||
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.
|
||||
What is happening is the second peer is dialing the first peer on the /ip4/ address then opens the database.
|
||||
|
||||
|
||||
**PLEASE NOTE:**
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
## OrbitDB API - v2.4
|
||||
## OrbitDB API - v2.5
|
||||
|
||||
OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses IPFS
|
||||
as its data storage and Libp2p Pubsub to automatically sync databases with peers. It's an eventually consistent database that uses Merkle-CRDTs for conflict-free database writes and merges making OrbitDB an excellent choice for p2p and decentralized apps, blockchain applications and local first web applications.
|
||||
|
8662
package-lock.json
generated
8662
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orbitdb/core",
|
||||
"version": "2.4.0",
|
||||
"version": "2.5.0",
|
||||
"description": "Distributed p2p database on IPFS",
|
||||
"author": "Haad",
|
||||
"license": "MIT",
|
||||
@ -30,19 +30,17 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@chainsafe/libp2p-gossipsub": "^14.1.0",
|
||||
"@chainsafe/libp2p-yamux": "^7.0.1",
|
||||
"@helia/block-brokers": "^4.0.0",
|
||||
"@libp2p/circuit-relay-v2": "^2.1.5",
|
||||
"@libp2p/circuit-relay-v2": "^3.1.0",
|
||||
"blockstore-level": "^2.0.1",
|
||||
"c8": "^8.0.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"fs-extra": "^11.2.0",
|
||||
"helia": "^5.0.0",
|
||||
"helia": "^5.2.1",
|
||||
"it-all": "^3.0.4",
|
||||
"jsdoc": "^4.0.2",
|
||||
"mocha": "^10.2.0",
|
||||
"path-browserify": "^1.0.1",
|
||||
"playwright-test": "^14.0.0",
|
||||
"playwright-test": "^14.1.6",
|
||||
"rimraf": "^5.0.5",
|
||||
"standard": "^17.1.0",
|
||||
"webpack": "^5.89.0",
|
||||
|
@ -16,13 +16,17 @@ const ManifestStore = async ({ ipfs, storage } = {}) => {
|
||||
*/
|
||||
|
||||
storage = storage || await ComposedStorage(
|
||||
await LRUStorage({ size: 1000 }),
|
||||
await LRUStorage({ size: 100000 }),
|
||||
await IPFSBlockStorage({ ipfs, pin: true })
|
||||
)
|
||||
|
||||
const get = async (address) => {
|
||||
const bytes = await storage.get(address)
|
||||
const { value } = await Block.decode({ bytes, codec, hasher })
|
||||
if (value) {
|
||||
// Write to storage to make sure it gets pinned on IPFS
|
||||
await storage.put(address, bytes)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
|
10
src/sync.js
10
src/sync.js
@ -194,9 +194,8 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
||||
const stream = await libp2p.dialProtocol(remotePeer, headsSyncAddress, { signal })
|
||||
await pipe(sendHeads, stream, receiveHeads(peerId))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
peers.delete(peerId)
|
||||
if (e.code === 'ERR_UNSUPPORTED_PROTOCOL') {
|
||||
if (e.name === 'UnsupportedProtocolError') {
|
||||
// Skip peer, they don't have this database currently
|
||||
} else {
|
||||
events.emit('error', e)
|
||||
@ -232,6 +231,10 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handlePeerDisconnected = async event => {
|
||||
peers.delete(event.detail.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a log entry to the Sync Protocol to be sent to peers.
|
||||
* @function add
|
||||
@ -259,6 +262,7 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
||||
pubsub.removeEventListener('message', handleUpdateMessage)
|
||||
await libp2p.unhandle(headsSyncAddress)
|
||||
await pubsub.unsubscribe(address)
|
||||
libp2p.removeEventListener('peer:disconnect', handlePeerDisconnected)
|
||||
peers.clear()
|
||||
}
|
||||
}
|
||||
@ -277,6 +281,8 @@ const Sync = async ({ ipfs, log, events, onSynced, start, timeout }) => {
|
||||
pubsub.addEventListener('message', handleUpdateMessage)
|
||||
// Subscribe to the pubsub channel for this database through which updates are sent
|
||||
await pubsub.subscribe(address)
|
||||
// Remove disconnected peers from `peers`, as otherwise they will not resync heads on reconnection
|
||||
libp2p.addEventListener('peer:disconnect', handlePeerDisconnected)
|
||||
started = true
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,6 @@ const Libp2pOptions = {
|
||||
transports: [
|
||||
webSockets({
|
||||
filter: all
|
||||
}),
|
||||
webRTC(),
|
||||
circuitRelayTransport({
|
||||
discoverRelays: 1
|
||||
})
|
||||
],
|
||||
connectionEncrypters: [noise()],
|
||||
@ -43,16 +39,14 @@ const Libp2pOptions = {
|
||||
*/
|
||||
const Libp2pBrowserOptions = {
|
||||
addresses: {
|
||||
listen: ['/webrtc']
|
||||
listen: ['/webrtc', '/p2p-circuit']
|
||||
},
|
||||
transports: [
|
||||
webSockets({
|
||||
filter: all
|
||||
}),
|
||||
webRTC(),
|
||||
circuitRelayTransport({
|
||||
discoverRelays: 1
|
||||
})
|
||||
circuitRelayTransport()
|
||||
],
|
||||
connectionEncrypters: [noise()],
|
||||
streamMuxers: [yamux()],
|
||||
|
@ -32,7 +32,6 @@ const server = await createLibp2p({
|
||||
relay: circuitRelayServer({
|
||||
reservations: {
|
||||
maxReservations: 5000,
|
||||
reservationTtl: 1000,
|
||||
defaultDataLimit: BigInt(1024 * 1024 * 1024)
|
||||
}
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user