Compare commits
11 Commits
initial-co
...
change-log
| Author | SHA1 | Date | |
|---|---|---|---|
| c33b5c5df5 | |||
| f8f2adaf6f | |||
| b393655a5e | |||
|
|
7452a23ac6 | ||
| b35cb62e1e | |||
| 56d3ec3f90 | |||
| cbb8774382 | |||
|
|
c8627a42b2 | ||
| 272a8c43ac | |||
| c04cee256f | |||
| f693a3c5bb |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
.vscode
|
||||
input.json
|
||||
.vscode/
|
||||
input.json
|
||||
|
||||
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"go.gopath": "/home/nedim/go",
|
||||
"go.useLanguageServer": true
|
||||
}
|
||||
23
README.md
23
README.md
@@ -3,15 +3,16 @@ A tool for testing xmpp servers load
|
||||
|
||||
## Environment variables
|
||||
|
||||
| Variable | Required | Default Value | Description |
|
||||
| ------------------------------------------------- | -------- | --------------------------------- | ---------------------------------------------- |
|
||||
| **Credentials:** |
|
||||
| |
|
||||
| CREDENTIALS_FILE_LOCATION | NO | input.json | Database username |
|
||||
| |
|
||||
| **GeneralOptions:** |
|
||||
| |
|
||||
| PRESENCE_STATUS_DELAY | NO | 120000000000 - 2 mins | Delay for online presence message loop |
|
||||
| COMMAND_REPLY_DELAY | NO | 10 sec | Delay for online presence message loop |
|
||||
| |
|
||||
| Variable | Required | Default Value | Description |
|
||||
| ------------------------------------------------- | -------- | --------------------------------- | -----------------------------------------------------------|
|
||||
| **Credentials:** |
|
||||
| |
|
||||
| CREDENTIALS_FILE_LOCATION | NO | input.json | Database username |
|
||||
| |
|
||||
| **GeneralOptions:** |
|
||||
| |
|
||||
| PRESENCE_STATUS_DELAY | NO | 2 min | Delay for online presence message loop |
|
||||
| COMMAND_REPLY_DELAY | NO | 10 sec | Delay for command message reply |
|
||||
| EXECUTE_SIGLE_STATUS_MESSAGE | NO | false | Send one presence stanza message for clients and terminate|
|
||||
| |
|
||||
|
||||
|
||||
1
go.mod
1
go.mod
@@ -6,6 +6,7 @@ require gosrc.io/xmpp v0.5.1
|
||||
|
||||
require (
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
github.com/twinj/uuid v1.0.0 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
|
||||
nhooyr.io/websocket v1.6.5 // indirect
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@@ -57,6 +57,8 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/twinj/uuid v1.0.0 h1:fzz7COZnDrXGTAOHGuUGYd6sG+JMq+AoE7+Jlu0przk=
|
||||
github.com/twinj/uuid v1.0.0/go.mod h1:mMgcE1RHFUFqe5AfiwlINXisXfDGro23fWdPUfOMjRY=
|
||||
github.com/twitchyliquid64/golang-asm v0.0.0-20190126203739-365674df15fc/go.mod h1:NoCfSFWosfqMqmmD7hApkirIK9ozpHjxRnRxs1l413A=
|
||||
go.coder.com/go-tools v0.0.0-20190317003359-0c6a35b74a16/go.mod h1:iKV5yK9t+J5nG9O3uF6KYdPEz3dyfMyB15MN1rbQ8Qw=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
|
||||
3
just1.json
Normal file
3
just1.json
Normal file
@@ -0,0 +1,3 @@
|
||||
[
|
||||
{"username": "DEVICE1", "host": "rolling-stock-sandbox2-openfire.onsmartengineering.com", "port": 5222, "ping": 15, "password": "7905efdb805e"}
|
||||
]
|
||||
2
main.go
2
main.go
@@ -36,7 +36,7 @@ func main() {
|
||||
|
||||
}
|
||||
// Delay before sending another message
|
||||
time.Sleep(time.Duration(appConfig.AppConfig.GeneralOptions.PresenceStatusDelay))
|
||||
time.Sleep(time.Duration(appConfig.AppConfig.GeneralOptions.PresenceStatusDelay * 1000000000))
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@@ -11,10 +12,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/twinj/uuid"
|
||||
appConfig "github.com/xmpploadtesting/config"
|
||||
"gosrc.io/xmpp"
|
||||
"gosrc.io/xmpp/stanza"
|
||||
"mellium.im/xmpp"
|
||||
)
|
||||
|
||||
const rolingStockPresenceMessage = `ROLLING STOCK PRESENCE MESSAGE
|
||||
@@ -44,6 +45,61 @@ const rolingStockPresenceMessage = `ROLLING STOCK PRESENCE MESSAGE
|
||||
"digiID": "digi-00000000-00000000-0040FFFF-FF801D30"
|
||||
}`
|
||||
|
||||
const commandMessageExample = `{"device_jid":"device1@rolling-stock-sandbox2-openfire.onsmartengineering.com",
|
||||
"message_id":"df26acfa-bdd4-40f4-a980-0638bbdb096e-1632473349400",
|
||||
"api_version":1,
|
||||
"from_id":"agent@rolling-stock-sandbox2-openfire.onsmartengineering.com",
|
||||
"commands":[{"name":"demo_command","uuid":"0388ffd0-3f69-4600-b545-ed19f6378a0a",
|
||||
"params":{"user_id":"21","api_version":1,"command":"demo_command","player_id":"8","arg":"senad.uka@toptal.com help"}}]}`
|
||||
|
||||
const commandResponse = `{"api_version": 1,
|
||||
"message_id": "766318f3-d1d3-4359-bf2d-e69d508733f4-1632410186320",
|
||||
"responses": [{"params": {"message": "Unsupported command. Type help for the list of supported commands", "response_code": "SUCCESS"},
|
||||
"uuid": "5a041416-4184-4529-a7d3-7bfdd9fc1739",
|
||||
"name": "demo_command"}],
|
||||
"player_id": "3"}`
|
||||
|
||||
// CommandMessage -
|
||||
type CommandMessage struct {
|
||||
APIVersion int `json:"api_version"`
|
||||
MessageID string `json:"message_id"`
|
||||
Commands []Command `json:"commands"`
|
||||
}
|
||||
|
||||
// Command -
|
||||
type Command struct {
|
||||
Params CommandParams `json:"params"`
|
||||
UUID string `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// CommandParams -
|
||||
type CommandParams struct {
|
||||
Command string `json:"message"`
|
||||
PlayerID string `json:"player_id"`
|
||||
}
|
||||
|
||||
// CommandMessageResponse -
|
||||
type CommandMessageResponse struct {
|
||||
APIVersion int `json:"api_version"`
|
||||
MessageID string `json:"message_id"`
|
||||
Responses []Response `json:"responses"`
|
||||
PlayerID string `json:"player_id"`
|
||||
}
|
||||
|
||||
// Response -
|
||||
type Response struct {
|
||||
Params ResponseParams `json:"params"`
|
||||
UUID string `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// ResponseParams -
|
||||
type ResponseParams struct {
|
||||
Message string `json:"message"`
|
||||
ResponseCode string `json:"response_code"`
|
||||
}
|
||||
|
||||
// XMPPService - struct containing
|
||||
type XMPPService struct {
|
||||
Router *xmpp.Router
|
||||
@@ -105,9 +161,9 @@ func Init() {
|
||||
Config: xmpp.Config{
|
||||
|
||||
TransportConfiguration: xmpp.TransportConfiguration{
|
||||
Address: credential.Host + ":" + strconv.Itoa(credential.Port),
|
||||
Domain: credential.Host,
|
||||
// TLSConfig: &tls.Config{InsecureSkipVerify: false},
|
||||
Address: credential.Host + ":" + strconv.Itoa(credential.Port),
|
||||
Domain: credential.Host,
|
||||
TLSConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
},
|
||||
Jid: credential.Jid + "@" + credential.Host,
|
||||
Credential: xmpp.Password(credential.Credential),
|
||||
@@ -118,6 +174,10 @@ func Init() {
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
statusMesageDelay := int64(rand.Intn(appConfig.AppConfig.GeneralOptions.CommandReplyDelay))
|
||||
log.Printf("Delaying client connection for: %v secconds", statusMesageDelay)
|
||||
// Delay For two seccond to allow all clients to connect
|
||||
time.Sleep(time.Duration(statusMesageDelay * 1000000000))
|
||||
|
||||
client, err := xmpp.NewClient(&xmppClient.Config, xmppService.Router, errorHandler)
|
||||
|
||||
@@ -137,8 +197,6 @@ func Init() {
|
||||
}()
|
||||
|
||||
}
|
||||
// // Delay For two seccond to allow all clients to connect
|
||||
// time.Sleep(time.Duration(2000000000))
|
||||
// Wait untill all client connections are open sucessfuly
|
||||
wg.Wait()
|
||||
|
||||
@@ -146,6 +204,12 @@ func Init() {
|
||||
|
||||
// SendOnlinePresenceStanza - send online presence stnza with data, to server
|
||||
func SendOnlinePresenceStanza(client *xmpp.Client, jid string) error {
|
||||
|
||||
statusMesageDelay := int64(rand.Intn(appConfig.AppConfig.GeneralOptions.CommandReplyDelay))
|
||||
log.Printf("Delaying online stanza presence message for: %v, secconds", statusMesageDelay*1000000000)
|
||||
// Delay For two seccond to allow all clients to connect
|
||||
time.Sleep(time.Duration(statusMesageDelay * 1000000000))
|
||||
|
||||
onlinePresencePacket := stanza.NewPresence(stanza.Attrs{From: jid, Type: stanza.StanzaType(stanza.PresenceShowChat)})
|
||||
onlinePresencePacket.Status = rolingStockPresenceMessage
|
||||
|
||||
@@ -187,6 +251,13 @@ func getClientConfigsFromFile(filePath string) ([]ClientCredentials, error) {
|
||||
|
||||
func handleMessage(s xmpp.Sender, p stanza.Packet) {
|
||||
|
||||
commandMessageResponse := CommandMessageResponse{}
|
||||
err := json.Unmarshal([]byte(commandResponse), &commandMessageResponse)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("unable to unmarshal Command Meassage Response: %v", commandResponse)
|
||||
}
|
||||
|
||||
msg, ok := p.(stanza.Message)
|
||||
if !ok {
|
||||
log.Printf(" message not OK")
|
||||
@@ -199,14 +270,37 @@ func handleMessage(s xmpp.Sender, p stanza.Packet) {
|
||||
return
|
||||
}
|
||||
|
||||
commandMessage := CommandMessage{}
|
||||
err = json.Unmarshal([]byte(msg.Body), &commandMessage)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("<%v> unable to unmarshal Command Meassage: %v", msg.To, msg.Body)
|
||||
}
|
||||
if len(commandMessageResponse.Responses) > 0 || len(commandMessage.Commands) > 0 {
|
||||
// messageIDUUID := uuid.NewV4().String()
|
||||
commandMessageUUID := uuid.NewV4().String()
|
||||
commandMessageResponse.Responses[0].UUID = commandMessageUUID
|
||||
commandMessageResponse.PlayerID = commandMessage.Commands[0].Params.PlayerID
|
||||
commandMessageResponse.MessageID = commandMessage.MessageID
|
||||
|
||||
} else {
|
||||
log.Printf("<%v> There are no commands inside command message : %v", msg.To, commandMessage)
|
||||
}
|
||||
|
||||
m, err := json.Marshal(commandMessageResponse)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("<%v> unable to marshal Command Meassage response : %v", msg.To, commandMessageResponse)
|
||||
}
|
||||
|
||||
log.Printf("<%v> received following message: %v", msg.To, msg.Body)
|
||||
commandReplyDelay := int64(rand.Intn(appConfig.AppConfig.GeneralOptions.CommandReplyDelay))
|
||||
log.Printf("Waiting FOR: %v", commandReplyDelay*1000000000)
|
||||
// Delay For two second to allow all clients to connect
|
||||
// Delay For two seccond to allow all clients to connect
|
||||
time.Sleep(time.Duration(commandReplyDelay * 1000000000))
|
||||
|
||||
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: `{"status": "OK"}`}
|
||||
err := s.Send(reply)
|
||||
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: string(m)}
|
||||
err = s.Send(reply)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Error sending to %v message %v", msg.From, err)
|
||||
BIN
xmpploadtesting
BIN
xmpploadtesting
Binary file not shown.
Reference in New Issue
Block a user