Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add packet timeout callback #50 (Rebase) #202

Closed
wants to merge 11 commits into from

Conversation

thatmattlove
Copy link

Hello,

I've been following #176 for a little while, and figured I'd take a stab at rebasing the work done by @hamptonmoore. I'm hoping I did it correctly; if not, feel free to request changes as needed and I'll do my best. I'd love to see this get merged in.

Thanks!

ping.go Outdated
@@ -503,6 +515,24 @@ func (p *Pinger) runLoop(
}
}

func (p *Pinger) CheckInFlightPackets() {
// Loop through each item in map
if time.Duration(p.TTL) == maxPacketTimeout {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misunderstand what TTL is. This is the ICMP packet network TTL. AKA, how many router hops. Not time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all; it would be more accurate to say I misunderstand the codebase and changes, and admittedly did not take much time to understand it. 🙃 I saw TTL added as a new property since @hamptonmoore's original PR, which had property PacketTimeout, and made a fast correlation between the two. I will go back through @hamptonmoore's original PR and re-implement the PacketTimeout property as it was before.

ping.go Outdated
ipv4: false,
network: "ip",
protocol: "udp",
InFlightPackets: firstSequence,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentionally not exported, it's only for internal use to avoid data races.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. However, it was originally exported in @hamptonmoore's PR, so I left it as-is. I will adjust it as private in my next commit.

ping.go Outdated
return
}
currentTime := time.Now()
for id, inflight := range p.InFlightPackets {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a very expensive way to deal with this. I need to think about if there are better solutions than walking the whole map every time.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree, however I just adapted the original implementation from #176, which seemed to be accepted at the time. While you're considering a better solution, I'll do the same as I go through the codebase for the other code reviews and see if anything stands out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original though on this was to spawn a time.Timer() that would send the timeout down the main packet watching channel. If a packet arrives before the timer ends, we .Stop() it.

What do you think?

@SuperQ
Copy link
Contributor

SuperQ commented Jan 21, 2023

See #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants