mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
fix: using ttl counters for hosts making host discovery way more stable
This commit is contained in:
parent
5c2dc44a2d
commit
883f200e85
1 changed files with 9 additions and 2 deletions
|
@ -11,6 +11,7 @@ type Targets struct {
|
|||
Interface *net.Endpoint
|
||||
Gateway *net.Endpoint
|
||||
Targets map[string]*net.Endpoint
|
||||
TTL map[string]uint
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
|
@ -20,6 +21,7 @@ func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
|
|||
Interface: iface,
|
||||
Gateway: gateway,
|
||||
Targets: make(map[string]*net.Endpoint),
|
||||
TTL: make(map[string]uint),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,8 +38,12 @@ func (tp *Targets) Remove(ip, mac string) {
|
|||
defer tp.lock.Unlock()
|
||||
|
||||
if e, found := tp.Targets[mac]; found {
|
||||
tp.Session.Events.Add("target.lost", e)
|
||||
delete(tp.Targets, mac)
|
||||
tp.TTL[mac]--
|
||||
if tp.TTL[mac] == 0 {
|
||||
tp.Session.Events.Add("target.lost", e)
|
||||
delete(tp.Targets, mac)
|
||||
delete(tp.TTL, mac)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +83,7 @@ func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
|
|||
}
|
||||
|
||||
tp.Targets[mac] = e
|
||||
tp.TTL[mac] = 2
|
||||
|
||||
tp.Session.Events.Add("target.new", e)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue