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

Commit

Permalink
resource requester: avoid stucking
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioribeiro committed Oct 22, 2014
1 parent 2c1298e commit 07a3efb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/p2p_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class P2PManager extends BaseObject {
}

requestResource(resource, callbackSuccess, callbackFail) {
if (this.swarm.size() === 0) {
if (this.swarm.utils.contributors === 0) {
callbackFail()
} else {
this.swarm.sendInterested(resource, callbackSuccess, callbackFail)
Expand Down
7 changes: 6 additions & 1 deletion src/resource_requester.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ class ResourceRequester extends BaseObject {
this.cdnRequester = new CDNRequester()
this.p2pManager = new P2PManager(params)
this.isInitialBuffer = true
this.sameSource = 0
}

requestResource(resource, bufferLength, callback) {
if (resource === this.resource) {
this.sameSource += 1
}
this.resource = resource
this.callback = callback
if (bufferLength < Settings.lowBufferLength || this.isInitialBuffer || _.size(this.p2pManager.swarm.utils.contributors) === 0) {
if (bufferLength < Settings.lowBufferLength || this.isInitialBuffer || _.size(this.p2pManager.swarm.utils.contributors) === 0 || this.sameSource >= 3) {
this.requestToCDN()
this.sameSource = 0
} else {
this.requestToP2P()
}
Expand Down

0 comments on commit 07a3efb

Please sign in to comment.