add -shuffle flag

This commit is contained in:
Norwin Roosen 2019-01-11 18:27:29 +01:00
parent c4b0185b8d
commit 850380bf6f
1 changed files with 13 additions and 0 deletions

13
main.go
View File

@ -8,6 +8,7 @@ import (
_ "image/jpeg"
_ "image/png"
"log"
"math/rand"
"net"
_ "net/http/pprof"
"os"
@ -24,6 +25,7 @@ var image_offsety = flag.Int("yoffset", 0, "Offset of posted image from top bord
var connections = flag.Int("connections", 10, "Number of simultaneous connections/threads. Each Thread posts a subimage")
var address = flag.String("host", "127.0.0.1:1337", "Server address")
var runtime = flag.String("runtime", "1", "Runtime in Minutes")
var shuffle = flag.Bool("shuffle", false, "pixel send ordering")
func main() {
flag.Parse()
@ -50,6 +52,10 @@ func main() {
// Generate and split messages into equal chunks
commands := genCommands(readImage(*image_path), *image_offsetx, *image_offsety)
if *shuffle {
shuffleCommands(commands)
}
commandGroups := chunkCommands(commands, *connections)
for _, messages := range commandGroups {
go bomb(messages)
@ -138,3 +144,10 @@ func chunkCommands(commands [][]byte, numChunks int) [][][]byte {
}
return chunks
}
func shuffleCommands(slice [][]byte) {
for i := range slice {
j := rand.Intn(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
}