Added more test accounts

This commit is contained in:
2024-02-26 23:38:49 +01:00
parent d1afccd4bd
commit 23a9567871
4 changed files with 58 additions and 38 deletions

View File

@ -1,3 +1,3 @@
module stresstest
go 1.21.6
go 1.22

View File

@ -1,6 +1,9 @@
package main
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
"net"
@ -15,11 +18,19 @@ var (
message = []byte{1, 0}
)
func init() {
func main() {
flag.Parse()
wg := sync.WaitGroup{}
for i := 0; i < *numClients; i++ {
wg.Add(1)
go udpClient(&wg, i)
}
wg.Wait()
}
func udpClient(wg *sync.WaitGroup) {
func udpClient(wg *sync.WaitGroup, id int) {
defer wg.Done()
clientAddr, err := net.ResolveUDPAddr("udp", *address)
@ -38,6 +49,18 @@ func udpClient(wg *sync.WaitGroup) {
defer conn.Close()
loginRequest := [2]string{fmt.Sprintf("user%d", id+1), sha256Text("password")}
data, err := json.Marshal(loginRequest)
if err != nil {
fmt.Println("Error creating JSON:", err)
return
}
request := append([]byte{2}, data...)
fmt.Println(string(request))
conn.Write(request)
for {
_, err := conn.Write(message)
@ -50,13 +73,7 @@ func udpClient(wg *sync.WaitGroup) {
}
}
func main() {
wg := sync.WaitGroup{}
for i := 0; i < *numClients; i++ {
wg.Add(1)
go udpClient(&wg)
}
wg.Wait()
func sha256Text(password string) string {
sum := sha256.Sum256([]byte(password))
return hex.EncodeToString(sum[:])
}