MCPcopy Create free account
hub / github.com/daodst/chat / ForServer

Method ForServer

federationapi/statistics/statistics.go:30–59  ·  view source on GitHub ↗

ForServer returns server statistics for the given server name. If it does not exist, it will create empty statistics and return those.

(serverName gomatrixserverlib.ServerName)

Source from the content-addressed store, hash-verified

28// ForServer returns server statistics for the given server name. If it
29// does not exist, it will create empty statistics and return those.
30func (s *Statistics) ForServer(serverName gomatrixserverlib.ServerName) *ServerStatistics {
31 // If the map hasn't been initialised yet then do that.
32 if s.servers == nil {
33 s.mutex.Lock()
34 s.servers = make(map[gomatrixserverlib.ServerName]*ServerStatistics)
35 s.mutex.Unlock()
36 }
37 // Look up if we have statistics for this server already.
38 s.mutex.RLock()
39 server, found := s.servers[serverName]
40 s.mutex.RUnlock()
41 // If we don't, then make one.
42 if !found {
43 s.mutex.Lock()
44 server = &ServerStatistics{
45 statistics: s,
46 serverName: serverName,
47 interrupt: make(chan struct{}),
48 }
49 s.servers[serverName] = server
50 s.mutex.Unlock()
51 blacklisted, err := s.DB.IsServerBlacklisted(serverName)
52 if err != nil {
53 logrus.WithError(err).Errorf("Failed to get blacklist entry %q", serverName)
54 } else {
55 server.blacklisted.Store(blacklisted)
56 }
57 }
58 return server
59}
60
61// ServerStatistics contains information about our interactions with a
62// remote federated host, e.g. how many times we were successful, how

Callers 7

getQueueMethod · 0.45
PerformLeaveMethod · 0.45

Calls 3

LockMethod · 0.80
UnlockMethod · 0.80
IsServerBlacklistedMethod · 0.65

Tested by

no test coverage detected