<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 Storage = require('./storage');
var UploadHandler = require('./upload_handler')
var PlaybackInfo = require('./playback_info')
var log = require('./log').getInstance()

class Peer extends BaseObject {
  constructor(params) {
    this.storage = Storage.getInstance()
    this.ident = params.ident
    this.swarm = params.swarm
    this.dataChannel = params.dataChannel
    this.dataChannel.on("data", (data) => this.messageReceived(data))
    this.uploadHandler = UploadHandler.getInstance()
    this.playbackInfo = PlaybackInfo.getInstance()
    this.score = 1000
    this.late = 0
  }

  sendSatisfy(resource) {
    if (this.uploadHandler.getSlot(this.ident)) {
      this.send('satisfy', resource, this.storage.getItem(resource))
      this.playbackInfo.updateChunkStats('p2psent')
    } else {
      log.warn("cannot send satisfy, no upload slot available")
      this.send("busy", resource)
    }
  }

  interestedReceived(resource) {
    if (this.storage.contain(resource)) {
      if (this.uploadHandler.getSlot(this.ident)) {
        this.send('contain', resource)
      } else {
        this.send('busy', resource)
      }
    } else {
      this.send("choke", resource)
    }
  }

  messageReceived(data) {
    var [command, resource, content] = data.split("$")
    switch (command) {
      case 'interested':
        this.interestedReceived(resource)
        break
      case 'contain':
        this.swarm.containReceived(this, resource)
        break
      case 'request':
        this.sendSatisfy(resource)
        break
      case 'choke':
        this.swarm.chokeReceived(resource)
        break
      case 'satisfy':
        log.debug('received _satisfy_')
        this.swarm.satisfyReceived(this, resource, content)
        break
      case 'busy':
        this.swarm.busyReceived(this)
        break
    }
  }
<commit_msg>peer: ensure content is not empty<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 Storage = require('./storage');
var UploadHandler = require('./upload_handler')
var PlaybackInfo = require('./playback_info')
var log = require('./log').getInstance()

class Peer extends BaseObject {
  constructor(params) {
    this.storage = Storage.getInstance()
    this.ident = params.ident
    this.swarm = params.swarm
    this.dataChannel = params.dataChannel
    this.dataChannel.on("data", (data) => this.messageReceived(data))
    this.uploadHandler = UploadHandler.getInstance()
    this.playbackInfo = PlaybackInfo.getInstance()
    this.score = 1000
    this.late = 0
  }

  sendSatisfy(resource) {
    if (this.uploadHandler.getSlot(this.ident)) {
      this.send('satisfy', resource, this.storage.getItem(resource))
      this.playbackInfo.updateChunkStats('p2psent')
    } else {
      log.warn("cannot send satisfy, no upload slot available")
      this.send("busy", resource)
    }
  }

  interestedReceived(resource) {
    if (this.storage.contain(resource)) {
      if (this.uploadHandler.getSlot(this.ident)) {
        this.send('contain', resource)
      } else {
        this.send('busy', resource)
      }
    } else {
      this.send("choke", resource)
    }
  }

  messageReceived(data) {
    var [command, resource, content] = data.split("$")
    switch (command) {
      case 'interested':
        this.interestedReceived(resource)
        break
      case 'contain':
        this.swarm.containReceived(this, resource)
        break
      case 'request':
        this.sendSatisfy(resource)
        break
      case 'choke':
        this.swarm.chokeReceived(resource)
        break
      case 'satisfy':
        log.debug('received _satisfy_')
        if (content.length > 0) {
          this.swarm.satisfyReceived(this, resource, content)
        }
        break
      case 'busy':
        this.swarm.busyReceived(this)
        break
    }
  }

{'fraction_non_alphanumeric': 0.1254180602006689, 'fraction_numerical': 0.005016722408026756, 'mean_word_length': 2.7822944896115627, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '2673499', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1238, 'n_words': 274}