-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnet_tcp.go
82 lines (60 loc) · 1.59 KB
/
net_tcp.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package proc
import (
"io/ioutil"
"strconv"
"strings"
)
type NetTCPSockets struct {
Sockets []NetTCPSocket `json:"sockets"`
}
type NetTCPSocket struct {
NetSocket
RetransmitTimeout uint64 `json:"retransmit_timeout"`
PredictedTick uint64 `json:"predicted_tick"`
AckQuick uint8 `json:"ack_quick"`
AckPingpong bool `json:"ack_pingpong"`
SendingCongestionWindow uint64 `json:"sending_congestion_window"`
SlowStartSizeThreshold int64 `json:"slow_start_size_threshold"`
}
func ReadNetTCPSockets(path string, ip NetIPDecoder) (*NetTCPSockets, error) {
b, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
lines := strings.Split(string(b), "\n")
tcp := &NetTCPSockets{}
for i := 1; i < len(lines); i++ {
line := lines[i]
f := strings.Fields(line)
if len(f) < 17 {
continue
}
s, err := parseNetSocket(f, ip)
if err != nil {
return nil, err
}
var n int64
e := &NetTCPSocket{
NetSocket: *s,
}
if e.RetransmitTimeout, err = strconv.ParseUint(f[12], 10, 64); err != nil {
return nil, err
}
if e.PredictedTick, err = strconv.ParseUint(f[13], 10, 64); err != nil {
return nil, err
}
if n, err = strconv.ParseInt(f[14], 10, 8); err != nil {
return nil, err
}
e.AckQuick = uint8(n >> 1)
e.AckPingpong = ((n & 1) == 1)
if e.SendingCongestionWindow, err = strconv.ParseUint(f[15], 10, 64); err != nil {
return nil, err
}
if e.SlowStartSizeThreshold, err = strconv.ParseInt(f[16], 10, 32); err != nil {
return nil, err
}
tcp.Sockets = append(tcp.Sockets, *e)
}
return tcp, nil
}