mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-03-30 18:35:59 +00:00
refactor
This commit is contained in:
@@ -91,6 +91,7 @@ module Simplex.Messaging.Agent.Client
|
||||
AgentServersSummary (..),
|
||||
SMPServerSessions (..),
|
||||
XFTPServerSessions (..),
|
||||
getAgentServersStats,
|
||||
getAgentServersSummary,
|
||||
getAgentSubscriptions,
|
||||
slowNetworkConfig,
|
||||
@@ -1970,11 +1971,10 @@ incXFTPServerStat AgentClient {xftpServersStats} userId srv sel n = do
|
||||
-- and stats are used to track real network activity (probably also via smpClients),
|
||||
-- so they [stats] would be accounted for proxy (unless we want double counting messages as sent and proxied)
|
||||
data AgentServersSummary = AgentServersSummary
|
||||
{ smpServersSessions :: Map (UserId, SMPServer) SMPServerSessions,
|
||||
smpServersStats :: Map (UserId, SMPServer) AgentSMPServerStatsData,
|
||||
{ serverStats :: AgentServerStats,
|
||||
smpServersSessions :: Map (UserId, SMPServer) SMPServerSessions,
|
||||
onlyProxiedSMPServers :: [SMPServer],
|
||||
xftpServersSessions :: Map (UserId, XFTPServer) XFTPServerSessions,
|
||||
xftpServersStats :: Map (UserId, XFTPServer) AgentXFTPServerStatsData
|
||||
xftpServersSessions :: Map (UserId, XFTPServer) XFTPServerSessions
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
@@ -1993,29 +1993,29 @@ data XFTPServerSessions = XFTPServerSessions
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
getAgentServersStats :: AgentClient -> IO AgentPersistedServerStats
|
||||
getAgentServersStats :: AgentClient -> IO AgentServerStats
|
||||
getAgentServersStats AgentClient {smpServersStats, xftpServersStats} = do
|
||||
sss <- readTVarIO smpServersStats
|
||||
smpServersStatsData <- mapM (atomically . getAgentSMPServerStats) sss
|
||||
xss <- readTVarIO xftpServersStats
|
||||
xftpServersStatsData <- mapM (atomically . getAgentXFTPServerStats) xss
|
||||
pure AgentPersistedServerStats {smpServersStatsData, xftpServersStatsData}
|
||||
|
||||
getAgentServersSummary :: AgentClient -> IO AgentServersSummary
|
||||
getAgentServersSummary AgentClient {smpServersStats, xftpServersStats} = do
|
||||
sss <- readTVarIO smpServersStats
|
||||
sss' <- mapM (atomically . getAgentSMPServerStats) sss
|
||||
xss <- readTVarIO xftpServersStats
|
||||
xss' <- mapM (atomically . getAgentXFTPServerStats) xss
|
||||
pure
|
||||
AgentServersSummary
|
||||
{ smpServersSessions = M.empty, -- collect, see SMPServerSessions
|
||||
smpServersStats = sss',
|
||||
onlyProxiedSMPServers = [], -- collect, smpProxiedRelays (key) minus smpClients
|
||||
xftpServersSessions = M.empty, -- collect, see XFTPServerSessions
|
||||
AgentServerStats
|
||||
{ smpServersStats = sss',
|
||||
xftpServersStats = xss'
|
||||
}
|
||||
|
||||
getAgentServersSummary :: AgentClient -> IO AgentServersSummary
|
||||
getAgentServersSummary c = do
|
||||
serverStats <- getAgentServersStats c
|
||||
pure
|
||||
AgentServersSummary
|
||||
{ serverStats,
|
||||
smpServersSessions = M.empty, -- collect, see SMPServerSessions
|
||||
onlyProxiedSMPServers = [], -- collect, smpProxiedRelays (key) minus smpClients
|
||||
xftpServersSessions = M.empty -- collect, see XFTPServerSessions
|
||||
}
|
||||
|
||||
data SubInfo = SubInfo {userId :: UserId, server :: Text, rcvId :: Text, subError :: Maybe String}
|
||||
deriving (Show)
|
||||
|
||||
|
||||
@@ -346,18 +346,9 @@ setAgentXFTPServerStats s d = do
|
||||
writeTVar (replDeleteAttempts s) $! _replDeleteAttempts d
|
||||
writeTVar (replDeleteErr s) $! _replDeleteErr d
|
||||
|
||||
-- Type for gathering both smp and xftp stats across all users and servers.
|
||||
--
|
||||
-- Idea is to provide agent with a single path to save/restore stats, instead of managing it in UI
|
||||
-- and providing agent with "initial stats".
|
||||
--
|
||||
-- Agent would use this unifying type to write/read json representation of all stats
|
||||
-- and populating AgentClient maps:
|
||||
-- smpServersStats :: TMap (UserId, SMPServer) AgentSMPServerStats,
|
||||
-- xftpServersStats :: TMap (UserId, XFTPServer) AgentXFTPServerStats
|
||||
data AgentPersistedServerStats = AgentPersistedServerStats
|
||||
{ smpServersStatsData :: Map (UserId, SMPServer) AgentSMPServerStatsData,
|
||||
xftpServersStatsData :: Map (UserId, XFTPServer) AgentXFTPServerStatsData
|
||||
data AgentServerStats = AgentServerStats
|
||||
{ smpServersStats :: Map (UserId, SMPServer) AgentSMPServerStatsData,
|
||||
xftpServersStats :: Map (UserId, XFTPServer) AgentXFTPServerStatsData
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
@@ -365,4 +356,4 @@ $(J.deriveJSON defaultJSON ''AgentSMPServerStatsData)
|
||||
|
||||
$(J.deriveJSON defaultJSON ''AgentXFTPServerStatsData)
|
||||
|
||||
$(J.deriveJSON defaultJSON ''AgentPersistedServerStats)
|
||||
$(J.deriveJSON defaultJSON ''AgentServerStats)
|
||||
|
||||
Reference in New Issue
Block a user