<commit_before>'use strict'

var inherits = require('util').inherits
var merge = require('merge')
var Q = require('q')

var Attributes = require('./attributes')
var ChannelData = require('./channel_data')
var Packet = require('./packet')
var StunClient = require('stun-js').StunClient

var debug = require('debug')
var debugLog = debug('turn-js')
var errorLog = debug('turn-js:error')

// Constructor
var TurnClient = function (host, port, username, password, transport) {
  StunClient.call(this, host, port, transport)
  this.username = username
  this.password = password

  // register channel_data decoder
  this._decoders.push({
    decoder: ChannelData.decode,
    listener: this.dispatchChannelDataPacket.bind(this)
  })
}

// Inherit from StunClient
inherits(TurnClient, StunClient)

var pjson = require('../package.json')
var defaultSoftwareTag = pjson.name + ' v' + pjson.version

TurnClient.channelBindingLifetime = 600
TurnClient.defaultAllocationLifetime = 600
TurnClient.permissionLifetime = 300

TurnClient.DEFAULTS = {
  software: defaultSoftwareTag,
  lifetime: TurnClient.defaultAllocationLifetime,
  dontFragment: false
}


/** TurnClient opertions */

// Execute allocation
TurnClient.prototype.allocateP = function () {
  var self = this
  // send an allocate request without credentials
  return this.sendAllocateP()
    .then(function (allocateReply) {
      var errorCode = allocateReply.getAttribute(Attributes.ERROR_CODE)
      // check if the reply includes an error code attr
      if (errorCode) {
        // check of this is a 401 Unauthorized error
        if (errorCode.code === 401) {
          // throw error if username and password are undefined
          if (self.username === undefined || self.password === undefined) {
            throw new Error('allocate error: unauthorized access, while username and/or password are undefined')
          }
          // create a new allocate request
          var args = {}
          self.nonce = args.nonce = allocateReply.getAttribute(Attributes.NONCE).value
          self.realm = args.realm = allocateReply.getAttribute(Attributes.REALM).value
          args.user = self.username
          args.pwd = <PASSWORD><commit_msg>code aesthetics<commit_after>'use strict'

var inherits = require('util').inherits
var merge = require('merge')
var Q = require('q')

var Attributes = require('./attributes')
var ChannelData = require('./channel_data')
var Packet = require('./packet')
var StunClient = require('stun-js').StunClient

var debug = require('debug')
var debugLog = debug('turn-js')
var errorLog = debug('turn-js:error')

// Constructor
var TurnClient = function (host, port, username, password, transport) {
  StunClient.call(this, host, port, transport)
  this.username = username
  this.password = password

  // register channel_data decoder
  this._decoders.push({
    decoder: ChannelData.decode,
    listener: this.dispatchChannelDataPacket.bind(this)
  })
}

// Inherit from StunClient
inherits(TurnClient, StunClient)

var pjson = require('../package.json')
var defaultSoftwareTag = pjson.name + ' v' + pjson.version

TurnClient.channelBindingLifetime = 600
TurnClient.defaultAllocationLifetime = 600
TurnClient.createPermissionLifetime = 300

TurnClient.DEFAULTS = {
  software: defaultSoftwareTag,
  lifetime: TurnClient.defaultAllocationLifetime,
  dontFragment: false
}


/** TurnClient opertions */

// Execute allocation
TurnClient.prototype.allocateP = function () {
  var self = this
  // send an allocate request without credentials
  return this.sendAllocateP()
    .then(function (allocateReply) {
      var errorCode = allocateReply.getAttribute(Attributes.ERROR_CODE)
      // check if the reply includes an error code attr
      if (errorCode) {
        // check of this is a 401 Unauthorized error
        if (errorCode.code === 401) {
          // throw error if username and password are undefined
          if (self.username === undefined || self.password === undefined) {
            throw new Error('allocate error: unauthorized access, while username and/or password are undefined')
          }
          // create a new allocate request
          var args = {}
          self.nonce = args.nonce = allocateReply.getAttribute(Attributes.NONCE).value
          self.realm = args.realm = allocateReply.getAttribute(Attributes.REALM).value
          args.user = self.username
          args.pwd = <PASSWORD>
{'fraction_non_alphanumeric': 0.1073855913004078, 'fraction_numerical': 0.006796556411418215, 'mean_word_length': 3.542181069958848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '68013', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1205, 'n_words': 338}