mirror of
https://github.com/oneclickvirt/backtrace.git
synced 2026-11-24 23:39:41 +08:00
feat: strengthen three-carrier return route detection
Sync ASN metadata / sync (push) Has been cancelled
Sync ASN metadata / sync (push) Has been cancelled
This commit is contained in:
1 parent
c350b4e1f8
commit
5369aa16f7
23 files changed
+1187
-136
No files matched your search
+10
-1
@@ -544,6 +544,15 @@ func (h *Hop) Add(r *Reply) *Node {
|
||||
|
||||
// Trace is a simple traceroute tool using DefaultTracer.
|
||||
func Trace(ip net.IP) ([]*Hop, error) {
|
||||
return TraceContext(context.Background(), ip)
|
||||
}
|
||||
|
||||
// TraceContext runs an ICMP traceroute that stops promptly when the caller's
|
||||
// context is canceled.
|
||||
func TraceContext(ctx context.Context, ip net.IP) ([]*Hop, error) {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
hops := make([]*Hop, 0, DefaultTracer.MaxHops)
|
||||
touch := func(dist int) *Hop {
|
||||
for _, h := range hops {
|
||||
@@ -555,7 +564,7 @@ func Trace(ip net.IP) ([]*Hop, error) {
|
||||
hops = append(hops, h)
|
||||
return h
|
||||
}
|
||||
err := DefaultTracer.Trace(context.Background(), ip, func(r *Reply) {
|
||||
err := DefaultTracer.Trace(ctx, ip, func(r *Reply) {
|
||||
touch(r.Hops).Add(r)
|
||||
})
|
||||
if err != nil && err != context.DeadlineExceeded {
|
||||
|
||||
Reference in new issue
Block a user