diff --git a/go.mod b/go.mod index 7cebce8c670575236cdad392bf45ece2e29bb57f..37df386469724d383bee66c2c9098e7a7410565a 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,10 @@ 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/v4 v4.3.6 - gitlab.com/elixxir/crypto v0.0.7-0.20221110181326-dd7e5293feb0 - gitlab.com/elixxir/primitives v0.0.3-0.20221110181119-e83320a48b13 - gitlab.com/xx_network/crypto v0.0.5-0.20221110181048-76f0c556fe95 + gitlab.com/elixxir/client/v4 v4.3.9-0.20221117174054-7a48e9fb3283 + gitlab.com/elixxir/crypto v0.0.7-0.20221121233335-83f145891bc7 + gitlab.com/elixxir/primitives v0.0.3-0.20221114231218-cc461261a6af + gitlab.com/xx_network/crypto v0.0.5-0.20221121220724-8eefdbb0eb46 gitlab.com/xx_network/primitives v0.0.4-0.20221110180011-fd6ea3058225 golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa ) diff --git a/go.sum b/go.sum index 8dea96fab5b018e6020bb502a12cb828ff29b348..c4ba4b5956ead423f1b811dbdd842ee1f925addf 100644 --- a/go.sum +++ b/go.sum @@ -369,20 +369,20 @@ 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/v4 v4.3.6 h1:QERsZEPqSyX3Bm0pkbBglCHE12JmdSd0tTDGN7fn/NM= -gitlab.com/elixxir/client/v4 v4.3.6/go.mod h1:RuOuVCGNCoCUFqLpbLEs/GJ9ILxo8rB5j8oBdYkl4Q8= +gitlab.com/elixxir/client/v4 v4.3.9-0.20221117174054-7a48e9fb3283 h1:TYsCqI18+g4DgENJoFahnQFQKBZwg/t5XgYMCBV5e5M= +gitlab.com/elixxir/client/v4 v4.3.9-0.20221117174054-7a48e9fb3283/go.mod h1:4jD++3DAylNUM4BL5+wEIoe+oAvkbnc//wjCgnhyKpw= gitlab.com/elixxir/comms v0.0.4-0.20221110181420-84bca6216fe4 h1:bLRjVCyMVde4n2hTVgoyyIAWrKI4CevpChchkPeb6A0= gitlab.com/elixxir/comms v0.0.4-0.20221110181420-84bca6216fe4/go.mod h1:XhI2/CMng+xcH3mAs+1aPz29PSNu1079XMJ8V+xxihw= -gitlab.com/elixxir/crypto v0.0.7-0.20221110181326-dd7e5293feb0 h1:IgspAliiN6MGqJX7LZ+1GinCX6bNJw6KlIa+rvEo2+A= -gitlab.com/elixxir/crypto v0.0.7-0.20221110181326-dd7e5293feb0/go.mod h1:IqswRNqsGooEOt2tP1LzeAcBOccVW0aUiJFH5B7UGfg= +gitlab.com/elixxir/crypto v0.0.7-0.20221121233335-83f145891bc7 h1:yhc8jQ27JKypdRE41NpfJPaYRS0sNkOwugaIyoscDiU= +gitlab.com/elixxir/crypto v0.0.7-0.20221121233335-83f145891bc7/go.mod h1:oRh3AwveOEvpk9E3kRcMGK8fImcEnN0PY4jr9HDgQE8= gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is= gitlab.com/elixxir/ekv v0.2.1/go.mod h1:USLD7xeDnuZEavygdrgzNEwZXeLQJK/w1a+htpN+JEU= -gitlab.com/elixxir/primitives v0.0.3-0.20221110181119-e83320a48b13 h1:U3tbClFN5BLYlAoMj+o6VWAs9akbFiJstMGCuk1aB94= -gitlab.com/elixxir/primitives v0.0.3-0.20221110181119-e83320a48b13/go.mod h1:DUnCTXYKgjpro5+6ITySKIf+qzW2vhW40IVHMimdsqw= +gitlab.com/elixxir/primitives v0.0.3-0.20221114231218-cc461261a6af h1:xcPqknK1ehNb9xwcutTdoR0YgD7DC/ySh9z49tIpSxQ= +gitlab.com/elixxir/primitives v0.0.3-0.20221114231218-cc461261a6af/go.mod h1:DUnCTXYKgjpro5+6ITySKIf+qzW2vhW40IVHMimdsqw= gitlab.com/xx_network/comms v0.0.4-0.20221110181111-4f0694876936 h1:eQQ4zUvGWIzCWdBJ6qlysWUMwrc2tM8GripFqdT1SAs= gitlab.com/xx_network/comms v0.0.4-0.20221110181111-4f0694876936/go.mod h1:+RfHgk75ywMvmucOpPS7rSUlsnbPyBuLsr13tsthUTE= -gitlab.com/xx_network/crypto v0.0.5-0.20221110181048-76f0c556fe95 h1:rC6lx6sD6u617Qu0ZndKZQRjXuRkyrI9Q6Y0Ki+dnK4= -gitlab.com/xx_network/crypto v0.0.5-0.20221110181048-76f0c556fe95/go.mod h1:acWUBKCpae/XVaQF7J9RnLAlBT13i5r7gnON+mrIxBk= +gitlab.com/xx_network/crypto v0.0.5-0.20221121220724-8eefdbb0eb46 h1:6AHgUpWdJ72RVTTdJSvfThZiYTQNUnrPaTCl/EkRLpg= +gitlab.com/xx_network/crypto v0.0.5-0.20221121220724-8eefdbb0eb46/go.mod h1:acWUBKCpae/XVaQF7J9RnLAlBT13i5r7gnON+mrIxBk= gitlab.com/xx_network/primitives v0.0.4-0.20221110180011-fd6ea3058225 h1:TAn87e6Zt9KwcSnWKyIul5eu8T0RHY9FDubCGs3G0dw= gitlab.com/xx_network/primitives v0.0.4-0.20221110180011-fd6ea3058225/go.mod h1:rP/2IsqIFHapuIB4mstXKItvwoJRQ9Wlms/NGeutHsk= gitlab.com/xx_network/ring v0.0.3-0.20220902183151-a7d3b15bc981 h1:1s0vX9BbkiD0IVXwr3LOaTBcq1wBrWcUWMBK0s8r0Z0= diff --git a/wasm/cmix.go b/wasm/cmix.go index fbda07a4f3a9d1d7d9db8b4d96f48b948fc024ce..3e4bb971d219de9922add778d0fa58878d548122 100644 --- a/wasm/cmix.go +++ b/wasm/cmix.go @@ -53,6 +53,7 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} { "AddHealthCallback": js.FuncOf(c.AddHealthCallback), "RemoveHealthCallback": js.FuncOf(c.RemoveHealthCallback), "RegisterClientErrorCallback": js.FuncOf(c.RegisterClientErrorCallback), + "TrackServicesWithIdentity": js.FuncOf(c.TrackServicesWithIdentity), "TrackServices": js.FuncOf(c.TrackServices), // connect.go @@ -76,13 +77,13 @@ func newCmixJS(api *bindings.Cmix) map[string]interface{} { // Users of this function should delete the storage directory on error. // // Parameters: -// - args[0] - NDF JSON ([ndf.NetworkDefinition]) (string). -// - args[1] - Storage directory path (string). -// - args[2] - Password used for storage (Uint8Array). -// - args[3] - Registration code (string). +// - args[0] - NDF JSON ([ndf.NetworkDefinition]) (string). +// - args[1] - Storage directory path (string). +// - args[2] - Password used for storage (Uint8Array). +// - args[3] - Registration code (string). // // Returns: -// - Throws a TypeError if creating new [Cmix] fails. +// - Throws a TypeError if creating new [Cmix] fails. func NewCmix(_ js.Value, args []js.Value) interface{} { password := utils.CopyBytesToGo(args[2]) @@ -107,13 +108,13 @@ func NewCmix(_ js.Value, args []js.Value) interface{} { // subprocesses to perform network operations. // // Parameters: -// - args[0] - Storage directory path (string). -// - args[1] - Password used for storage (Uint8Array). -// - args[2] - JSON of [xxdk.CMIXParams] (Uint8Array). +// - args[0] - Storage directory path (string). +// - args[1] - Password used for storage (Uint8Array). +// - args[2] - JSON of [xxdk.CMIXParams] (Uint8Array). // // Returns a promise: -// - Resolves to a Javascript representation of the [Cmix] object. -// - Rejected with an error if loading [Cmix] fails. +// - Resolves to a Javascript representation of the [Cmix] object. +// - Rejected with an error if loading [Cmix] fails. func LoadCmix(_ js.Value, args []js.Value) interface{} { storageDir := args[0].String() password := utils.CopyBytesToGo(args[1]) @@ -134,7 +135,7 @@ func LoadCmix(_ js.Value, args []js.Value) interface{} { // GetID returns the ID for this [bindings.Cmix] in the cmixTracker. // // Returns: -// - Tracker ID (int). +// - Tracker ID (int). func (c *Cmix) GetID(js.Value, []js.Value) interface{} { return c.api.GetID() } diff --git a/wasm/follow.go b/wasm/follow.go index 684b0ffcc90ffe66fe10d84469fdd473f65d34b3..5828de89671dccfcd2766ead1c04466d79d4fcc9 100644 --- a/wasm/follow.go +++ b/wasm/follow.go @@ -29,31 +29,31 @@ import ( // tracks the network events and hands them off to workers for handling. // - Historical Round Retrieval (/network/rounds/historical.go) // retrieves data about rounds that are too old to be stored by the client. -// - Message Retrieval Worker Group (/network/rounds/retrieve.go) -// requests all messages in a given round from the gateway of the last -// nodes. -// - Message Handling Worker Group (/network/message/handle.go) -// decrypts and partitions messages when signals via the Switchboard. -// - Health Tracker (/network/health), -// via the network instance, tracks the state of the network. -// - Garbled Messages (/network/message/garbled.go) -// can be signaled to check all recent messages that could be decoded. It -// uses a message store on disk for persistence. -// - Critical Messages (/network/message/critical.go) -// ensures all protocol layer mandatory messages are sent. It uses a message -// store on disk for persistence. -// - KeyExchange Trigger (/keyExchange/trigger.go) -// responds to sent rekeys and executes them. +// - Message Retrieval Worker Group (/network/rounds/retrieve.go) +// requests all messages in a given round from the gateway of the last +// nodes. +// - Message Handling Worker Group (/network/message/handle.go) +// decrypts and partitions messages when signals via the Switchboard. +// - Health Tracker (/network/health), +// via the network instance, tracks the state of the network. +// - Garbled Messages (/network/message/garbled.go) +// can be signaled to check all recent messages that could be decoded. It +// uses a message store on disk for persistence. +// - Critical Messages (/network/message/critical.go) +// ensures all protocol layer mandatory messages are sent. It uses a message +// store on disk for persistence. +// - KeyExchange Trigger (/keyExchange/trigger.go) +// responds to sent rekeys and executes them. // - KeyExchange Confirm (/keyExchange/confirm.go) -// responds to confirmations of successful rekey operations. +// responds to confirmations of successful rekey operations. // - Auth Callback (/auth/callback.go) // handles both auth confirm and requests. // // Parameters: -// - args[0] - Timeout when stopping threads in milliseconds (int). +// - args[0] - Timeout when stopping threads in milliseconds (int). // // Returns: -// - Throws a TypeError if starting the network follower fails. +// - Throws a TypeError if starting the network follower fails. func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} { err := c.api.StartNetworkFollower(args[0].Int()) if err != nil { @@ -71,8 +71,8 @@ func (c *Cmix) StartNetworkFollower(_ js.Value, args []js.Value) interface{} { // most likely be in an unrecoverable state and need to be trashed. // // Returns: -// - Throws a TypeError if the follower is in the wrong state to stop or if it -// fails to stop. +// - Throws a TypeError if the follower is in the wrong state to stop or if it +// fails to stop. func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { err := c.api.StopNetworkFollower() if err != nil { @@ -88,11 +88,11 @@ func (c *Cmix) StopNetworkFollower(js.Value, []js.Value) interface{} { // timeout is reached. It will return true if the network is healthy. // // Parameters: -// - args[0] - Timeout when stopping threads in milliseconds (int). +// - args[0] - Timeout when stopping threads in milliseconds (int). // // Returns a promise: -// - A promise that resolves if the network is healthy and rejects if the -// network is not healthy. +// - A promise that resolves if the network is healthy and rejects if the +// network is not healthy. func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} { timeoutMS := args[0].Int() promiseFn := func(resolve, reject func(args ...interface{}) js.Value) { @@ -111,19 +111,20 @@ func (c *Cmix) WaitForNetwork(_ js.Value, args []js.Value) interface{} { // at least 70% of the nodes. Returns false otherwise. // // Returns: -// - Returns true if network is ready to send on (boolean). +// - Returns true if network is ready to send on (boolean). func (c *Cmix) ReadyToSend(js.Value, []js.Value) interface{} { return c.api.ReadyToSend() } // NetworkFollowerStatus gets the state of the network follower. It returns a // status with the following values: -// Stopped - 0 -// Running - 2000 -// Stopping - 3000 +// +// Stopped - 0 +// Running - 2000 +// Stopping - 3000 // // Returns: -// - Network status code (int). +// - Network status code (int). func (c *Cmix) NetworkFollowerStatus(js.Value, []js.Value) interface{} { return c.api.NetworkFollowerStatus() } @@ -131,11 +132,11 @@ func (c *Cmix) NetworkFollowerStatus(js.Value, []js.Value) interface{} { // GetNodeRegistrationStatus returns the current state of node registration. // // Returns: -// - JSON of [bindings.NodeRegistrationReport] containing the number of nodes -// that the user is registered with and the number of nodes present in the -// NDF. -// - An error if it cannot get the node registration status. The most likely -// cause is that the network is unhealthy. +// - JSON of [bindings.NodeRegistrationReport] containing the number of nodes +// that the user is registered with and the number of nodes present in the +// NDF. +// - An error if it cannot get the node registration status. The most likely +// cause is that the network is unhealthy. func (c *Cmix) GetNodeRegistrationStatus(js.Value, []js.Value) interface{} { b, err := c.api.GetNodeRegistrationStatus() if err != nil { @@ -151,12 +152,12 @@ func (c *Cmix) GetNodeRegistrationStatus(js.Value, []js.Value) interface{} { // 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). +// - 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. +// - 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 { @@ -171,11 +172,11 @@ func (c *Cmix) IsReady(_ js.Value, args []js.Value) interface{} { // resume them. // // Parameters: -// - args[0] - The timeout, in milliseconds, to wait when stopping threads -// before failing (int). +// - args[0] - The timeout, in milliseconds, to wait when stopping threads +// before failing (int). // // Returns: -// - Throws TypeError if pausing fails. +// - 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 { @@ -190,12 +191,12 @@ func (c *Cmix) PauseNodeRegistrations(_ js.Value, args []js.Value) interface{} { // 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). +// - 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. +// - 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 { @@ -214,7 +215,7 @@ func (c *Cmix) ChangeNumberOfNodeRegistrations(_ js.Value, args []js.Value) inte // may not enter the stopped state appropriately. This can be used instead. // // Returns: -// - True if there are running processes (boolean). +// - True if there are running processes (boolean). func (c *Cmix) HasRunningProcessies(js.Value, []js.Value) interface{} { return c.api.HasRunningProcessies() } @@ -223,7 +224,7 @@ func (c *Cmix) HasRunningProcessies(js.Value, []js.Value) interface{} { // messages can be sent. // // Returns: -// - True if the network is healthy (boolean). +// - True if the network is healthy (boolean). func (c *Cmix) IsHealthy(js.Value, []js.Value) interface{} { return c.api.IsHealthy() } @@ -233,13 +234,15 @@ func (c *Cmix) IsHealthy(js.Value, []js.Value) interface{} { // conditions if multiple threads are in the process of starting or stopping. // // Returns: -// - JSON of strings (Uint8Array). +// - JSON of strings (Uint8Array). +// - Throws TypeError if getting the processes fails. // // JSON Example: -// { -// "FileTransfer{BatchBuilderThread, FilePartSendingThread#0, FilePartSendingThread#1, FilePartSendingThread#2, FilePartSendingThread#3}", -// "MessageReception Worker 0" -// } +// +// { +// "FileTransfer{BatchBuilderThread, FilePartSendingThread#0, FilePartSendingThread#1, FilePartSendingThread#2, FilePartSendingThread#3}", +// "MessageReception Worker 0" +// } func (c *Cmix) GetRunningProcesses(js.Value, []js.Value) interface{} { list, err := c.api.GetRunningProcesses() if err != nil { @@ -259,19 +262,19 @@ type networkHealthCallback struct { // Callback receives notification if network health changes. // // Parameters: -// - health - Returns true if the network is healthy and false otherwise -// (boolean). +// - health - Returns true if the network is healthy and false otherwise +// (boolean). func (nhc *networkHealthCallback) Callback(health bool) { nhc.callback(health) } // AddHealthCallback adds a callback that gets called whenever the network // health changes. Returns a registration ID that can be used to unregister. // // Parameters: -// - args[0] - Javascript object that has functions that implement the -// [bindings.NetworkHealthCallback] interface. +// - args[0] - Javascript object that has functions that implement the +// [bindings.NetworkHealthCallback] interface. // // Returns: -// - A registration ID that can be used to unregister the callback (int). +// - A registration ID that can be used to unregister the callback (int). func (c *Cmix) AddHealthCallback(_ js.Value, args []js.Value) interface{} { return c.api.AddHealthCallback( &networkHealthCallback{utils.WrapCB(args[0], "Callback")}) @@ -280,7 +283,7 @@ func (c *Cmix) AddHealthCallback(_ js.Value, args []js.Value) interface{} { // RemoveHealthCallback removes a health callback using its registration ID. // // Parameters: -// - args[0] - Callback registration ID (int). +// - args[0] - Callback registration ID (int). func (c *Cmix) RemoveHealthCallback(_ js.Value, args []js.Value) interface{} { c.api.RemoveHealthCallback(int64(args[0].Int())) return nil @@ -301,8 +304,8 @@ func (ce *clientError) Report(source, message, trace string) { // StopNetworkFollower. // // Parameters: -// - args[0] - Javascript object that has functions that implement the -// [bindings.ClientError] interface. +// - args[0] - Javascript object that has functions that implement the +// [bindings.ClientError] interface. func (c *Cmix) RegisterClientErrorCallback(_ js.Value, args []js.Value) interface{} { c.api.RegisterClientErrorCallback( &clientError{utils.WrapCB(args[0], "Report")}) @@ -321,44 +324,68 @@ type trackServicesCallback struct { // which will be non-null. // // Parameters: -// - marshalData - Returns the JSON of [message.ServiceList] (Uint8Array). -// - err - Returns an error on failure (Error). +// - marshalData - Returns the JSON of [message.ServiceList] (Uint8Array). +// - err - Returns an error on failure (Error). // // Example JSON: -// [ -// { -// "Id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", // bytes of id.ID encoded as base64 string -// "Services": [ -// { -// "Identifier": "AQID", // bytes encoded as base64 string -// "Tag": "TestTag 1", // string -// "Metadata": "BAUG" // bytes encoded as base64 string -// } -// ] -// }, -// { -// "Id": "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", -// "Services": [ -// { -// "Identifier": "AQID", -// "Tag": "TestTag 2", -// "Metadata": "BAUG" -// } -// ] -// }, -// ] +// +// [ +// { +// "Id": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", // bytes of id.ID encoded as base64 string +// "Services": [ +// { +// "Identifier": "AQID", // bytes encoded as base64 string +// "Tag": "TestTag 1", // string +// "Metadata": "BAUG" // bytes encoded as base64 string +// } +// ] +// }, +// { +// "Id": "AAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD", +// "Services": [ +// { +// "Identifier": "AQID", +// "Tag": "TestTag 2", +// "Metadata": "BAUG" +// } +// ] +// }, +// ] func (tsc *trackServicesCallback) Callback(marshalData []byte, err error) { tsc.callback(utils.CopyBytesToJS(marshalData), utils.JsTrace(err)) } +// TrackServicesWithIdentity will return via a callback the list of services the +// backend keeps track of for the provided identity. This may be passed into +// other bindings call which may need context on the available services for this +// single identity. This will only return services for the given identity. +// +// Parameters: +// - args[0] - ID of [E2e] object in tracker (int). +// - args[1] - Javascript object that has functions that implement the +// [bindings.ClientError] interface. +// +// Returns: +// - Throws TypeError if the [E2e] ID is invalid. +func (c *Cmix) TrackServicesWithIdentity(_ js.Value, args []js.Value) interface{} { + err := c.api.TrackServicesWithIdentity(args[0].Int(), + &trackServicesCallback{utils.WrapCB(args[0], "Callback")}) + if err != nil { + utils.Throw(utils.TypeError, err) + return nil + } + + return nil +} + // TrackServices will return, via a callback, the list of services that the // backend keeps track of, which is formally referred to as a // [message.ServiceList]. This may be passed into other bindings call that may // need context on the available services for this client. // // Parameters: -// - args[0] - Javascript object that has functions that implement the -// [bindings.TrackServicesCallback] interface. +// - args[0] - Javascript object that has functions that implement the +// [bindings.TrackServicesCallback] interface. func (c *Cmix) TrackServices(_ js.Value, args []js.Value) interface{} { c.api.TrackServices( &trackServicesCallback{utils.WrapCB(args[0], "Callback")})