You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 5, 2023. It is now read-only.
* docs: Update README to match new version.
* docs: Update events example to use new API.
* docs: Correctly print out db query results.
* test: Remove concurrent.
* test: Remove unimplemented and 3rd party AC tests.
* test: Remove unimplemented and 3rd party identity tests.
* docs: Move jsdoc config to conf directory.
* Point package.json main at index.js to access all exported functions.
* docs: Vetted AC docs; these examples should work if implemented in code. Explicitly show orbit-db function imports.
* docs: Fix incorrectly declared write objects.
* docs: Improved canAppend documentation. Better JS syntax highlighting.
* docs: wss and define filters for localhost separately.
* docs: Simplified webSockets implementation with filters.
* docs: Return manifest json only (no hash). JS highlighting.
* docs: Remove operations documentation.
* docs: Update heading levels.
* docs: Differentiate between db types which expose put/add function.
* docs: Correctly import IPFS and pass config.
* docs: A simple method for full db replication.
* docs: Link to existing examples of db implementation.
* docs: Update heading.
* docs: JS code formatting. import statements.
* docs: Expand on the concepts of identities and identity management.
* docs: Describe head sync-ing and full replication.
* docs: Comprehensive explanation of setting up a db and sync-ing/replicating data across peers. Examples can be run in node.js.
* docs: Syntax highlighting. Correct code implementation for custom/3rd party storage implementations.
* docs: Getting started cleanup.
* docs: Manifest as an IPLD data strcture.
const db = orbitdb.open('my-db', { AccessController: IPFSAccessController(write: ['*']) })
41
-
```
71
+
72
+
**The access information cannot be changed after the initial setup (as it is immutable).** If different write access is needed, you will need to set up a new database and associated IPFSAccessController. It is important to note that this will change the address of the database.
42
73
43
74
## OrbitDB Access Controller
44
75
45
76
The OrbitDB access controller provides configurable write access using grant and revoke.
When granting or revoking access, a capability and the identity's id must be defined.
60
99
61
100
Grant and revoke are not limited to 'write' access only. A custom access capability can be specified, for example, `db.access.grant('custom-access', identity1.id)`.
62
101
102
+
The OrbitDBAccessController is a mutable access controller. Granting and revoking access does not change the address of the database.
103
+
63
104
## Custom Access Controller
64
105
65
106
Access can be customized by implementing a custom access controller. To implement a custom access controller, specify:
66
107
67
-
- A curried function with the function signature `async ({ orbitdb, identities, address })`,
108
+
- A partial function with the function signature `async ({ orbitdb, identities, address })`,
68
109
- A `type` constant,
69
-
- A canAppend function with the param `entry`.
110
+
- A canAppend function with the param `entry` and a boolean return type.
70
111
71
-
```
112
+
The canAppend function must return true if the entry can be appended to the log or false otherwise.
// return true if the entry can be appended to the log, false otherwise.
79
122
}
80
123
}
81
124
@@ -84,7 +127,7 @@ CustomAccessController.type = type
84
127
85
128
Additional configuration can be passed to the access controller by adding one or more parameters to the `CustomAccessController` function. For example, passing a configurable object parameter with the variable `write`:
@@ -95,7 +138,7 @@ The main driver of the access controller is the canAppend function. This specifi
95
138
96
139
How the custom access controller evaluates access will be determined by its use case, but in most instances, the canAppend function will want to check whether the entry being created can be written to the database (and underlying operations log). Therefore, the entry's identity will need to be used to retrieve the identity's id:
97
140
98
-
```
141
+
```js
99
142
write = [identity.id]
100
143
101
144
constcanAppend=async (entry) => {
@@ -119,8 +162,11 @@ In the above example, the `entry.identity` will be the hash of the identity. Usi
119
162
120
163
Before passing the custom access controller to the `open` function, it must be added to OrbitDB's AccessControllers:
Copy file name to clipboardExpand all lines: docs/CONNECTING_PEERS.md
+28-18Lines changed: 28 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -7,20 +7,24 @@ OrbitDB peers connect to one another using js-libp2p. Connection settings will v
7
7
Node.js allows libp2p to open connections with other Node.js daemons.
8
8
9
9
```javascript
10
-
ipfs1 =awaitIPFS.create({ repo:'./ipfs1' })
11
-
ipfs2 =awaitIPFS.create({ repo:'./ipfs2' })
10
+
import { create } from'ipfs-core'
11
+
12
+
constipfs1=awaitcreate({ repo:'./ipfs1' })
13
+
constipfs2=awaitcreate({ repo:'./ipfs2' })
12
14
13
15
constcid=awaitipfs1.block.put('here is some data')
14
16
constblock=awaitipfs2.block.get(cid)
15
17
```
16
18
17
-
On localhost or a local network, both ipfs nodes should discover each other quickly enough that ipfs2 will retrieve the block added to ipfs1.
19
+
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.
18
20
19
-
In remote networks, retrieval of content across peers may take significantly longer. To speed up communication between the two peers, connect one peer to another directly 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:
21
+
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:
@@ -35,17 +39,17 @@ For various security reasons, a browser cannot dial another peer over a raw TCP
35
39
On the server, listen for incoming websocket connections:
36
40
37
41
```javascript
38
-
import { WebSockets } from'@libp2p/websockets'
42
+
import { webSockets } from'@libp2p/websockets'
39
43
import { create } from'ipfs-core'
40
44
41
-
ipfs1 =awaitIPFS.create({
45
+
ipfs1 =awaitcreate({
42
46
libp2p: {
43
47
addresses: {
44
48
listen: [
45
-
'/ip4/0.0.0.0/tcp/0/ws'
49
+
'/ip4/0.0.0.0/tcp/0/wss'
46
50
]
47
51
},
48
-
transports: [newWebSockets()]
52
+
transports: [webSockets()]
49
53
},
50
54
repo:'./ipfs1'
51
55
})
@@ -55,21 +59,27 @@ Within the browser, dial into the server using the server's exposed web socket:
55
59
56
60
```javascript
57
61
// import the following libraries if using a build environment such as vite.
58
-
import { WebSockets } from'@libp2p/websockets'
62
+
import { webSockets } from'@libp2p/websockets'
59
63
import { create } from'ipfs-core'
60
-
import { all } from'@libp2p/websockets/filters'
61
64
62
-
// uncomment { filter: all } if no tls certificate is deployed. Only do this in development environments.
63
-
constws=newwebSockets(/* { filter: all } */)
65
+
constws=newwebSockets()
64
66
65
-
ipfs1 =awaitIPFS.create({
67
+
ipfs1 =awaitcreate({
66
68
libp2p: {
67
-
transports: [newwebSockets()]
69
+
transports: [ws]
68
70
}},
69
71
repo:'./ipfs1'
70
72
})
71
73
```
72
74
75
+
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:
76
+
77
+
```
78
+
import { all } from '@libp2p/websockets/filters'
79
+
80
+
const ws = webSockets({ filter: all })
81
+
```
82
+
73
83
## Browser to Browser and Node Daemon to Browser
74
84
75
85
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.
@@ -86,7 +96,7 @@ In the first browser peer, configure
0 commit comments