From 997b98e345989c53873965b3263acd799b311585 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 12 Mar 2019 05:21:04 +0000 Subject: [PATCH 1/2] Fix for falsely detected AP profile in case of timeout --- src/Network/Probe.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index b061595d2..135c36b74 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -35,6 +35,7 @@ use DomXPath; class Probe { private static $baseurl; + private static $istimeout; /** * @brief Rearrange the array so that it always has the same order @@ -124,6 +125,7 @@ class Probe $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($curlResult->isTimeout()) { Logger::log("Probing timeout for " . $url, Logger::DEBUG); + self::$istimeout = true; return false; } $xml = $curlResult->getBody(); @@ -334,16 +336,22 @@ class Probe $uid = local_user(); } + self::$istimeout = false; + if ($network != Protocol::ACTIVITYPUB) { $data = self::detect($uri, $network, $uid); } else { $data = null; } - $ap_profile = ActivityPub::probeProfile($uri); + // When the previous detection process had got a time out + // we could falsely detect a Friendica profile as AP profile. + if (!self::$istimeout) { + $ap_profile = ActivityPub::probeProfile($uri); - if (!empty($ap_profile) && empty($network) && (defaults($data, 'network', '') != Protocol::DFRN)) { - $data = $ap_profile; + if (!empty($ap_profile) && empty($network) && (defaults($data, 'network', '') != Protocol::DFRN)) { + $data = $ap_profile; + } } if (!isset($data['url'])) { @@ -756,6 +764,7 @@ class Probe $curlResult = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($curlResult->isTimeout()) { + self::$istimeout = true; return false; } $data = $curlResult->getBody(); @@ -824,6 +833,7 @@ class Probe { $curlResult = Network::curl($noscrape_url); if ($curlResult->isTimeout()) { + self::$istimeout = true; return false; } $content = $curlResult->getBody(); @@ -1075,6 +1085,7 @@ class Probe { $curlResult = Network::curl($hcard_url); if ($curlResult->isTimeout()) { + self::$istimeout = true; return false; } $content = $curlResult->getBody(); @@ -1327,6 +1338,7 @@ class Probe } elseif (Strings::normaliseLink($pubkey) == 'http://') { $curlResult = Network::curl($pubkey); if ($curlResult->isTimeout()) { + self::$istimeout = true; return false; } $pubkey = $curlResult->getBody(); @@ -1359,6 +1371,7 @@ class Probe // Fetch all additional data from the feed $curlResult = Network::curl($data["poll"]); if ($curlResult->isTimeout()) { + self::$istimeout = true; return false; } $feed = $curlResult->getBody(); @@ -1573,6 +1586,7 @@ class Probe { $curlResult = Network::curl($url); if ($curlResult->isTimeout()) { + self::$istimeout = true; return false; } $feed = $curlResult->getBody(); From 4b9820031542d83a0273ac79f833831e8ed93b73 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 12 Mar 2019 05:45:02 +0000 Subject: [PATCH 2/2] Added logging --- src/Network/Probe.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 135c36b74..3dceb81bc 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -352,6 +352,8 @@ class Probe if (!empty($ap_profile) && empty($network) && (defaults($data, 'network', '') != Protocol::DFRN)) { $data = $ap_profile; } + } else { + Logger::notice('Time out detected. AP will not be probed.', ['url' => $url]); } if (!isset($data['url'])) {