From d67d59a25a951f236ee9bde74fd29ed773b3dd86 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 27 Feb 2015 19:14:20 -0400 Subject: [PATCH] propellor spin --- config-joey.hs | 2 +- src/Propellor/Property/Tor.hs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/config-joey.hs b/config-joey.hs index bd1a496..f9f4eaa 100644 --- a/config-joey.hs +++ b/config-joey.hs @@ -86,7 +86,7 @@ clam = standardSystem "clam.kitenet.net" Unstable "amd64" & Network.ipv6to4 & Tor.isRelay & Tor.named "kite1" - & Tor.bandwidthRate "128 kibibytes" + & Tor.bandwidthRate (Tor.PerMonth "400 GB") & Docker.configured & Docker.garbageCollected `period` Daily diff --git a/src/Propellor/Property/Tor.hs b/src/Propellor/Property/Tor.hs index 27c9761..3a0926b 100644 --- a/src/Propellor/Property/Tor.hs +++ b/src/Propellor/Property/Tor.hs @@ -80,15 +80,24 @@ configured settings = File.fileProperty "tor configured" go mainConfig toconfig (k, v) = k ++ " " ++ v fromconfig = separate (== ' ') -type BwLimit = String +data BwLimit + = PerSecond String + | PerDay String + | PerMonth String -- | Limit incoming and outgoing traffic to the specified --- amount, per second. +-- amount each. -- --- For example, "30 kibibytes" is the minimum limit for a useful relay. +-- For example, PerSecond "30 kibibytes" is the minimum limit +-- for a useful relay. bandwidthRate :: BwLimit -> Property NoInfo -bandwidthRate s = case readSize dataUnits s of - Just sz -> configured [("BandwidthRate", show sz ++ " bytes")] +bandwidthRate (PerSecond s) = bandwidthRate' s 1 +bandwidthRate (PerDay s) = bandwidthRate' s (24*60*60) +bandwidthRate (PerMonth s) = bandwidthRate' s (31*24*60*60) + +bandwidthRate' :: String -> Integer -> Property NoInfo +bandwidthRate' s divby = case readSize dataUnits s of + Just sz -> configured [("BandwidthRate", show (sz `div` divby) ++ " bytes")] Nothing -> property ("unable to parse " ++ s) noChange hiddenServiceAvailable :: HiddenServiceName -> Int -> Property NoInfo