mirror of
https://github.com/friendica/friendica
synced 2024-12-22 13:20:15 +00:00
Merge pull request #14428 from annando/gserver-loop
Prevent a loop when trying to detect the server type
This commit is contained in:
commit
d48d07e18d
1 changed files with 5 additions and 33 deletions
|
@ -1780,43 +1780,15 @@ class GServer
|
|||
*/
|
||||
private static function detectNetworkViaContacts(string $url, array $serverdata): array
|
||||
{
|
||||
$contacts = [];
|
||||
|
||||
$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)) {
|
||||
$contact = DBA::selectFirst('contact', ['network'], ["`network` != ? AND NOT `failed` AND `uid` = ? AND `baseurl` IN (?, ?)", Protocol::PHANTOM, 0, $url, Strings::normaliseLink($url)]);
|
||||
if (empty($contact)) {
|
||||
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)) {
|
||||
$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;
|
||||
}
|
||||
if (in_array($serverdata['detection-method'], self::DETECT_UNSPECIFIC)) {
|
||||
$serverdata['detection-method'] = self::DETECT_CONTACTS;
|
||||
}
|
||||
|
||||
return $serverdata;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue