forked from quic-go/quic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
59 lines (50 loc) · 1.09 KB
/
path.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package quic
import (
"fmt"
"github.com/VividCortex/ewma"
"net"
)
// Defines a path between two endpoints
// It is part of QED
type Path struct {
isPathZero bool
pathID uint32
weight int
owd float64
local net.PacketConn
remote net.Addr
vewma ewma.MovingAverage
}
func NewPath(pathId uint32, pconn net.PacketConn, remote net.Addr, weight int) *Path {
return &Path{
isPathZero: false,
pathID: pathId,
weight: weight,
owd: 0,
local: pconn,
remote: remote,
vewma: ewma.NewMovingAverage(5),
}
}
func (p *Path) GetWeight() int {
return p.weight
}
func (p *Path) GetPathID() uint32 {
return p.pathID
}
func (p *Path) setOwd(owd float64) {
p.vewma.Add(owd)
p.owd = owd
}
func (p *Path) contains(address net.Addr) bool {
return (p.local.LocalAddr() == address || p.remote == address)
}
func (p *Path) Write() string {
return fmt.Sprintf("%d\n%s\n%s", p.pathID, p.local.LocalAddr().String(), p.remote.String())
}
func (p *Path) MovingAverage() float64 {
if p.vewma.Value() == 0.0 {
return p.owd
}
return p.vewma.Value()
}