Merge commit '0082da0c27b5ac3e56495c0c11365b549c84b079' (peerscrawl.php modifications) from main into weblate

This commit is contained in:
pezcurrel 2022-11-16 11:34:34 +01:00
commit 7672e18347

View file

@ -332,11 +332,17 @@ function ckexarr($inst) {
require(__DIR__.'/../site/mustard/include/ghs.php');
require(__DIR__.'/../site/mustard/include/ght.php');
function ismultibyte($s) {
preg_replace('/./u','.',$s,-1,$c);
(strlen($s)>$c) ? $r=true : $r=false;
return($r);
}
function validhostname($url) {
$hostname=preg_replace('#/.*#','',$url);
$hostname=preg_replace('#:[0-9]+$#','',$hostname);
$hostname=idn_to_ascii($hostname);
// echo($hostname.N);
if (ismultibyte($hostname)) $hostname=idn_to_ascii($hostname);
//echo($hostname.N);
if (strlen($hostname)>253) return(false);
$labels=explode('.',$hostname);
foreach($labels as $label) {
@ -372,17 +378,12 @@ function crawl($list,$id) {
$rtela=$now-$rtini;
gecho('>>> '.$inst.N,true,false);
gecho('@@@ Round '.$id.', '.$i.'/'.$c.': TET: '.ght($now-$tini,null,0).'; ETR of this round: '.ght($rtela/$i*$c-$rtela,null,0).'; using '.ghs(memory_get_usage(true)).' mem. (peak: '.ghs(memory_get_peak_usage(true)).'); '.count($insts).' responding insts; '.count($nlist).' insts in next round list; '.count($ainsts).' total.'.N,true,false);
if (ckexarr($inst)) {
gecho('NOTICE: I wont try and load peers from «'.$inst.'» since its in the exclude list.'.N,true,false);
} elseif ($opts['excludedead'] && in_array($inst,$deadinsts)) {
gecho('NOTICE: I wont try and load peers from «'.$inst.'» since its DEAD.'.N,true,false);
} else {
gecho('Trying to load «'.$inst.s peers...'.N,true,false);
$peers=getfc('https://'.$inst.'/api/v1/instance/peers',$opts['timeout']);
if ($peers['cont']===false) {
gecho('ERROR: '.$peers['emsg'].N,true,true);
} else {
$peers=json_decode($peers['cont'],true);
$peers=@json_decode($peers['cont'],true);
if (!is_array($peers)) {
gecho('ERROR: $peers is not an array (its type is '.gettype($peers).').'.N,true,true);
} else {
@ -428,7 +429,6 @@ function crawl($list,$id) {
}
}
}
}
if (count($nlist)>0) {
unset($list);
crawl($nlist,$id+1);