Skip to content

Commit

Permalink
dns attackerがいくつかのURLにアクセスする
Browse files Browse the repository at this point in the history
  • Loading branch information
kazeburo committed Nov 23, 2023
1 parent 4b5ede1 commit d6c1fc6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bench/cmd/bench/benchmarker.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (b *benchmarker) run(ctx context.Context) error {

loadAttackHTTPClient := b.loadAttackHTTPClient()
// FIXME: LIMITは負荷をみて調整したい
loadAttackLimiter := rate.NewLimiter(rate.Limit(900), 1)
loadAttackLimiter := rate.NewLimiter(rate.Limit(1200), 1)
go func() { b.loadAttackCoordinator(ctx) }()

for {
Expand Down
7 changes: 4 additions & 3 deletions bench/internal/attacker/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,20 @@ func (a *DnsWaterTortureAttacker) Attack(ctx context.Context, httpClient *http.C
name := unsafe.String(&b[0], len(b))
ip := a.lookup(ctx, name)
if ip != nil && atomic.AddUint64(&a.resolvedRequests, 1)%5 == 0 {
// TODO target url
host := fmt.Sprintf("%s:%d", strings.TrimRight(name, "."), config.TargetPort)
url := fmt.Sprintf("%s://%s/",
// root, favicon.ico, api/user/me, api/tag, api/livestream/search?limit=50 をランダムに
endpoints := []string{"", "", "", "favicon.ico", "api/user/me", "api/tag", "api/livestream/search?limit=50"}
url := fmt.Sprintf("%s://%s/%s",
config.HTTPScheme,
host,
endpoints[rand.Intn(len(endpoints))],
)
valueCtx := context.WithValue(ctx, config.AttackHTTPClientContextKey,
fmt.Sprintf("%s:%d", ip.String(), config.TargetPort))
req, err := http.NewRequestWithContext(valueCtx, "GET", url, nil)
if err != nil {
return
}
// TODO: user-agent
req.Header.Set("User-Agent", "isucandar")
res, err := httpClient.Do(req)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion bench/internal/resolver/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (r *DNSResolver) Lookup(ctx context.Context, network, addr string) (net.IP,

for _, ans := range in.Answer {
if record, ok := ans.(*dns.A); ok {
// TODO: IPアドレスが競技者のものか確認
if r.UseCache && ans.Header().Ttl > 0 {
cache.Add(addr, cacheEntry{
IP: record.A,
Expand Down

0 comments on commit d6c1fc6

Please sign in to comment.