<commit_before>'use strict'

var Duplex = require('stream').Duplex
var inherits = require('util').inherits
var myUtils = require('../../utils')
var netstring = require('netstring-stream')
var signalingFactory = require('../../signaling/in-band/factory')
var winston = require('winston')
var winstonWrapper = require('winston-meta-wrapper')

function UdpStream (peerAddress, sessionId, socket, version) {
  if (!(this instanceof UdpStream)) {
    return new UdpStream(peerAddress, sessionId, socket, version)
  }
  // logging
  this._log = winstonWrapper(winston)
  this._log.addMeta({
    module: '1tp:transports:streams:udp'
  })
  // verify attributes
  if (peerAddress.address === undefined || peerAddress.port === undefined) {
    var peerAddressError = 'incorrect peerAddress: address and/or port attribute is undefined'
    throw new Error(peerAddressError)
  }
  // init
  Duplex.call(this, UdpStream.DEFAULTS)

  this._peerAddress = peerAddress
  this._sessionId = (sessionId === null) ? myUtils.generateSessionId() : sessionId
  this._socket = socket
  this._version = version

  this._destroyed = false

  // register _error handler
  myUtils.mixinEventEmitterErrorFunction(this)

  // done
  this._log.debug('created new udp stream.')
}

UdpStream.DEFAULTS = {
  allowHalfOpen: true,
  readableObjectMode: false,
  writableObjectMode: false
}

inherits(UdpStream, Duplex)

// Half-closes the socket -- i.e. sends a FIN packet.
UdpStream.prototype.end = function () {
  this._log.debug('ending stream for udp session ' + this._sessionId)
  var self = this
  this._sendSignalingMessage(signalingFactory.MESSAGE.FIN, function () {
    self._end()<commit_msg>infer version from utils module<commit_after>'use strict'

var Duplex = require('stream').Duplex
var inherits = require('util').inherits
var myUtils = require('../../utils')
var netstring = require('netstring-stream')
var signalingFactory = require('../../signaling/in-band/factory')
var winston = require('winston')
var winstonWrapper = require('winston-meta-wrapper')

function UdpStream (peerAddress, sessionId, socket) {
  if (!(this instanceof UdpStream)) {
    return new UdpStream(peerAddress, sessionId, socket)
  }
  // logging
  this._log = winstonWrapper(winston)
  this._log.addMeta({
    module: '1tp:transports:streams:udp'
  })
  // verify attributes
  if (peerAddress.address === undefined || peerAddress.port === undefined) {
    var peerAddressError = 'incorrect peerAddress: address and/or port attribute is undefined'
    throw new Error(peerAddressError)
  }
  // init
  Duplex.call(this, UdpStream.DEFAULTS)

  this._peerAddress = peerAddress
  this._sessionId = (sessionId === null) ? myUtils.generateSessionId() : sessionId
  this._socket = socket
  this._version = myUtils.version

  this._destroyed = false

  // register _error handler
  myUtils.mixinEventEmitterErrorFunction(this)

  // done
  this._log.debug('created new udp stream.')
}

UdpStream.DEFAULTS = {
  allowHalfOpen: true,
  readableObjectMode: false,
  writableObjectMode: false
}

inherits(UdpStream, Duplex)

// Half-closes the socket -- i.e. sends a FIN packet.
UdpStream.prototype.end = function () {
  this._log.debug('ending stream for udp session ' + this._sessionId)
  var self = this
  this._sendSignalingMessage(signalingFactory.MESSAGE.FIN, function () {
    self._end()
{'fraction_non_alphanumeric': 0.12365269461077845, 'fraction_numerical': 0.0005988023952095808, 'mean_word_length': 4.320063694267516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4201684', 'n_tokens_mistral': 1041, 'n_tokens_neox': 1020, 'n_words': 243}