Merge commit '0082da0c27b5ac3e56495c0c11365b549c84b079' (peerscrawl.php modifications) from main into weblate
This commit is contained in:
commit
7672e18347
1 changed files with 50 additions and 50 deletions
|
@ -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,58 +378,52 @@ 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 won’t try and load peers from «'.$inst.'» since it’s in the exclude list.'.N,true,false);
|
||||
} elseif ($opts['excludedead'] && in_array($inst,$deadinsts)) {
|
||||
gecho('NOTICE: I won’t try and load peers from «'.$inst.'» since it’s DEAD.'.N,true,false);
|
||||
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 {
|
||||
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);
|
||||
$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 {
|
||||
$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);
|
||||
gecho('LOADED!'.N,true,false);
|
||||
if (in_array($inst,$insts)) {
|
||||
gecho('NOTICE: «'.$inst.'» is not a new instance (it was already in $insts).'.N,true,false);
|
||||
} else {
|
||||
gecho('LOADED!'.N,true,false);
|
||||
if (in_array($inst,$insts)) {
|
||||
gecho('NOTICE: «'.$inst.'» is not a new instance (it was already in $insts).'.N,true,false);
|
||||
gecho('NEW INSTANCE FOUND: «'.$inst.'».'.N,true,false);
|
||||
$insts[]=$inst;
|
||||
fwrite($peersf,$inst.N);
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
if (!is_string($peer)) {
|
||||
gecho(' ERROR: I won’t add this peer to next round list because its name is not a string.'.N,true,true);
|
||||
} elseif (!validhostname($peer)) {
|
||||
gecho(' ERROR: I won’t add «'.$peer.'» to next round list because it’s not a valid hostname.'.N,true,true);
|
||||
} elseif (ckexarr($peer)) {
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because its name matches with an exclusion regex.'.N,true,true);
|
||||
} elseif (in_array($peer,$ainsts)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $ainsts.'.N,true,false);
|
||||
} elseif (in_array($peer,$nlist)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $nlist.'.N,true,false);
|
||||
// questo qui sotto diventa ridondante ora che uso $ainsts e lo popolo a inizio funzione
|
||||
/*} elseif (in_array($peer,$list)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $list.'.N,true,false);
|
||||
// questo qui sotto è sempre stato ridondante
|
||||
} elseif (in_array($peer,$insts)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $insts.'.N,true,false);
|
||||
}*/
|
||||
} elseif ($opts['excludedead'] && in_array($peer,$deadinsts)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s DEAD.'.N,true,false);
|
||||
} else {
|
||||
gecho('NEW INSTANCE FOUND: «'.$inst.'».'.N,true,false);
|
||||
$insts[]=$inst;
|
||||
fwrite($peersf,$inst.N);
|
||||
}
|
||||
foreach ($peers as $peer) {
|
||||
if (!is_string($peer)) {
|
||||
gecho(' ERROR: I won’t add this peer to next round list because its name is not a string.'.N,true,true);
|
||||
} elseif (!validhostname($peer)) {
|
||||
gecho(' ERROR: I won’t add «'.$peer.'» to next round list because it’s not a valid hostname.'.N,true,true);
|
||||
} elseif (ckexarr($peer)) {
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because its name matches with an exclusion regex.'.N,true,true);
|
||||
} elseif (in_array($peer,$ainsts)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $ainsts.'.N,true,false);
|
||||
} elseif (in_array($peer,$nlist)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $nlist.'.N,true,false);
|
||||
// questo qui sotto diventa ridondante ora che uso $ainsts e lo popolo a inizio funzione
|
||||
/*} elseif (in_array($peer,$list)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $list.'.N,true,false);
|
||||
// questo qui sotto è sempre stato ridondante
|
||||
} elseif (in_array($peer,$insts)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s already in $insts.'.N,true,false);
|
||||
}*/
|
||||
} elseif ($opts['excludedead'] && in_array($peer,$deadinsts)) {
|
||||
if ($opts['verbose'])
|
||||
gecho(' NOTICE: I won’t add «'.$peer.'» to next round list because it’s DEAD.'.N,true,false);
|
||||
} else {
|
||||
//EVVIVA!
|
||||
gecho(' ADDING PEER «'.$peer.'» to next round list.'.N,true,false);
|
||||
$nlist[]=$peer;
|
||||
}
|
||||
//EVVIVA!
|
||||
gecho(' ADDING PEER «'.$peer.'» to next round list.'.N,true,false);
|
||||
$nlist[]=$peer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue