github.com/xmplusdev/xray-core@v1.8.10/common/peer/latency.go (about)

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