@@ -43,6 +43,11 @@ module.exports = class Monitor extends ReadyResource {
43
43
if ( ! this . entry && this . name ) this . entry = await this . drive . entry ( this . name )
44
44
if ( this . entry ) this . _setEntryInfo ( )
45
45
46
+ this . uploadSpeedometer = speedometer ( )
47
+ this . downloadSpeedometer = speedometer ( )
48
+
49
+ this . _updatePeers ( )
50
+
46
51
// Handlers
47
52
this . blobs . core . on ( 'peer-add' , this . _boundPeerUpdate )
48
53
this . blobs . core . on ( 'peer-remove' , this . _boundPeerUpdate )
@@ -71,26 +76,24 @@ module.exports = class Monitor extends ReadyResource {
71
76
}
72
77
73
78
_onUpload ( index , bytes , from ) {
74
- if ( ! this . uploadSpeedometer ) this . uploadSpeedometer = speedometer ( )
75
- this . uploadStats . speed = this . uploadSpeedometer ( bytes )
76
- this . _updateStats ( this . uploadStats , index , bytes , from )
79
+ this . _updateStats ( this . uploadSpeedometer , this . uploadStats , index , bytes , from )
77
80
}
78
81
79
82
_onDownload ( index , bytes , from ) {
80
- if ( ! this . downloadSpeedometer ) this . downloadSpeedometer = speedometer ( )
81
- this . downloadStats . speed = this . downloadSpeedometer ( bytes )
82
- this . _updateStats ( this . downloadStats , index , bytes , from )
83
+ this . _updateStats ( this . downloadSpeedometer , this . downloadStats , index , bytes , from )
83
84
}
84
85
85
86
_updatePeers ( ) {
86
87
this . uploadStats . peers = this . downloadStats . peers = this . peers = this . blobs . core . peers . length
87
88
}
88
89
89
- _updateStats ( stats , index , bytes , from ) {
90
+ _updateStats ( speed , stats , index , bytes , from ) {
90
91
if ( ! this . entry || this . closing ) return
91
92
if ( ! isWithinRange ( index , this . entry ) ) return
92
93
93
94
if ( ! stats . startTime ) stats . startTime = Date . now ( )
95
+
96
+ stats . speed = speed ( bytes )
94
97
stats . blocks ++
95
98
stats . monitoringBytes += bytes
96
99
stats . totalBytes += bytes
0 commit comments