diff --git a/htools/Ganeti/Confd/Server.hs b/htools/Ganeti/Confd/Server.hs index 53891c34af7acb8134c3bdff45bcc4ea4821fa05..b4b13854f7ea294188e6a6e17a90fdd14c0ab4b3 100644 --- a/htools/Ganeti/Confd/Server.hs +++ b/htools/Ganeti/Confd/Server.hs @@ -100,6 +100,10 @@ configReloadTimeout = C.confdConfigReloadTimeout * 1000000 configReloadRatelimit :: Int configReloadRatelimit = C.confdConfigReloadRatelimit * 1000000 +-- | Ratelimit timeout in seconds, as an 'Integer'. +reloadRatelimitSec :: Integer +reloadRatelimitSec = fromIntegral C.confdConfigReloadRatelimit + -- | Initial poll round. initialPoll :: ReloadModel initialPoll = ReloadPoll 0 @@ -448,8 +452,7 @@ onInotify inotify path cref mstate _ = ctime <- getCurrentTime (newfstat, _) <- safeUpdateConfig path (reloadFStat state) cref let state' = state { reloadFStat = newfstat, reloadTime = ctime } - if abs (reloadTime state - ctime) < - fromIntegral C.confdConfigReloadRatelimit + if abs (reloadTime state - ctime) < reloadRatelimitSec then do mode <- moveToPolling "too many reloads" inotify path cref mstate return state' { reloadModel = mode } diff --git a/htools/Ganeti/Confd/Utils.hs b/htools/Ganeti/Confd/Utils.hs index 667055f7e0926bcf54daba9cb944461af513b28d..71f4ef0069dd49bbd49c6f8cef620c966a8ae716 100644 --- a/htools/Ganeti/Confd/Utils.hs +++ b/htools/Ganeti/Confd/Utils.hs @@ -44,6 +44,10 @@ import qualified Ganeti.Path as Path import Ganeti.JSON import Ganeti.Utils +-- | Type-adjusted max clock skew constant. +maxClockSkew :: Integer +maxClockSkew = fromIntegral C.confdMaxClockSkew + -- | Returns the HMAC key. getClusterHmac :: IO HashKey getClusterHmac = Path.confdHmacKey >>= fmap B.unpack . B.readFile @@ -64,7 +68,7 @@ parseMessage :: HashKey -> String -> Integer parseMessage hmac msg curtime = do (salt, origmsg, request) <- parseRequest hmac msg ts <- tryRead "Parsing timestamp" salt::Result Integer - if abs (ts - curtime) > fromIntegral C.confdMaxClockSkew + if abs (ts - curtime) > maxClockSkew then fail "Too old/too new timestamp or clock skew" else return (origmsg, request)