| 58 | } |
| 59 | |
| 60 | func (wg *WireGuard) GetStats(ctx context.Context, request *common.StatRequest) (*common.StatResponse, error) { |
| 61 | wg.mu.RLock() |
| 62 | state := wg.state |
| 63 | wg.mu.RUnlock() |
| 64 | |
| 65 | if state != lifecycleRunning { |
| 66 | return nil, errWireGuardNotStarted |
| 67 | } |
| 68 | |
| 69 | switch request.GetType() { |
| 70 | case common.StatType_UserStat: |
| 71 | return wg.handleUserStats(ctx, request) |
| 72 | |
| 73 | case common.StatType_UsersStat: |
| 74 | return wg.handleUsersStats(ctx, request) |
| 75 | |
| 76 | case common.StatType_Outbound, common.StatType_Outbounds: |
| 77 | // handleInterfaceOutboundStats falls back to the configured interface name when GetName() is empty, |
| 78 | // so both stat types are satisfied by the same call. |
| 79 | return wg.handleInterfaceOutboundStats(request.GetName(), request.GetReset_()) |
| 80 | |
| 81 | case common.StatType_Inbound, common.StatType_Inbounds: |
| 82 | return nil, errors.New("inbound stats not applicable for wireguard") |
| 83 | default: |
| 84 | return nil, errors.New("unsupported stat type") |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | func (wg *WireGuard) GetUserOnlineStats(ctx context.Context, email string) (*common.OnlineStatResponse, error) { |
| 89 | wg.mu.RLock() |