From a1fbdffd36dce6e542ebd57708f62bff42f1b5b6 Mon Sep 17 00:00:00 2001 From: postmannen Date: Wed, 22 Sep 2021 16:08:55 +0200 Subject: [PATCH] added isReply to message structure --- message_and_subject.go | 7 +++++++ requests.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/message_and_subject.go b/message_and_subject.go index fd35a9d..ab861bf 100644 --- a/message_and_subject.go +++ b/message_and_subject.go @@ -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 diff --git a/requests.go b/requests.go index 335d18a..d233c8f 100644 --- a/requests.go +++ b/requests.go @@ -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)