mirror of
https://github.com/go-ping/ping.git
synced 2025-06-26 06:01:40 +00:00
refactor CheckInFlightPackets
to use packet UUID
This commit is contained in:
parent
46c548aa5a
commit
ccc75a38ee
31
ping.go
31
ping.go
@ -92,13 +92,12 @@ func New(addr string) *Pinger {
|
|||||||
var firstSequence = map[uuid.UUID]map[int]InFlightPacket{}
|
var firstSequence = map[uuid.UUID]map[int]InFlightPacket{}
|
||||||
firstSequence[firstUUID] = make(map[int]InFlightPacket)
|
firstSequence[firstUUID] = make(map[int]InFlightPacket)
|
||||||
return &Pinger{
|
return &Pinger{
|
||||||
Count: -1,
|
Count: -1,
|
||||||
Interval: time.Second,
|
Interval: time.Second,
|
||||||
RecordRtts: true,
|
RecordRtts: true,
|
||||||
Size: timeSliceLength + trackerLength,
|
Size: timeSliceLength + trackerLength,
|
||||||
Timeout: time.Duration(math.MaxInt64),
|
Timeout: time.Duration(math.MaxInt64),
|
||||||
PacketTimeout: time.Duration(math.MaxInt64),
|
Tracker: r.Uint64(),
|
||||||
Tracker: r.Uint64(),
|
|
||||||
|
|
||||||
addr: addr,
|
addr: addr,
|
||||||
done: make(chan interface{}),
|
done: make(chan interface{}),
|
||||||
@ -129,10 +128,6 @@ type Pinger struct {
|
|||||||
// packets have been received.
|
// packets have been received.
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
|
||||||
// PacketTimeout specifies a timeout before the OnTimeout function is called
|
|
||||||
// for a packet not being received
|
|
||||||
PacketTimeout time.Duration
|
|
||||||
|
|
||||||
// Count tells pinger to stop after sending (and receiving) Count echo
|
// Count tells pinger to stop after sending (and receiving) Count echo
|
||||||
// packets. If this option is not specified, pinger will operate until
|
// packets. If this option is not specified, pinger will operate until
|
||||||
// interrupted.
|
// interrupted.
|
||||||
@ -522,15 +517,17 @@ func (p *Pinger) runLoop(
|
|||||||
|
|
||||||
func (p *Pinger) CheckInFlightPackets() {
|
func (p *Pinger) CheckInFlightPackets() {
|
||||||
// Loop through each item in map
|
// Loop through each item in map
|
||||||
if p.PacketTimeout == maxPacketTimeout {
|
if time.Duration(p.TTL) == maxPacketTimeout {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
for seq, pkt := range p.InFlightPackets {
|
for id, inflight := range p.InFlightPackets {
|
||||||
if pkt.DispatchedTime.Add(p.PacketTimeout).Before(currentTime) {
|
for seq, pkt := range inflight {
|
||||||
delete(p.InFlightPackets, seq)
|
if pkt.DispatchedTime.Add(time.Duration(p.TTL)).Before(currentTime) {
|
||||||
if p.OnTimeout != nil {
|
delete(p.InFlightPackets[id], seq)
|
||||||
p.OnTimeout(seq, &pkt)
|
if p.OnTimeout != nil {
|
||||||
|
p.OnTimeout(seq, &pkt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user