Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d5af577

Browse files
committed
Merge pull request #45 from ipfs/feat/bootstrap
WIP - Bootstrap feature
2 parents e47046a + 467ef34 commit d5af577

File tree

15 files changed

+353
-103
lines changed

15 files changed

+353
-103
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
**/node_modules/
22
**/*.log
3+
tests/repo-tests*
34

45
# Logs
56
logs

src/cli/commands/bootstrap/add.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const Command = require('ronin').Command
4+
const IPFS = require('../../../ipfs-core')
5+
const debug = require('debug')
6+
const log = debug('cli:version')
7+
log.error = debug('cli:version:error')
8+
9+
module.exports = Command.extend({
10+
desc: 'Show peers in the bootstrap list',
11+
12+
options: {},
13+
14+
run: (multiaddr) => {
15+
var node = new IPFS()
16+
node.bootstrap.add(multiaddr, (err, list) => {
17+
if (err) { return log.error(err) }
18+
})
19+
}
20+
})

src/cli/commands/bootstrap/list.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict'
2+
3+
const Command = require('ronin').Command
4+
const IPFS = require('../../../ipfs-core')
5+
const debug = require('debug')
6+
const log = debug('cli:version')
7+
log.error = debug('cli:version:error')
8+
9+
module.exports = Command.extend({
10+
desc: 'Show peers in the bootstrap list',
11+
12+
options: {},
13+
14+
run: (name) => {
15+
var node = new IPFS()
16+
node.bootstrap.list((err, list) => {
17+
if (err) { return log.error(err) }
18+
list.forEach(node => { console.log(node) })
19+
})
20+
}
21+
})

src/cli/commands/bootstrap/rm.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict'
2+
3+
const Command = require('ronin').Command
4+
const IPFS = require('../../../ipfs-core')
5+
const debug = require('debug')
6+
const log = debug('cli:version')
7+
log.error = debug('cli:version:error')
8+
9+
module.exports = Command.extend({
10+
desc: 'Show peers in the bootstrap list',
11+
12+
options: {},
13+
14+
run: (multiaddr) => {
15+
var node = new IPFS()
16+
node.bootstrap.rm(multiaddr, (err, list) => {
17+
if (err) { return log.error(err) }
18+
})
19+
}
20+
})

src/http-api/routes/bootstrap.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const server = require('./../index.js').server
4+
const resources = require('./../resources')
5+
6+
server.route({
7+
method: 'GET',
8+
path: '/api/v0/bootstrap',
9+
handler: resources.version.list
10+
})
11+
12+
server.route({
13+
method: 'POST',
14+
path: '/api/v0/boostrap',
15+
handler: resources.version.add
16+
})
17+
18+
server.route({
19+
method: 'DELETE',
20+
path: '/api/v0/boostrap',
21+
handler: resources.version.add
22+
})

src/ipfs-core/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ const os = require('os')
44

55
exports = module.exports
66

7-
exports.repoPath = process.env.IPFS_PATH || os.homedir() + '/.ipfs'
7+
exports.repoPath = function () {
8+
return process.env.IPFS_PATH || os.homedir() + '/.ipfs'
9+
}

src/ipfs-core/index.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function IPFS () {
1111
throw new Error('Must be instantiated with new')
1212
}
1313

14-
var repo = new IPFSRepo(config.repoPath)
14+
var repo = new IPFSRepo(config.repoPath())
1515

1616
this.daemon = callback => {
1717
// 1. read repo to get peer data
@@ -76,4 +76,38 @@ function IPFS () {
7676

7777
gc: function () {}
7878
}
79+
80+
this.bootstrap = {
81+
list: (callback) => {
82+
repo.config.get((err, config) => {
83+
if (err) { return callback(err) }
84+
callback(null, config.Bootstrap)
85+
})
86+
},
87+
add: (multiaddr, callback) => {
88+
repo.config.get((err, config) => {
89+
if (err) { return callback(err) }
90+
config.Bootstrap.push(multiaddr)
91+
repo.config.set(config, err => {
92+
if (err) { return callback(err) }
93+
94+
callback()
95+
})
96+
})
97+
},
98+
rm: (multiaddr, callback) => {
99+
repo.config.get((err, config) => {
100+
if (err) { return callback(err) }
101+
config.Bootstrap = config.Bootstrap.filter(mh => {
102+
if (mh === multiaddr) {
103+
return false
104+
} else { return true }
105+
})
106+
repo.config.set(config, err => {
107+
if (err) { return callback(err) }
108+
callback()
109+
})
110+
})
111+
}
112+
}
79113
}

tests/repo-example/config

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1 @@
1-
{
2-
"Identity": {
3-
"PeerID": "QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A",
4-
"PrivKey": "CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=="
5-
},
6-
"Datastore": {
7-
"Type": "",
8-
"Path": "",
9-
"StorageMax": "",
10-
"StorageGCWatermark": 0,
11-
"GCPeriod": "",
12-
"Params": null,
13-
"NoSync": false
14-
},
15-
"Addresses": {
16-
"Swarm": [
17-
"/ip4/0.0.0.0/tcp/4001",
18-
"/ip6/::/tcp/4001"
19-
],
20-
"API": "/ip4/127.0.0.1/tcp/5001",
21-
"Gateway": "/ip4/127.0.0.1/tcp/8080"
22-
},
23-
"Mounts": {
24-
"IPFS": "/ipfs",
25-
"IPNS": "/ipns",
26-
"FuseAllowOther": false
27-
},
28-
"Version": {
29-
"Current": "0.4.0-dev",
30-
"Check": "error",
31-
"CheckDate": "0001-01-01T00:00:00Z",
32-
"CheckPeriod": "172800000000000",
33-
"AutoUpdate": "minor"
34-
},
35-
"Discovery": {
36-
"MDNS": {
37-
"Enabled": true,
38-
"Interval": 10
39-
}
40-
},
41-
"Ipns": {
42-
"RepublishPeriod": "",
43-
"RecordLifetime": "",
44-
"ResolveCacheSize": 128
45-
},
46-
"Bootstrap": [
47-
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
48-
"/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z",
49-
"/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
50-
"/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm",
51-
"/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
52-
"/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
53-
"/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
54-
"/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3",
55-
"/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"
56-
],
57-
"Tour": {
58-
"Last": ""
59-
},
60-
"Gateway": {
61-
"HTTPHeaders": null,
62-
"RootRedirect": "",
63-
"Writable": false
64-
},
65-
"SupernodeRouting": {
66-
"Servers": [
67-
"/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U",
68-
"/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6",
69-
"/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH",
70-
"/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP",
71-
"/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R",
72-
"/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4",
73-
"/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v",
74-
"/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN"
75-
]
76-
},
77-
"API": {
78-
"HTTPHeaders": null
79-
},
80-
"Swarm": {
81-
"AddrFilters": null
82-
},
83-
"Log": {
84-
"MaxSizeMB": 250,
85-
"MaxBackups": 1,
86-
"MaxAgeDays": 0
87-
}
88-
}
1+
{"Identity":{"PeerID":"QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A","PrivKey":"CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=="},"Datastore":{"Type":"","Path":"","StorageMax":"","StorageGCWatermark":0,"GCPeriod":"","Params":null,"NoSync":false},"Addresses":{"Swarm":["/ip4/0.0.0.0/tcp/4001","/ip6/::/tcp/4001"],"API":"/ip4/127.0.0.1/tcp/5001","Gateway":"/ip4/127.0.0.1/tcp/8080"},"Mounts":{"IPFS":"/ipfs","IPNS":"/ipns","FuseAllowOther":false},"Version":{"Current":"0.4.0-dev","Check":"error","CheckDate":"0001-01-01T00:00:00Z","CheckPeriod":"172800000000000","AutoUpdate":"minor"},"Discovery":{"MDNS":{"Enabled":true,"Interval":10}},"Ipns":{"RepublishPeriod":"","RecordLifetime":"","ResolveCacheSize":128},"Bootstrap":["/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ","/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z","/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM","/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm","/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu","/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64","/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd","/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3","/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx"],"Tour":{"Last":""},"Gateway":{"HTTPHeaders":null,"RootRedirect":"","Writable":false},"SupernodeRouting":{"Servers":["/ip4/104.236.176.52/tcp/4002/ipfs/QmXdb7tWTxdFEQEFgWBqkuYSrZd3mXrC7HxkD4krGNYx2U","/ip4/104.236.179.241/tcp/4002/ipfs/QmVRqViDByUxjUMoPnjurjKvZhaEMFDtK35FJXHAM4Lkj6","/ip4/104.236.151.122/tcp/4002/ipfs/QmSZwGx8Tn8tmcM4PtDJaMeUQNRhNFdBLVGPzRiNaRJtFH","/ip4/162.243.248.213/tcp/4002/ipfs/QmbHVEEepCi7rn7VL7Exxpd2Ci9NNB6ifvqwhsrbRMgQFP","/ip4/128.199.219.111/tcp/4002/ipfs/Qmb3brdCYmKG1ycwqCbo6LUwWxTuo3FisnJV2yir7oN92R","/ip4/104.236.76.40/tcp/4002/ipfs/QmdRBCV8Cz2dGhoKLkD3YjPwVFECmqADQkx5ZteF2c6Fy4","/ip4/178.62.158.247/tcp/4002/ipfs/QmUdiMPci7YoEUBkyFZAh2pAbjqcPr7LezyiPD2artLw3v","/ip4/178.62.61.185/tcp/4002/ipfs/QmVw6fGNqBixZE4bewRLT2VXX7fAHUHs8JyidDiJ1P7RUN"]},"API":{"HTTPHeaders":null},"Swarm":{"AddrFilters":null},"Log":{"MaxSizeMB":250,"MaxBackups":1,"MaxAgeDays":0}}

tests/test-api/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,32 @@
44

55
const fs = require('fs')
66
const expect = require('chai').expect
7-
process.env.IPFS_PATH = process.cwd() + '/tests/repo-example'
87
const api = require('../../src/http-api')
8+
const ncp = require('ncp').ncp
9+
const rimraf = require('rimraf')
910

1011
describe('api', () => {
12+
const repoExample = process.cwd() + '/tests/repo-example'
13+
const repoTests = process.cwd() + '/tests/repo-tests' + Date.now()
14+
process.env.IPFS_PATH = repoTests
15+
1116
before(done => {
12-
api.start(err => {
17+
ncp(repoExample, repoTests, err => {
1318
expect(err).to.not.exist
14-
done()
19+
api.start(err => {
20+
expect(err).to.not.exist
21+
done()
22+
})
1523
})
1624
})
1725

1826
after(done => {
1927
api.stop((err) => {
2028
expect(err).to.not.exist
21-
done()
29+
rimraf(repoTests, err => {
30+
expect(err).to.not.exist
31+
done()
32+
})
2233
})
2334
})
2435

tests/test-api/test-version.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* globals describe, it */
2+
23
'use strict'
34

