From f559fcfadd7079140ed64bab68275527f46d334e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 2 May 2017 15:52:27 -0400 Subject: add prevEntered pointer Client requires this always point to the previous Entered it accepted, so a hash chain of Entered is built up, and there is no possibility for ambiguity about which order a client received two Entered activies in. So restoreHashes now has to try every possible combination of known hashes for both prevEntered and prevActivity. That could be significantly more work, but it would be unusual for there to be a lot of known hashes, so it should be ok. --graphviz shows this additional hash chain with grey edges (and leaves out edges identical to the other hash chain) While testing this with an artifical network lag, it turned out that signature verification was failing for Reject messages sent by the user. Didn't quite figure out what was at the bottom of that, but the Activity Entered that was sent back in a Reject message was clearly not useful, because it probably had both its prevEntered and prevActivity hashes set to Nothing (because restoreHashes didn't restore them, because the original Activity Entered was out of the expected chain). So, switched Rejected to use a Hash. (And renamed Rejected to EnteredRejected to make it more clear what it's rejecting.) Also, added a lastAccepted hash to EnteredRejected. This lets the developer find its way back to the accepted chain when some of its input gets rejected. This commit was sponsored by Trenton Cronholm on Patreon. --- WebSockets.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'WebSockets.hs') diff --git a/WebSockets.hs b/WebSockets.hs index 7750cf8..a220c68 100644 --- a/WebSockets.hs +++ b/WebSockets.hs @@ -44,6 +44,7 @@ import Data.Maybe import Text.Read import Control.Monad import Network.URI +import System.IO -- | Framing protocol used over a websocket connection. -- @@ -126,7 +127,7 @@ runClientApp :: URI -> ClientApp a -> IO (Maybe a) runClientApp serverurl app = do rv <- newEmptyTMVarIO let go conn = do - r <- app conn + r <- app conn `catch` showerr atomically $ putTMVar rv r catchJust catchconnclosed (runClientWith host port endpoint connectionOptions [] go) @@ -139,9 +140,15 @@ runClientApp serverurl app = do (':':s) -> fromMaybe 80 (readMaybe s) _ -> 80 endpoint = uriPath serverurl + catchconnclosed ConnectionClosed = Just () catchconnclosed _ = Nothing + showerr :: SomeException -> IO a + showerr e = do + hPutStrLn stderr (show e) + throwIO e + -- | Make a client that sends and receives AnyMessages over a websocket. clientApp :: Mode -- cgit v1.2.3