From 87fffeb698c03f27fc51194e9c4774baec383df6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Thu, 16 May 2024 19:29:36 +0100 Subject: [PATCH] core: command to debug user network state --- cabal.project | 2 +- scripts/nix/sha256map.nix | 2 +- src/Simplex/Chat.hs | 3 +++ src/Simplex/Chat/Controller.hs | 8 +++++++- src/Simplex/Chat/View.hs | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cabal.project b/cabal.project index 94b077e12c..5278284f26 100644 --- a/cabal.project +++ b/cabal.project @@ -12,7 +12,7 @@ constraints: zip +disable-bzip2 +disable-zstd source-repository-package type: git location: https://github.com/simplex-chat/simplexmq.git - tag: 58c1be236a9b14967240903ae4868eb925472d0d + tag: 7d30eb6548e81df197931e755b8b6853774d622a source-repository-package type: git diff --git a/scripts/nix/sha256map.nix b/scripts/nix/sha256map.nix index 1ea111506a..20f192994f 100644 --- a/scripts/nix/sha256map.nix +++ b/scripts/nix/sha256map.nix @@ -1,5 +1,5 @@ { - "https://github.com/simplex-chat/simplexmq.git"."58c1be236a9b14967240903ae4868eb925472d0d" = "0hqzzgm9845ppq1afqp93b2rq7hfj24s35bmx9vrjf5rr8pw3f5y"; + "https://github.com/simplex-chat/simplexmq.git"."7d30eb6548e81df197931e755b8b6853774d622a" = "07fs1y6mamkiz6cxv94n2palismxc0yi5mjwb03jla6hfvqdrmxp"; "https://github.com/simplex-chat/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38"; "https://github.com/simplex-chat/direct-sqlcipher.git"."f814ee68b16a9447fbb467ccc8f29bdd3546bfd9" = "1ql13f4kfwkbaq7nygkxgw84213i0zm7c1a8hwvramayxl38dq5d"; "https://github.com/simplex-chat/sqlcipher-simple.git"."a46bd361a19376c5211f1058908fc0ae6bf42446" = "1z0r78d8f0812kxbgsm735qf6xx8lvaz27k1a0b4a2m0sshpd5gl"; diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 6e91d39c63..be93199fe4 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -2225,6 +2225,8 @@ processChatCommand' vr = \case counts <- map (first decodeLatin1) <$> withAgent' getMsgCounts let allMsgs = foldl' (\(ts, ds) (_, (t, d)) -> (ts + t, ds + d)) (0, 0) counts pure CRAgentMsgCounts {msgCounts = ("all", allMsgs) : sortOn (Down . snd) (filter (\(_, (_, d)) -> d /= 0) counts)} + GetAgentUserNetworkState -> + CRAgentUserNetworkState <$> (readTVarIO =<< asks (userNetworkState . smpAgent)) GetAgentSubs diff -> withUser $ \User {userId} -> lift $ CRAgentSubs <$> withAgent' (\a -> getAgentSubscriptions a diff (Just userId)) -- CustomChatCommand is unsupported, it can be processed in preCmdHook -- in a modified CLI app or core - the hook should return Either ChatResponse ChatCommand @@ -7372,6 +7374,7 @@ chatCommandP = "/get workers" $> GetAgentWorkers, "/get workers details" $> GetAgentWorkersDetails, "/get msgs" $> GetAgentMsgCounts, + "/debug net" $> GetAgentUserNetworkState, "//" *> (CustomChatCommand <$> A.takeByteString) ] where diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index 66e3ea1b60..8696798523 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -67,7 +67,7 @@ import Simplex.Chat.Types.UITheme import Simplex.Chat.Util (liftIOEither) import Simplex.FileTransfer.Description (FileDescriptionURI) import Simplex.Messaging.Agent (AgentClient, SubscriptionsInfo) -import Simplex.Messaging.Agent.Client (AgentLocks, AgentWorkersDetails (..), AgentWorkersSummary (..), ProtocolTestFailure, UserNetworkInfo) +import Simplex.Messaging.Agent.Client (AgentLocks, AgentWorkersDetails (..), AgentWorkersSummary (..), ProtocolTestFailure, UserNetworkInfo, UNSOffline, UserNetworkState) import Simplex.Messaging.Agent.Env.SQLite (AgentConfig, NetworkConfig) import Simplex.Messaging.Agent.Lock import Simplex.Messaging.Agent.Protocol @@ -501,6 +501,7 @@ data ChatCommand | GetAgentWorkers | GetAgentWorkersDetails | GetAgentMsgCounts + | GetAgentUserNetworkState | -- The parser will return this command for strings that start from "//". -- This command should be processed in preCmdHook CustomChatCommand ByteString @@ -746,6 +747,7 @@ data ChatResponse | CRAgentWorkersSummary {agentWorkersSummary :: AgentWorkersSummary} | CRAgentSubs {agentSubs :: SubscriptionsInfo} | CRAgentMsgCounts {msgCounts :: [(Text, (Int, Int))]} + | CRAgentUserNetworkState {networkState :: UserNetworkState} | CRContactDisabled {user :: User, contact :: Contact} | CRConnectionDisabled {connectionEntity :: ConnectionEntity} | CRAgentRcvQueueDeleted {agentConnId :: AgentConnId, server :: SMPServer, agentQueueId :: AgentQueueId, agentError_ :: Maybe AgentErrorType} @@ -1478,6 +1480,10 @@ $(JQ.deriveJSON (sumTypeJSON $ dropPrefix "RCSR") ''RemoteCtrlStopReason) $(JQ.deriveJSON (sumTypeJSON $ dropPrefix "RHSR") ''RemoteHostStopReason) +$(JQ.deriveJSON defaultJSON ''UNSOffline) + +$(JQ.deriveJSON defaultJSON ''UserNetworkState) + $(JQ.deriveJSON (sumTypeJSON $ dropPrefix "CR") ''ChatResponse) $(JQ.deriveFromJSON defaultJSON ''ArchiveConfig) diff --git a/src/Simplex/Chat/View.hs b/src/Simplex/Chat/View.hs index 5c2a8acf50..f88b388ebd 100644 --- a/src/Simplex/Chat/View.hs +++ b/src/Simplex/Chat/View.hs @@ -371,6 +371,7 @@ responseToView hu@(currentRH, user_) ChatConfig {logLevel, showReactions, showRe plain . LB.unpack $ J.encode agentWorkersDetails -- this would be huge, but copypastable when has its own line ] CRAgentMsgCounts {msgCounts} -> ["received messages (total, duplicates):", plain . LB.unpack $ J.encode msgCounts] + CRAgentUserNetworkState {networkState} -> ["user network state:", plain . LB.unpack $ J.encode networkState] CRContactDisabled u c -> ttyUser u ["[" <> ttyContact' c <> "] connection is disabled, to enable: " <> highlight ("/enable " <> viewContactName c) <> ", to delete: " <> highlight ("/d " <> viewContactName c)] CRConnectionDisabled entity -> viewConnectionEntityDisabled entity CRAgentRcvQueueDeleted acId srv aqId err_ ->