45
const expect = require('chai').expect

tests/test-cli-offline/index.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1-
/* globals describe */
1+
/* globals describe, before, after */
22

33
'use strict'
44

5-
var fs = require('fs')
5+
const fs = require('fs')
6+
const ncp = require('ncp').ncp
7+
const rimraf = require('rimraf')
8+
const expect = require('chai').expect
69

710
describe('cli-offline', () => {
8-
var tests = fs.readdirSync(__dirname)
11+
const repoExample = process.cwd() + '/tests/repo-example'
12+
const repoTests = process.cwd() + '/tests/repo-tests' + Date.now()
13+
14+
before(done => {
15+
ncp(repoExample, repoTests, err => {
16+
process.env.IPFS_PATH = repoTests
17+
expect(err).to.equal(null)
18+
done()
19+
})
20+
})
21+
22+
after(done => {
23+
rimraf(repoTests, err => {
24+
expect(err).to.equal(null)
25+
done()
26+
})
27+
})
28+
29+
const tests = fs.readdirSync(__dirname)
930
tests.filter(file => {
1031
if (file === 'index.js') {
1132
return false
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* globals describe, it */
2+
3+
'use strict'
4+
5+
const expect = require('chai').expect
6+
const nexpect = require('nexpect')
7+
8+
describe('bootstrap', () => {
9+
const defaultList = [
10+
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
11+
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
12+
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
13+
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
14+
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
15+
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
16+
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
17+
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
18+
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx'
19+
]
20+
21+
const updatedList = [
22+
'/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
23+
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
24+
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
25+
'/ip4/162.243.248.213/tcp/4001/ipfs/QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
26+
'/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
27+
'/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
28+
'/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
29+
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
30+
'/ip4/104.236.151.122/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
31+
'/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
32+
]
33+
34+
it('list the bootstrap nodes', done => {
35+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
36+
.run((err, stdout, exitcode) => {
37+
expect(stdout).to.deep.equal(defaultList)
38+
expect(err).to.not.exist
39+
expect(exitcode).to.equal(0)
40+
done()
41+
})
42+
})
43+
44+
it('add another bootstrap node', done => {
45+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'add', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'])
46+
.run((err, stdout, exitcode) => {
47+
expect(err).to.not.exist
48+
expect(exitcode).to.equal(0)
49+
50+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
51+
.run((err, stdout, exitcode) => {
52+
expect(stdout).to.deep.equal(updatedList)
53+
expect(err).to.not.exist
54+
expect(exitcode).to.equal(0)
55+
done()
56+
})
57+
})
58+
})
59+
60+
it('rm a bootstrap node', done => {
61+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'rm', '/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'])
62+
.run((err, stdout, exitcode) => {
63+
expect(err).to.not.exist
64+
expect(exitcode).to.equal(0)
65+
66+
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'bootstrap', 'list'])
67+
.run((err, stdout, exitcode) => {
68+
expect(stdout).to.deep.equal(defaultList)
69+
expect(err).to.not.exist
70+
expect(exitcode).to.equal(0)
71+
done()
72+
})
73+
})
74+
})
75+
})

0 commit comments

Comments
 (0)