From 686dcc8b172b77e3e612ba4badbb88879d0f5599 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 27 Apr 2017 15:26:50 -0400 Subject: Leave the prevMessage out of Activity serialization to save BW. Do include it in the data that gets signed, so it can be recovered by trying each likely (recently seen) Activity as the prevMessage, and checking the signature. The UserState and DeveloperState already had the necessary state about recently seen hashes, so this does not impact data use. One tricky bit is that relayFromSocket needs to wait for the TMChan to be empty before calling restorePrevActivityHash. Otherwise, the hashes of items in the channel that have not been processed yet won't be tried. The TMChan is not really being used as a channel since only 1 item can be in it. It could be converted to a TMVar, but closeTMChan is used so I left it as a channel. Note that the server does not restore hashes of messages that pass through it; it's just a dumb relay. Sending a single key press now only needs 94 bytes of data to be sent, down from 169! --- Also switched to SHA512, since hashes are no longer being sent over the wire and so the larger size does not matter. SHA512 is slightly faster and more secure. This commit was sponsored by Ewen McNeill. --- Role/Downloader.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Role/Downloader.hs') diff --git a/Role/Downloader.hs b/Role/Downloader.hs index d49b4ec..4d5f6cc 100644 --- a/Role/Downloader.hs +++ b/Role/Downloader.hs @@ -4,7 +4,7 @@ import Types import Log import CmdLine import SessionID -import Role.Developer (run', processSessionStart, getServerMessage, Output(..)) +import Role.Developer import Control.Concurrent.STM import Control.Concurrent.STM.TMChan @@ -13,13 +13,13 @@ import Data.Time.Clock.POSIX run :: DownloadOpts -> IO () run = run' downloader . downloadUrl -downloader :: TMChan (Message Entered) -> TMChan AnyMessage -> SessionID -> IO () -downloader _ichan ochan sid = do +downloader :: TMVar (TVar DeveloperState) -> TMChan (Message Entered) -> TMChan AnyMessage -> SessionID -> IO () +downloader dsv _ichan ochan sid = do let logfile = sessionLogFile "." sid putStrLn $ "Starting download to " ++ logfile putStrLn "(Will keep downloading until the debug-me session is done.)" withLogger logfile $ \logger -> do - (st, _startoutput) <- processSessionStart ochan logger + (st, _startoutput) <- processSessionStart ochan logger dsv go logger st where go logger st = do -- cgit v1.2.3