-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (49 loc) · 1.18 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"log"
"os"
"os/signal"
"runtime"
"syscall"
"time"
"github.com/edpryk/buter/cli"
"github.com/edpryk/buter/internal/runner"
)
var (
configs []cli.UserConfig
rootContext context.Context
cancelRootContext context.CancelFunc
sigEnd = make(chan os.Signal)
attackCompletedSig = make(chan int)
)
func main() {
attackStartTime := time.Now()
configs = cli.ParseFlags()
cli.PrintInfo()
signal.Notify(sigEnd, syscall.SIGINT)
log.SetFlags(2)
for _, config := range configs {
if config.Timeout > 0 {
rootContext, cancelRootContext = context.WithTimeout(context.Background(), time.Duration(10*time.Second))
} else {
rootContext, cancelRootContext = context.WithCancel(context.Background())
}
if config.Delay <= 0 {
config.Delay = 1
}
defer cancelRootContext()
go runner.RunAttack(rootContext, runner.AttackConfig{
AttackCompletedSig: attackCompletedSig,
UserConfig: config,
})
select {
case <-sigEnd:
log.Println("Closed by Interruption")
cancelRootContext()
case <-attackCompletedSig:
}
log.Printf("Attack completed in %s\n", time.Now().Sub(attackStartTime))
runtime.GC()
}
}