diff --git a/bindings/follow.go b/bindings/follow.go index 503aa5e1a5301ab1cd0124044e7a57a87fe28eea..56c653af47ac981c01b805d1a43079c1bbc60cb1 100644 --- a/bindings/follow.go +++ b/bindings/follow.go @@ -10,6 +10,7 @@ package bindings import ( "encoding/json" "fmt" + jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/message" "time" @@ -82,6 +83,25 @@ func (c *Cmix) WaitForNetwork(timeoutMS int) bool { return false } +// ReadyToSend determines if the network is ready to send messages on. It +// returns true if the network is healthy and if the client has registered with +// at least 70% of the nodes. Returns false otherwise. +func (c *Cmix) ReadyToSend() bool { + // Check if the network is currently healthy + if !c.api.GetCmix().IsHealthy() { + return false + } + + // If the network is healthy, then check the number of nodes that the client + // is currently registered with + numReg, total, err := c.api.GetNodeRegistrationStatus() + if err != nil { + jww.FATAL.Panicf("Failed to get node registration status: %+v", err) + } + + return numReg >= total*7/10 +} + // NetworkFollowerStatus gets the state of the network follower. It returns a // status with the following values: // Stopped - 0