-
Notifications
You must be signed in to change notification settings - Fork 1
/
attack_options.go
62 lines (52 loc) · 1.85 KB
/
attack_options.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
62
// SPDX-FileCopyrightText: 2021 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: GPL-3.0-or-later
package gorankusu
import (
"time"
vegeta "github.com/tsenart/vegeta/v12/lib"
)
// DefaultAttackDuration define default attack duration per Target.
// This is default value for [AttackOptions.Duration].
const DefaultAttackDuration = 10 * time.Second
// DefaultAttackRatePerSecond define default attack rate per second per
// Target.
// This is default value for [AttackOptions.RatePerSecond].
const DefaultAttackRatePerSecond = 500
// DefaultAttackTimeout define default timeout for each attack request.
// This is default value for [AttackOptions.Timeout].
const DefaultAttackTimeout = 30 * time.Second
// AttackOptions define the options for attacking HTTP endpoint.
type AttackOptions struct {
// Duration define the duration for each attack to be executed,
// in seconds.
// For example, if the AttackRate is 500 and AttackDuration is 10
// seconds, the total of request for each target will be 5000
// requests.
// This field is optional, default to DefaultAttackDuration if its
// zero.
Duration time.Duration
// RatePerSecond define the number of request per second.
// This field is optional, default to DefaultAttackRatePerSecond if
// its zero.
RatePerSecond int
ratePerSecond vegeta.Rate
// Timeout define the overall time to run the attack on each target.
// This field is optional, default to DefaultAttackTimeout if its
// zero.
Timeout time.Duration
}
func (attackOpts *AttackOptions) init() {
if attackOpts.Timeout == 0 {
attackOpts.Timeout = DefaultAttackTimeout
}
if attackOpts.RatePerSecond == 0 {
attackOpts.RatePerSecond = DefaultAttackRatePerSecond
}
attackOpts.ratePerSecond = vegeta.Rate{
Freq: attackOpts.RatePerSecond,
Per: time.Second,
}
if attackOpts.Duration == 0 {
attackOpts.Duration = DefaultAttackDuration
}
}