Skip to content

Commit

Permalink
v7.0-b9: * **Cloud** Supported list_preferred in online service nod…
Browse files Browse the repository at this point in the history
…e detection.
  • Loading branch information
Hai Zheng committed Nov 6, 2024
1 parent 05c829c commit 038ae23
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 40 deletions.
4 changes: 2 additions & 2 deletions litespeed-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin Name: LiteSpeed Cache
* Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration
* Description: High-performance page caching and site optimization from LiteSpeed
* Version: 7.0-b8
* Version: 7.0-b9
* Author: LiteSpeed Technologies
* Author URI: https://www.litespeedtech.com
* License: GPLv3
Expand Down Expand Up @@ -34,7 +34,7 @@
return;
}

!defined('LSCWP_V') && define('LSCWP_V', '7.0-b8');
!defined('LSCWP_V') && define('LSCWP_V', '7.0-b9');

!defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR);
!defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro
* **Core** Minimum required PHP version escalated to PHP v7.2.0.
* **Core** Minimum required WP version escalated to WP v5.3.
* **Cloud** Dropped `Domain Key`. Used sodium encryption for authentication and validation.
* **Cloud** Supported `list_preferred` in online service node detection.
* **Config** Improved QUIC.cloud CDN config to auto turn ON after activiated online service.
* **Database Optimize** Fixed Autoload summary for WP6.6+. (Mukesh Panchal/Viktor Szépe)
* **CLI** New QUIC.cloud CDN CLI `wp litespeed-online cdn_init --ssl-cert=xxx.pem --ssl-key=xxx -method=cname|ns|cfi`.
* **CLI** New QUIC.cloud CDN CLI `wp litespeed-online link [email protected] --api-key=xxxx`.
* **CLI** New QUIC.cloud CDN CLI `wp litespeed-online cdn_status`.
* **CLI** QUIC.cloud CDN CLI `wp litespeed-online ping` supports `--force` args now.
* **CLI** QUIC.cloud CLI `wp litespeed-online ping` supports `--force` args now.
* **Image Optimization** Dropped `Auto Pull Cron` setting. Added PHP const `LITESPEED_IMG_OPTM_ORI` support.
* **Crawler** Enhanced hash generation function for cryptographic security.
* **Crawler** Added back `Role Simulator` w/ IP limited to `127.0.0.1` only.
Expand Down
93 changes: 56 additions & 37 deletions src/cloud.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,49 +979,17 @@ public function detect_cloud($service, $force = false)
}

// Ping closest cloud
$speed_list = array();
foreach ($json['list'] as $v) {
// Exclude possible failed 503 nodes
if (!empty($this->_summary['disabled_node']) && !empty($this->_summary['disabled_node'][$v]) && time() - $this->_summary['disabled_node'][$v] < 86400) {
continue;
}
$speed_list[$v] = Utility::ping($v);
}

if (!$speed_list) {
self::debug('nodes are in 503 failed nodes');
return false;
$valid_clouds = false;
if (!empty($json['list_preferred'])) {
$valid_clouds = $this->_get_closest_nodes($json['list_preferred'], $service);
}

$min = min($speed_list);

if ($min == 99999) {
self::debug('failed to ping all clouds');
return false;
}

// Random pick same time range ip (230ms 250ms)
$range_len = strlen($min);
$range_num = substr($min, 0, 1);
$valid_clouds = array();
foreach ($speed_list as $node => $speed) {
if (strlen($speed) == $range_len && substr($speed, 0, 1) == $range_num) {
$valid_clouds[] = $node;
}
// Append the lower speed ones
elseif ($speed < $min * 4) {
$valid_clouds[] = $node;
}
if (!$valid_clouds) {
$valid_clouds = $this->_get_closest_nodes($json['list'], $service);
}

if (!$valid_clouds) {
$msg = __('Cloud Error', 'litespeed-cache') . ": [Service] $service [Info] " . __('No available Cloud Node.', 'litespeed-cache');
Admin_Display::error($msg);
return false;
}

self::debug('Closest nodes list', $valid_clouds);

// Check server load
if (in_array($service, self::$SERVICES_LOAD_CHECK)) { // TODO
$valid_cloud_loads = array();
Expand Down Expand Up @@ -1064,6 +1032,57 @@ public function detect_cloud($service, $force = false)
return $this->_summary['server.' . $service];
}

/**
* Ping to choose the closest nodes
* @since 7.0
*/
private function _get_closest_nodes($list, $service)
{
$speed_list = array();
foreach ($list as $v) {
// Exclude possible failed 503 nodes
if (!empty($this->_summary['disabled_node']) && !empty($this->_summary['disabled_node'][$v]) && time() - $this->_summary['disabled_node'][$v] < 86400) {
continue;
}
$speed_list[$v] = Utility::ping($v);
}

if (!$speed_list) {
self::debug('nodes are in 503 failed nodes');
return false;
}

$min = min($speed_list);

if ($min == 99999) {
self::debug('failed to ping all clouds');
return false;
}

// Random pick same time range ip (230ms 250ms)
$range_len = strlen($min);
$range_num = substr($min, 0, 1);
$valid_clouds = array();
foreach ($speed_list as $node => $speed) {
if (strlen($speed) == $range_len && substr($speed, 0, 1) == $range_num) {
$valid_clouds[] = $node;
}
// Append the lower speed ones
elseif ($speed < $min * 4) {
$valid_clouds[] = $node;
}
}

if (!$valid_clouds) {
$msg = __('Cloud Error', 'litespeed-cache') . ": [Service] $service [Info] " . __('No available Cloud Node.', 'litespeed-cache');
Admin_Display::error($msg);
return false;
}

self::debug('Closest nodes list', $valid_clouds);
return $valid_clouds;
}

/**
* May need to convert to queue service
*/
Expand Down

0 comments on commit 038ae23

Please sign in to comment.