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

Commit

Permalink
peer, stats, warm: unplug chunks sent/recv report (closes #71)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioribeiro committed Oct 11, 2014
1 parent 4321f5d commit 82cd63a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var BaseObject = require('base_object');
var Storage = require('./storage');
var UploadHandler = require('./upload_handler')
var Stats = require('./stats')
var log = require('./log');

class Peer extends BaseObject {
Expand All @@ -16,6 +17,7 @@ class Peer extends BaseObject {
this.dataChannel = params.dataChannel
this.dataChannel.on("data", (data) => this.messageReceived(data))
this.uploadHandler = UploadHandler.getInstance()
this.stats = Stats.getInstance()
this.score = 1000
this.sendPing()
}
Expand All @@ -37,7 +39,7 @@ class Peer extends BaseObject {
sendSatisfy(resource) {
if (this.uploadHandler.getSlot(this.ident)) {
this.send('satisfy', resource, this.storage.getItem(resource))
this.swarm.chunksSent += 1
this.stats.updateStats('p2psent')
} else {
log.warn("cannot send satisfy, no upload slot available")
this.send("busy", resource)
Expand Down
6 changes: 3 additions & 3 deletions src/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Stats extends BaseObject {
constructor() {
this.recv_cdn = 0
this.recv_p2p = 0
this.sent_p2p = 0
this.bufferLength = 0
}

Expand All @@ -19,7 +20,6 @@ class Stats extends BaseObject {
if (Settings.statsReport) {
this.addEventListeners()
this.bufferLengthTimer = setInterval(() => this.updateBufferLength(), 1000)
this.updateStats()
this.triggerStats({status: "on"})
}
}
Expand All @@ -44,8 +44,8 @@ class Stats extends BaseObject {
updateStats(method=null) {
if (method === "p2p") this.recv_p2p++
else if (method === "cdn") this.recv_cdn++
var chunksSent = this.main.resourceRequester.p2pManager.swarm.chunksSent
var stats = {chunksFromP2P: this.recv_p2p, chunksFromCDN: this.recv_cdn, chunksSent: chunksSent}
else if (method === "p2psent") this.sent_p2p++
var stats = {chunksFromP2P: this.recv_p2p, chunksFromCDN: this.recv_cdn, chunksSent: this.sent_p2p}
this.triggerStats(stats)
}

Expand Down
3 changes: 0 additions & 3 deletions src/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Swarm extends BaseObject {
this.utils = new SwarmUtils(this)
this.peers = []
this.satisfyCandidate = undefined
this.chunksSent = 0
this.chokedClients = 0
this.avgSegmentSize = 0
this.peersContainsResource = []
Expand Down Expand Up @@ -51,8 +50,6 @@ class Swarm extends BaseObject {
this.utils.decrementScore(badPeers)
}



sendTo(recipients, command, resource, content='') {
if (recipients === 'contributors') {
_.each(this.utils.contributors, function(peer) { peer.send(command, resource, content) }, this)
Expand Down

0 comments on commit 82cd63a

Please sign in to comment.