|
1 | 1 | 'use strict'
|
2 | 2 |
|
3 |
| -/* |
4 |
| - * Create an IPFS node helper |
5 |
| - */ |
6 | 3 | window.createNode = (callback) => {
|
| 4 | + // Create a new repository for IPFS in a random path always |
7 | 5 | const repoPath = '/tmp/ipfs' + Math.random()
|
8 | 6 | const node = new window.Ipfs(repoPath)
|
9 | 7 |
|
10 |
| - node.init({ emptyRepo: true, bits: 2048 }, updateConfig) |
| 8 | + // Initialize our repository with no extra files |
| 9 | + node.init({ emptyRepo: true }, updateConfig) |
11 | 10 |
|
12 | 11 | function updateConfig (err) {
|
13 |
| - if (err) { |
14 |
| - return callback(err) |
15 |
| - } |
| 12 | + if (err) return callback(err) |
16 | 13 |
|
| 14 | + // Retrieve the initialized default configuration |
17 | 15 | node.config.get((err, config) => {
|
18 |
| - if (err) { |
19 |
| - return callback(err) |
20 |
| - } |
| 16 | + if (err) return callback(err) |
| 17 | + |
| 18 | + // Add our webrtc-star address so we can find other peers easily |
21 | 19 | const signalDomain = 'star-signal.cloud.ipfs.team'
|
22 | 20 | const wstarMultiaddr = `/libp2p-webrtc-star/dns/${signalDomain}/wss/ipfs/${config.Identity.PeerID}`
|
23 |
| - |
24 | 21 | config.Addresses.Swarm = config.Addresses.Swarm.concat([ wstarMultiaddr ])
|
25 | 22 |
|
| 23 | + // Set the new configuration |
26 | 24 | node.config.replace(config, bootNode)
|
27 | 25 | })
|
28 | 26 | }
|
29 | 27 |
|
30 | 28 | function bootNode (err) {
|
31 |
| - if (err) { |
32 |
| - return callback(err) |
33 |
| - } |
| 29 | + if (err) return callback(err) |
34 | 30 |
|
35 | 31 | node.load((err) => {
|
36 |
| - if (err) { |
37 |
| - return callback(err) |
38 |
| - } |
| 32 | + if (err) return callback(err) |
39 | 33 |
|
| 34 | + // Actually start all the services and start ipfs |
40 | 35 | node.goOnline((err) => {
|
41 |
| - if (err) { |
42 |
| - return callback(err) |
43 |
| - } |
44 |
| - |
45 |
| - // console.log('IPFS node is ready') |
| 36 | + if (err) return callback(err) |
46 | 37 | callback(null, node)
|
47 | 38 | })
|
48 | 39 | })
|
|
0 commit comments