feat: persist authenticated queue probe RTT

This commit is contained in:
Josh Creek
2026-09-01 09:40:25 +01:00
parent 25cc182793
commit def60169a8
7 changed files with 131 additions and 2 deletions
+10
View File
@@ -26,6 +26,9 @@ const maxBodyBytes = 8 << 10
type CandidateProvider func(playerID, ticketID string) (domain.Candidate, error)
type CandidateProviderV2 func(playerID, ticketID string, spec domain.QueueSpec) (domain.Candidate, error)
type ProbeProvider func(playerID, region string, opaqueLocation, nonce []byte, receivedAt time.Time) (domain.ProbeEvidence, []byte, error)
type ProbeRecorder interface {
RecordProbe(context.Context, string, string, time.Duration, time.Time) error
}
type QueueBackend interface {
Create(context.Context, string, string, string, domain.QueueSpec, time.Time) (domain.QueueTicket, error)
@@ -86,6 +89,7 @@ type Service struct {
QueueBackend QueueBackend
CandidateIndex CandidateIndex
Probe ProbeProvider
ProbeRecorder ProbeRecorder
Assignment AssignmentProvider
Now func() time.Time
Proposals map[string]*domain.Proposal
@@ -653,6 +657,12 @@ func (s *Service) probe(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusUnprocessableEntity, "invalid_probe")
return
}
if s.ProbeRecorder != nil {
if err := s.ProbeRecorder.RecordProbe(r.Context(), playerID, region, evidence.ServerRTT, receivedAt); err != nil {
writeError(w, http.StatusServiceUnavailable, "probe_persistence_failed")
return
}
}
writeJSON(w, http.StatusAccepted, map[string]any{"region": region, "server_rtt_ms": evidence.ServerRTT.Milliseconds(), "status": "accepted"})
}