mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
fix: pruning HID devices after 10 minutes of inactivity
This commit is contained in:
parent
b9c4982457
commit
b7c6e61428
1 changed files with 21 additions and 0 deletions
|
@ -61,6 +61,25 @@ func (mod *HIDRecon) onDeviceDetected(buf []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
var maxDeviceTTL = 10 * time.Minute
|
||||
|
||||
func (mod *HIDRecon) devPruner() {
|
||||
mod.waitGroup.Add(1)
|
||||
defer mod.waitGroup.Done()
|
||||
|
||||
mod.Debug("devices pruner started.")
|
||||
for mod.Running() {
|
||||
for _, dev := range mod.Session.HID.Devices() {
|
||||
sinceLastSeen := time.Since(dev.LastSeen)
|
||||
if sinceLastSeen > maxDeviceTTL {
|
||||
mod.Debug("device %s not seen in %s, removing.", dev.Address, sinceLastSeen)
|
||||
mod.Session.HID.Remove(dev.Address)
|
||||
}
|
||||
}
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func (mod *HIDRecon) Start() error {
|
||||
if err := mod.Configure(); err != nil {
|
||||
return err
|
||||
|
@ -70,6 +89,8 @@ func (mod *HIDRecon) Start() error {
|
|||
mod.waitGroup.Add(1)
|
||||
defer mod.waitGroup.Done()
|
||||
|
||||
go mod.devPruner()
|
||||
|
||||
mod.Info("hopping on %d channels every %s", nrf24.TopChannel, mod.hopPeriod)
|
||||
for mod.Running() {
|
||||
if mod.isSniffing() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue