This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +107
-31
lines changed Expand file tree Collapse file tree 10 files changed +107
-31
lines changed Original file line number Diff line number Diff line change 2424 },
2525 "dependencies" : {
2626 "async" : " ^2.6.0" ,
27+ "big.js" : " ^5.0.3" ,
2728 "bs58" : " ^4.0.1" ,
2829 "cids" : " ~0.5.2" ,
2930 "concat-stream" : " ^1.6.0" ,
6869 "eslint-plugin-react" : " ^7.5.1" ,
6970 "go-ipfs-dep" : " ^0.4.13" ,
7071 "gulp" : " ^3.9.1" ,
71- "interface-ipfs-core" : " ~0.43.0" ,
7272 "hapi" : " ^16.6.2" ,
73+ "interface-ipfs-core" : " ~0.47.0" ,
7374 "ipfsd-ctl" : " ~0.27.0" ,
7475 "pre-commit" : " ^1.2.2" ,
7576 "socket.io" : " ^2.0.4" ,
Original file line number Diff line number Diff line change 11'use strict'
22
33const promisify = require ( 'promisify-es6' )
4+ const Big = require ( 'big.js' )
45
56const transform = function ( res , callback ) {
67 callback ( null , {
78 provideBufLen : res . ProvideBufLen ,
8- wantlist : res . Wantlist ,
9- peers : res . Peers ,
10- blocksReceived : res . BlocksReceived ,
11- dataReceived : res . DataReceived ,
12- blocksSent : res . BlocksSent ,
13- dataSent : res . DataSent ,
14- dupBlksReceived : res . DupBlksReceived ,
15- dupDataReceived : res . DupDataReceived
9+ wantlist : res . Wantlist || [ ] ,
10+ peers : res . Peers || [ ] ,
11+ blocksReceived : new Big ( res . BlocksReceived ) ,
12+ dataReceived : new Big ( res . DataReceived ) ,
13+ blocksSent : new Big ( res . BlocksSent ) ,
14+ dataSent : new Big ( res . DataSent ) ,
15+ dupBlksReceived : new Big ( res . DupBlksReceived ) ,
16+ dupDataReceived : new Big ( res . DupDataReceived )
1617 } )
1718}
1819
Original file line number Diff line number Diff line change 11'use strict'
22
33const promisify = require ( 'promisify-es6' )
4+ const Big = require ( 'big.js' )
45
56const transform = function ( res , callback ) {
67 callback ( null , {
7- numObjects : res . NumObjects ,
8- repoSize : res . RepoSize ,
8+ numObjects : new Big ( res . NumObjects ) ,
9+ repoSize : new Big ( res . RepoSize ) ,
910 repoPath : res . RepoPath ,
1011 version : res . Version ,
11- storageMax : res . StorageMax
12+ storageMax : new Big ( res . StorageMax )
1213 } )
1314}
1415
Original file line number Diff line number Diff line change 11'use strict'
22
33const promisify = require ( 'promisify-es6' )
4+ const Big = require ( 'big.js' )
45
56const transform = function ( res , callback ) {
67 callback ( null , {
78 provideBufLen : res . ProvideBufLen ,
8- wantlist : res . Wantlist ,
9- peers : res . Peers ,
10- blocksReceived : res . BlocksReceived ,
11- dataReceived : res . DataReceived ,
12- blocksSent : res . BlocksSent ,
13- dataSent : res . DataSent ,
14- dupBlksReceived : res . DupBlksReceived ,
15- dupDataReceived : res . DupDataReceived
9+ wantlist : res . Wantlist || [ ] ,
10+ peers : res . Peers || [ ] ,
11+ blocksReceived : new Big ( res . BlocksReceived ) ,
12+ dataReceived : new Big ( res . DataReceived ) ,
13+ blocksSent : new Big ( res . BlocksSent ) ,
14+ dataSent : new Big ( res . DataSent ) ,
15+ dupBlksReceived : new Big ( res . DupBlksReceived ) ,
16+ dupDataReceived : new Big ( res . DupDataReceived )
1617 } )
1718}
1819
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const toPull = require ( 'stream-to-pull-stream' )
4+ const pull = require ( 'pull-stream' )
5+ const transformChunk = require ( './bw-util' )
6+ const deferred = require ( 'pull-defer' )
7+
8+ module . exports = ( send ) => {
9+ return ( hash , opts ) => {
10+ opts = opts || { }
11+
12+ const p = deferred . source ( )
13+
14+ send ( {
15+ path : 'stats/bw' ,
16+ qs : opts
17+ } , ( err , stream ) => {
18+ if ( err ) {
19+ return p . end ( err )
20+ }
21+
22+ p . resolve ( pull (
23+ toPull . source ( stream ) ,
24+ pull . map ( transformChunk )
25+ ) )
26+ } )
27+
28+ return p
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const Stream = require ( 'readable-stream' )
4+ const pump = require ( 'pump' )
5+ const transformChunk = require ( './bw-util' )
6+
7+ module . exports = ( send ) => {
8+ return ( hash , opts ) => {
9+ opts = opts || { }
10+
11+ const pt = new Stream . Transform ( {
12+ objectMode : true ,
13+ transform ( chunk , encoding , cb ) {
14+ cb ( null , transformChunk ( chunk ) )
15+ }
16+ } )
17+
18+ send ( {
19+ path : 'stats/bw' ,
20+ qs : opts
21+ } , ( err , stream ) => {
22+ if ( err ) {
23+ return pt . destroy ( err )
24+ }
25+
26+ pump ( stream , pt )
27+ } )
28+
29+ return pt
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const Big = require ( 'big.js' )
4+
5+ module . exports = ( chunk ) => {
6+ return {
7+ totalIn : new Big ( chunk . TotalIn ) ,
8+ totalOut : new Big ( chunk . TotalOut ) ,
9+ rateIn : new Big ( chunk . RateIn ) ,
10+ rateOut : new Big ( chunk . RateOut )
11+ }
12+ }
Original file line number Diff line number Diff line change 22
33const promisify = require ( 'promisify-es6' )
44const streamToValue = require ( '../utils/stream-to-value' )
5+ const transformChunk = require ( './bw-util' )
56
6- const transform = function ( res , callback ) {
7- streamToValue ( res , ( err , data ) => {
7+ const transform = ( res , callback ) => {
8+ return streamToValue ( res , ( err , data ) => {
89 if ( err ) {
910 return callback ( err )
1011 }
1112
12- callback ( null , {
13- totalIn : data [ 0 ] . TotalIn ,
14- totalOut : data [ 0 ] . TotalOut ,
15- rateIn : data [ 0 ] . RateIn ,
16- rateOut : data [ 0 ] . RateOut
17- } )
13+ callback ( null , transformChunk ( data [ 0 ] ) )
1814 } )
1915}
2016
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ module.exports = (arg) => {
88 return {
99 bitswap : require ( './bitswap' ) ( send ) ,
1010 bw : require ( './bw' ) ( send ) ,
11+ bwReadableStream : require ( './bw-readable-stream' ) ( send ) ,
12+ bwPullStream : require ( './bw-pull-stream' ) ( send ) ,
1113 repo : require ( './repo' ) ( send )
1214 }
1315}
Original file line number Diff line number Diff line change 11'use strict'
22
33const promisify = require ( 'promisify-es6' )
4+ const Big = require ( 'big.js' )
45
56const transform = function ( res , callback ) {
67 callback ( null , {
7- numObjects : res . NumObjects ,
8- repoSize : res . RepoSize ,
8+ numObjects : new Big ( res . NumObjects ) ,
9+ repoSize : new Big ( res . RepoSize ) ,
910 repoPath : res . RepoPath ,
1011 version : res . Version ,
11- storageMax : res . StorageMax
12+ storageMax : new Big ( res . StorageMax )
1213 } )
1314}
1415
You can’t perform that action at this time.
0 commit comments