StartCoarseClock starts a background goroutine that updates coarseTime every second. Call this once at startup before processing packets. The goroutine stops when ctx is cancelled.
(ctx context.Context)
| 16 | // Call this once at startup before processing packets. |
| 17 | // The goroutine stops when ctx is cancelled. |
| 18 | func StartCoarseClock(ctx context.Context) { |
| 19 | coarseTime.Store(time.Now().Unix()) // Initialize immediately |
| 20 | go func() { |
| 21 | ticker := time.NewTicker(time.Second) |
| 22 | defer ticker.Stop() |
| 23 | for { |
| 24 | select { |
| 25 | case <-ctx.Done(): |
| 26 | return |
| 27 | case <-ticker.C: |
| 28 | coarseTime.Store(time.Now().Unix()) |
| 29 | } |
| 30 | } |
| 31 | }() |
| 32 | } |
| 33 | |
| 34 | // ClientHello contains parsed TLS ClientHello data from QUIC Initial packet. |
| 35 | type ClientHello struct { |