<commit_before><?php
/**
 * An object to represent lots of information about an RPC-peer machine
 *
 * @author  <NAME>  <EMAIL>
 * @version 0.0.1
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package mnet
 */

class mnet_peer {

    var $id                 = 0;
    var $wwwroot            = '';
    var $ip_address         = '';
    var $name               = '';
    var $public_key         = '';
    var $public_key_expires = 0;
    var $last_connect_time  = 0;
    var $last_log_id        = 0;
    var $keypair            = array();
    var $error              = array();

    function mnet_peer() {
        return true;
    }

    function bootstrap($wwwroot) {

        if ( ! $this->set_wwwroot($wwwroot) ) {
            $hostname = mnet_get_hostname_from_uri($wwwroot);

            // Get the IP address for that host - if this fails, it will
            // return the hostname string
            $ip_address = gethostbyname($hostname);

            // Couldn't find the IP address?
            if ($ip_address === $hostname && !preg_match('/^\d+\.\d+\.\d+.\d+$/',$hostname)) {
                $this->error[] = array('code' => 2, 'text' => get_string("noaddressforhost", 'mnet'));
                return false;
            }

            $this->name = $wwwroot;

            // TODO: In reality, this will be prohibitively slow... need another
            // default - maybe blank string
            $homepage = file_get_contents($wwwroot);
            if (!empty($homepage)) {
                $count = preg_match("@<title>(.*)</title>@siU", $homepage, $matches);
                if ($count > 0) {
                    $this->name = $matches[1];
                }
            }

            if (substr($wwwroot, 0, -1) == '/') {
                $wwwroot = substr($wwwroot, 0, -1);
            }

            $this->wwwroot              = $wwwroot;
            $this->ip_address           = $ip_address;
            $this->deleted              = 0;
            $this->public_key           = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
            $this->public_key_expires   = $this->check_common_name($this->public_key);
            $this->last_connect_time    = 0;
            $this->last_log_id          = 0;
            if ($this->public_key_expires == false) {
                $this->public_key == '';
                return false;
            }
        }

        return true;<commit_msg>Mnet:  Bugfix:  Prevent a second record to be created for an existing host if the user entered http://example.com/ as the wwwroot<commit_after><?php
/**
 * An object to represent lots of information about an RPC-peer machine
 *
 * @author  <NAME>  <EMAIL>
 * @version 0.0.1
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package mnet
 */

class mnet_peer {

    var $id                 = 0;
    var $wwwroot            = '';
    var $ip_address         = '';
    var $name               = '';
    var $public_key         = '';
    var $public_key_expires = 0;
    var $last_connect_time  = 0;
    var $last_log_id        = 0;
    var $keypair            = array();
    var $error              = array();

    function mnet_peer() {
        return true;
    }

    function bootstrap($wwwroot) {

        if (substr($wwwroot, 0, -1) == '/') {
            $wwwroot = substr($wwwroot, 0, -1);
        }

        if ( ! $this->set_wwwroot($wwwroot) ) {
            $hostname = mnet_get_hostname_from_uri($wwwroot);

            // Get the IP address for that host - if this fails, it will
            // return the hostname string
            $ip_address = gethostbyname($hostname);

            // Couldn't find the IP address?
            if ($ip_address === $hostname && !preg_match('/^\d+\.\d+\.\d+.\d+$/',$hostname)) {
                $this->error[] = array('code' => 2, 'text' => get_string("noaddressforhost", 'mnet'));
                return false;
            }

            $this->name = $wwwroot;

            // TODO: In reality, this will be prohibitively slow... need another
            // default - maybe blank string
            $homepage = file_get_contents($wwwroot);
            if (!empty($homepage)) {
                $count = preg_match("@<title>(.*)</title>@siU", $homepage, $matches);
                if ($count > 0) {
                    $this->name = $matches[1];
                }
            }

            $this->wwwroot              = $wwwroot;
            $this->ip_address           = $ip_address;
            $this->deleted              = 0;
            $this->public_key           = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
            $this->public_key_expires   = $this->check_common_name($this->public_key);
            $this->last_connect_time    = 0;
            $this->last_log_id          = 0;
            if ($this->public_key_expires == false) {
                $this->public_key == '';
                return false;
            }
        }

        return true;
{'fraction_non_alphanumeric': 0.13887775551102205, 'fraction_numerical': 0.006813627254509018, 'mean_word_length': 1.5322171486555047, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 29, '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': '174180', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1464, 'n_words': 333}