Skip to content

Commit

Permalink
fix: include responseTo parameter
Browse files Browse the repository at this point in the history
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 <link@sub-pop.net>
  • Loading branch information
subpop committed Mar 10, 2023
1 parent 9e745f3 commit bf66558
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions internal/work/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions worker/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 7 additions & 6 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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 {
Expand Down

0 comments on commit bf66558

Please sign in to comment.