summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2015-02-27 19:14:20 -0400
committerJoey Hess2015-02-27 19:14:20 -0400
commitd67d59a25a951f236ee9bde74fd29ed773b3dd86 (patch)
tree53974ecbdb867d54edca7fdf2506aa9ce20e1eb8
parentf0a4e642c490c4a91e62788e0c46f192b402e7f0 (diff)
propellor spin
-rw-r--r--config-joey.hs2
-rw-r--r--src/Propellor/Property/Tor.hs19
2 files changed, 15 insertions, 6 deletions
diff --git a/config-joey.hs b/config-joey.hs
index bd1a4965..f9f4eaa7 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 27c9761f..3a0926be 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