<commit_before><?php

namespace Tempo;

use ArrayObject;
use Symfony\Component\Process\Process;
use InvalidArgumentException;
use RuntimeException;

class Node extends ArrayObject
{
    /** @var string $host */
    private $host;

    /** @var array $options */
    private $options;

    /**
     * @param string $host IP Address or hostname
     * @param array $options Associative array of options
     *
     * Available options are:
     *      user - The user to use for the ssh connection
     *      controlMasterSocket - The socket file to use for connection sharing (see ControlPath in ssh_config(5))
     *      controlLifetime - The socket file to use for connection sharing (see ControlPersist in ssh_config(5))
     */
    public function __construct($host, $options = array())
    {
        $this->host = $host;
        $this->options = $options;

        // Set some nice default options
        $this->options = array_merge(array(
            'controlMasterSocket' => sprintf(
                '~/.ssh/tempo_ctlmstr_%s',
                $this
            ),
            'controlLifetime' => '10m',
        ), $this->options);
    }

    public function __toString()
    {
        if (isset($this->options['user'])) {
            return sprintf(
                '%s@%s',
                $this->options['user'],
                $this->host
            );
        } else {
            return $this->host;
        }
    }

    private function establishControlMaster()
    {
        $returnVal = null;
        $checkCommand = sprintf(
            '[ -S %s ]',
            $this->options['controlMasterSocket']
        );
        system($checkCommand, $returnVal);
        if ($returnVal === 0) {
            return;
        }

        printf(
            "Establishing a connection to: %s\n",
            $this
        );
        $controlCommand = sprintf(
            'ssh -nTM -S %s -o "ControlPersist=%s" %s',
            $this->options['controlMasterSocket'],
            '10m',
            $this
        );
        passthru($controlCommand, $returnVal);
        if ($returnVal !== 0) {
            throw new RuntimeException(sprintf(
                'could not establish control connection using command: %s',<commit_msg>Added support for a non-standard ssh port<commit_after><?php

namespace Tempo;

use ArrayObject;
use Symfony\Component\Process\Process;
use InvalidArgumentException;
use RuntimeException;

class Node extends ArrayObject
{
    /** @var string $host */
    private $host;

    /** @var array $options */
    private $options;

    /**
     * @param string $host IP Address or hostname
     * @param array $options Associative array of options
     *
     * Available options are:
     *      user - The user to use for the ssh connection
     *      controlMasterSocket - The socket file to use for connection sharing (see ControlPath in ssh_config(5))
     *      controlLifetime - The socket file to use for connection sharing (see ControlPersist in ssh_config(5))
     */
    public function __construct($host, $options = array())
    {
        $this->host = $host;
        $this->options = $options;

        // Set some nice default options
        $this->options = array_merge(array(
            'controlMasterSocket' => sprintf(
                '~/.ssh/tempo_ctlmstr_%s',
                $this
            ),
            'controlLifetime' => '10m',
        ), $this->options);
    }

    public function __toString()
    {
        if (isset($this->options['user'])) {
            return sprintf(
                '%s@%s',
                $this->options['user'],
                $this->host
            );
        } else {
            return $this->host;
        }
    }

    private function establishControlMaster()
    {
        // Check if control master socket already exists
        $returnVal = null;
        $checkCommand = sprintf(
            '[ -S %s ]',
            $this->options['controlMasterSocket']
        );
        system($checkCommand, $returnVal);
        if ($returnVal === 0) {
            return;
        }

        printf(
            "Establishing a connection to: %s\n",
            $this
        );
        $args = array(
            '-n', // Redirects stdin from /dev/null (actually, prevents reading from stdin).
            '-T', // Disable pseudo-tty allocation.
            '-M', // Places the ssh client into "master" mode for connection sharing.
            sprintf(
                '-S %s', // Specifies the location of a control socket for connection sharing
                escapeshellarg($this->options['controlMasterSocket'])
            ),
            sprintf(
                '-o %s', // ControlPersist - How long to persist the master socket for
                escapeshellarg('ControlPersist='.$this->options['controlLifetime'])
            )
        );
        if (isset($this->options['port'])) {
            $args[] = sprintf(
                '-p %d', // Specifies the location of a control socket for connection sharing
                $this->options['port']
            );
        }
        $controlCommand = sprintf(
            'ssh %s %s',
            implode(' ', $args),
            $this
        );
        passthru($controlCommand, $returnVal);
        if ($returnVal !== 0) {
            throw new RuntimeException(sprintf(
                'could not establish control connection using command: %s',
{'fraction_non_alphanumeric': 0.11596887736198593, 'fraction_numerical': 0.002593553167839941, 'mean_word_length': 1.7336708860759493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 30, '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': '3348910', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1397, 'n_words': 407}