From 9b9b446bbdec0330169d682e39a188e52dc6b81f Mon Sep 17 00:00:00 2001 From: postmannen Date: Thu, 26 Aug 2021 06:08:39 +0200 Subject: [PATCH] added toNodes as a field in message --- read_socket_or_tcp_listener.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/read_socket_or_tcp_listener.go b/read_socket_or_tcp_listener.go index 700e2a5..8bfea84 100644 --- a/read_socket_or_tcp_listener.go +++ b/read_socket_or_tcp_listener.go @@ -161,6 +161,40 @@ func convertBytesToSAMs(b []byte) ([]subjectAndMessage, error) { return nil, fmt.Errorf("error: unmarshal of file failed: %#v", err) } + // -------------------- + MsgSliceTmp := []Message{} + + for _, v := range MsgSlice { + switch { + // if toNode specified, we don't care about the toHosts. + case v.ToNode != "": + MsgSliceTmp = append(MsgSliceTmp, v) + continue + + // if toNodes specified, we use the original message, and + // create new node messages for each of the nodes specified. + case len(v.ToNodes) != 0: + fmt.Printf("\n * Found TonNodes: %#v\n\n", len(v.ToNodes)) + for _, n := range v.ToNodes { + m := v + m.ToNodes = nil + m.ToNode = n + MsgSliceTmp = append(MsgSliceTmp, m) + } + continue + + // No toNode or toNodes specified. Drop the message by not appending it to + // the slice since it is not valid. + default: + continue + } + } + + MsgSlice = MsgSliceTmp + // -------------------- + + // TODO: Implement check for empty toNode field. + sam := []subjectAndMessage{} // Range over all the messages parsed from json, and create a subject for