diff --git a/go.mod b/go.mod index c6ef9a18a2925ddd8c306148fba7b3ec4e4b12b5..068d30f7417324d7ba46320687eaf000a3a7834d 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/hack-pad/go-indexeddb v0.2.0 github.com/pkg/errors v0.9.1 github.com/spf13/jwalterweatherman v1.1.0 - gitlab.com/elixxir/client v1.5.1-0.20221027214841-c43fddb9a242 + gitlab.com/elixxir/client v1.5.1-0.20221027221053-4600e5df627a gitlab.com/elixxir/crypto v0.0.7-0.20221027040529-dbcb6eb2b087 gitlab.com/elixxir/primitives v0.0.3-0.20221025020430-f5d2eb330fbc gitlab.com/xx_network/crypto v0.0.5-0.20221025020316-517fa8f91d2c diff --git a/go.sum b/go.sum index 2405c6a2698dbb7f7c1155b8c45fe4c2daf4b7ab..0297cceae4671fce8a923c753d3e7395af23f58b 100644 --- a/go.sum +++ b/go.sum @@ -616,8 +616,8 @@ github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo= github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= -gitlab.com/elixxir/client v1.5.1-0.20221027214841-c43fddb9a242 h1:vyoO87vVV7aFGkEIjIEgQhFtVEvUcOF9W0qpFX+ytro= -gitlab.com/elixxir/client v1.5.1-0.20221027214841-c43fddb9a242/go.mod h1:as23IqjgFKv4MLoOrjBNDUy1BdUrTqR0CMDJ5kWVL4o= +gitlab.com/elixxir/client v1.5.1-0.20221027221053-4600e5df627a h1:Zh5Da3oXTP/0/3LfnRLe/wrbfNqU3T5fpItazio/k4Y= +gitlab.com/elixxir/client v1.5.1-0.20221027221053-4600e5df627a/go.mod h1:as23IqjgFKv4MLoOrjBNDUy1BdUrTqR0CMDJ5kWVL4o= gitlab.com/elixxir/comms v0.0.4-0.20221027214216-31527f2bb34c h1:Xqi7zsiet2yvquYc6WuQ3fcpOAUYwHnigCRLH/e5H6I= gitlab.com/elixxir/comms v0.0.4-0.20221027214216-31527f2bb34c/go.mod h1:TkgvoInYGMz9x2FSv9rZHsfJ54/A30uWQuQ1AIx8sQI= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= diff --git a/wasm/cmix.go b/wasm/cmix.go index cf18ee064a83604569e6e757a71a888f6161f557..0d6b2799dd02fe14527be95b495dd601895011b9 100644 --- a/wasm/cmix.go +++ b/wasm/cmix.go @@ -38,19 +38,22 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} { c.GetReceptionRegistrationValidationSignature), // follow.go - "StartNetworkFollower": js.FuncOf(c.StartNetworkFollower), - "StopNetworkFollower": js.FuncOf(c.StopNetworkFollower), - "WaitForNetwork": js.FuncOf(c.WaitForNetwork), - "ReadyToSend": js.FuncOf(c.ReadyToSend), - "NetworkFollowerStatus": js.FuncOf(c.NetworkFollowerStatus), - "GetNodeRegistrationStatus": js.FuncOf(c.GetNodeRegistrationStatus), - "HasRunningProcessies": js.FuncOf(c.HasRunningProcessies), - "IsHealthy": js.FuncOf(c.IsHealthy), - "GetRunningProcesses": js.FuncOf(c.GetRunningProcesses), - "AddHealthCallback": js.FuncOf(c.AddHealthCallback), - "RemoveHealthCallback": js.FuncOf(c.RemoveHealthCallback), - "RegisterClientErrorCallback": js.FuncOf(c.RegisterClientErrorCallback), - "TrackServices": js.FuncOf(c.TrackServices), + "StartNetworkFollower": js.FuncOf(c.StartNetworkFollower), + "StopNetworkFollower": js.FuncOf(c.StopNetworkFollower), + "WaitForNetwork": js.FuncOf(c.WaitForNetwork), + "ReadyToSend": js.FuncOf(c.ReadyToSend), + "NetworkFollowerStatus": js.FuncOf(c.NetworkFollowerStatus), + "GetNodeRegistrationStatus": js.FuncOf(c.GetNodeRegistrationStatus), + "IsReady": js.FuncOf(c.IsReady), + "PauseNodeRegistrations": js.FuncOf(c.PauseNodeRegistrations), + "ChangeNumberOfNodeRegistrations": js.FuncOf(c.ChangeNumberOfNodeRegistrations), + "HasRunningProcessies": js.FuncOf(c.HasRunningProcessies), + "IsHealthy": js.FuncOf(c.IsHealthy), + "GetRunningProcesses": js.FuncOf(c.GetRunningProcesses), + "AddHealthCallback": js.FuncOf(c.AddHealthCallback), + "RemoveHealthCallback": js.FuncOf(c.RemoveHealthCallback), + "RegisterClientErrorCallback": js.FuncOf(c.RegisterClientErrorCallback), + "TrackServices": js.FuncOf(c.TrackServices), // connect.go "Connect": js.FuncOf(c.Connect), diff --git a/wasm/follow.go b/wasm/follow.go index 1ce3a46522741666e052d0be53acc2148ee6249e..684b0ffcc90ffe66fe10d84469fdd473f65d34b3 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -146,6 +146,66 @@ func (c *Cmix) GetNodeRegistrationStatus(js.Value, []js.Value) interface{} { return utils.CopyBytesToJS(b) } +// IsReady returns true if at least the given percent of node registrations have +// completed. If not all have completed, then it returns false and howClose will +// be a percent (0-1) of node registrations completed. +// +// Parameters: +// - args[0] - The percentage of nodes required to be registered with to be +// ready. This is a number between 0 and 1 (float64). +// +// Returns: +// - JSON of [bindings.IsReadyInfo] (Uint8Array). +// - Throws TypeError if getting the information fails. +func (c *Cmix) IsReady(_ js.Value, args []js.Value) interface{} { + isReadyInfo, err := c.api.IsReady(args[0].Float()) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return utils.CopyBytesToJS(isReadyInfo) +} + +// PauseNodeRegistrations stops all node registrations and returns a function to +// resume them. +// +// Parameters: +// - args[0] - The timeout, in milliseconds, to wait when stopping threads +// before failing (int). +// +// Returns: +// - Throws TypeError if pausing fails. +func (c *Cmix) PauseNodeRegistrations(_ js.Value, args []js.Value) interface{} { + err := c.api.PauseNodeRegistrations(args[0].Int()) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return nil +} + +// ChangeNumberOfNodeRegistrations changes the number of parallel node +// registrations up to the initialized maximum. +// +// Parameters: +// - args[0] - The number of parallel node registrations (int). +// - args[1] - The timeout, in milliseconds, to wait when changing node +// registrations before failing (int). +// +// Returns: +// - Throws TypeError if changing registrations fails. +func (c *Cmix) ChangeNumberOfNodeRegistrations(_ js.Value, args []js.Value) interface{} { + err := c.api.ChangeNumberOfNodeRegistrations(args[0].Int(), args[1].Int()) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return nil +} + // HasRunningProcessies checks if any background threads are running and returns // true if one or more are. //