当前位置: 首页>>代码示例>>PHP>>正文


PHP poll_peer函数代码示例

本文整理汇总了PHP中poll_peer函数的典型用法代码示例。如果您正苦于以下问题:PHP poll_peer函数的具体用法?PHP poll_peer怎么用?PHP poll_peer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了poll_peer函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mysql_query

// Send a heartbeat to all reserve peers in our list to make sure they are still online
$sql = "SELECT * FROM `new_peers_list`";
$sql_result = mysql_query($sql);
$sql_num_results = mysql_num_rows($sql_result);
for ($i = 0; $i < $sql_num_results; $i++) {
    $sql_row = mysql_fetch_array($sql_result);
    if (rand(1, 3) == 2) {
        $ip_address = $sql_row["IP_Address"];
        $domain = $sql_row["domain"];
        $subfolder = $sql_row["subfolder"];
        $port_number = $sql_row["port_number"];
        $poll_failures = $sql_row["poll_failures"];
        //Send a challenge hash to see if a timekoin server is active
        $poll_challenge = rand(1, 999999);
        $hash_solution = hash('crc32', $poll_challenge);
        $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 10, "peerlist.php?action=poll&challenge={$poll_challenge}");
        if ($poll_peer == $hash_solution) {
            //Got a response from an active Timekoin server
            $sql = "UPDATE `new_peers_list` SET `poll_failures` = 0 WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1";
            mysql_query($sql);
        } else {
            //No response, record polling failure for future reference
            $poll_failures++;
            $sql = "UPDATE `new_peers_list` SET `poll_failures` = '{$poll_failures}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1";
            mysql_query($sql);
        }
    }
    // End Randomize Check
}
// End for Loop
// Clean up reserve peer list by removing those that have no responded for over 30 poll attempts
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:peerlist.php

