Skip to content
Snippets Groups Projects
Commit 9d3867b1 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add constants for two values which we re-evaluate


Two constants which we use as Integer are defined as Int in
Constants.hs (coming from constants.py), so we do the conversion every
time we use it. Let's move them to top-level names, so that the
conversion is only done once.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 5448799c
No related branches found
No related tags found
No related merge requests found
......@@ -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 }
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment