MCPcopy Create free account
hub / github.com/PasarGuard/node / GetUserOnlineStats

Method GetUserOnlineStats

backend/wireguard/stats.go:88–120  ·  view source on GitHub ↗
(ctx context.Context, email string)

Source from the content-addressed store, hash-verified

86}
87
88func (wg *WireGuard) GetUserOnlineStats(ctx context.Context, email string) (*common.OnlineStatResponse, error) {
89 wg.mu.RLock()
90 state := wg.state
91 wg.mu.RUnlock()
92
93 if state != lifecycleRunning {
94 return nil, errWireGuardNotStarted
95 }
96
97 // Get user's public key directly from PeerStore
98 var keys []string
99 if peer := wg.peerStore.GetByEmail(email); peer != nil {
100 keys = []string{peer.PublicKey.String()}
101 }
102 if len(keys) == 0 {
103 return &common.OnlineStatResponse{
104 Name: email,
105 Value: 0,
106 }, nil
107 }
108
109 if wg.statsTracker.AnyActiveSince(keys, time.Now().Add(-onlineActivityThreshold)) {
110 return &common.OnlineStatResponse{
111 Name: email,
112 Value: 1,
113 }, nil
114 }
115
116 return &common.OnlineStatResponse{
117 Name: email,
118 Value: 0,
119 }, nil
120}
121
122func (wg *WireGuard) GetUserOnlineIpListStats(ctx context.Context, email string) (*common.StatsOnlineIpListResponse, error) {
123 wg.mu.RLock()

Callers

nothing calls this directly

Calls 3

GetByEmailMethod · 0.80
AnyActiveSinceMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected