From bf6655879dfda9ff6d298cedc8223879de91ae8a Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Fri, 10 Mar 2023 12:05:45 -0500
Subject: [PATCH] fix: include responseTo parameter
package worker omitted the response_to parameter when implementing the
com.redhat.Yggdrasil1.Worker1.Dispatch method, *and* omitted including
the same parameter when calling the
com.redhat.Yggdrasil1.Dispatcher1.Transmit method.
Signed-off-by: Link Dupont
---
internal/work/dispatcher.go | 4 ++--
worker/echo/main.go | 4 ++--
worker/worker.go | 13 +++++++------
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/internal/work/dispatcher.go b/internal/work/dispatcher.go
index c68f2b25..dfad8481 100644
--- a/internal/work/dispatcher.go
+++ b/internal/work/dispatcher.go
@@ -234,7 +234,7 @@ func (d *Dispatcher) EmitEvent(event ipc.DispatcherEvent) error {
}
// Transmit implements the com.redhat.Yggdrasil1.Dispatcher1.Transmit method.
-func (d *Dispatcher) Transmit(sender dbus.Sender, addr string, messageID string, metadata map[string]string, data []byte) (responseCode int, responseMetadata map[string]string, responseData []byte, responseError *dbus.Error) {
+func (d *Dispatcher) Transmit(sender dbus.Sender, addr string, messageID string, responseTo string, metadata map[string]string, data []byte) (responseCode int, responseMetadata map[string]string, responseData []byte, responseError *dbus.Error) {
name, err := d.senderName(sender)
if err != nil {
return TransmitResponseErr, nil, nil, NewDBusError("Transmit", fmt.Sprintf("cannot get name for sender: %v", err))
@@ -277,7 +277,7 @@ func (d *Dispatcher) Transmit(sender dbus.Sender, addr string, messageID string,
Data: yggdrasil.Data{
Type: yggdrasil.MessageTypeData,
MessageID: messageID,
- ResponseTo: "",
+ ResponseTo: responseTo,
Version: 1,
Sent: time.Now(),
Directive: addr,
diff --git a/worker/echo/main.go b/worker/echo/main.go
index 7bd4fdfc..687c89bf 100644
--- a/worker/echo/main.go
+++ b/worker/echo/main.go
@@ -17,12 +17,12 @@ import (
// echo opens a new dbus connection and calls the
// com.redhat.Yggdrasil1.Dispatcher1.Transmit method, returning the metadata and
// data it received.
-func echo(w *worker.Worker, addr string, id string, metadata map[string]string, data []byte) error {
+func echo(w *worker.Worker, addr string, id string, responseTo string, metadata map[string]string, data []byte) error {
if err := w.EmitEvent(ipc.WorkerEventNameWorking, fmt.Sprintf("echoing %v", data)); err != nil {
return fmt.Errorf("cannot call EmitEvent: %w", err)
}
- responseCode, responseMetadata, responseData, err := w.Transmit(addr, id, metadata, data)
+ responseCode, responseMetadata, responseData, err := w.Transmit(addr, id, responseTo, metadata, data)
if err != nil {
return fmt.Errorf("cannot call Transmit: %w", err)
}
diff --git a/worker/worker.go b/worker/worker.go
index 8d9fdf72..8d48ce90 100644
--- a/worker/worker.go
+++ b/worker/worker.go
@@ -14,7 +14,7 @@ import (
)
// RxFunc is a function type that gets called each time the worker receives data.
-type RxFunc func(w *Worker, addr string, id string, metadata map[string]string, data []byte) error
+type RxFunc func(w *Worker, addr string, id string, responseTo string, metadata map[string]string, data []byte) error
// EventHandlerFunc is a function type that gets called each time the worker
// receives a com.redhat.Yggdrasil1.Dispatcher1.Event signal.
@@ -146,11 +146,11 @@ func (w *Worker) GetFeature(name string) string {
// Transmit wraps a com.redhat.Yggdrasil1.Dispatcher1.Transmit method call for
// ease of use from the worker.
-func (w *Worker) Transmit(addr string, id string, metadata map[string]string, data []byte) (responseCode int, responseMetadata map[string]string, responseData []byte, err error) {
+func (w *Worker) Transmit(addr string, id string, responseTo string, metadata map[string]string, data []byte) (responseCode int, responseMetadata map[string]string, responseData []byte, err error) {
// Look up the Dispatcher object on the bus connection and call its Transmit
// method, returning the data received.
obj := w.conn.Object("com.redhat.Yggdrasil1.Dispatcher1", "/com/redhat/Yggdrasil1/Dispatcher1")
- err = obj.Call("com.redhat.Yggdrasil1.Dispatcher1.Transmit", 0, addr, id, metadata, data).Store(&responseCode, &responseMetadata, &responseData)
+ err = obj.Call("com.redhat.Yggdrasil1.Dispatcher1.Transmit", 0, addr, id, responseTo, metadata, data).Store(&responseCode, &responseMetadata, &responseData)
if err != nil {
responseCode = -1
return
@@ -168,12 +168,13 @@ func (w *Worker) EmitEvent(event ipc.WorkerEventName, message string) error {
return w.conn.Emit(dbus.ObjectPath(path.Join("/com/redhat/Yggdrasil1/Worker1", w.directive)), "com.redhat.Yggdrasil1.Worker1.Event", args...)
}
-// dispatch implements com.redhat.Yggdrasil1.Worker1.dispatch by calling the
+// dispatch implements com.redhat.Yggdrasil1.Worker1.Dispatch by calling the
// worker's RxFunc in a goroutine.
-func (w *Worker) dispatch(addr string, id string, metadata map[string]string, data []byte) *dbus.Error {
+func (w *Worker) dispatch(addr string, id string, responseTo string, metadata map[string]string, data []byte) *dbus.Error {
// Log the data received at a high log level for debugging purposes.
log.Tracef("addr = %v", addr)
log.Tracef("id = %v", id)
+ log.Tracef("responseTo = %v", responseTo)
log.Tracef("metadata = %#v", metadata)
log.Tracef("data = %v", data)
@@ -182,7 +183,7 @@ func (w *Worker) dispatch(addr string, id string, metadata map[string]string, da
}
go func() {
- if err := w.rx(w, addr, id, metadata, data); err != nil {
+ if err := w.rx(w, addr, id, responseTo, metadata, data); err != nil {
log.Errorf("cannot call rx: %v", err)
}
if err := w.EmitEvent(ipc.WorkerEventNameEnd, ""); err != nil {