Commit 6176a979 authored by noplanman's avatar noplanman

Modify return value of _curl function and improve some variable naming.

parent c2c9f68d
......@@ -96,25 +96,24 @@ foreach ($pods as $pod) {
$user_rating = round(array_sum($user_ratings) / count($user_ratings), 2);
}
// Default link to fetch node info.
$link = "https://{$domain}/nodeinfo/1.0";
$nodeinfo_meta = _curl("https://{$domain}/.well-known/nodeinfo");
extract(_curl("https://{$domain}/.well-known/nodeinfo"));
$outputwellknown = $curl_body;
// Default link to fetch node info.
$nodeinfo_url = "https://{$domain}/nodeinfo/1.0";
if ($outputwellknown !== false) {
$info = json_decode($outputwellknown, true);
$link = max($info['links'])['href'];
if ($nodeinfo_meta['body'] !== false) {
$info = json_decode($nodeinfo_meta['body'], true);
$nodeinfo_url = max($info['links'])['href'];
}
_debug('Nodeinfo link', $link);
extract(_curl($link));
_debug('Nodeinfo link', $nodeinfo_url);
$nodeinfo = _curl($nodeinfo_url);
$outputssl = $curl_body;
$outputsslerror = $curl_error;
$info = $curl_info;
$conntime = $curl_conntime;
$nstime = $curl_nstime;
$outputssl = $nodeinfo['body'];
$outputsslerror = $nodeinfo['error'];
$info = $nodeinfo['info'];
$conntime = $nodeinfo['conntime'];
$nstime = $nodeinfo['nstime'];
$latency = $conntime - $nstime;
$sslexpire = $info[0]['Expire date'] ?? null;
......@@ -462,7 +461,14 @@ function _debug($label, $var = null, $dump = false)
printf('%s: %s%s', $label, $output, $newline);
}
function _curl($url)
/**
* Execute cURL request and return array of data.
*
* @param string $url
*
* @return array
*/
function _curl(string $url): array
{
$chss = curl_init();
curl_setopt($chss, CURLOPT_URL, $url);
......@@ -471,12 +477,14 @@ function _curl($url)
curl_setopt($chss, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($chss, CURLOPT_CERTINFO, 1);
curl_setopt($chss, CURLOPT_CAINFO, c('cafullpath'));
return [
'curl_body' => curl_exec($chss),
'curl_error' => curl_error($chss),
'curl_info' => curl_getinfo($chss, CURLINFO_CERTINFO),
'curl_conntime' => curl_getinfo($chss, CURLINFO_CONNECT_TIME),
'curl_nstime' => curl_getinfo($chss, CURLINFO_NAMELOOKUP_TIME),
$data = [
'body' => curl_exec($chss),
'error' => curl_error($chss),
'info' => curl_getinfo($chss, CURLINFO_CERTINFO),
'conntime' => curl_getinfo($chss, CURLINFO_CONNECT_TIME),
'nstime' => curl_getinfo($chss, CURLINFO_NAMELOOKUP_TIME),
];
curl_close($chss);
return $data;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment