2020-02-05 19:26:43 +01:00
|
|
|
package pixelflut
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2020-02-06 01:01:05 +01:00
|
|
|
"net"
|
2020-02-13 22:26:50 +01:00
|
|
|
"sync"
|
2020-02-05 19:26:43 +01:00
|
|
|
)
|
|
|
|
|
2020-02-06 01:01:05 +01:00
|
|
|
// @speed: add some performance reporting mechanism on these functions when
|
|
|
|
// called as goroutines
|
|
|
|
|
2020-02-06 13:39:24 +01:00
|
|
|
// bombAddress writes the given message via plain TCP to the given address,
|
2020-02-13 23:57:56 +01:00
|
|
|
// as fast as possible, until stop is closed.
|
2020-02-13 22:26:50 +01:00
|
|
|
func bombAddress(message []byte, address string, stop chan bool, wg *sync.WaitGroup) {
|
2020-02-05 19:26:43 +01:00
|
|
|
conn, err := net.Dial("tcp", address)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
2020-02-13 22:26:50 +01:00
|
|
|
bombConn(message, conn, stop)
|
|
|
|
wg.Done()
|
2020-02-06 01:01:05 +01:00
|
|
|
}
|
|
|
|
|
2020-02-13 22:26:50 +01:00
|
|
|
func bombConn(message []byte, conn net.Conn, stop chan bool) {
|
2020-02-05 19:26:43 +01:00
|
|
|
for {
|
2020-02-13 22:26:50 +01:00
|
|
|
select {
|
|
|
|
case <-stop:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
_, err := conn.Write(message)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-02-05 19:26:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|