1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| package peer
|
| import (
| "sync"
| )
|
| type Latency interface {
| Value() uint64
| }
|
| type HasLatency interface {
| ConnectionLatency() Latency
| HandshakeLatency() Latency
| }
|
| type AverageLatency struct {
| access sync.Mutex
| value uint64
| }
|
| func (al *AverageLatency) Update(newValue uint64) {
| al.access.Lock()
| defer al.access.Unlock()
|
| al.value = (al.value + newValue*2) / 3
| }
|
| func (al *AverageLatency) Value() uint64 {
| return al.value
| }
|
|