diff options
Diffstat (limited to 'internal/handler/websocket/handler.go')
| -rw-r--r-- | internal/handler/websocket/handler.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go index de71926..dfe7b9e 100644 --- a/internal/handler/websocket/handler.go +++ b/internal/handler/websocket/handler.go | |||
| @@ -33,6 +33,7 @@ type MetricsRecorder interface { | |||
| 33 | DecrementSubscriptions() | 33 | DecrementSubscriptions() |
| 34 | SetActiveSubscriptions(count int) | 34 | SetActiveSubscriptions(count int) |
| 35 | RecordRequest(method, status string, duration float64) | 35 | RecordRequest(method, status string, duration float64) |
| 36 | RecordAuthAttempt(success bool) | ||
| 36 | RecordBlockedEvent(kind int32) | 37 | RecordBlockedEvent(kind int32) |
| 37 | } | 38 | } |
| 38 | 39 | ||
| @@ -522,6 +523,13 @@ func (h *Handler) sendAuthChallenge(ctx context.Context, conn *websocket.Conn, c | |||
| 522 | } | 523 | } |
| 523 | 524 | ||
| 524 | func (h *Handler) handleAuth(ctx context.Context, conn *websocket.Conn, raw []json.RawMessage, state *connState) error { | 525 | func (h *Handler) handleAuth(ctx context.Context, conn *websocket.Conn, raw []json.RawMessage, state *connState) error { |
| 526 | success := false | ||
| 527 | defer func() { | ||
| 528 | if h.metrics != nil { | ||
| 529 | h.metrics.RecordAuthAttempt(success) | ||
| 530 | } | ||
| 531 | }() | ||
| 532 | |||
| 525 | if len(raw) != 2 { | 533 | if len(raw) != 2 { |
| 526 | return fmt.Errorf("AUTH expects 2 elements") | 534 | return fmt.Errorf("AUTH expects 2 elements") |
| 527 | } | 535 | } |
| @@ -560,6 +568,7 @@ func (h *Handler) handleAuth(ctx context.Context, conn *websocket.Conn, raw []js | |||
| 560 | state.authenticatedPubkey = authEvent.PubKey | 568 | state.authenticatedPubkey = authEvent.PubKey |
| 561 | log.Printf("WebSocket client authenticated: %s", authEvent.PubKey[:16]) | 569 | log.Printf("WebSocket client authenticated: %s", authEvent.PubKey[:16]) |
| 562 | 570 | ||
| 571 | success = true | ||
| 563 | // Don't send OK for AUTH - it's not an EVENT | 572 | // Don't send OK for AUTH - it's not an EVENT |
| 564 | return nil | 573 | return nil |
| 565 | } | 574 | } |
