Skip to content

Commit

Permalink
replace time.Sleep with ticker/channel
Browse files Browse the repository at this point in the history
  • Loading branch information
mwyvr committed Mar 28, 2023
1 parent ae6050b commit db96d93
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions knockr.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
)

const (
timeoutMS = 1500
timeoutMS = 1000
delayMS = 100
)

Expand Down Expand Up @@ -124,6 +124,8 @@ func portknock(cfg *config) error {
log.Printf("%s: %5s %s", cfg.address, "DNS", err.Error())
}

delay := time.NewTicker(cfg.delay)

for _, v := range cfg.ports {
address := fmt.Sprintf("%s:%d", cfg.address, v)

Expand All @@ -142,7 +144,7 @@ func portknock(cfg *config) error {
log.Printf("%s: %5d %s", cfg.address, v, result)
}

time.Sleep(cfg.delay)
<-delay.C
}

return nil
Expand Down

0 comments on commit db96d93

Please sign in to comment.