@@ -26,29 +26,54 @@ export class HyperStructInfoTracker {
26
26
}
27
27
28
28
genStatusLine ( ) {
29
- var netCfg = 'Not swarming'
30
- if ( this . netCfg ) {
31
- if ( this . netCfg . announce ) netCfg = `Announced to seed`
32
- else if ( this . netCfg . lookup ) netCfg = `Watching for announced seeders`
33
- }
29
+ var netCfg = this . genStatusNetCfg ( )
34
30
if ( ! this . struct ) {
35
- return `${ chalk . bold ( short ( this . keyStr ) ) } : ${ netCfg } `
31
+ return `${ this . genStatusIdent ( ) } : ${ netCfg } `
36
32
}
37
33
38
- var stats = this . netStats
39
- var dl = bytes ( stats . download [ stats . download . length - 1 ] , { unitSeparator : ' ' } )
40
- var ul = bytes ( stats . upload [ stats . download . length - 1 ] , { unitSeparator : ' ' } )
41
34
return `
42
- ${ chalk . bold ( short ( this . keyStr ) ) } (${ chalk . bold ( this . struct . type ) } ):
43
- ${ this . peers . length } connected |
44
- ${ typeof this . totalBlocks !== 'undefined'
45
- ? `${ this . totalBlocks ? Math . round ( this . downloadedBlocks / this . totalBlocks * 100 ) : 100 } % downloaded (${ bytes ( this . size ) } total)`
46
- : 'Calculating...' }
47
- [↓${ dl } /s ↑${ ul } /s]
35
+ ${ this . genStatusIdent ( ) } :
36
+ ${ this . genStatusPeerCount ( ) } |
37
+ ${ this . genStatusPctDownloaded ( ) }
38
+ ${ this . genStatusNetStats ( ) }
48
39
- ${ netCfg }
49
40
` . split ( '\n' ) . map ( s => s . trim ( ) ) . join ( ' ' )
50
41
}
51
42
43
+ genStatusIdent ( long = false ) {
44
+ if ( ! this . struct ) return `${ chalk . bold ( maybeShort ( this . keyStr , ! long ) ) } `
45
+ return `${ chalk . bold ( maybeShort ( this . keyStr , ! long ) ) } (${ chalk . bold ( this . struct . type ) } )`
46
+ }
47
+
48
+ genStatusPeerCount ( ) {
49
+ return `${ this . peers . length } connected`
50
+ }
51
+
52
+ genStatusPctDownloaded ( ) {
53
+ if ( typeof this . totalBlocks === 'undefined' ) return ''
54
+ if ( this . totalBlocks ) {
55
+ return `${ this . totalBlocks ? Math . round ( this . downloadedBlocks / this . totalBlocks * 100 ) : 100 } % downloaded (${ bytes ( this . size ) } total)`
56
+ }
57
+ return 'Calculating...'
58
+ }
59
+
60
+ genStatusNetStats ( ) {
61
+ var stats = this . netStats
62
+ if ( ! stats ) return ''
63
+ var dl = bytes ( stats . download [ stats . download . length - 1 ] , { unitSeparator : ' ' } )
64
+ var ul = bytes ( stats . upload [ stats . download . length - 1 ] , { unitSeparator : ' ' } )
65
+ return `[↓${ dl } /s ↑${ ul } /s]`
66
+ }
67
+
68
+ genStatusNetCfg ( ) {
69
+ var netCfg = 'Not swarming'
70
+ if ( this . netCfg ) {
71
+ if ( this . netCfg . announce ) netCfg = `Announced to seed`
72
+ else if ( this . netCfg . lookup ) netCfg = `Watching for announced seeders`
73
+ }
74
+ return netCfg
75
+ }
76
+
52
77
async fetchState ( ) {
53
78
this . netCfg = await hyper . getClient ( ) . network . status ( this . discoveryKey )
54
79
@@ -104,6 +129,11 @@ function short (key) {
104
129
return `${ key . slice ( 0 , 6 ) } ..${ key . slice ( - 2 ) } `
105
130
}
106
131
132
+ function maybeShort ( key , yesShort ) {
133
+ if ( yesShort ) return short ( key )
134
+ return key
135
+ }
136
+
107
137
async function countHasCoreBlocks ( core , from , to ) {
108
138
var count = 0
109
139
for ( let i = from ; i < to ; i ++ ) {
0 commit comments