1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-01-18 21:59:30 +00:00

added isReply to message structure

This commit is contained in:
postmannen 2021-09-22 16:08:55 +02:00
parent 8d0b4420c9
commit a1fbdffd36
2 changed files with 14 additions and 0 deletions

View file

@ -40,6 +40,13 @@ type Message struct {
// shell command to execute in a cli session.
// TODO:
ReplyMethodArgs []string `json:"replyMethodArgs" yaml:"replyMethodArgs"`
// IsReply are used to tell that this is a reply message. By default
// the system sends the output of a request method back to the node
// the message originated from. If it is a reply method we want the
// result of the reply message to be sent to the central server, so
// we can use this value if set to swap the toNode, and fromNode
// fields.
IsReply bool `json:"isReply" yaml:"isReply"`
// From what node the message originated
FromNode Node
// ACKTimeout for waiting for an ack message

View file

@ -282,6 +282,7 @@ func newReplyMessage(proc process, message Message, outData []byte) {
Method: message.ReplyMethod,
MethodArgs: message.ReplyMethodArgs,
MethodTimeout: message.ReplyMethodTimeout,
IsReply: true,
ACKTimeout: message.ReplyACKTimeout,
Retries: message.ReplyRetries,
Directory: message.Directory,
@ -1141,6 +1142,12 @@ func (m methodREQCliCommand) handler(proc process, message Message, node string)
case out := <-outCh:
cancel()
// If this is this a reply message swap the toNode and fromNode
// fields so the output of the command are sent to central node.
if message.IsReply {
message.ToNode, message.FromNode = message.FromNode, message.ToNode
}
// Prepare and queue for sending a new message with the output
// of the action executed.
newReplyMessage(proc, message, out)