Skip to content
Snippets Groups Projects
Commit 7d5be535 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

Moved the logic in WaitForRoundCompletion to WaitForMessageDelivery,

which better describes what it was doing, and make
WaitForRoundCompletion wait for completion or failure of a
specific round
parent d442ce9b
No related branches found
No related tags found
No related merge requests found
......@@ -31,12 +31,19 @@ type NetworkHealthCallback interface {
Callback(bool)
}
// RoundEventHandler handles round events happening on the cMix network.
// RoundEventCallback handles waiting on the exact state of a round on
// the cMix network.
type RoundEventCallback interface {
EventCallback(rid, state int, timedOut bool)
}
// RoundEventHandler handles round events happening on the cMix network.
// RoundCompletionCallback is returned when the completion of a round is known.
type RoundCompletionCallback interface {
EventCallback(rid int, success, timedOut bool)
}
// MessageDeliveryCallback gets called on the determination if all events
// related to a message send were successful.
type MessageDeliveryCallback interface {
EventCallback(msgID []byte, delivered, timedOut bool, roundResults []byte)
}
......
......@@ -333,18 +333,35 @@ func (c *Client) RegisterRoundEventsHandler(rid int, cb RoundEventCallback,
return newRoundUnregister(roundID, ec, c.api.GetRoundEvents())
}
// RegisterMessageDeliveryCB allows the caller to get notified if the rounds a
// message was sent in successfully completed. Under the hood, this uses the same
// interface as RegisterRoundEventsHandler, but provides a convenient way to use
// the interface in its most common form, looking up the result of message
// retrieval
// WaitForRoundCompletion allows the caller to get notified if a round
// has completed (or failed). Under the hood, this uses an API which uses the internal
// round data, network historical round lookup, and waiting on network events
// to determine what has (or will) occur.
//
// The callbacks will return at timeoutMS if no state update occurs
func (c *Client) WaitForRoundCompletion(roundID int,
rec RoundCompletionCallback, timeoutMS int) error {
f := func(allRoundsSucceeded, timedOut bool, rounds map[id.Round]api.RoundResult) {
rec.EventCallback(roundID, allRoundsSucceeded, timedOut)
}
timeout := time.Duration(timeoutMS) * time.Millisecond
return c.api.GetRoundResults([]id.Round{id.Round(roundID)}, timeout, f)
}
// WaitForMessageDelivery allows the caller to get notified if the rounds a
// message was sent in successfully completed. Under the hood, this uses an API
// which uses the internal round data, network historical round lookup, and
// waiting on network events to determine what has (or will) occur.
//
// The callbacks will return at timeoutMS if no state update occurs
//
// 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) WaitForRoundCompletion(marshaledSendReport []byte,
func (c *Client) WaitForMessageDelivery(marshaledSendReport []byte,
mdc MessageDeliveryCallback, timeoutMS int) error {
sr, err := UnmarshalSendReport(marshaledSendReport)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment