Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit 82cd63a

Browse files
committed
peer, stats, warm: unplug chunks sent/recv report (closes #71)
1 parent 4321f5d commit 82cd63a

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/peer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
var BaseObject = require('base_object');
77
var Storage = require('./storage');
88
var UploadHandler = require('./upload_handler')
9+
var Stats = require('./stats')
910
var log = require('./log');
1011

1112
class Peer extends BaseObject {
@@ -16,6 +17,7 @@ class Peer extends BaseObject {
1617
this.dataChannel = params.dataChannel
1718
this.dataChannel.on("data", (data) => this.messageReceived(data))
1819
this.uploadHandler = UploadHandler.getInstance()
20+
this.stats = Stats.getInstance()
1921
this.score = 1000
2022
this.sendPing()
2123
}
@@ -37,7 +39,7 @@ class Peer extends BaseObject {
3739
sendSatisfy(resource) {
3840
if (this.uploadHandler.getSlot(this.ident)) {
3941
this.send('satisfy', resource, this.storage.getItem(resource))
40-
this.swarm.chunksSent += 1
42+
this.stats.updateStats('p2psent')
4143
} else {
4244
log.warn("cannot send satisfy, no upload slot available")
4345
this.send("busy", resource)

src/stats.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Stats extends BaseObject {
1111
constructor() {
1212
this.recv_cdn = 0
1313
this.recv_p2p = 0
14+
this.sent_p2p = 0
1415
this.bufferLength = 0
1516
}
1617

@@ -19,7 +20,6 @@ class Stats extends BaseObject {
1920
if (Settings.statsReport) {
2021
this.addEventListeners()
2122
this.bufferLengthTimer = setInterval(() => this.updateBufferLength(), 1000)
22-
this.updateStats()
2323
this.triggerStats({status: "on"})
2424
}
2525
}
@@ -44,8 +44,8 @@ class Stats extends BaseObject {
4444
updateStats(method=null) {
4545
if (method === "p2p") this.recv_p2p++
4646
else if (method === "cdn") this.recv_cdn++
47-
var chunksSent = this.main.resourceRequester.p2pManager.swarm.chunksSent
48-
var stats = {chunksFromP2P: this.recv_p2p, chunksFromCDN: this.recv_cdn, chunksSent: chunksSent}
47+
else if (method === "p2psent") this.sent_p2p++
48+
var stats = {chunksFromP2P: this.recv_p2p, chunksFromCDN: this.recv_cdn, chunksSent: this.sent_p2p}
4949
this.triggerStats(stats)
5050
}
5151

src/swarm.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class Swarm extends BaseObject {
1717
this.utils = new SwarmUtils(this)
1818
this.peers = []
1919
this.satisfyCandidate = undefined
20-
this.chunksSent = 0
2120
this.chokedClients = 0
2221
this.avgSegmentSize = 0
2322
this.peersContainsResource = []
@@ -51,8 +50,6 @@ class Swarm extends BaseObject {
5150
this.utils.decrementScore(badPeers)
5251
}
5352

54-
55-
5653
sendTo(recipients, command, resource, content='') {
5754
if (recipients === 'contributors') {
5855
_.each(this.utils.contributors, function(peer) { peer.send(command, resource, content) }, this)

0 commit comments

Comments
 (0)