@@ -10,7 +10,6 @@ const SPDY = require('libp2p-spdy')
10
10
const KadDHT = require ( 'libp2p-kad-dht' )
11
11
const MPLEX = require ( 'pull-mplex' )
12
12
const SECIO = require ( 'libp2p-secio' )
13
- const assert = require ( 'assert' )
14
13
15
14
/**
16
15
* Options for the libp2p bundle
@@ -104,33 +103,31 @@ const libp2pBundle = (opts) => {
104
103
} )
105
104
}
106
105
107
- // Now that we have our custom libp2p bundle, let's start up the ipfs node!
108
- const node = new IPFS ( {
109
- libp2p : libp2pBundle
110
- } )
111
-
112
- // Listen for the node to start, so we can log out some metrics
113
- node . once ( 'start' , ( err ) => {
114
- assert . ifError ( err , 'Should startup without issue' )
106
+ async function main ( ) {
107
+ // Now that we have our custom libp2p bundle, let's start up the ipfs node!
108
+ const node = await IPFS . create ( {
109
+ libp2p : libp2pBundle
110
+ } )
115
111
116
112
// Lets log out the number of peers we have every 2 seconds
117
- setInterval ( ( ) => {
118
- node . swarm . peers ( ( err , peers ) => {
119
- if ( err ) {
120
- console . log ( 'An error occurred trying to check our peers:' , err )
121
- process . exit ( 1 )
122
- }
113
+ setInterval ( async ( ) => {
114
+ try {
115
+ const peers = await node . swarm . peers ( )
123
116
console . log ( `The node now has ${ peers . length } peers.` )
124
- } )
117
+ } catch ( err ) {
118
+ console . log ( 'An error occurred trying to check our peers:' , err )
119
+ }
125
120
} , 2000 )
126
121
127
122
// Log out the bandwidth stats every 4 seconds so we can see how our configuration is doing
128
- setInterval ( ( ) => {
129
- node . stats . bw ( ( err , stats ) => {
130
- if ( err ) {
131
- console . log ( 'An error occurred trying to check our stats:' , err )
132
- }
123
+ setInterval ( async ( ) => {
124
+ try {
125
+ const stats = await node . stats . bw ( )
133
126
console . log ( `\nBandwidth Stats: ${ JSON . stringify ( stats , null , 2 ) } \n` )
134
- } )
127
+ } catch ( err ) {
128
+ console . log ( 'An error occurred trying to check our stats:' , err )
129
+ }
135
130
} , 4000 )
136
- } )
131
+ }
132
+
133
+ main ( )
0 commit comments