This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +101
-66
lines changed Expand file tree Collapse file tree 8 files changed +101
-66
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const defaultConfig = require ( '../runtime/config-nodejs.js' )
4
+ const isMultiaddr = require ( 'mafmt' ) . IPFS . matches
5
+
6
+ function isValidMultiaddr ( ma ) {
7
+ try {
8
+ return isMultiaddr ( ma )
9
+ } catch ( err ) {
10
+ return false
11
+ }
12
+ }
13
+
14
+ module . exports = ( { repo } ) => {
15
+ return async function add ( multiaddr , options ) {
16
+ options = options || { }
17
+
18
+ if ( multiaddr && ! isValidMultiaddr ( multiaddr ) ) {
19
+ throw new Error ( `${ multiaddr } is not a valid Multiaddr` )
20
+ }
21
+
22
+ const config = await repo . config . get ( )
23
+ if ( options . default ) {
24
+ config . Bootstrap = defaultConfig ( ) . Bootstrap
25
+ } else if ( multiaddr && config . Bootstrap . indexOf ( multiaddr ) === - 1 ) {
26
+ config . Bootstrap . push ( multiaddr )
27
+ }
28
+ await repo . config . set ( config )
29
+
30
+ return {
31
+ Peers : options . default ? defaultConfig ( ) . Bootstrap : [ multiaddr ]
32
+ }
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ module . exports = ( { repo } ) => {
4
+ return async function list ( ) {
5
+ const config = await repo . config . get ( )
6
+ return { Peers : config . Bootstrap || [ ] }
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const isMultiaddr = require ( 'mafmt' ) . IPFS . matches
4
+
5
+ function isValidMultiaddr ( ma ) {
6
+ try {
7
+ return isMultiaddr ( ma )
8
+ } catch ( err ) {
9
+ return false
10
+ }
11
+ }
12
+
13
+ module . exports = ( { repo } ) => {
14
+ return async function rm ( multiaddr , options ) {
15
+ options = options || { }
16
+
17
+ if ( multiaddr && ! isValidMultiaddr ( multiaddr ) ) {
18
+ throw new Error ( `${ multiaddr } is not a valid Multiaddr` )
19
+ }
20
+
21
+ let res = [ ]
22
+ const config = await repo . config . get ( )
23
+
24
+ if ( options . all ) {
25
+ res = config . Bootstrap || [ ]
26
+ config . Bootstrap = [ ]
27
+ } else {
28
+ config . Bootstrap = ( config . Bootstrap || [ ] ) . filter ( ma => ma !== multiaddr )
29
+ }
30
+
31
+ await repo . config . set ( config )
32
+
33
+ if ( ! options . all && multiaddr ) {
34
+ res . push ( multiaddr )
35
+ }
36
+
37
+ return { Peers : res }
38
+ }
39
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,11 @@ exports.bitswap = {
6
6
unwant : require ( './bitswap/unwant' ) ,
7
7
wantlist : require ( './bitswap/wantlist' )
8
8
}
9
+ exports . bootstrap = {
10
+ add : require ( './bootstrap/add' ) ,
11
+ list : require ( './bootstrap/list' ) ,
12
+ rm : require ( './bootstrap/rm' )
13
+ }
9
14
exports . config = require ( './config' )
10
15
exports . id = require ( './id' )
11
16
exports . init = require ( './init' )
Original file line number Diff line number Diff line change @@ -314,6 +314,11 @@ function createApi ({
314
314
315
315
const api = {
316
316
add,
317
+ bootstrap : {
318
+ add : Commands . bootstrap . add ( { repo } ) ,
319
+ list : Commands . bootstrap . list ( { repo } ) ,
320
+ rm : Commands . bootstrap . rm ( { repo } )
321
+ } ,
317
322
config : Commands . config ( { repo } ) ,
318
323
id : Commands . id ( { peerInfo } ) ,
319
324
init : ( ) => { throw new AlreadyInitializedError ( ) } ,
Original file line number Diff line number Diff line change @@ -150,6 +150,11 @@ function createApi ({
150
150
unwant : Commands . bitswap . unwant ( { bitswap } ) ,
151
151
wantlist : Commands . bitswap . wantlist ( { bitswap } )
152
152
} ,
153
+ bootstrap : {
154
+ add : Commands . bootstrap . add ( { repo } ) ,
155
+ list : Commands . bootstrap . list ( { repo } ) ,
156
+ rm : Commands . bootstrap . rm ( { repo } )
157
+ } ,
153
158
config : Commands . config ( { repo } ) ,
154
159
id : Commands . id ( { peerInfo } ) ,
155
160
init : ( ) => { throw new AlreadyInitializedError ( ) } ,
Original file line number Diff line number Diff line change @@ -112,6 +112,11 @@ function createApi ({
112
112
113
113
const api = {
114
114
add,
115
+ bootstrap : {
116
+ add : Commands . bootstrap . add ( { repo } ) ,
117
+ list : Commands . bootstrap . list ( { repo } ) ,
118
+ rm : Commands . bootstrap . rm ( { repo } )
119
+ } ,
115
120
config : Commands . config ( { repo } ) ,
116
121
id : Commands . id ( { peerInfo } ) ,
117
122
init : ( ) => { throw new AlreadyInitializedError ( ) } ,
You can’t perform that action at this time.
0 commit comments