diff --git a/get_online_session_communities.php b/get_online_session_communities.php index dcb12e5..0716822 100644 --- a/get_online_session_communities.php +++ b/get_online_session_communities.php @@ -29,16 +29,16 @@ */ $known_servers = array( "http://13.233.251.36:8081", - "http://open.session.codes", - "https://movistar.ht-rewrite.com", +// "http://open.session.codes", +// "https://movistar.ht-rewrite.com", "https://open.getsession.org", - "https://sog.zcyph.cc" +// "https://sog.zcyph.cc" ); $known_pubkeys = array( "13.233.251.36:8081" => "efcaecf00aebf5b75e62cf1fd550c6052842e1415a9339406e256c8b27cd2039", - "movistar.ht-rewrite.com" => "70d0a83cee9fe81bc2746eca379fbc4fca02a625cbe95b60a9bddbcf3f50045a", - "open.session.codes" => "c7fbfa183b601f4d393a43644dae11e5f644db2a18c747865db1ca922e632e32", +// "movistar.ht-rewrite.com" => "70d0a83cee9fe81bc2746eca379fbc4fca02a625cbe95b60a9bddbcf3f50045a", +// "open.session.codes" => "c7fbfa183b601f4d393a43644dae11e5f644db2a18c747865db1ca922e632e32", "open.getsession.org" => "a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238", "sog.zcyph.cc" => "e56fa54f9da6df91928f97023e8651e2df10fb6cf743a1ec96d0543acb8f2e7a" ); @@ -73,6 +73,7 @@ // print_r($servers); // print_r($rooms); +// print_r($pubkeys); // print_r($addr_assignments); // print_r($room_assignments); //TODO: We also assigned empty room arrays. Should probably be fixed @@ -208,6 +209,8 @@ $reduced_servers = array_unique($reduced_servers); sort($reduced_servers); +// print_r($offline_servers); + return $reduced_servers; } @@ -578,8 +581,8 @@ $preview_link_alt = $server . "/view/room/" . $token; // test if preview_links are 404 - if(!url_is_reachable($preview_link)) { - if(!url_is_reachable($preview_link_alt)) { + if(!url_is_200($preview_link)) { + if(!url_is_200($preview_link_alt)) { $preview_link = null; // $preview_link and $preview_link_alt not reachable } else { diff --git a/helper_functions.php b/helper_functions.php index 8c58013..c8948de 100644 --- a/helper_functions.php +++ b/helper_functions.php @@ -13,6 +13,29 @@ curl_exec($ch); $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); +// echo($url . " is " . $retcode . PHP_EOL); + if ($retcode != 0) { + return true; + } + else { + return false; + } + } + + /* + * Helper function for to decide room preview link + */ + function url_is_200($url) { + global $curl_connecttimeout_ms; + global $curl_timeout_ms; + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS , $curl_connecttimeout_ms); + curl_setopt($ch, CURLOPT_TIMEOUT_MS, $curl_timeout_ms); + curl_exec($ch); + $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); // echo($url . " is " . $retcode . PHP_EOL); if ($retcode == 200) { return true; @@ -26,6 +49,7 @@ * file_get_contents alternative that circumvents flaky routing to Chinese servers */ function curl_get_contents($url) { + // use separate timeouts to reliably get data from Chinese server with repeated tries $connecttimeout = 2; // wait at most X seconds to connect $timeout = 3; // can't take longer than X seconds for the whole curl process $sleep = 2; // sleep between tries in seconds