-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprocess.go
More file actions
49 lines (44 loc) · 1.07 KB
/
process.go
File metadata and controls
49 lines (44 loc) · 1.07 KB
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
package kping
import (
"fmt"
"os"
"time"
)
// process ICMP packets
func (p *kping) process() {
stime := time.Now()
for event := range p.ipEventChan {
_, ok := p.stats[event.ip]
if !ok {
p.stats[event.ip] = &Statistic{
ipEvents: make(map[int]ipEvent, p.count),
RTTs: make([]float64, 0, p.count*2),
}
}
event2, ok := p.stats[event.ip].ipEvents[event.seq]
if !ok {
event2 = ipEvent{
ip: event.ip,
seq: event.seq,
}
}
if event.sendDuration != 0 {
p.stats[event.ip].SentNum++
event2.sendDuration = event.sendDuration
} else if event.recvRTT != 0 {
p.stats[event.ip].RecvNum++
event2.recvRTT = event.recvRTT
}
p.stats[event.ip].ipEvents[event.seq] = event2
if event2.recvRTT != 0 && event2.sendDuration != 0 {
rtt := float64(event2.recvRTT) / float64(time.Millisecond)
if rtt <= 0.01 {
rtt = 2
}
rtts := p.stats[event.ip].RTTs
rtts = append(rtts, rtt)
p.stats[event.ip].RTTs = rtts
}
}
fmt.Fprintf(os.Stderr, "kping process: done, ipCount: %d, usedTime: %s\n", len(p.stats), time.Since(stime))
}