Skip to content

Commit c6dbc39

Browse files
committed
Merge branch 'master' of github.com:RangerMauve/dweb-browser
2 parents e07ae32 + 210d91e commit c6dbc39

File tree

6 files changed

+2079
-73
lines changed

6 files changed

+2079
-73
lines changed

app/config.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const USER_DATA = app.getPath('userData')
55
const DEFAULT_EXTENSIONS_DIR = path.join(USER_DATA, 'extensions')
66
const DEFAULT_IPFS_DIR = path.join(USER_DATA, 'ipfs')
77
const DEFAULT_HYPER_DIR = path.join(USER_DATA, 'hyper')
8-
// const DEFAULT_SSB_DIR = path.join(USER_DATA, 'ssb')
8+
const DEFAULT_SSB_APPNAME = 'agregore-ssb'
99
const DEFAULT_BT_DIR = path.join(USER_DATA, 'bt')
1010

1111
const DEFAULT_PAGE = 'agregore://welcome'
@@ -71,8 +71,17 @@ module.exports = require('rc')('agregore', {
7171
storage: DEFAULT_HYPER_DIR
7272
},
7373

74-
// All options here: https://github.com/ssbc/ssb-config#configuration
75-
ssbOptions: {},
74+
/**
75+
* All ssb options here: https://github.com/ssbc/ssb-config#configuration
76+
* For bundled ssb server we use ssbd. Pass in an array of require'd ssb plugins
77+
*/
78+
ssbOptions: {
79+
appname: DEFAULT_SSB_APPNAME,
80+
ssbd: {
81+
runServer: true,
82+
plugins: require('@metacentre/shipyard-ssb')
83+
}
84+
},
7685

7786
// All options here: https://github.com/webtorrent/webtorrent/blob/master/docs/api.md
7887
btOptions: {

app/protocols/ssb-protocol.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ const fetchToHandler = require('./fetch-to-handler')
33
module.exports = async function createHandler (options, session) {
44
return fetchToHandler(async () => {
55
const { makeSsbFetch } = require('ssb-fetch')
6+
const appname = process.env.ssb_appname || options.appname || 'ssb'
67

7-
const fetch = makeSsbFetch(options)
8+
/** connect to running ssb-server */
9+
if (!!options.ssbd?.runServer === false) {
10+
const fetch = makeSsbFetch({ ...options, appname })
11+
return fetch
12+
}
813

14+
/** bundle ssb-server with agregore browser */
15+
const ssbd = require('ssbd')
16+
const sbot = ssbd({ ...options, appname })
17+
const fetch = makeSsbFetch({ ...options, appname, sbot })
918
return fetch
1019
}, session)
1120
}

docs/Fetch-SSB.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
2+
# config
3+
4+
All ssb options here: <https://github.com/ssbc/ssb-config#configuration>
5+
6+
## default config
7+
8+
Agregore has this default configuration:
9+
10+
```js
11+
ssbOptions: {
12+
appname: 'agregore-ssb',
13+
ssbd: {
14+
runServer: true,
15+
plugins: require('@metacentre/shipyard-ssb')
16+
}
17+
},
18+
```
19+
20+
The ssb data directory resides at `~/.agregore-ssb`
21+
22+
## custom config
23+
24+
Custom configuration can be set in `~/.agregorerc`
25+
26+
The ssb data directory can be changed by altering `appname`.
27+
28+
To connnect to a different ssb-server, set `runServer` to false. For example:
29+
30+
```json
31+
{
32+
"ssbOptions": {
33+
"ssbd": {
34+
"appname": "ssb",
35+
"runServer": false
36+
}
37+
}
38+
}
39+
```
40+
41+
In this case `ssb-fetch` will connect to the server configured at `~/.ssb`
42+
43+
## ssb_appname env var
44+
45+
If agregore is run in an environment with `ssb_appname` set, `ssb-fetch` will use config in that directory.
46+
47+
For example, from the root directory of agregore:
48+
49+
```sh
50+
ssb_appname=ssb-test yarn start
51+
```
52+
53+
will use config at `~/.ssb-test/config`
54+
55+
# plugins
56+
57+
## default plugins list
58+
59+
ssb functionality is provided by [Secret-Stack muxrpc plugins](https://github.com/ssbc/secret-stack/blob/main/PLUGINS.md). Agregore bundles [`ssbd` an ssb daemon](https://github.com/av8ta/ssbd) with a default selection of plugins preinstalled.
60+
61+
## custom plugins list
62+
63+
Custom plugins can optionally be specified in `~/.agregorerc` instead. An absolute path is necessary.
64+
65+
```json
66+
{
67+
"ssbOptions": {
68+
"ssbd": {
69+
"plugins": ["/absolute/path/to/list/of/plugins/to/require"]
70+
}
71+
},
72+
}
73+
```
74+
75+
The list of plugins is a module exporting an array of require'd ssb plugins. Below is an example from [shipyard-ssb](https://github.com/metacentre/shipyard-ssb):
76+
77+
```js
78+
module.exports = [
79+
require('ssb-db'),
80+
require('ssb-master'),
81+
require('ssb-private1'),
82+
require('ssb-onion'),
83+
require('ssb-unix-socket'),
84+
require('ssb-no-auth'),
85+
require('ssb-gossip'),
86+
require('ssb-replicate'),
87+
require('ssb-friends'),
88+
require('ssb-blobs'),
89+
require('ssb-invite'),
90+
require('ssb-local'),
91+
require('ssb-logging'),
92+
require('ssb-query'),
93+
require('ssb-links'),
94+
require('ssb-ws'),
95+
require('ssb-ebt'),
96+
require('ssb-ooo'),
97+
]
98+
```
99+
100+
## user supplied override plugins
101+
102+
`ssbd` uses `ssb-plugins` under the hood as another way to specify plugins. These plugins will override the plugins above. They are [installed manually](https://github.com/ssbc/ssb-plugins#installing-a-user-configured-ssb-plugin-manually) to the node_modules directory in the ssb data directory. Historically in `~/.ssb/node_modules/`. In the case of agregore, in `~/.agregore-ssb/node_modules/`.
103+
104+
# config scenarios in ~/.agregorerc
105+
106+
Run bundled `ssbd` with *bundled* plugins. Data dir `~/.agregore-ssb`
107+
108+
```json
109+
{
110+
"ssbOptions": {
111+
"ssbd": {
112+
"runServer": true
113+
}
114+
}
115+
}
116+
```
117+
118+
Run bundled `ssbd` with *custom* plugins. Data dir `~/.agregore-ssb`
119+
120+
Note the absolute path to plugins
121+
122+
```json
123+
{
124+
"ssbOptions": {
125+
"ssbd": {
126+
"runServer": true,
127+
"plugins": ["/home/av8ta/.agregore-plugins/index.js"]
128+
}
129+
}
130+
}
131+
```
132+
133+
Run bundled `ssbd` with *bundled* plugins. With previously existing data dir `~/.ssb`
134+
135+
```json
136+
{
137+
"ssbOptions": {
138+
"appname": "ssb",
139+
"ssbd": {
140+
"runServer": true
141+
}
142+
}
143+
}
144+
```
145+
146+
Do *not bundle* `ssbd`. Connect to running ssb-server. Data dir `~/.ssb`
147+
148+
```json
149+
{
150+
"ssbOptions": {
151+
"appname": "ssb",
152+
"ssbd": {
153+
"runServer": false
154+
}
155+
}
156+
}
157+
```
158+
159+
Do *not bundle* `ssbd`. Attempt to pass through config & connect to running ssb-server. Data dir `~/.ssb`
160+
161+
```json
162+
{
163+
"ssbOptions": {
164+
"appname": "ssb",
165+
"npm": {
166+
"port": 8043
167+
},
168+
"ssbd": {
169+
"runServer": false
170+
}
171+
}
172+
}
173+
```
174+
175+
The npm port config here has no effect because agregore is unable to configure an already running ssb server. In cases like this, place your ssb config in the appropriate file.
176+
177+
In `~/.agregorerc`
178+
179+
```json
180+
{
181+
"ssbOptions": {
182+
"appname": "ssb",
183+
"ssbd": {
184+
"runServer": false
185+
}
186+
}
187+
}
188+
```
189+
190+
In `~/.ssb/config`
191+
192+
```json
193+
{
194+
"npm": {
195+
"port": 8043
196+
}
197+
}
198+
```

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
- [Using the fetch API with the `hyper://` protocol](Fetch-Hyper.md)
88
- [Using the fetch API with the `gemini://` protocol](Fetch-Gemini.md)
99
- [Using the fetch API with the `ipfs://` protocol](Fetch-IPFS.md)
10+
- [Using the fetch API with the `ssb://` protocol](Fetch-SSB.md)

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
"standard": "^14.3.4"
178178
},
179179
"dependencies": {
180+
"@metacentre/shipyard-ssb": "^1.2.0",
180181
"abort-controller": "^3.0.0",
181182
"bt-fetch": "^3.1.1",
182183
"create-desktop-shortcuts": "^1.7.0",
@@ -196,6 +197,7 @@
196197
"sanitize-filename": "^1.6.3",
197198
"scoped-fs": "^1.4.1",
198199
"ssb-fetch": "^1.5.2",
200+
"ssbd": "^0.0.3",
199201
"whatwg-mimetype": "https://github.com/jsdom/whatwg-mimetype#v2.3.0",
200202
"wrtc": "^0.4.7"
201203
}

0 commit comments

Comments
 (0)