<commit_before>// Copyright 2014 <NAME> <<EMAIL>>.
// All rights reserved.
// Use of this source code is governed by a Apache
// license that can be found in the LICENSE file.

var BaseObject = require('base_object')
var CDNRequester = require('./cdn_requester')
var P2PManager = require('./p2p_manager')
var Settings = require('./settings')
var Storage = require('./storage')

class ResourceRequester extends BaseObject {
  constructor(params) {
    this.cdnRequester = new CDNRequester()
    this.p2pManager = new P2PManager(params)
    this.storage = Storage.getInstance()
    this.isInitialBuffer = true
  }

  requestResource(resource, bufferLength, callback) {
    this.resource = resource
    this.callback = callback
    if (this.storage.contain(resource)) {
      // it means that something went wrong on flash side. getting from cdn.
      this.requestToCDN()
    } else if (bufferLength < Settings.lowBufferLength || this.isInitialBuffer || this.p2pManager.swarm.size() === 0) {
      this.requestToCDN()
    } else {
      this.requestToP2P()
    }
  }

  requestToCDN() {<commit_msg>resource requester: avoid p2p if contributors is equal to 0<commit_after>// Copyright 2014 <NAME> <<EMAIL>>.
// All rights reserved.
// Use of this source code is governed by a Apache
// license that can be found in the LICENSE file.

var BaseObject = require('base_object')
var CDNRequester = require('./cdn_requester')
var P2PManager = require('./p2p_manager')
var Settings = require('./settings')
var Storage = require('./storage')
var _ = require('underscore')

class ResourceRequester extends BaseObject {
  constructor(params) {
    this.cdnRequester = new CDNRequester()
    this.p2pManager = new P2PManager(params)
    this.storage = Storage.getInstance()
    this.isInitialBuffer = true
  }

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

  requestToCDN() {
{'fraction_non_alphanumeric': 0.11657303370786516, 'fraction_numerical': 0.011235955056179775, 'mean_word_length': 3.7488888888888887, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2819220', 'n_tokens_mistral': 645, 'n_tokens_neox': 631, 'n_words': 175}