From dd4c6aeae1cf30035f3c7c3d52e58082f6b7aa36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 17 Nov 2019 21:53:00 +0100 Subject: Announce periodically and on local identity changes --- src/Main.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index 6bd0967..5ce9f86 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -75,16 +75,15 @@ main = do interactiveLoop :: Storage -> String -> IO () interactiveLoop st bhost = runInputT defaultSettings $ do erebosHead <- liftIO $ loadLocalState st - let serebos = wrappedLoad (headRef erebosHead) :: Stored LocalState - Just self = verifyIdentity $ lsIdentity $ fromStored serebos - outputStrLn $ T.unpack $ displayIdentity self + outputStrLn $ T.unpack $ maybe (error "failed to verify local identity") displayIdentity $ + verifyIdentity $ lsIdentity $ fromStored $ wrappedLoad $ headRef erebosHead haveTerminalUI >>= \case True -> return () False -> error "Requires terminal" extPrint <- getExternalPrint let extPrintLn str = extPrint $ str ++ "\n"; chanPeer <- liftIO $ - startServer extPrintLn bhost self + startServer erebosHead extPrintLn bhost [ (T.pack "attach", SomeService (emptyServiceState :: AttachService)) , (T.pack "dmsg", SomeService (emptyServiceState :: DirectMessageService)) ] @@ -123,8 +122,10 @@ interactiveLoop st bhost = runInputT defaultSettings $ do then (cmdSetPeer $ read scmd, args) else (fromMaybe (cmdUnknown scmd) $ lookup scmd commands, args) _ -> (cmdSend, input) + curHead <- liftIO $ loadLocalState st res <- liftIO $ runExceptT $ flip execStateT cstate $ runReaderT cmd CommandInput - { ciSelf = self + { ciSelf = fromMaybe (error "failed to verify local identity") $ + verifyIdentity $ lsIdentity $ fromStored $ wrappedLoad $ headRef curHead , ciLine = line , ciPrint = extPrintLn , ciPeers = liftIO $ readMVar peers -- cgit v1.2.3