diff --git a/cabal.project b/cabal.project index 7d7339a7fb..af664652db 100644 --- a/cabal.project +++ b/cabal.project @@ -9,7 +9,7 @@ constraints: zip +disable-bzip2 +disable-zstd source-repository-package type: git location: https://github.com/simplex-chat/simplexmq.git - tag: 681fa93bf342d7c836fa0ff69b767dcd08526f03 + tag: ec1b72cb8013a65a5d9783104a47ae44f5730089 source-repository-package type: git diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index 0598bba8f1..690f78ea4f 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -913,7 +913,7 @@ data ChatError | ChatErrorAgent {agentError :: AgentErrorType, connectionEntity_ :: Maybe ConnectionEntity} | ChatErrorStore {storeError :: StoreError} | ChatErrorDatabase {databaseError :: DatabaseError} - | ChatErrorRemoteCtrl {remoteControllerError :: RemoteCtrlError} + | ChatErrorRemoteCtrl {remoteCtrlError :: RemoteCtrlError} | ChatErrorRemoteHost {remoteHostId :: RemoteHostId, remoteHostError :: RemoteHostError} deriving (Show, Exception, Generic) diff --git a/src/Simplex/Chat/Remote.hs b/src/Simplex/Chat/Remote.hs index 4671f43537..82d2e9e630 100644 --- a/src/Simplex/Chat/Remote.hs +++ b/src/Simplex/Chat/Remote.hs @@ -132,19 +132,18 @@ startRemoteCtrl = uiEvent <- async $ atomically $ readTMVar accepted waitEitherCatchCancel listener uiEvent >>= \case Left _ -> pure () -- discover got cancelled or crashed on some UDP error - Right (Left _) -> pure () -- readTMVar blocked indefinitely (should not happen) - Right (Right remoteCtrlId) -> do + Right (Left _) -> toView . CRChatError Nothing . ChatError $ CEException "Crashed while waiting for remote session confirmation" + Right (Right remoteCtrlId) -> -- got connection confirmation - (source, fingerprint) <- - atomically $ - TM.lookup remoteCtrlId discovered >>= \case - Nothing -> error "Session accepted without getting registered" - Just found -> found <$ writeTVar discovered mempty -- flush unused sources - host <- async $ runRemoteHost remoteCtrlId source fingerprint - chatWriteVar remoteCtrlSession $ Just RemoteCtrlSession {ctrlAsync = host, accepted} - _ <- waitCatch host - chatWriteVar remoteCtrlSession Nothing - toView $ CRRemoteCtrlStopped {remoteCtrlId} + atomically (TM.lookup remoteCtrlId discovered) >>= \case + Nothing -> toView . CRChatError Nothing . ChatError $ CEInternalError "Remote session accepted without getting discovered first" + Just (source, fingerprint) -> do + atomically $ writeTVar discovered mempty -- flush unused sources + host <- async $ runRemoteHost remoteCtrlId source fingerprint + chatWriteVar remoteCtrlSession $ Just RemoteCtrlSession {ctrlAsync = host, accepted} + _ <- waitCatch host + chatWriteVar remoteCtrlSession Nothing + toView $ CRRemoteCtrlStopped {remoteCtrlId} chatWriteVar remoteCtrlSession $ Just RemoteCtrlSession {ctrlAsync = listener, accepted} pure CRRemoteCtrlStarted diff --git a/src/Simplex/Chat/Remote/Types.hs b/src/Simplex/Chat/Remote/Types.hs index fa9b3fb359..5902476fc1 100644 --- a/src/Simplex/Chat/Remote/Types.hs +++ b/src/Simplex/Chat/Remote/Types.hs @@ -5,7 +5,7 @@ module Simplex.Chat.Remote.Types where import Control.Concurrent.Async (Async) -import Data.Aeson (ToJSON) +import Data.Aeson (ToJSON (..)) import Data.ByteString.Char8 (ByteString) import Data.Int (Int64) import Data.Text (Text) @@ -13,6 +13,7 @@ import GHC.Generics (Generic) import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Transport.HTTP2.Client (HTTP2Client) import UnliftIO.STM +import Simplex.Messaging.Encoding.String (strToJEncoding, strToJSON) type RemoteHostId = Int64 @@ -38,6 +39,11 @@ data RemoteCtrl = RemoteCtrl } deriving (Show, Generic, ToJSON) +-- XXX: until fixed in master +instance ToJSON C.KeyHash where + toEncoding = strToJEncoding + toJSON = strToJSON + data RemoteHostSession = RemoteHostSession { -- | Path for local resources to be synchronized with host storePath :: FilePath,