forked from adamlaska/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
144 lines (128 loc) · 4.29 KB
/
main.go
File metadata and controls
144 lines (128 loc) · 4.29 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
"github.com/letsencrypt/boulder/cmd"
)
type Config struct {
// Execution plan parameters
Plan struct {
Actions []string // things to do
Rate int64 // requests / s
RateDelta string // requests / s^2
Runtime string // how long to run for
}
ExternalState string // path to file to load/save registrations etc to/from
DontSaveState bool // don't save changes to external state
DirectoryURL string // ACME server directory URL
DomainBase string // base domain name to create authorizations for
HTTPOneAddrs []string // addresses to listen for http-01 validation requests on
TLSALPNOneAddrs []string // addresses to listen for tls-alpn-01 validation requests on
DNSAddrs []string // addresses to listen for DNS requests on
FakeDNS string // IPv6 address to use for all DNS A requests
RealIP string // value of the Real-IP header to use when bypassing CDN
CertKeySize int // size of the key to use when creating CSRs
RegEmail string // email to use in registrations
Results string // path to save metrics to
MaxRegs int // maximum number of registrations to create
MaxNamesPerCert int // maximum number of names on one certificate/order
ChallengeStrategy string // challenge selection strategy ("random", "http-01", "dns-01", "tls-alpn-01")
RevokeChance float32 // chance of revoking certificate after issuance, between 0.0 and 1.0
}
func main() {
configPath := flag.String("config", "", "Path to configuration file for load-generator")
resultsPath := flag.String("results", "", "Path to latency results file")
rateArg := flag.Int("rate", 0, "")
runtimeArg := flag.String("runtime", "", "")
deltaArg := flag.String("delta", "", "")
flag.Parse()
if *configPath == "" {
fmt.Fprintf(os.Stderr, "-config argument must not be empty\n")
os.Exit(1)
}
configBytes, err := ioutil.ReadFile(*configPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to read load-generator config file %q: %s\n", *configPath, err)
os.Exit(1)
}
var config Config
err = json.Unmarshal(configBytes, &config)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse load-generator config file: %s\n", err)
os.Exit(1)
}
if *resultsPath != "" {
config.Results = *resultsPath
}
if *rateArg != 0 {
config.Plan.Rate = int64(*rateArg)
}
if *runtimeArg != "" {
config.Plan.Runtime = *runtimeArg
}
if *deltaArg != "" {
config.Plan.RateDelta = *deltaArg
}
s, err := New(
config.DirectoryURL,
config.CertKeySize,
config.DomainBase,
config.RealIP,
config.MaxRegs,
config.MaxNamesPerCert,
config.Results,
config.RegEmail,
config.Plan.Actions,
config.ChallengeStrategy,
config.RevokeChance,
)
cmd.FailOnError(err, "Failed to create load generator")
if config.ExternalState != "" {
err = s.Restore(config.ExternalState)
cmd.FailOnError(err, "Failed to load registration snapshot")
}
runtime, err := time.ParseDuration(config.Plan.Runtime)
cmd.FailOnError(err, "Failed to parse plan runtime")
var delta *RateDelta
if config.Plan.RateDelta != "" {
parts := strings.Split(config.Plan.RateDelta, "/")
if len(parts) != 2 {
fmt.Fprintf(os.Stderr, "RateDelta is malformed")
os.Exit(1)
}
rate, err := strconv.Atoi(parts[0])
cmd.FailOnError(err, "Failed to parse increase portion of RateDelta")
period, err := time.ParseDuration(parts[1])
cmd.FailOnError(err, "Failed to parse period portion of RateDelta")
delta = &RateDelta{Inc: int64(rate), Period: period}
}
if len(config.HTTPOneAddrs) == 0 &&
len(config.TLSALPNOneAddrs) == 0 &&
len(config.DNSAddrs) == 0 {
cmd.Fail("There must be at least one bind address in " +
"HTTPOneAddrs, TLSALPNOneAddrs or DNSAddrs\n")
}
go cmd.CatchSignals(nil, nil)
err = s.Run(
config.HTTPOneAddrs,
config.TLSALPNOneAddrs,
config.DNSAddrs,
config.FakeDNS,
Plan{
Runtime: runtime,
Rate: config.Plan.Rate,
Delta: delta,
})
cmd.FailOnError(err, "Failed to run load generator")
if config.ExternalState != "" && !config.DontSaveState {
err = s.Snapshot(config.ExternalState)
cmd.FailOnError(err, "Failed to save registration snapshot")
}
fmt.Println("[+] All done, bye bye ^_^")
}