多次校对时间等等

This commit is contained in:
yml2213
2026-06-19 23:22:20 +08:00
parent dd96bc0402
commit f04ba4ed64
3 changed files with 392 additions and 43 deletions
+54 -2
View File
@@ -100,8 +100,13 @@ type appState struct {
resultsMu sync.RWMutex
results map[string]string
scheduleMu sync.Mutex
schedule *time.Timer
scheduleMu sync.Mutex
schedule *time.Timer
warmupSchedule *time.Timer
resyncSchedule *time.Timer
warmupsMu sync.RWMutex
warmups map[string]WarmupData
fontMu sync.Mutex
font *truetype.Font
@@ -144,6 +149,53 @@ type ExchangeResult struct {
Message string
}
type TimeSample struct {
ServerTime time.Time
LocalTime time.Time
RTT time.Duration
Offset time.Duration
ErrorBound time.Duration
RawCurrentTime int64
Samples int
Source string
Fallback bool
}
type TimeCalibration struct {
Offset time.Duration
ErrorBound time.Duration
RTT time.Duration
Samples int
CreatedAt time.Time
Source string
Fallback bool
}
func (c TimeCalibration) EstimatedServerNow() time.Time {
if c.CreatedAt.IsZero() {
return time.Now().UTC()
}
return time.Now().Add(c.Offset).UTC()
}
func (c TimeCalibration) IsZero() bool {
return c.CreatedAt.IsZero()
}
type WarmupData struct {
CSRF string
RoleName string
CreatedAt time.Time
}
// EstimatedServerNow 根据采样偏移估算当前斗鱼时间。
func (t TimeSample) EstimatedServerNow() time.Time {
if t.LocalTime.IsZero() {
return t.ServerTime
}
return time.Now().Add(t.Offset).UTC()
}
type memoryLogStore struct {
mu sync.RWMutex
nextID int64