mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 19:03:43 +00:00
feat: persist authenticated queue probe RTT
This commit is contained in:
@@ -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"})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user