diff options
author | tobiasKaminsky <tobias@kaminsky.me> | 2020-02-21 11:40:29 +0300 |
---|---|---|
committer | tobiasKaminsky <tobias@kaminsky.me> | 2020-02-21 14:46:09 +0300 |
commit | 4fc6892d9d7d60ff0c213736f216ff1b1b86cf47 (patch) | |
tree | 2e2d130d1f5c83982de34d9783fa855bbbcf9de3 | |
parent | 93e11cd86ec7b26da0c59f6ba54dddf69b2e6f8d (diff) |
Use either updateSegment or random for throttled release
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
-rw-r--r-- | config/config.php | 1 | ||||
-rw-r--r-- | index.php | 2 | ||||
-rw-r--r-- | src/Response.php | 42 |
3 files changed, 42 insertions, 3 deletions
diff --git a/config/config.php b/config/config.php index ed66719..8a16186 100644 --- a/config/config.php +++ b/config/config.php @@ -26,6 +26,7 @@ declare(strict_types=1); */ return [ 'Nextcloud' => [ + 'release' => '2019-02-24 17:05', 'linux' => [ 'version' => '2.6.2', 'versionstring' => 'Nextcloud Client 2.6.2', @@ -83,6 +83,7 @@ $oem = isset($_GET['oem']) ? (string)$_GET['oem'] : null; $platform = isset($_GET['platform']) ? (string)$_GET['platform'] : null; $version = isset($_GET['version']) ? (string)$_GET['version'] : null; $isSparkle = isset($_GET['sparkle']) ? true : false; +$updateSegment = isset($_GET['updatesegment']) ? (int)$_GET['updatesegment'] : -1; if($oem === null || $platform === null || $version === null) { die(); @@ -96,6 +97,7 @@ $response = new \ClientUpdateServer\Response( $platform, $version, $isSparkle, + $updateSegment, $config ); echo $response->buildResponse(); diff --git a/src/Response.php b/src/Response.php index fa53d93..28df1e2 100644 --- a/src/Response.php +++ b/src/Response.php @@ -39,17 +39,20 @@ class Response { * @param string $platform * @param string $version * @param bool $isSparkle + * @param int $updatesegment * @param array $config */ public function __construct(string $oem, string $platform, string $version, bool $isSparkle, + int $updateSegment, array $config) { $this->oem = $oem; $this->platform = $platform; $this->version = $version; $this->isSparkle = $isSparkle; + $this->updateSegment = $updateSegment; $this->config = $config; } @@ -85,14 +88,47 @@ class Response { return []; } - $values = $this->config[$this->oem][$this->platform]; - if(version_compare($this->version, $values['version']) === -1) { - return $values; + $releaseTimeStamp = date_create($this->config[$this->oem]['release']); + + if ($this->updateSegment != -1) { + // updateSegment is 0-99, so even fine grained control is possible + $elapsedHours = $this->diffInHours(date_create(), $releaseTimeStamp); + $chunk = intdiv($this->updateSegment, 10); // 10 chunks + $throttle = intdiv($elapsedHours, 10); + + if ($throttle >= $chunk) { + $values = $this->config[$this->oem][$this->platform]; + if(version_compare($this->version, $values['version']) === -1) { + return $values; + } + } + } else if (isset($this->config[$this->oem]['release'])) { + // TODO remove after complete rollout of 2.6.4 + // throttle down: starting with 10% increase every 12h by 10% -> after 5d 100% + $elapsedHours = $this->diffInHours(date_create(), $releaseTimeStamp); + $throttle = intdiv($elapsedHours, 10); // 10 chunks + + if ($throttle >= rand(0, 10)) { + $values = $this->config[$this->oem][$this->platform]; + if(version_compare($this->version, $values['version']) === -1) { + return $values; + } + } + } else { // fallback if no updateSegment is provided + $values = $this->config[$this->oem][$this->platform]; + if(version_compare($this->version, $values['version']) === -1) { + return $values; + } } return []; } + private function diffInHours(\DateTime $date1, \DateTime $date2) : int { + $diff = $date2->diff($date1); + return $diff->h + ($diff->days * 24); + } + /** * Returns the current time stamp * @return string |