ZP-739 Implemtent ping higher and lower bound. Released under the Affero GNU...

ZP-739 Implemtent ping higher and lower bound. Released under the Affero GNU General Public License (AGPL) version 3.
parent 6331dd1a
......@@ -69,6 +69,7 @@
* true - use the complete email address.
*/
define('USE_FULLEMAIL_FOR_LOGIN', false);
/**********************************************************************************
* Default FileStateMachine settings
*/
......@@ -218,6 +219,18 @@
// NOTE: THIS IS AN EXPERIMENTAL FEATURE WHICH COULD PREVENT YOUR MOBILES FROM SYNCHRONIZING.
define('USE_PARTIAL_FOLDERSYNC', false);
// The minimum accepted time in second that a ping command should last.
// It is strongly advised to keep this config to false. Some device
// might not be able to send a higher value than the one specificied here and thus
// unable to start a push connection.
// If set to false, there will be no lower bound to the ping lifetime.
define('PING_LOWER_BOUND_LIFETIME', false);
// The maximum accepted time in second that a ping command should last.
// If set to false, there will be no higher bound to the ping lifetime.
define('PING_HIGHER_BOUND_LIFETIME', false);
/**********************************************************************************
* Backend settings
*/
......
......@@ -283,6 +283,22 @@ class ZPush {
define('USE_PARTIAL_FOLDERSYNC', false);
}
if (!defined('PING_LOWER_BOUND_LIFETIME')) {
define('PING_LOWER_BOUND_LIFETIME', false);
}
elseif(PING_LOWER_BOUND_LIFETIME !== false && (!is_int(PING_LOWER_BOUND_LIFETIME) || PING_LOWER_BOUND_LIFETIME < 1)){
throw new FatalMisconfigurationException("The PING_LOWER_BOUND_LIFETIME value must be 'false' or a number higher than 0.");
}
if (!defined('PING_HIGHER_BOUND_LIFETIME')) {
define('PING_HIGHER_BOUND_LIFETIME', false);
}
elseif(PING_HIGHER_BOUND_LIFETIME !== false && (!is_int(PING_HIGHER_BOUND_LIFETIME) || PING_HIGHER_BOUND_LIFETIME < 1)){
throw new FatalMisconfigurationException("The PING_HIGHER_BOUND_LIFETIME value must be 'false' or a number higher than 0.");
}
if(PING_HIGHER_BOUND_LIFETIME !== false && PING_LOWER_BOUND_LIFETIME !== false && PING_HIGHER_BOUND_LIFETIME < PING_LOWER_BOUND_LIFETIME){
throw new FatalMisconfigurationException("The PING_HIGHER_BOUND_LIFETIME value must be greater or equal to PING_LOWER_BOUND_LIFETIME.");
}
// the check on additional folders will not throw hard errors, as this is probably changed on live systems
if (isset($additionalFolders) && !is_array($additionalFolders))
ZLog::Write(LOGLEVEL_ERROR, "ZPush::CheckConfig() : The additional folders synchronization not available as array.");
......
......@@ -154,6 +154,9 @@ class Ping extends RequestProcessor {
if(!self::$decoder->getElementEndTag())
return false;
if(!$this->LifetimeBetweenBound($sc->GetLifetime())){
$pingstatus = SYNC_PINGSTATUS_HBOUTOFRANGE;
}
// save changed data
foreach ($sc as $folderid => $spa)
$sc->SaveCollection($spa);
......@@ -165,8 +168,13 @@ class Ping extends RequestProcessor {
$pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS;
ZLog::Write(LOGLEVEL_DEBUG, "HandlePing(): no pingable folders found and no initialization data sent. Returning SYNC_PINGSTATUS_FAILINGPARAMS.");
}
elseif(!$this->LifetimeBetweenBound($sc->GetLifetime())){
$pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS;
ZLog::Write(LOGLEVEL_DEBUG, "HandlePing(): ping lifetime not between bound (higher bound:`".PING_HIGHER_BOUND_LIFETIME."` lower bound:`".PING_LOWER_BOUND_LIFETIME."` current lifetime:`".$sc->GetLifetime()."`. Returning SYNC_PINGSTATUS_FAILINGPARAMS.");
}
}
// Check for changes on the default LifeTime, set interval and ONLY on pingable collections
try {
if (!$pingstatus && empty($fakechanges)) {
......@@ -220,9 +228,39 @@ class Ping extends RequestProcessor {
}
self::$encoder->endTag();
}
elseif($pingstatus == SYNC_PINGSTATUS_HBOUTOFRANGE){
self::$encoder->startTag(SYNC_PING_LIFETIME);
if($sc->GetLifetime() > PING_HIGHER_BOUND_LIFETIME){
self::$encoder->content(PING_HIGHER_BOUND_LIFETIME);
}
else{
self::$encoder->content(PING_LOWER_BOUND_LIFETIME);
}
self::$encoder->endTag();
}
}
self::$encoder->endTag();
return true;
}
/**
* Return true if the ping lifetime is between the specified bound (PING_HIGHER_BOUND_LIFETIME and PING_LOWER_BOUND_LIFETIME). If no bound are specified, it returns true.
*
* @access private
* @return boolean
*/
private function LifetimeBetweenBound($lifetime){
if(PING_HIGHER_BOUND_LIFETIME !== false && PING_LOWER_BOUND_LIFETIME !== false){
return ($lifetime <= PING_HIGHER_BOUND_LIFETIME && $lifetime >= PING_LOWER_BOUND_LIFETIME);
}
if(PING_HIGHER_BOUND_LIFETIME !== false){
return $lifetime <= PING_HIGHER_BOUND_LIFETIME;
}
if(PING_LOWER_BOUND_LIFETIME !== false){
return $lifetime >= PING_LOWER_BOUND_LIFETIME;
}
return true;
}
}
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