function gen_simple_poll_test($ip_address, $domain, $subfolder, $port_number) { $simple_poll_fail = FALSE; // Reset Variable TKRandom::seed(transaction_cycle(0, TRUE)); // Grab random Transaction Foundation Hash $rand_block = TKRandom::num(0, foundation_cycle(0, TRUE) - 5); // Range from Start to Last 5 Foundation Hash $random_foundation_hash = mysql_result(mysql_query("SELECT hash FROM `transaction_foundation` WHERE `block` = {$rand_block} LIMIT 1"), 0, 0); // Grab random Transaction Hash $rand_block2 = TKRandom::num(transaction_cycle(0 - transaction_cycle(0, TRUE), TRUE), transaction_cycle(-1000, TRUE)); // Range from Start to Last 1000 Transaction Hash $rand_block2 = transaction_cycle(0 - $rand_block2); $random_transaction_hash = mysql_result(mysql_query("SELECT hash FROM `transaction_history` WHERE `timestamp` = {$rand_block2} LIMIT 1"), 0, 0); $rand_block2 = ($rand_block2 - TRANSACTION_EPOCH - 300) / 300; if (empty($random_foundation_hash) == FALSE) { $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 64, "foundation.php?action=block_hash&block_number={$rand_block}"); // Is it valid? if (empty($poll_peer) == TRUE) { // No response? $simple_poll_fail = TRUE; } else { // Is it valid? if ($poll_peer == $random_foundation_hash) { // Got a good response from an active Timekoin server $simple_poll_fail = FALSE; } else { // Wrong Response? $simple_poll_fail = TRUE; } } } if (empty($random_transaction_hash) == FALSE) { $poll_peer = poll_peer($ip_address, $domain, $subfolder, $port_number, 64, "transclerk.php?action=block_hash&block_number={$rand_block2}"); // Is it valid? if (empty($poll_peer) == TRUE) { //No response? $simple_poll_fail = TRUE; } else { // Is it valid? if ($poll_peer == $random_transaction_hash) { //Got a good response from an active Timekoin server $simple_poll_fail = FALSE; } else { //Wrong Response? $simple_poll_fail = TRUE; } } } return $simple_poll_fail; }
//*********************************************************************************** //*********************************************************************************** } else { // Entire Transaction History in sync, reset block check start to 0 $block_check_start = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'block_check_start' LIMIT 1"), 0, "field_data"); if ($block_check_start > 0) { mysql_query("UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'block_check_start' LIMIT 1"); mysql_query("UPDATE `main_loop_status` SET `field_data` = '1' WHERE `main_loop_status`.`field_name` = 'block_check_back' LIMIT 1"); // Reset Performance Data mysql_query("UPDATE `main_loop_status` SET `field_data` = '10' WHERE `main_loop_status`.`field_name` = 'peer_transaction_performance' LIMIT 1"); mysql_query("UPDATE `main_loop_status` SET `field_data` = '10' WHERE `main_loop_status`.`field_name` = 'peer_transaction_start_blocks' LIMIT 1"); } 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); }
function tools_bar() { $default_walk = foundation_cycle(0, TRUE) * 500; $default_check = transaction_cycle(0, TRUE) - 10; $default_current = transaction_cycle(0, TRUE); return '<table cellspacing="10" border="0"><tr><td><FORM ACTION="index.php?menu=tools&action=walk_history" METHOD="post"><input type="submit" value="History Walk"/></td> <td>Block#<input type="text" size="7" name="walk_history" value="' . $default_walk . '" /></td></FORM><td>|</br>|</td> <td><FORM ACTION="index.php?menu=tools&action=check_tables" METHOD="post"><input type="submit" value="Check DB"/></td></FORM></td><td>|</br>|</td> <td><FORM ACTION="index.php?menu=tools&action=optimize_tables" METHOD="post"><input type="submit" value="Optimize DB"/></td></FORM></td><td>|</br>|</td> <td><FORM ACTION="index.php?menu=tools&action=repair_tables" METHOD="post"><input type="submit" value="Repair DB"/></td></FORM> </tr></table><hr></hr> <table cellspacing="10" border="0"><tr><td><FORM ACTION="index.php?menu=tools&action=schedule_check" METHOD="post"><input type="submit" value="Schedule Check"/></td> <td>Block#<input type="text" size="7" name="schedule_check" value="' . $default_check . '" /></td></FORM><td>|</br>|</td> <td><FORM ACTION="index.php?menu=tools&action=repair" METHOD="post"><input type="submit" value="Repair"/></td> <td>From Block#<input type="text" size="7" name="repair_from" value="' . $default_check . '" /></td> </FORM></tr></table>'; }
write_log("Updating Balance Index From Transaction Queue", "BA"); check_crypt_balance($sql_row["public_key"]); $created = TRUE; break; } } } if ($created == FALSE) { // 1000 Transaction Cycles Back in time to index $time_back = time() - 300000; $sql = "SELECT public_key_to FROM `transaction_history` WHERE `timestamp` > {$time_back} GROUP BY `public_key_to` ORDER BY RAND() LIMIT 1"; $sql_result = mysql_query($sql); $sql_row = mysql_fetch_array($sql_result); $public_key_hash = hash('md5', $sql_row["public_key_to"]); // Run a balance index if one does not already exist $balance_index = mysql_result(mysql_query("SELECT public_key_hash FROM `balance_index` WHERE `public_key_hash` = '{$public_key_from}' AND `block` = '" . foundation_cycle(-1, TRUE) . "' LIMIT 1"), 0, 0); if (empty($balance_index) == TRUE) { // No index balance, go ahead and create one write_log("Updating Balance Index From Transaction History", "BA"); check_crypt_balance($sql_row["public_key_to"]); } } } //*********************************************************************************** //*********************************************************************************** $loop_active = mysql_result(mysql_query("SELECT * FROM `main_loop_status` WHERE `field_name` = 'balance_heartbeat_active' LIMIT 1"), 0, "field_data"); // Check script status if ($loop_active == 3) { // Time to exit mysql_query("UPDATE `main_loop_status` SET `field_data` = '0' WHERE `main_loop_status`.`field_name` = 'balance_heartbeat_active' LIMIT 1"); exit;
function check_crypt_balance($public_key) { if (empty($public_key) == TRUE) { return 0; } // Do we already have an index to reference for faster access? $public_key_hash = hash('md5', $public_key); $current_generation_block = transaction_cycle(0, TRUE); $current_foundation_block = foundation_cycle(0, TRUE); // Check to make sure enough lead time exist in advance to building // another balance index. (60 blocks) or 5 hours if ($current_generation_block - $current_foundation_block * 500 > 60) { // -1 Foundation Blocks (Standard) $previous_foundation_block = foundation_cycle(-1, TRUE); } else { // -2 Foundation Blocks - Buffers 5 hours after the newest foundation block $previous_foundation_block = foundation_cycle(-2, TRUE); } $sql = "SELECT * FROM `balance_index` WHERE `block` = {$previous_foundation_block} AND `public_key_hash` = '{$public_key_hash}' LIMIT 1"; $sql_result = mysql_query($sql); $sql_row = mysql_fetch_array($sql_result); if (empty($sql_row["block"]) == TRUE) { // No index exist yet, so after the balance check is complete, record the result // for later use $crypto_balance = 0; // Create time range $end_time_range = $previous_foundation_block * 500; $index_balance1 = check_crypt_balance_range($public_key, 0, $end_time_range); // Check balance between the last block and now $start_time_range = $end_time_range; $end_time_range = transaction_cycle(0, TRUE); $index_balance2 = check_crypt_balance_range($public_key, $start_time_range, $end_time_range); // Store index in database for future access $sql = "INSERT INTO `balance_index` (`block` ,`public_key_hash` ,`balance`)\n\t\tVALUES ('{$previous_foundation_block}', '{$public_key_hash}', '{$index_balance1}')"; mysql_query($sql); return $index_balance1 + $index_balance2; } else { $crypto_balance = $sql_row["balance"]; // Check balance between the last block and now $start_time_range = $previous_foundation_block * 500; $end_time_range = transaction_cycle(0, TRUE); $index_balance = check_crypt_balance_range($public_key, $start_time_range, $end_time_range); return $crypto_balance + $index_balance; } }
if ($new_peer_difference <= 0) { // Enough new peers saved, break out of for loop early break; } } // End For loop check } // End New Peers vs Max New Peers check //*********************************************************************************** //*********************************************************************************** // Send a heartbeat to all active peers in our list to make sure they are still online $sql = "SELECT * FROM `active_peer_list`"; $sql_result = mysql_query($sql); $sql_num_results = mysql_num_rows($sql_result); // Grab random Transaction Foundation Hash $rand_block = rand(0, foundation_cycle(0, TRUE) - 5); // Range from Start to Last 5 Foundation Hash $random_foundation_hash = mysql_result(mysql_query("SELECT hash FROM `transaction_foundation` WHERE `block` = {$rand_block} LIMIT 1"), 0, 0); // Grab random Transaction Hash $rand_block2 = rand(transaction_cycle(0 - transaction_cycle(0, TRUE), TRUE), transaction_cycle(-1000, TRUE)); // Range from Start to Last 1000 Transaction Hash $rand_block2 = transaction_cycle(0 - $rand_block2); $random_transaction_hash = mysql_result(mysql_query("SELECT hash FROM `transaction_history` WHERE `timestamp` = {$rand_block2} LIMIT 1"), 0, 0); $rand_block2 = ($rand_block2 - TRANSACTION_EPOCH - 300) / 300; for ($i = 0; $i < $sql_num_results; $i++) { $sql_row = mysql_fetch_array($sql_result); if (rand(1, 2) == 2) { $ip_address = $sql_row["IP_Address"]; $domain = $sql_row["domain"]; $subfolder = $sql_row["subfolder"]; $port_number = $sql_row["port_number"];
$next_transaction_cycle = transaction_cycle(1); $foundation_status = intval(mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'foundation_heartbeat_active' LIMIT 1"), 0, 0)); // Can we work on the key balances in the database? // Not allowed 120 seconds before and 40 seconds after transaction cycle. // Don't run if the Foundation Manager is busy (idle = 2) if ($next_transaction_cycle - time() > 120 && time() - $current_transaction_cycle > 40 && $foundation_status == 2) { $current_transaction_block = transaction_cycle(0, TRUE); $current_foundation_block = foundation_cycle(0, TRUE); // Check to make sure enough lead time exist in advance to building // another balance index. (60 cycles) or 5 hours if ($current_transaction_block - $current_foundation_block * 500 > 60) { // -1 Foundation Blocks (Standard) $cache_block = foundation_cycle(-1, TRUE); } else { // -2 Foundation Blocks - Buffers 5 hours after the newest foundation block $cache_block = foundation_cycle(-2, TRUE); } // Build self balance index first $public_key_hash = hash('md5', my_public_key()); $balance_index = mysql_result(mysql_query("SELECT block FROM `balance_index` WHERE `public_key_hash` = '{$public_key_hash}' AND `block` = {$cache_block} LIMIT 1"), 0, 0); if ($balance_index === FALSE) { // Create self first :) check_crypt_balance(my_public_key()); } // Build Balance Index for Transactions about to be Processed in the Queue $sql = "SELECT public_key FROM `transaction_queue` WHERE `attribute` = 'T'"; $sql_result = mysql_query($sql); $sql_num_results = mysql_num_rows($sql_result); $queue_index_created = FALSE; if ($sql_num_results > 0) { for ($i = 0; $i < $sql_num_results; $i++) {
function tools_bar() { $default_walk = foundation_cycle(0, TRUE) * 500; $default_check = transaction_cycle(0, TRUE) - 10; $default_current = transaction_cycle(0, TRUE); return '<FORM ACTION="index.php?menu=tools&action=walk_history" METHOD="post"> <table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="History Walk"/></td> <td>Cycle#<input type="text" size="6" name="walk_history" value="' . $default_walk . '" /></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=schedule_check" METHOD="post"> <table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Check"/></td> <td>Cycle#<input type="text" size="6" name="schedule_check" value="' . $default_check . '" /></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=repair" METHOD="post"> <table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Repair" onclick="return confirm(\'Transaction Repair Can Take a Long Time. Continue?\');" /></td> <td>From Cycle#<input type="text" size="6" name="repair_from" value="' . $default_check . '" /></td></tr></table></FORM> <br><br><hr> <FORM ACTION="index.php?menu=tools&action=check_tables" METHOD="post" onclick="return confirm(\'Database Check Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Check DB"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=optimize_tables" METHOD="post" onclick="return confirm(\'Database Optimize Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Optimize DB"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=repair_tables" METHOD="post" onclick="return confirm(\'Database Repair Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Repair DB"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=clear_foundation" METHOD="post" onclick="return confirm(\'This Will Clear All Foundation Hashes. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Foundation"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=clear_banlist" METHOD="post" onclick="return confirm(\'This Will Clear All Banned IPs. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Banlist"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=clear_gen" METHOD="post" onclick="return confirm(\'This Will Clear The Peer Generation List & Election Queue. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Gen"/></td></tr></table></FORM> <br><br>'; }
function tools_bar() { $default_walk = foundation_cycle(0, TRUE) * 500; $default_check = transaction_cycle(0, TRUE) - 10; $default_current = transaction_cycle(0, TRUE); $main_active = mysql_result(mysql_query("SELECT field_data FROM `main_loop_status` WHERE `field_name` = 'main_heartbeat_active' LIMIT 1"), 0, 0); if ($main_active != FALSE) { $disable_db_util = "DISABLED"; } return '<FORM ACTION="index.php?menu=tools&action=walk_history" METHOD="post"> <table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="History Walk"/></td> <td>Cycle#<input type="text" size="6" name="walk_history" value="' . $default_walk . '" /></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=schedule_check" METHOD="post"> <table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Check"/></td> <td>Cycle#<input type="text" size="6" name="schedule_check" value="' . $default_check . '" /></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=repair" METHOD="post"> <table style="float: left;" cellspacing="5" border="0"><tr><td><input type="submit" value="Repair" onclick="return confirm(\'Transaction Repair Can Take a Long Time. Continue?\');" /></td> <td>From Cycle#<input type="text" size="6" name="repair_from" value="' . $default_check . '" /></td></tr></table></FORM> <br><br><hr> <FORM ACTION="index.php?menu=tools&action=check_tables" METHOD="post" onclick="return confirm(\'Database Check Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Check DB"/ ' . $disable_db_util . '></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=optimize_tables" METHOD="post" onclick="return confirm(\'Database Optimize Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Optimize DB" ' . $disable_db_util . '/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=repair_tables" METHOD="post" onclick="return confirm(\'Database Repair Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Repair DB" ' . $disable_db_util . '/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=clear_foundation" METHOD="post" onclick="return confirm(\'This Will Clear All Foundation Hashes. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Foundation"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=clear_banlist" METHOD="post" onclick="return confirm(\'This Will Clear All Banned IPs. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Banlist"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=clear_gen" METHOD="post" onclick="return confirm(\'This Will Clear The Peer Generation List & Election Queue. Continue?\');"> <table style="float: left;" cellspacing="6" border="0"><tr><td><input type="submit" value="Clear Gen"/></td></tr></table></FORM> <br><br>'; }
function tools_bar() { $default_walk = foundation_cycle(0, TRUE) * 500; $default_check = transaction_cycle(0, TRUE) - 10; $default_current = transaction_cycle(0, TRUE); return '<FORM ACTION="index.php?menu=tools&action=walk_history" METHOD="post"> <table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="History Walk"/></td> <td>Block#<input type="text" size="7" name="walk_history" value="' . $default_walk . '" /></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=check_tables" METHOD="post" onclick="return confirm(\'Database Check Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Check DB"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=optimize_tables" METHOD="post" onclick="return confirm(\'Database Optimize Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Optimize DB"/></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=repair_tables" METHOD="post" onclick="return confirm(\'Database Repair Can Take a Long Time. Continue?\');"> <table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Repair DB"/></td></tr></table></FORM> <br><br><br><hr> <FORM ACTION="index.php?menu=tools&action=schedule_check" METHOD="post"> <table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Schedule Check"/></td> <td>Block#<input type="text" size="7" name="schedule_check" value="' . $default_check . '" /></td></tr></table></FORM> <FORM ACTION="index.php?menu=tools&action=repair" METHOD="post"> <table style="float: left;" cellspacing="10" border="0"><tr><td><input type="submit" value="Repair" onclick="return confirm(\'Transaction Repair Can Take a Long Time. Continue?\');" /></td> <td>From Block#<input type="text" size="7" name="repair_from" value="' . $default_check . '" /></td></tr></table></FORM> <br><br><br>'; }