<commit_before>// a single connection
var config  = require('./config');
var logger  = require('./logger');
var trans   = require('./transaction');
var dns     = require('dns');
var plugins = require('./plugins');
var constants = require('./constants');
var rfc1869   = require('./rfc1869');

var line_regexp = /^([^\n]*\n)/;

var connection = exports;

function setupClient(self) {
    self.client.pause();
    self.remote_ip = self.client.remoteAddress;
    logger.lognotice("got connection from: " + self.remote_ip);
    
    self.client.on('error', function (err) {
        if (!self.disconnected) {
            logger.logwarn("client closed with err: " + err);
            self.disconnect();
        }
    });
    
    dns.reverse(self.remote_ip, function(err, domains) {
        if (err) {
            switch (err.code) {
                case dns.NXDOMAIN: self.remote_host = 'NXDOMAIN'; break;
                default:           self.remote_host = 'DNSERROR'; break;
            }
        }
        else {
            self.remote_host = domains[0] || 'Unknown';
        }
        self.client.on('data', function (data) {
            self.process_data(data);
        });
        self.client.resume();
        self.transaction = trans.createTransaction();
        // TODO - check for early talkers before this
        plugins.run_hooks('connect', self);
    });
}

function Connection(client) {
    this.client = client;
    this.current_data = '';
    this.current_line = null;
    this.state = 'cmd'; // command or data
    this.early_talker_delay = config.get('early_talker_delay', 'value') || 1000;
    
    setupClient(this);
}

exports.Connection = Connection;<commit_msg>Listen for data earlier so we can check for early talkers before dns results return<commit_after>// a single connection
var config  = require('./config');
var logger  = require('./logger');
var trans   = require('./transaction');
var dns     = require('dns');
var plugins = require('./plugins');
var constants = require('./constants');
var rfc1869   = require('./rfc1869');

var line_regexp = /^([^\n]*\n)/;

var connection = exports;

function setupClient(self) {
    self.client.pause();
    self.remote_ip = self.client.remoteAddress;
    logger.lognotice("got connection from: " + self.remote_ip);
    
    self.client.on('error', function (err) {
        if (!self.disconnected) {
            logger.logwarn("client closed with err: " + err);
            self.disconnect();
        }
    });
    
    self.client.on('data', function (data) {
        self.process_data(data);
    });
    
    dns.reverse(self.remote_ip, function(err, domains) {
        if (err) {
            switch (err.code) {
                case dns.NXDOMAIN: self.remote_host = 'NXDOMAIN'; break;
                default:           self.remote_host = 'DNSERROR'; break;
            }
        }
        else {
            self.remote_host = domains[0] || 'Unknown';
        }
        self.client.resume();
        self.transaction = trans.createTransaction();
        // TODO - check for early talkers before this
        plugins.run_hooks('connect', self);
    });
}

function Connection(client) {
    this.client = client;
    this.current_data = '';
    this.current_line = null;
    this.state = 'pause';
    this.early_talker_delay = config.get('early_talker_delay', 'value') || 1000;
    
    setupClient(this);
}

exports.Connection = Connection;
{'fraction_non_alphanumeric': 0.14654161781946073, 'fraction_numerical': 0.0076201641266119575, 'mean_word_length': 2.392644135188867, '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': '7097292', 'n_tokens_mistral': 1027, 'n_tokens_neox': 1007, 'n_words': 222}