<commit_before>var net             = require('net');
var tls             = require('tls');
var util            = require('util');
var DuplexStream    = require('stream').Duplex;
var Socks           = require('socksjs');
var ircLineParser   = require('./irclineparser');
var getConnectionFamily = require('./getconnectionfamily');
var iconv           = require('iconv-lite');

function Connection(options) {
    DuplexStream.call(this, { readableObjectMode: true });

    this.options = options || {};

    this.connected = false;
    this.requested_disconnect = false;

    this.auto_reconnect = options.auto_reconnect || false;
    this.reconnect_attempts = 0;

    // When an IRC connection was successfully registered.
    this.registered = false;

    this.read_buffer = [];
    this.reading_buffer = false;

    this.read_command_buffer = [];

    this.localAddress = this.options.localAddress;

    // Buffers for data sent from the IRCd
    this.hold_last = false;
    this.held_data = null;

    this._timers = [];
}

util.inherits(Connection, DuplexStream);

module.exports = Connection;

Connection.prototype.registeredSuccessfully = function() {
    this.registered = Date.now();
};

Connection.prototype.connect = function() {
    var socket_connect_event_name = 'connect';
    var that = this;
    var options = this.options;
    var dest_addr;

    if (options.socks) {
        dest_addr = this.socks.host;
    } else {
        dest_addr = options.host;
    }

    this.disposeSocket();

    this.requested_disconnect = false;

    if (!this.options.encoding || !this.setEncoding(this.options.encoding)) {
        this.setEncoding('utf8');
    }

    getConnectionFamily(dest_addr, function getConnectionFamilyCb(err, family, host) {
        var outgoing_addr = this.localAddress || '0.0.0.0';
        var ircd_host = host;
        var ircd_port = options.port || 6667;

        if (options.socks) {
            console.log('Connecting via socks to ' + options.host + ':' + ircd_port);
            that.socket = Socks.connect({
                host: options.host,
                port: ircd_port,
                ssl: options.tls,
                rejectUnauthorized: options.rejectUnauthorized
            }, {
                host: host,
                port: options.socks.port || 8080,
                user: options.socks.user,
                pass: options.socks.pass,
                localAddress: outgoing_addr
            });
        } else {
            console.log('Connecting directly to ' + ircd_host + ':' + ircd_port);
            if (options.tls) {
                that.socket = tls.connect({
                    host: ircd_host,
                    port: ircd_port,
                    rejectUnauthorized: options.rejectUnauthorized,
                    localAddress: outgoing_addr
                });
<commit_msg>Connection options 'tls + 'ssl' alias<commit_after>var net             = require('net');
var tls             = require('tls');
var util            = require('util');
var DuplexStream    = require('stream').Duplex;
var Socks           = require('socksjs');
var ircLineParser   = require('./irclineparser');
var getConnectionFamily = require('./getconnectionfamily');
var iconv           = require('iconv-lite');

function Connection(options) {
    DuplexStream.call(this, { readableObjectMode: true });

    this.options = options || {};

    this.connected = false;
    this.requested_disconnect = false;

    this.auto_reconnect = options.auto_reconnect || false;
    this.reconnect_attempts = 0;

    // When an IRC connection was successfully registered.
    this.registered = false;

    this.read_buffer = [];
    this.reading_buffer = false;

    this.read_command_buffer = [];

    this.localAddress = this.options.localAddress;

    // Buffers for data sent from the IRCd
    this.hold_last = false;
    this.held_data = null;

    this._timers = [];
}

util.inherits(Connection, DuplexStream);

module.exports = Connection;

Connection.prototype.registeredSuccessfully = function() {
    this.registered = Date.now();
};

Connection.prototype.connect = function() {
    var socket_connect_event_name = 'connect';
    var that = this;
    var options = this.options;
    var dest_addr;

    if (options.socks) {
        dest_addr = this.socks.host;
    } else {
        dest_addr = options.host;
    }

    this.disposeSocket();

    this.requested_disconnect = false;

    if (!this.options.encoding || !this.setEncoding(this.options.encoding)) {
        this.setEncoding('utf8');
    }

    getConnectionFamily(dest_addr, function getConnectionFamilyCb(err, family, host) {
        var outgoing_addr = this.localAddress || '0.0.0.0';
        var ircd_host = host;
        var ircd_port = options.port || 6667;

        if (options.socks) {
            console.log('Connecting via socks to ' + options.host + ':' + ircd_port);
            that.socket = Socks.connect({
                host: options.host,
                port: ircd_port,
                ssl: options.tls,
                rejectUnauthorized: options.rejectUnauthorized
            }, {
                host: host,
                port: options.socks.port || 8080,
                user: options.socks.user,
                pass: options.socks.pass,
                localAddress: outgoing_addr
            });
        } else {
            console.log('Connecting directly to ' + ircd_host + ':' + ircd_port);
            if (options.tls || options.ssl) {
                that.socket = tls.connect({
                    host: ircd_host,
                    port: ircd_port,
                    rejectUnauthorized: options.rejectUnauthorized,
                    localAddress: outgoing_addr
                });

{'fraction_non_alphanumeric': 0.11336244541484716, 'fraction_numerical': 0.004890829694323144, 'mean_word_length': 2.1444261394838002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2082764', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1594, 'n_words': 335}