mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-17 13:05:57 +00:00
31 lines
434 B
Go
31 lines
434 B
Go
|
|
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
|
||
|
|
}
|