UpdateStatsBatch applies many peer stats updates under a single lock.
(samples []Sample)
| 47 | |
| 48 | // UpdateStatsBatch applies many peer stats updates under a single lock. |
| 49 | func (st *Tracker) UpdateStatsBatch(samples []Sample) { |
| 50 | if len(samples) == 0 { |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | st.mu.Lock() |
| 55 | defer st.mu.Unlock() |
| 56 | |
| 57 | now := time.Now() |
| 58 | for _, sample := range samples { |
| 59 | st.applySampleLocked(sample, now) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func (st *Tracker) applySampleLocked(sample Sample, activeAt time.Time) { |
| 64 | entry, exists := st.stats[sample.PublicKey] |