Skip to content
Snippets Groups Projects
Commit 113f6bca authored by Josh Brooks's avatar Josh Brooks
Browse files

Implement an easier bindings option

parent 4ee33929
No related branches found
No related tags found
No related merge requests found
///////////////////////////////////////////////////////////////////////////////
// Copyright © 2020 xx network SEZC //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file //
///////////////////////////////////////////////////////////////////////////////
package api
import (
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/globals"
"gitlab.com/elixxir/client/interfaces/utility"
"gitlab.com/elixxir/client/network/gateway"
pb "gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/comms/network"
ds "gitlab.com/elixxir/comms/network/dataStructures"
"gitlab.com/elixxir/primitives/states"
"gitlab.com/xx_network/primitives/id"
"time"
)
// Adjudicates on the rounds requested. Checks if they are older rounds or in progress rounds.
// Sends updates on the rounds with callbacks
func (c *Client) RegisterMessageDelivery(roundList []id.Round, timeoutMS int) error {
// Get the oldest round in the buffer
networkInstance := c.network.GetInstance()
oldestRound := networkInstance.GetOldestRoundID()
timeout := time.Duration(timeoutMS)*time.Millisecond
/*check message delivery*/
sendResults := make(chan ds.EventReturn, len(roundList))
roundEvents := c.GetRoundEvents()
rndEventObjs := make([]*ds.EventCallback, len(roundList))
// Generate a message
msg := &pb.HistoricalRounds{
Rounds: []uint64{},
}
for i, rnd := range roundList {
if rnd < oldestRound {
// If round is older that oldest round in our buffer
// Add it to the historical round request (performed later)
msg.Rounds = append(msg.Rounds, uint64(rnd))
} else {
// Otherwise, the round is in process OR hasn't happened yet.
// Check if the round has happened by looking at the buffer
ri, err := networkInstance.GetRound(rnd)
if err != nil {
jww.ERROR.Printf("Failed to ger round [%d] in buffer: %v", rnd, err)
continue
}
// If the round is done (completed or failed) send the results
// through the channel
if states.Round(ri.State) == states.COMPLETED ||
states.Round(ri.State) == states.FAILED {
sendResults <- ds.EventReturn{
RoundInfo: ri,
}
continue
}
// If it is still in progress, create a monitoring channel
rndEventObjs[i] = roundEvents.AddRoundEventChan(rnd, sendResults,
timeout, states.COMPLETED, states.FAILED)
}
}
// Find out what happened to old (historical) rounds
go c.getHistoricalRounds(msg, networkInstance, sendResults)
// Determine the success of all rounds requested
go func() {
success, numRoundFail, numTimeout := utility.TrackResults(sendResults, len(roundList))
if !success {
globals.Log.WARN.Printf("RegisterMessageDelivery failed for %v/%v rounds. " +
"%v round(s) failed, %v timeouts", numRoundFail+numTimeout, len(roundList),
numRoundFail, numTimeout)
}
}()
return nil
}
// Helper function which asynchronously pings a random gateway until
// it gets information on it's requested historical rounds
func (c *Client) getHistoricalRounds(msg *pb.HistoricalRounds,
instance *network.Instance, sendResults chan ds.EventReturn) {
var resp *pb.HistoricalRoundsResponse
for {
// Find a gateway to request about the roundRequests
gwHost, err := gateway.Get(instance.GetPartialNdf().Get(), c.comms, c.rng.GetStream())
if err != nil {
globals.Log.FATAL.Panicf("Failed to track network, NDF has corrupt "+
"data: %s", err)
}
// If an error, retry with (potentially) a different gw host.
// If no error from received gateway request, exit loop
//vand process rounds
resp, err = c.comms.RequestHistoricalRounds(gwHost, msg)
if err == nil {
break
}
}
// Process historical rounds, sending back to the caller thread
for _, ri := range resp.Rounds {
sendResults <- ds.EventReturn{
RoundInfo: ri,
TimedOut: false,
}
}
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.1
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
gitlab.com/elixxir/comms v0.0.4-0.20210210215855-f8a4b9751c59
gitlab.com/elixxir/comms v0.0.4-0.20210212194414-4c36bb47fa96
gitlab.com/elixxir/crypto v0.0.7-0.20210210215733-951b4e717763
gitlab.com/elixxir/ekv v0.1.4
gitlab.com/elixxir/primitives v0.0.3-0.20210210215643-bf48247248e5
......
......@@ -253,6 +253,8 @@ gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0
gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/comms v0.0.4-0.20210210215855-f8a4b9751c59 h1:/MSWVvLFV8Z2H37l+9fC3z5aO/fXktwd3RKFT21dvcM=
gitlab.com/elixxir/comms v0.0.4-0.20210210215855-f8a4b9751c59/go.mod h1:ZXv+fpI/kRCzxxX6p4JXlonJVDl49t4+v71kEkBipgM=
gitlab.com/elixxir/comms v0.0.4-0.20210212194414-4c36bb47fa96 h1:66NNOMK9zQqW3xmGYll8wB/BKD5jMHOyYjpgwQD7b+Q=
gitlab.com/elixxir/comms v0.0.4-0.20210212194414-4c36bb47fa96/go.mod h1:ZXv+fpI/kRCzxxX6p4JXlonJVDl49t4+v71kEkBipgM=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
gitlab.com/elixxir/crypto v0.0.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment