(ctx context.Context, email string)
| 86 | } |
| 87 | |
| 88 | func (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 | |
| 122 | func (wg *WireGuard) GetUserOnlineIpListStats(ctx context.Context, email string) (*common.StatsOnlineIpListResponse, error) { |
| 123 | wg.mu.RLock() |
nothing calls this directly
no test coverage detected