Merge pull request #14428 from annando/gserver-loop

Prevent a loop when trying to detect the server type
This commit is contained in:
Tobias Diekershoff 2024-09-10 07:30:30 +02:00 committed by GitHub
commit d48d07e18d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1780,43 +1780,15 @@ class GServer
*/ */
private static function detectNetworkViaContacts(string $url, array $serverdata): array private static function detectNetworkViaContacts(string $url, array $serverdata): array
{ {
$contacts = []; $contact = DBA::selectFirst('contact', ['network'], ["`network` != ? AND NOT `failed` AND `uid` = ? AND `baseurl` IN (?, ?)", Protocol::PHANTOM, 0, $url, Strings::normaliseLink($url)]);
if (empty($contact)) {
$nurl = Strings::normaliseLink($url);
$apcontacts = DBA::select('apcontact', ['url'], ['baseurl' => [$url, $nurl]]);
while ($apcontact = DBA::fetch($apcontacts)) {
$contacts[Strings::normaliseLink($apcontact['url'])] = $apcontact['url'];
}
DBA::close($apcontacts);
$pcontacts = DBA::select('contact', ['url', 'nurl'], ['uid' => 0, 'baseurl' => [$url, $nurl]]);
while ($pcontact = DBA::fetch($pcontacts)) {
$contacts[$pcontact['nurl']] = $pcontact['url'];
}
DBA::close($pcontacts);
if (empty($contacts)) {
return $serverdata; return $serverdata;
} }
$serverdata['network'] = $contact['network'];
$time = time();
foreach ($contacts as $contact) {
// Endlosschleife verhindern wegen gsid!
$data = Probe::uri($contact);
if (in_array($data['network'], Protocol::FEDERATED)) {
$serverdata['network'] = $data['network'];
if (in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) { if (in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) {
$serverdata['detection-method'] = self::DETECT_CONTACTS; $serverdata['detection-method'] = self::DETECT_CONTACTS;
} }
break;
} elseif ((time() - $time) > 10) {
// To reduce the stress on remote systems we probe a maximum of 10 seconds
break;
}
}
return $serverdata; return $serverdata;
} }