summaryrefslogtreecommitdiffhomepage
path: root/Storage.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-23 17:42:45 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-23 17:42:45 -0400
commit823ebff934cf2e23afae199c24cc599983209438 (patch)
tree7588b3693dcff7f3b773ceb68b01eea989ccf250 /Storage.hs
parentc2aa90a92349be09d88270c3ee6d4b7fddbf4768 (diff)
downloadkeysafe-823ebff934cf2e23afae199c24cc599983209438.tar.gz
Added --chaff-max-delay option for slower chaffing.
This commit was sponsored by Jeff Goeke-Smith on Patreon.
Diffstat (limited to 'Storage.hs')
-rw-r--r--Storage.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/Storage.hs b/Storage.hs
index b5d847f..b5d07f5 100644
--- a/Storage.hs
+++ b/Storage.hs
@@ -10,6 +10,7 @@ module Storage (module Storage, module Types.Storage) where
import Types
import Types.Storage
import Types.Server
+import Types.Cost
import Share
import Storage.Local
import Storage.Network
@@ -22,6 +23,8 @@ import System.IO
import System.FilePath
import Control.Monad
import Crypto.Random
+import System.Random
+import Control.Concurrent.Thread.Delay
import Control.Concurrent.Async
import qualified Data.Set as S
import Network.Wai.Handler.Warp (Port)
@@ -134,8 +137,8 @@ tryUploadQueued d = do
processresults (StoreAlreadyExists:rs) c =
processresults rs ("Unable to upload a share to a server due to a name conflict.":c)
-storeChaff :: HostName -> Port -> IO ()
-storeChaff hn port = forever $ do
+storeChaff :: HostName -> Port -> Maybe Seconds -> IO ()
+storeChaff hn port delayseconds = forever $ do
putStrLn $ "Sending chaff to " ++ hn ++ " (press ctrl-c to stop)"
putStrLn "Legend: + = successful upload, ! = upload failure"
rng <- (cprgCreate <$> createEntropyPool) :: IO SystemRNG
@@ -151,6 +154,7 @@ storeChaff hn port = forever $ do
server = networkStorage Nothing $
Server (ServerName hn) Untrusted [ServerAddress hn port]
objsize = objectSize defaultTunables * shareOverhead defaultTunables
+ maxmsdelay = ceiling $ 1000000 * fromMaybe 0 delayseconds
go sis rng n = do
let (b, rng') = cprgGenerate objsize rng
let share = Share 0 (StorableObject b)
@@ -161,4 +165,6 @@ storeChaff hn port = forever $ do
StoreSuccess -> putStr "+"
_ -> putStr "!"
hFlush stdout
+ msdelay <- getStdRandom (randomR (0, maxmsdelay))
+ delay msdelay
go sis' rng' n