summaryrefslogtreecommitdiffhomepage
path: root/Server.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-27 15:26:50 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-27 15:55:39 -0400
commit686dcc8b172b77e3e612ba4badbb88879d0f5599 (patch)
tree5dd568eb15fe1a64a0c77adda8901509396ebd73 /Server.hs
parentf6a9cd9c705850a19e2677150c1168bea1a7a9c7 (diff)
downloaddebug-me-686dcc8b172b77e3e612ba4badbb88879d0f5599.tar.gz
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.
Diffstat (limited to 'Server.hs')
-rw-r--r--Server.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/Server.hs b/Server.hs
index 62d0a3c..f8e8588 100644
--- a/Server.hs
+++ b/Server.hs
@@ -7,6 +7,7 @@ import CmdLine
import WebSockets
import SessionID
import Log
+import PrevActivity
import Network.Wai
import Network.Wai.Handler.Warp
@@ -144,7 +145,7 @@ user o ssv conn = withSessionID (serverDirectory o) $ \(loghv, sid) -> do
-- (The user is allowed to send Developer messages too.. perhaps
-- they got them from a developer connected to them some other
-- way.)
- relayfromuser session = relayFromSocket conn $ \msg -> do
+ relayfromuser session = relayFromSocket conn noRecentActivity (return ()) $ \msg -> do
l <- mkLog msg <$> getPOSIXTime
writeSession session l
@@ -183,11 +184,13 @@ developer o ssv sid conn = bracket setup cleanup go
-- Relay all Developer amessages from the developer's websocket
-- to the broadcast channel.
- relayfromdeveloper session = relayFromSocket conn $ \msg -> case msg of
- Developer _ -> do
- l <- mkLog msg <$> getPOSIXTime
- writeSession session l
- User _ -> return () -- developer cannot send User messages
+ relayfromdeveloper session = relayFromSocket conn noRecentActivity (return ())
+ $ \msg -> case msg of
+ Developer _ -> do
+ l <- mkLog msg <$> getPOSIXTime
+ writeSession session l
+ -- developer cannot send User messages
+ User _ -> return ()
-- Relay user messages from the developer's clone of the
-- broadcast channel to the developer's websocket.