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

Commit a34c207

Browse files
committed
Refactor create-node
1 parent fdbd17b commit a34c207

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

examples/transfer-files/complete/js/create-node.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
11
'use strict'
22

3-
/*
4-
* Create an IPFS node helper
5-
*/
63
window.createNode = (callback) => {
4+
// Create a new repository for IPFS in a random path always
75
const repoPath = '/tmp/ipfs' + Math.random()
86
const node = new window.Ipfs(repoPath)
97

10-
node.init({ emptyRepo: true, bits: 2048 }, updateConfig)
8+
// Initialize our repository with no extra files
9+
node.init({ emptyRepo: true }, updateConfig)
1110

1211
function updateConfig (err) {
13-
if (err) {
14-
return callback(err)
15-
}
12+
if (err) return callback(err)
1613

14+
// Retrieve the initialized default configuration
1715
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
2119
const signalDomain = 'star-signal.cloud.ipfs.team'
2220
const wstarMultiaddr = `/libp2p-webrtc-star/dns/${signalDomain}/wss/ipfs/${config.Identity.PeerID}`
23-
2421
config.Addresses.Swarm = config.Addresses.Swarm.concat([ wstarMultiaddr ])
2522

23+
// Set the new configuration
2624
node.config.replace(config, bootNode)
2725
})
2826
}
2927

3028
function bootNode (err) {
31-
if (err) {
32-
return callback(err)
33-
}
29+
if (err) return callback(err)
3430

3531
node.load((err) => {
36-
if (err) {
37-
return callback(err)
38-
}
32+
if (err) return callback(err)
3933

34+
// Actually start all the services and start ipfs
4035
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)
4637
callback(null, node)
4738
})
4839
})

0 commit comments

Comments
 (0)