diff --git a/api/messages.go b/api/messages.go index 933af975b831491ff22fd7cf6e311f040e77e5aa..a44ca4ce0bbc90ebe8cc1b40f586b9cf938ab95b 100644 --- a/api/messages.go +++ b/api/messages.go @@ -38,9 +38,7 @@ const ( // Returns false if all rounds statuses were returned // rounds contains a mapping of all previously requested rounds to // their respective round results -type RoundEventCallback interface { - Report(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) -} +type RoundEventCallback func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]RoundResult) // Comm interface for RequestHistoricalRounds. // Constructed for testability with getRoundResults @@ -129,14 +127,14 @@ func (c *Client) getRoundResults(roundList []id.Round, timeout time.Duration, // If we know about all rounds, return if numResults == 0 { - roundCallback.Report(allRoundsSucceeded, false, roundsResults) + roundCallback(allRoundsSucceeded, false, roundsResults) return } // Wait for info about rounds or the timeout to occur select { case <-timer.C: - roundCallback.Report(false, true, roundsResults) + roundCallback(false, true, roundsResults) return case roundReport := <-sendResults: numResults-- diff --git a/bindings/callback.go b/bindings/callback.go index 68ca5646e0122f8a08b1d5d27ca580e2783e603c..4fc0431a41718961405f040fed2a0691aa86b44d 100644 --- a/bindings/callback.go +++ b/bindings/callback.go @@ -38,7 +38,7 @@ type RoundEventCallback interface { // RoundEventHandler handles round events happening on the cMix network. type MessageDeliveryCallback interface { - EventCallback(msgID []byte, delivered, timedOut bool) + EventCallback(msgID []byte, delivered, timedOut bool, roundResults []byte) } // AuthRequestCallback notifies the register whenever they receive an auth diff --git a/bindings/client.go b/bindings/client.go index 7402c02ecb97815aabc6b08497fd056115469462..866721af2ed32316a3191c0b60d7bfbdfe82691a 100644 --- a/bindings/client.go +++ b/bindings/client.go @@ -16,9 +16,7 @@ import ( "gitlab.com/elixxir/client/interfaces/contact" "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" - "gitlab.com/elixxir/client/interfaces/utility" "gitlab.com/elixxir/comms/mixmessages" - ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/primitives/states" "gitlab.com/xx_network/primitives/id" "time" @@ -307,37 +305,30 @@ func (c *Client) RegisterRoundEventsHandler(rid int, cb RoundEventCallback, // This function takes the marshaled send report to ensure a memory leak does // not occur as a result of both sides of the bindings holding a reference to // the same pointer. -func (c *Client) RegisterMessageDeliveryCB(marshaledSendReport []byte, - mdc MessageDeliveryCallback, timeoutMS int) (*Unregister, error) { +func (c *Client) WaitForRoundCompletion(marshaledSendReport []byte, + mdc MessageDeliveryCallback, timeoutMS int) error { sr, err := UnmarshalSendReport(marshaledSendReport) if err != nil { - return nil, errors.New(fmt.Sprintf("Failed to "+ - "RegisterMessageDeliveryCB: %+v", err)) + return errors.New(fmt.Sprintf("Failed to "+ + "WaitForRoundCompletion callback due to bad Send Report: %+v", err)) } - /*check message delivery*/ - sendResults := make(chan ds.EventReturn, len(sr.rl.list)) - roundEvents := c.api.GetRoundEvents() + f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult){ + results := make([]byte, len(sr.rl.list)) - reventObjs := make([]*ds.EventCallback, len(sr.rl.list)) + for i, r := range sr.rl.list{ + if result, exists := rounds[r]; exists{ + results[i] = byte(result) + } + } - for i, r := range sr.rl.list { - reventObjs[i] = roundEvents.AddRoundEventChan(r, sendResults, - time.Duration(timeoutMS)*time.Millisecond, states.COMPLETED, - states.FAILED) + mdc.EventCallback(sr.mid.Marshal(), allRoundsSucceeded, timedOut, results) } - go func() { - success, _, numTmeout := utility.TrackResults(sendResults, len(sr.rl.list)) - if !success { - mdc.EventCallback(sr.mid[:], false, numTmeout > 0) - } else { - mdc.EventCallback(sr.mid[:], true, false) - } - }() + timeout := time.Duration(timeoutMS)*time.Millisecond - return newRoundListUnregister(sr.rl.list, reventObjs, roundEvents), nil + return c.api.GetRoundResults(sr.rl.list, timeout, f) } // Returns a user object from which all information about the current user