diff --git a/bindings/follow.go b/bindings/follow.go index 4327964853f82e3f23146ecb3d017a5552e90146..a2c06f2acb0e5621604cfd7894166d69f4361d8d 100644 --- a/bindings/follow.go +++ b/bindings/follow.go @@ -99,13 +99,29 @@ func (c *Cmix) ReadyToSend() bool { jww.FATAL.Panicf("Failed to get node registration status: %+v", err) } - // FIXME: This is a fix put in place because not all nodes in the NDF are - // online. This should be fixed. - total = 340 - return numReg >= total*7/10 } +// IsReady returns true if at least percentReady of node registrations has +// completed. If not all have completed, then it returns false and howClose will +// be a percent (0-1) of node registrations completed. +func (c *Cmix) IsReady(percentReady float64) (isReady bool, howClose float64) { + // Check if the network is currently healthy + if !c.api.GetCmix().IsHealthy() { + return false, 0 + } + + numReg, numNodes, err := c.api.GetNodeRegistrationStatus() + if err != nil { + jww.FATAL.Panicf("Failed to get node registration status: %+v", err) + } + + isReady = (float64(numReg) / float64(numNodes)) >= percentReady + howClose = float64(numNodes) / (float64(numReg) * percentReady) + + return isReady, howClose +} + // NetworkFollowerStatus gets the state of the network follower. It returns a // status with the following values: // Stopped - 0 @@ -144,6 +160,27 @@ func (c *Cmix) GetNodeRegistrationStatus() ([]byte, error) { return json.Marshal(nodeRegReport) } +// PauseNodeRegistrations stops all node registrations and returns a function to +// resume them. +// +// Parameters: +// - timeoutMS - The timeout, in milliseconds, to wait when stopping threads. +func (c *Cmix) PauseNodeRegistrations(timeoutMS int) error { + timeout := time.Duration(timeoutMS) * time.Millisecond + return c.api.PauseNodeRegistrations(timeout) +} + +// ChangeNumberOfNodeRegistrations changes the number of parallel node +// registrations up to the initialized maximum. +// +// Parameters: +// - toRun - The number of parallel node registrations. +// - timeoutMS - The timeout, in milliseconds, to wait when changing node +// registrations. +func (c *Cmix) ChangeNumberOfNodeRegistrations(toRun int, timeout time.Duration) error { + return c.api.ChangeNumberOfNodeRegistrations(toRun, timeout) +} + // HasRunningProcessies checks if any background threads are running and returns // true if one or more are. // @@ -188,12 +225,6 @@ func (c *Cmix) AddHealthCallback(nhc NetworkHealthCallback) int64 { return int64(c.api.GetCmix().AddHealthCallback(nhc.Callback)) } -// IncreaseParallelNodeRegistration increases the number of parallel node -// registrations by num -func (c *Cmix) IncreaseParallelNodeRegistration(num int) error { - return c.api.IncreaseParallelNodeRegistration(num) -} - // RemoveHealthCallback removes a health callback using its registration ID. func (c *Cmix) RemoveHealthCallback(funcID int64) { c.api.GetCmix().RemoveHealthCallback(uint64(funcID)) diff --git a/cmix/interface.go b/cmix/interface.go index 2f1ee3db85102dc5e0a707295f4b91867f65791b..8fd4d51dbcc8e73513bb048ab2933397d2235f13 100644 --- a/cmix/interface.go +++ b/cmix/interface.go @@ -191,12 +191,12 @@ type Client interface { AddService(clientID *id.ID, newService message.Service, response message.Processor) - //PauseNodeRegistrations stops all node registrations - //and returns a function to resume them + // PauseNodeRegistrations stops all node registrations and returns a + // function to resume them. PauseNodeRegistrations(timeout time.Duration) error // ChangeNumberOfNodeRegistrations changes the number of parallel node - // registrations up to the initialized maximum + // registrations up to the initialized maximum. ChangeNumberOfNodeRegistrations(toRun int, timeout time.Duration) error // DeleteService deletes a message service. If only a single response is diff --git a/xxdk/cmix.go b/xxdk/cmix.go index 9ccf239dbaf6da0d00cef0bf7638090821a3ec2b..5189735c613fa7977af3ffad7c1b55d7750b64ef 100644 --- a/xxdk/cmix.go +++ b/xxdk/cmix.go @@ -182,7 +182,7 @@ func NewProtoCmix_Unsafe(ndfJSON, storageDir string, password []byte, storageSess.SetRegistrationTimestamp(protoUser.RegistrationTimestamp) // Move the registration state to indicate registered with registration on - // roto client + // proto client err = storageSess.ForwardRegistrationStatus(storage.PermissioningComplete) if err != nil { return err @@ -484,12 +484,16 @@ func (c *Cmix) GetNodeRegistrationStatus() (int, int, error) { return numRegistered, len(nodes) - numStale, nil } -// IncreaseParallelNodeRegistration increases the number of parallel node -// registrations by num -func (c *Cmix) IncreaseParallelNodeRegistration(num int) error { - jww.INFO.Printf("IncreaseParallelNodeRegistration(%d)", num) - svc := c.network.IncreaseParallelNodeRegistration(num) - return c.followerServices.add(svc) +// PauseNodeRegistrations stops all node registrations and returns a function to +// resume them. +func (c *Cmix) PauseNodeRegistrations(timeout time.Duration) error { + return c.network.PauseNodeRegistrations(timeout) +} + +// ChangeNumberOfNodeRegistrations changes the number of parallel node +// registrations up to the initialized maximum. +func (c *Cmix) ChangeNumberOfNodeRegistrations(toRun int, timeout time.Duration) error { + return c.network.ChangeNumberOfNodeRegistrations(toRun, timeout) } // GetPreferredBins returns the geographic bin or bins that the provided two