Merge pull request #10 from arionum/master

update node
This commit is contained in:
Ario Sius
2020-12-29 18:54:13 +01:00
committed by GitHub
3 changed files with 36 additions and 7 deletions

View File

@@ -250,6 +250,11 @@ function ec_verify($data, $signature, $key)
} }
return false; return false;
} }
// verify the validity of an url
function isValidURL($url)
{
return preg_match('|^(ht)?(f)?tp(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}
// POST data to an URL (usualy peer). The data is an array, json encoded with is sent as $_POST['data'] // POST data to an URL (usualy peer). The data is an array, json encoded with is sent as $_POST['data']
function peer_post($url, $data = [], $timeout = 60, $debug = false) function peer_post($url, $data = [], $timeout = 60, $debug = false)
@@ -258,6 +263,9 @@ function peer_post($url, $data = [], $timeout = 60, $debug = false)
if ($debug) { if ($debug) {
echo "\nPeer post: $url\n"; echo "\nPeer post: $url\n";
} }
if (!isValidURL($url)) {
return false;
}
$postdata = http_build_query( $postdata = http_build_query(
[ [
'data' => json_encode($data), 'data' => json_encode($data),

View File

@@ -1,6 +1,6 @@
<?php <?php
// ARO version // ARO version
define("VERSION", "1.0.0-alpha.5"); define("VERSION", "1.0.0-alpha.6");
// UTC timezone by default // UTC timezone by default
date_default_timezone_set("UTC"); date_default_timezone_set("UTC");

View File

@@ -239,7 +239,9 @@ $most_common = "";
$most_common_size = 0; $most_common_size = 0;
$most_common_height = 0; $most_common_height = 0;
$total_active_peers = 0; $total_active_peers = 0;
$largest_most_common = "";
$largest_most_common_size = 0;
$largest_most_common_height = 0;
// checking peers // checking peers
@@ -427,6 +429,11 @@ foreach ($r as $x) {
$most_common_size = $blocks_count[$data['id']]; $most_common_size = $blocks_count[$data['id']];
$most_common_height = $data['height']; $most_common_height = $data['height'];
} }
if ($blocks_count[$data['id']] > $largest_most_common_size && $data['height'] > $current['height']) {
$largest_most_common = $data['id'];
$largest_most_common_size = $blocks_count[$data['id']];
$largest_most_common_height = $data['height'];
}
// set the largest height block // set the largest height block
if ($data['height'] > $largest_height) { if ($data['height'] > $largest_height) {
$largest_height = $data['height']; $largest_height = $data['height'];
@@ -462,6 +469,9 @@ echo "Most common block size: $most_common_size\n";
echo "Most common height: $most_common_height\n\n"; echo "Most common height: $most_common_height\n\n";
echo "Longest chain height: $largest_height\n"; echo "Longest chain height: $largest_height\n";
echo "Longest chain size: $largest_size\n\n"; echo "Longest chain size: $largest_size\n\n";
echo "Larger Most common: $largest_most_common\n";
echo "Larger Most common block size: $largest_most_common_size\n";
echo "Larger Most common height: $largest_most_common_height\n\n";
echo "Total size: $total_active_peers\n\n"; echo "Total size: $total_active_peers\n\n";
echo "Current block: $current[height]\n"; echo "Current block: $current[height]\n";
@@ -480,11 +490,18 @@ if($largest_height-$most_common_height>100&&$largest_size==1&&$current['id']==$l
} }
// if there's a single node with over 100 blocks ahead on a single peer, use the most common block // if there's a single node with over 100 blocks ahead on a single peer, use the most common block
if($largest_height-$most_common_height>100&&$largest_size==1){ if($largest_height-$most_common_height>100 && $largest_size==1){
_log("Longest chain is way ahead, using most common block"); if($current['id']==$most_common && $largest_most_common_size>3){
$largest_height=$most_common_height; _log("Longest chain is way ahead, using largest most common block");
$largest_size=$most_common_size; $largest_height=$largest_most_common_height;
$largest_height_block=$most_common; $largest_size=$largest_most_common_size;
$largest_height_block=$largest_most_common;
} else {
_log("Longest chain is way ahead, using most common block");
$largest_height=$most_common_height;
$largest_size=$most_common_size;
$largest_height_block=$most_common;
}
} }
@@ -600,6 +617,10 @@ if ($current['height'] < $largest_height && $largest_height > 1) {
} }
// if current still doesn't match the data, something went wrong // if current still doesn't match the data, something went wrong
if ($data['id'] != $current['id']) { if ($data['id'] != $current['id']) {
if($largest_size==1){
//blacklisting the peer if it's the largest height on a broken blockchain
$db->run("UPDATE peers SET blacklisted=UNIX_TIMESTAMP()+1800 WHERE hostname=:host LIMIT 1",[':host'=>$host]);
}
continue; continue;
} }
// start syncing all blocks // start syncing all blocks