Compare commits

...

1 Commits

Author SHA1 Message Date
Evgeny Poberezkin 87fffeb698 core: command to debug user network state 2024-05-16 19:29:36 +01:00
5 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ constraints: zip +disable-bzip2 +disable-zstd
source-repository-package source-repository-package
type: git type: git
location: https://github.com/simplex-chat/simplexmq.git location: https://github.com/simplex-chat/simplexmq.git
tag: 58c1be236a9b14967240903ae4868eb925472d0d tag: 7d30eb6548e81df197931e755b8b6853774d622a
source-repository-package source-repository-package
type: git type: git
+1 -1
View File
@@ -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/hs-socks.git"."a30cc7a79a08d8108316094f8f2f82a0c5e1ac51" = "0yasvnr7g91k76mjkamvzab2kvlb1g5pspjyjn2fr6v83swjhj38";
"https://github.com/simplex-chat/direct-sqlcipher.git"."f814ee68b16a9447fbb467ccc8f29bdd3546bfd9" = "1ql13f4kfwkbaq7nygkxgw84213i0zm7c1a8hwvramayxl38dq5d"; "https://github.com/simplex-chat/direct-sqlcipher.git"."f814ee68b16a9447fbb467ccc8f29bdd3546bfd9" = "1ql13f4kfwkbaq7nygkxgw84213i0zm7c1a8hwvramayxl38dq5d";
"https://github.com/simplex-chat/sqlcipher-simple.git"."a46bd361a19376c5211f1058908fc0ae6bf42446" = "1z0r78d8f0812kxbgsm735qf6xx8lvaz27k1a0b4a2m0sshpd5gl"; "https://github.com/simplex-chat/sqlcipher-simple.git"."a46bd361a19376c5211f1058908fc0ae6bf42446" = "1z0r78d8f0812kxbgsm735qf6xx8lvaz27k1a0b4a2m0sshpd5gl";
+3
View File
@@ -2225,6 +2225,8 @@ processChatCommand' vr = \case
counts <- map (first decodeLatin1) <$> withAgent' getMsgCounts counts <- map (first decodeLatin1) <$> withAgent' getMsgCounts
let allMsgs = foldl' (\(ts, ds) (_, (t, d)) -> (ts + t, ds + d)) (0, 0) counts 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)} 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)) GetAgentSubs diff -> withUser $ \User {userId} -> lift $ CRAgentSubs <$> withAgent' (\a -> getAgentSubscriptions a diff (Just userId))
-- CustomChatCommand is unsupported, it can be processed in preCmdHook -- CustomChatCommand is unsupported, it can be processed in preCmdHook
-- in a modified CLI app or core - the hook should return Either ChatResponse ChatCommand -- in a modified CLI app or core - the hook should return Either ChatResponse ChatCommand
@@ -7372,6 +7374,7 @@ chatCommandP =
"/get workers" $> GetAgentWorkers, "/get workers" $> GetAgentWorkers,
"/get workers details" $> GetAgentWorkersDetails, "/get workers details" $> GetAgentWorkersDetails,
"/get msgs" $> GetAgentMsgCounts, "/get msgs" $> GetAgentMsgCounts,
"/debug net" $> GetAgentUserNetworkState,
"//" *> (CustomChatCommand <$> A.takeByteString) "//" *> (CustomChatCommand <$> A.takeByteString)
] ]
where where
+7 -1
View File
@@ -67,7 +67,7 @@ import Simplex.Chat.Types.UITheme
import Simplex.Chat.Util (liftIOEither) import Simplex.Chat.Util (liftIOEither)
import Simplex.FileTransfer.Description (FileDescriptionURI) import Simplex.FileTransfer.Description (FileDescriptionURI)
import Simplex.Messaging.Agent (AgentClient, SubscriptionsInfo) 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.Env.SQLite (AgentConfig, NetworkConfig)
import Simplex.Messaging.Agent.Lock import Simplex.Messaging.Agent.Lock
import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.Protocol
@@ -501,6 +501,7 @@ data ChatCommand
| GetAgentWorkers | GetAgentWorkers
| GetAgentWorkersDetails | GetAgentWorkersDetails
| GetAgentMsgCounts | GetAgentMsgCounts
| GetAgentUserNetworkState
| -- The parser will return this command for strings that start from "//". | -- The parser will return this command for strings that start from "//".
-- This command should be processed in preCmdHook -- This command should be processed in preCmdHook
CustomChatCommand ByteString CustomChatCommand ByteString
@@ -746,6 +747,7 @@ data ChatResponse
| CRAgentWorkersSummary {agentWorkersSummary :: AgentWorkersSummary} | CRAgentWorkersSummary {agentWorkersSummary :: AgentWorkersSummary}
| CRAgentSubs {agentSubs :: SubscriptionsInfo} | CRAgentSubs {agentSubs :: SubscriptionsInfo}
| CRAgentMsgCounts {msgCounts :: [(Text, (Int, Int))]} | CRAgentMsgCounts {msgCounts :: [(Text, (Int, Int))]}
| CRAgentUserNetworkState {networkState :: UserNetworkState}
| CRContactDisabled {user :: User, contact :: Contact} | CRContactDisabled {user :: User, contact :: Contact}
| CRConnectionDisabled {connectionEntity :: ConnectionEntity} | CRConnectionDisabled {connectionEntity :: ConnectionEntity}
| CRAgentRcvQueueDeleted {agentConnId :: AgentConnId, server :: SMPServer, agentQueueId :: AgentQueueId, agentError_ :: Maybe AgentErrorType} | 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 (sumTypeJSON $ dropPrefix "RHSR") ''RemoteHostStopReason)
$(JQ.deriveJSON defaultJSON ''UNSOffline)
$(JQ.deriveJSON defaultJSON ''UserNetworkState)
$(JQ.deriveJSON (sumTypeJSON $ dropPrefix "CR") ''ChatResponse) $(JQ.deriveJSON (sumTypeJSON $ dropPrefix "CR") ''ChatResponse)
$(JQ.deriveFromJSON defaultJSON ''ArchiveConfig) $(JQ.deriveFromJSON defaultJSON ''ArchiveConfig)
+1
View File
@@ -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 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] 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)] 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 CRConnectionDisabled entity -> viewConnectionEntityDisabled entity
CRAgentRcvQueueDeleted acId srv aqId err_ -> CRAgentRcvQueueDeleted acId srv aqId err_ ->