示例2: mysql_fetch_array

 $sql_row2 = mysql_fetch_array($sql_result2);
 $ip_address = $sql_row2["IP_Address"];
 $domain = $sql_row2["domain"];
 $subfolder = $sql_row2["subfolder"];
 $port_number = $sql_row2["port_number"];
 $qhash = $timestamp . base64_encode($public_key) . $crypt1 . $crypt2 . $crypt3 . $hash_check . $attribute;
 $qhash = hash('md5', $qhash);
 // Create map with request parameters
 $params = array('timestamp' => $timestamp, 'public_key' => base64_encode($public_key), 'crypt_data1' => $crypt1, 'crypt_data2' => $crypt2, 'crypt_data3' => $crypt3, 'hash' => $hash_check, 'attribute' => $attribute, 'qhash' => $qhash);
 // Build Http query using params
 $query = http_build_query($params);
 // Create Http context details
 $contextData = array('method' => 'POST', 'header' => "Connection: close\r\n" . "Content-Length: " . strlen($query) . "\r\n", 'content' => $query);
 // Create context resource for our request
 $context = stream_context_create(array('http' => $contextData));
 $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "queueclerk.php?action=input_transaction", $context);
 if ($poll_peer == "OK") {
     // Insert to the peer remotely was accepted
     switch ($attribute) {
         case "G":
             write_log("Timekoin Currency Generation Broadcast Accepted by remote Peer {$ip_address}{$domain}:{$port_number}/{$subfolder}", "G");
             modify_peer_grade($ip_address, $domain, $subfolder, $port_number, -3);
             break;
         case "T":
             write_log("Standard Transaction Broadcast Accepted by remote Peer {$ip_address}{$domain}:{$port_number}/{$subfolder}", "T");
             modify_peer_grade($ip_address, $domain, $subfolder, $port_number, -2);
             break;
     }
 } else {
     if ($poll_peer == "DUP") {
         // Insert to the peer, transaction is already there
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:treasurer.php

示例3: initialization_database

function initialization_database()
{
    // Clear IP Activity and Banlist for next start
    mysql_query("TRUNCATE TABLE `ip_activity`");
    mysql_query("TRUNCATE TABLE `ip_banlist`");
    // Clear Active & New Peers List
    mysql_query("DELETE FROM `active_peer_list` WHERE `active_peer_list`.`join_peer_list` != 0");
    // Permanent Peers Ignored
    mysql_query("TRUNCATE TABLE `new_peers_list`");
    // Record when started
    mysql_query("UPDATE `options` SET `field_data` = '" . time() . "' WHERE `options`.`field_name` = 'timekoin_start_time' LIMIT 1");
    //**************************************
    // Upgrade Database from v3.x earlier versions
    // Auto IP Update Settings
    $new_record_check = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'auto_update_generation_IP' LIMIT 1"), 0, 0);
    if ($new_record_check === FALSE) {
        // Does not exist, create it
        mysql_query("INSERT INTO `options` (`field_name` ,`field_data`) VALUES ('auto_update_generation_IP', '0')");
    }
    // CLI Mode Settings
    $new_record_check = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'cli_mode' LIMIT 1"), 0, 0);
    if ($new_record_check === FALSE) {
        // Does not exist, create it
        mysql_query("INSERT INTO `options` (`field_name` ,`field_data`) VALUES ('cli_mode', '1')");
    }
    // CLI Mode Port Settings
    $new_record_check = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'cli_port' LIMIT 1"), 0, 0);
    if ($new_record_check === FALSE) {
        // Does not exist, create it
        mysql_query("INSERT INTO `options` (`field_name` ,`field_data`) VALUES ('cli_port', '')");
    }
    // IPv4 + IPv6 Network Mode
    $new_record_check = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'network_mode' LIMIT 1"), 0, 0);
    if ($new_record_check === FALSE) {
        // Does not exist, create it
        mysql_query("INSERT INTO `options` (`field_name` ,`field_data`) VALUES ('network_mode', '1')");
    }
    // IPv6 Generation IP Field
    $new_record_check = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'generation_IP_v6' LIMIT 1"), 0, 0);
    if ($new_record_check === FALSE) {
        // Does not exist, create it
        mysql_query("INSERT INTO `options` (`field_name` ,`field_data`) VALUES ('generation_IP_v6', '')");
    }
    //**************************************
    // Check for an empty generation IP address,
    // if none exist, attempt to auto-detect one
    // and fill in the field.
    $poll_IP = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'generation_IP' LIMIT 1"), 0, 0);
    if (empty($poll_IP) == TRUE) {
        ini_set('user_agent', 'Timekoin Server (Main) v' . TIMEKOIN_VERSION);
        ini_set('default_socket_timeout', 3);
        // Timeout for request in seconds
        $poll_IP = filter_sql(poll_peer(NULL, 'timekoin.net', NULL, 80, 46, "ipv4.php"));
        if (empty($poll_IP) == FALSE) {
            mysql_query("UPDATE `options` SET `field_data` = '{$poll_IP}' WHERE `options`.`field_name` = 'generation_IP' LIMIT 1");
        }
    }
    //**************************************
    // Main Loop Status & Active Options Setup
    // Truncate to Free RAM
    mysql_query("TRUNCATE TABLE `main_loop_status`");
    $time = time();
    //**************************************
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('balance_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('foundation_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('generation_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('genpeer_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('main_heartbeat_active', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('main_last_heartbeat', '{$time}')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('peerlist_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('queueclerk_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('transclerk_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('treasurer_last_heartbeat', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('watchdog_heartbeat_active', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('watchdog_last_heartbeat', '{$time}')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('peer_transaction_start_blocks', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('peer_transaction_performance', '10')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('block_check_back', '1')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('block_check_start', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('firewall_blocked_peer', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('foundation_block_check', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('foundation_block_check_end', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('foundation_block_check_start', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('generation_peer_list_no_sync', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('no_peer_activity', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('time_sync_error', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('transaction_history_block_check', '0')");
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('update_available', '0')");
    //**************************************
    // Copy values from Database to RAM Database
    $db_to_RAM = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'allow_ambient_peer_restart' LIMIT 1"), 0, 0);
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('allow_ambient_peer_restart', '{$db_to_RAM}')");
    $db_to_RAM = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'allow_LAN_peers' LIMIT 1"), 0, 0);
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('allow_LAN_peers', '{$db_to_RAM}')");
    $db_to_RAM = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'server_request_max' LIMIT 1"), 0, 0);
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('server_request_max', '{$db_to_RAM}')");
    $db_to_RAM = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'max_active_peers' LIMIT 1"), 0, 0);
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('max_active_peers', '{$db_to_RAM}')");
    $db_to_RAM = mysql_result(mysql_query("SELECT field_data FROM `options` WHERE `field_name` = 'max_new_peers' LIMIT 1"), 0, 0);
    mysql_query("INSERT INTO `main_loop_status` (`field_name` ,`field_data`)VALUES ('max_new_peers', '{$db_to_RAM}')");
//.........这里部分代码省略.........
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:101,代码来源:function.php

示例4: filter_sql

             if (hash('md5', $queue_hash_test) == $current_hash) {
                 // This Transaction Already Exist in the Queue
                 $hash_match = TRUE;
                 break;
             } else {
                 // No match, continue searching
                 $hash_match = NULL;
             }
             // No match, move on to next record
             $queue_hash_test = NULL;
         }
     }
 }
 if (empty($hash_match) == TRUE) {
     // This peer has a different transaction, ask for the full details of it
     $poll_hash = filter_sql(poll_peer($ip_address, $domain, $subfolder, $port_number, 1500, "queueclerk.php?action=transaction&number={$current_hash}"));
     $transaction_timestamp = intval(find_string("-----timestamp=", "-----public_key", $poll_hash));
     $transaction_public_key = find_string("-----public_key=", "-----crypt1", $poll_hash);
     $transaction_crypt1 = find_string("-----crypt1=", "-----crypt2", $poll_hash);
     $transaction_crypt2 = find_string("-----crypt2=", "-----crypt3", $poll_hash);
     $transaction_crypt3 = find_string("-----crypt3=", "-----hash", $poll_hash);
     $transaction_hash = find_string("-----hash=", "-----attribute", $poll_hash);
     $transaction_attribute = find_string("-----attribute=", "-----end", $poll_hash);
     $transaction_qhash = find_string("---qhash=", "---endqhash", $poll_hash);
     // If a qhash is included, use this to verify the data
     if (empty($transaction_qhash) == FALSE) {
         $qhash = $transaction_timestamp . $transaction_public_key . $transaction_crypt1 . $transaction_crypt2 . $transaction_crypt3 . $transaction_hash . $transaction_attribute;
         $qhash = hash('md5', $qhash);
         // Compare hashes to make sure data is intact
         if ($transaction_qhash != $qhash) {
             write_log("Queue Hash Data MisMatch for Public Key: " . $transaction_public_key, "QC");
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:queueclerk.php

示例5: foundation_cycle

 }
 if (rand(1, 4) == 2) {
     // Poll a random block from a random peer for random accuracy :)
     // Within the range of the current foundation block to now
     $current_foundation_block = foundation_cycle(0, TRUE) * 500;
     $random_block = rand($current_foundation_block, transaction_cycle(-1, TRUE));
     $sql = perm_peer_mode();
     $sql_result = mysql_query($sql);
     $sql_num_results = mysql_num_rows($sql_result);
     if ($sql_num_results > 0) {
         $sql_row = mysql_fetch_array($sql_result);
         $ip_address = $sql_row["IP_Address"];
         $domain = $sql_row["domain"];
         $subfolder = $sql_row["subfolder"];
         $port_number = $sql_row["port_number"];
         $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 65, "transclerk.php?action=block_hash&block_number={$random_block}");
         if (empty($poll_peer) == TRUE) {
             // Add failure points to the peer in case further issues
             modify_peer_grade($ip_address, $domain, $subfolder, $port_number, 4);
         }
         if (empty($poll_peer) == FALSE && strlen($poll_peer) > 60) {
             // Do a real hash compare
             $current_generation_block = transaction_cycle(0, TRUE);
             $time1 = transaction_cycle(0 - $current_generation_block + $random_block);
             $time2 = transaction_cycle(0 - $current_generation_block + 1 + $random_block);
             $sql = "SELECT hash FROM `transaction_history` WHERE `timestamp` >= {$time1} AND `timestamp` < {$time2} ORDER BY `timestamp`, `hash`";
             $sql_result = mysql_query($sql);
             $sql_num_results = mysql_num_rows($sql_result);
             $random_hash_build = 0;
             if ($sql_num_results > 0) {
                 for ($i = 0; $i < $sql_num_results; $i++) {
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:transclerk.php

示例6: tk_decrypt

 $transaction_info = tk_decrypt($public_key, base64_decode($crypt1));
 if ($transaction_info == $crypt2) {
     // Check the IP/Domain field and poll the IP to see if
     // there is a valid Timekoin server at the address.
     $crypt3_data = tk_decrypt($public_key, base64_decode($crypt3));
     $peer_ip = find_string("---ip=", "---domain", $crypt3_data);
     $peer_domain = find_string("---domain=", "---subfolder", $crypt3_data);
     $peer_subfolder = find_string("---subfolder=", "---port", $crypt3_data);
     $peer_port_number = find_string("---port=", "---end", $crypt3_data);
     $delete_request = find_string("---end=", "---end2", $crypt3_data);
     // Check if IP is already in the generation peer list
     $IP_exist1 = mysql_result(mysql_query("SELECT * FROM `generating_peer_list` WHERE `IP_Address` = '{$peer_ip}' LIMIT 1"), 0, 1);
     // Calculate public key half-crypt-hash
     $arr1 = str_split($public_key, 181);
     // Poll the address that was encrypted to check for valid Timekoin server
     $gen_key_crypt = base64_decode(poll_peer($peer_ip, $peer_domain, $peer_subfolder, $peer_port_number, 256, "genpeer.php?action=gen_key_crypt"));
     $gen_key_crypt = tk_decrypt($public_key, $gen_key_crypt);
     $domain_fail = FALSE;
     // Reset Variable
     if (empty($peer_domain) == FALSE) {
         // Check if the hostname and IP fields actually match
         // and not made up or unrelated.
         $dns_ip = gethostbyname($peer_domain);
         if ($dns_ip != $peer_ip) {
             // No match between Domain IP and Encoded IP
             $domain_fail = TRUE;
         } else {
             $domain_fail = FALSE;
         }
     }
     // Does the public key half match what is encrypted in the 3rd crypt field from
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:genpeer.php

示例7: write_log

     if ($hash == $current_foundation_hash) {
         write_log("Transaction Foundation #{$rand_block} checks out OK", "FO");
         $repair_block = FALSE;
     } else {
         write_log("Transaction Foundation #{$rand_block} did NOT pass verification test. Transactions in this Foundation will be repaired.", "FO");
         $repair_block = TRUE;
     }
 } else {
     // Check foundation hash with peers
     for ($i = 0; $i < $sql_num_results; $i++) {
         $sql_row = mysql_fetch_array($sql_result);
         $ip_address = $sql_row["IP_Address"];
         $domain = $sql_row["domain"];
         $subfolder = $sql_row["subfolder"];
         $port_number = $sql_row["port_number"];
         $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 65, "foundation.php?action=block_hash&block_number={$rand_block}");
         if (empty($poll_peer) == TRUE) {
             // Add failure points to the peer in case further issues
             modify_peer_grade($ip_address, $domain, $subfolder, $port_number, 4);
         }
         if ($current_foundation_hash === $poll_peer) {
             $foundation_hash_match++;
         } else {
             if (empty($poll_peer) == FALSE && strlen($poll_peer) > 60) {
                 $foundation_hash_different++;
             } else {
                 // Polling Errors can cause false corruption assumptions
                 $poll_errors++;
             }
         }
     }
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:foundation.php

示例8: rand

             //Send a challenge hash to see if a timekoin server is active
             $poll_challenge = rand(1, 999999);
             $hash_solution = hash('crc32', $poll_challenge);
             $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 10, "peerlist.php?action=poll&challenge={$poll_challenge}");
             if ($poll_peer == $hash_solution) {
                 //Got a response from an active Timekoin server
                 $poll_failures--;
                 mysql_query("UPDATE `new_peers_list` SET `poll_failures` = {$poll_failures} WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
             } else {
                 //No response, record polling failure for future reference
                 $poll_failures++;
                 mysql_query("UPDATE `new_peers_list` SET `poll_failures` = '{$poll_failures}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
             }
         } else {
             // Is the server full to capacity with peers?
             $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 10, "peerlist.php?action=join");
             if ($poll_peer == "FULL") {
                 //Server is full, ramp up failure points to get it purged quicker
                 $poll_failures += 10;
                 mysql_query("UPDATE `new_peers_list` SET `poll_failures` = '{$poll_failures}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
             } else {
                 if ($poll_peer == "OK") {
                     //Got a response from an active Timekoin server that is not full to capacity yet
                     $poll_failures -= 5;
                     mysql_query("UPDATE `new_peers_list` SET `poll_failures` = {$poll_failures} WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
                 }
             }
         }
     }
     // End Randomize Check
 }
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:peerlist.php

示例9: my_domain

				<tr><th>Peer</th><th>My Failure Score</th></tr>';
            $my_domain = my_domain();
            $my_subfolder = my_subfolder();
            $my_port = my_port_number();
            // Polling what the active peers have
            $sql = "SELECT * FROM `active_peer_list`";
            $sql_result = mysql_query($sql);
            $sql_num_results = mysql_num_rows($sql_result);
            for ($i = 0; $i < $sql_num_results; $i++) {
                $sql_row = mysql_fetch_array($sql_result);
                $ip_address = $sql_row["IP_Address"];
                $domain = $sql_row["domain"];
                $subfolder = $sql_row["subfolder"];
                $port_number = $sql_row["port_number"];
                // Poll and give my domain to check against
                $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "peerlist.php?action=poll_failure&domain={$my_domain}&subfolder={$my_subfolder}&port={$my_port}");
                if ($poll_peer == "") {
                    $poll_peer = "No Response";
                } else {
                    $poll_peer = intval($poll_peer);
                }
                $body_string .= '<tr><td class="style2"><p style="word-wrap:break-word; font-size:12px;">' . $ip_address . $domain . ':' . $port_number . '/' . $subfolder . '</p></td>';
                $body_string .= '<td class="style2"><p style="font-size:12px;">' . $poll_peer . '</p></td></tr>';
            }
            $body_string .= '</table></div>';
            $quick_info = '<strong>Failure Scores</strong> that other peers have recorded for your server.';
            home_screen('Failure Scores From Peers', NULL, $body_string, $quick_info);
            exit;
        }
        if ($_GET["edit"] == "peer") {
            if ($_GET["type"] == "new") {
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:index.php

示例10: send_timekoins

function send_timekoins($my_private_key, $my_public_key, $send_to_public_key, $amount, $message)
{
    if (empty($my_private_key) == TRUE || empty($my_public_key) == TRUE || empty($send_to_public_key) == TRUE) {
        return FALSE;
    }
    ini_set('user_agent', 'Timekoin Client v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 3);
    // Timeout for request in seconds
    $arr1 = str_split($send_to_public_key, 181);
    $encryptedData1 = tk_encrypt($my_private_key, $arr1[0]);
    $encryptedData64_1 = base64_encode($encryptedData1);
    $encryptedData2 = tk_encrypt($my_private_key, $arr1[1]);
    $encryptedData64_2 = base64_encode($encryptedData2);
    // Sanitization of message
    // Filter symbols that might lead to a transaction hack attack
    $symbols = array("|", "?", "=");
    // SQL + URL
    $message = str_replace($symbols, "", $message);
    // Trim any message to 64 characters max and filter any sql
    $message = filter_sql(substr($message, 0, 64));
    $transaction_data = "AMOUNT={$amount}---TIME=" . time() . "---HASH=" . hash('sha256', $encryptedData64_1 . $encryptedData64_2) . "---MSG={$message}";
    $encryptedData3 = tk_encrypt($my_private_key, $transaction_data);
    $encryptedData64_3 = base64_encode($encryptedData3);
    $triple_hash_check = hash('sha256', $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3);
    $timestamp = transaction_cycle(0) + 1;
    $attribute = "T";
    $qhash = $timestamp . base64_encode($my_public_key) . $encryptedData64_1 . $encryptedData64_2 . $encryptedData64_3 . $triple_hash_check . $attribute;
    $qhash = hash('md5', $qhash);
    // Create map with request parameters
    $params = array('timestamp' => $timestamp, 'public_key' => base64_encode($my_public_key), 'crypt_data1' => $encryptedData64_1, 'crypt_data2' => $encryptedData64_2, 'crypt_data3' => $encryptedData64_3, 'hash' => $triple_hash_check, 'attribute' => $attribute, 'qhash' => $qhash);
    // Build Http query using params
    $query = http_build_query($params);
    // Create Http context details
    $contextData = array('method' => 'POST', 'header' => "Connection: close\r\n" . "Content-Length: " . strlen($query) . "\r\n", 'content' => $query);
    // Create context resource for our request
    $context = stream_context_create(array('http' => $contextData));
    // Try all Active Peer Servers
    $sql_result = mysql_query("SELECT * FROM `active_peer_list` ORDER BY RAND()");
    $sql_num_results = mysql_num_rows($sql_result);
    $return_results;
    for ($i = 0; $i < $sql_num_results; $i++) {
        $sql_row = mysql_fetch_array($sql_result);
        $ip_address = $sql_row["IP_Address"];
        $domain = $sql_row["domain"];
        $subfolder = $sql_row["subfolder"];
        $port_number = $sql_row["port_number"];
        $code = $sql_row["code"];
        $poll_peer = filter_sql(poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=send_tk&hash={$code}", $context));
        if ($poll_peer == "OK") {
            write_log("Peer: [{$ip_address}{$domain}:{$port_number}/{$subfolder}] Accepted the Transaction for Processing", "T");
            $return_results = TRUE;
        }
    }
    if ($return_results == TRUE) {
        // Success in sending transaction
        return TRUE;
    } else {
        // No peer servers accepted the transaction data :(
        write_log("No Peers Accepted the Transaction", "T");
        return FALSE;
    }
}
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:62,代码来源:function.php

示例11: mysql_query

            $body_string = '<div class="table"><table class="listing" border="0" cellspacing="0" cellpadding="0" >
				<tr><th>Peer</th><th>Time</th><th>Variance</th><th>Ping</th></tr>';
            // Add more possible peers to the new peer list by polling what the active peers have
            $sql = "SELECT * FROM `active_peer_list`";
            $sql_result = mysql_query($sql);
            $sql_num_results = mysql_num_rows($sql_result);
            $response_counter = 0;
            $variance_total = 0;
            for ($i = 0; $i < $sql_num_results; $i++) {
                $sql_row = mysql_fetch_array($sql_result);
                $ip_address = $sql_row["IP_Address"];
                $domain = $sql_row["domain"];
                $subfolder = $sql_row["subfolder"];
                $port_number = $sql_row["port_number"];
                $my_micro_time = microtime(TRUE);
                $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 12, "peerlist.php?action=polltime");
                $my_time = time();
                if ($my_time == $poll_peer && empty($poll_peer) == FALSE) {
                    $variance = '0 seconds';
                    $micro_time_variance = round((microtime(TRUE) - $my_micro_time) * 1000) . " ms";
                    $response_counter++;
                } else {
                    if (empty($poll_peer) == FALSE) {
                        $variance = $my_time - $poll_peer;
                        $response_counter++;
                        $variance_total = $variance_total + abs($variance);
                        $micro_time_variance = round((microtime(TRUE) - $my_micro_time) * 1000) . " ms";
                        if ($variance > 1) {
                            $variance = '+' . $variance . ' seconds';
                        } else {
                            if ($variance == 1) {
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:31,代码来源:index.php

示例12: peer_list

function peer_list()
{
    ini_set('user_agent', 'Timekoin Client (Peerlist) v' . TIMEKOIN_VERSION);
    ini_set('default_socket_timeout', 2);
    // Timeout for request in seconds
    $max_active_peers = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'max_active_peers' LIMIT 1"), 0, "field_data");
    $max_new_peers = mysql_result(mysql_query("SELECT * FROM `options` WHERE `field_name` = 'max_new_peers' LIMIT 1"), 0, "field_data");
    // How many active peers do we have?
    $active_peers = mysql_result(mysql_query("SELECT COUNT(join_peer_list) FROM `active_peer_list`"), 0);
    $new_peers = mysql_result(mysql_query("SELECT COUNT(poll_failures) FROM `new_peers_list`"), 0);
    if ($active_peers == 0) {
        // No active or new peers to poll from, start with the first contact servers
        // and copy them to the new peer list
        $sql = "SELECT * FROM `options` WHERE `field_name` = 'first_contact_server'";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        write_log("Peer List Empty. Adding First Contact Servers.", "PL");
        // First Contact Server Format
        //---ip=192.168.0.1---domain=timekoin.com---subfolder=timekoin---port=80---code=guest---end
        for ($i = 0; $i < $sql_num_results; $i++) {
            $sql_row = mysql_fetch_array($sql_result);
            $peer_ip = find_string("---ip=", "---domain", $sql_row["field_data"]);
            $peer_domain = find_string("---domain=", "---subfolder", $sql_row["field_data"]);
            $peer_subfolder = find_string("---subfolder=", "---port", $sql_row["field_data"]);
            $peer_port_number = find_string("---port=", "---code", $sql_row["field_data"]);
            $peer_code = find_string("---code=", "---end", $sql_row["field_data"]);
            // Insert into database as first contact server(s)
            $sql = "INSERT INTO `active_peer_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`last_heartbeat`, `join_peer_list`, `failed_sent_heartbeat`, `code`)\n\t\t\tVALUES ('{$peer_ip}', '{$peer_domain}', '{$peer_subfolder}', '{$peer_port_number}', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), '0', '{$peer_code}');";
            mysql_query($sql);
            $active_peers++;
        }
    }
    if ($active_peers < $max_active_peers) {
        //Start polling peers from the new peers list
        $sql = "SELECT * FROM `new_peers_list` ORDER BY RAND() LIMIT 10";
        $sql_result = mysql_query($sql);
        $sql_num_results = mysql_num_rows($sql_result);
        // Peer difference
        $peer_difference_count = $max_active_peers - $active_peers;
        for ($i = 0; $i < $sql_num_results; $i++) {
            $sql_row = mysql_fetch_array($sql_result);
            $ip_address = $sql_row["IP_Address"];
            $domain = $sql_row["domain"];
            $subfolder = $sql_row["subfolder"];
            $port_number = $sql_row["port_number"];
            $poll_failures = $sql_row["poll_failures"];
            $code = $sql_row["code"];
            // Check to make sure that this peer is not already in our active peer list
            $duplicate_check1 = mysql_result(mysql_query("SELECT * FROM `active_peer_list` WHERE `IP_Address` = '{$ip_address}' LIMIT 1"), 0, 0);
            $duplicate_check2 = mysql_result(mysql_query("SELECT * FROM `active_peer_list` WHERE `domain` LIKE '{$domain}' LIMIT 1"), 0, 1);
            if (empty($ip_address) == TRUE) {
                //Don't have an IP address, check for duplicate domain or my own domain
                if (empty($duplicate_check2) == TRUE) {
                    // Neither IP nor Domain exist
                    $duplicate_peer = FALSE;
                } else {
                    $duplicate_peer = TRUE;
                }
            } else {
                // Using IP only, is there a duplicate IP or Domain
                if (empty($duplicate_check1) == TRUE && empty($duplicate_check2) == TRUE) {
                    $duplicate_peer = FALSE;
                } else {
                    $duplicate_peer = TRUE;
                }
            }
            if ($duplicate_peer == FALSE) {
                // Poll Peer for Access
                if (empty($code) == TRUE) {
                    // Try guest access
                    $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=tk_hash_status&hash=guest");
                } else {
                    // Using custom code for peer
                    $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 5, "api.php?action=tk_hash_status&hash={$code}");
                }
                if ($poll_peer == TRUE) {
                    // Add this peer to the active list
                    // Insert this peer into our active peer table
                    // Save only domain name if both IP and Domain exist
                    if (empty($domain) == FALSE) {
                        $ip_address = NULL;
                    }
                    if (empty($code) == TRUE) {
                        $code = "guest";
                    }
                    // Store new peer in active list
                    $sql = "INSERT INTO `active_peer_list` (`IP_Address` ,`domain` ,`subfolder` ,`port_number` ,`last_heartbeat` ,`join_peer_list` ,`failed_sent_heartbeat` ,`code`)\n\t\t\tVALUES ('{$ip_address}', '{$domain}', '{$subfolder}', '{$port_number}', '" . time() . "', '" . time() . "', '0', '{$code}');";
                    if (mysql_query($sql) == TRUE) {
                        // Subtract 1 from the peer difference count
                        $peer_difference_count--;
                        write_log("Joined with Peer {$ip_address}:{$domain}:{$port_number}/{$subfolder}", "PL");
                    }
                } else {
                    //No response, record polling failure for future reference
                    $poll_failures++;
                    mysql_query("UPDATE `new_peers_list` SET `poll_failures` = '{$poll_failures}' WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
                }
            } else {
                // Active response will remove poll failures
                mysql_query("UPDATE `new_peers_list` SET `poll_failures` = 0 WHERE `IP_Address` = '{$ip_address}' AND `domain` = '{$domain}' AND `subfolder` = '{$subfolder}' AND `port_number` = {$port_number} LIMIT 1");
//.........这里部分代码省略.........
开发者ID:LoveLeAnon,项目名称:timekoin,代码行数:101,代码来源:task.php


注:本文中的poll_peer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。