| 52 | } |
| 53 | |
| 54 | func (s *statsReporter) callback(_, _ time.Time, virtual, _ map[netlogtype.Connection]netlogtype.Counts) { |
| 55 | s.L.Lock() |
| 56 | defer s.L.Unlock() |
| 57 | s.logger.Debug(context.Background(), "got stats callback") |
| 58 | // Accumulate stats until they've been reported. |
| 59 | if s.unreported && len(s.networkStats) > 0 { |
| 60 | for k, v := range virtual { |
| 61 | s.networkStats[k] = s.networkStats[k].Add(v) |
| 62 | } |
| 63 | } else { |
| 64 | s.networkStats = maps.Clone(virtual) |
| 65 | s.unreported = true |
| 66 | } |
| 67 | s.Broadcast() |
| 68 | } |
| 69 | |
| 70 | // reportLoop programs the source (tailnet.Conn) to send it stats via the |
| 71 | // callback, then reports them to the dest. |