From 3da318272ab4b574eeff2cf8ef5f7fc0c9d793c9 Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Wed, 25 May 2022 13:22:44 -0700 Subject: [PATCH] Have all Params objects adhere to json.Marshaler/Unmarshaler --- api/params.go | 14 ++ cmix/gateway/hostPool.go | 57 +++++++- .../receptionID/store/unknownRounds.go | 75 ++++++++-- cmix/message/params.go | 70 +++++++++- cmix/params.go | 131 ++++++++++++++++-- cmix/pickup/params.go | 77 +++++++++- cmix/rounds/params.go | 66 ++++++++- connect/connect.go | 16 ++- e2e/params.go | 50 ++++++- e2e/ratchet/partner/session/params.go | 41 +++++- e2e/rekey/params.go | 31 +++++ e2e/rekey/params_test.go | 1 + fileTransfer2/connect/params.go | 42 ++++++ fileTransfer2/e2e/params.go | 40 ++++++ fileTransfer2/params.go | 47 +++++++ single/params.go | 47 +++++++ 16 files changed, 764 insertions(+), 41 deletions(-) create mode 100644 e2e/rekey/params_test.go diff --git a/api/params.go b/api/params.go index 6430eb60c..39f9d8db3 100644 --- a/api/params.go +++ b/api/params.go @@ -8,6 +8,7 @@ package api import ( + "encoding/json" "gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/e2e/ratchet/partner/session" ) @@ -23,3 +24,16 @@ func GetDefaultParams() Params { Session: session.GetDefaultParams(), } } + +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} diff --git a/cmix/gateway/hostPool.go b/cmix/gateway/hostPool.go index 25dc7192e..ebc8ede74 100644 --- a/cmix/gateway/hostPool.go +++ b/cmix/gateway/hostPool.go @@ -14,6 +14,7 @@ package gateway import ( "encoding/binary" + "encoding/json" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/storage" @@ -108,7 +109,16 @@ type PoolParams struct { ForceConnection bool // HostParams is the parameters for the creation of new Host objects. - HostParams connect.HostParams + HostParams connect.HostParams `json:"-"` +} + +// poolParamsDisk will be the marshal-able and umarshal-able object. +type poolParamsDisk struct { + MaxPoolSize uint32 + PoolSize uint32 + ProxyAttempts uint32 + MaxPings uint32 + ForceConnection bool } // DefaultPoolParams returns a default set of PoolParams. @@ -132,6 +142,51 @@ func DefaultPoolParams() PoolParams { return p } +// GetParameters returns the default PoolParams, or +// override with given parameters, if set. +func GetParameters(params string) (PoolParams, error) { + p := DefaultPoolParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return PoolParams{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (f PoolParams) MarshalJSON() ([]byte, error) { + ppd := poolParamsDisk{ + MaxPoolSize: f.MaxPoolSize, + PoolSize: f.PoolSize, + ProxyAttempts: f.ProxyAttempts, + MaxPings: f.MaxPings, + ForceConnection: f.ForceConnection, + } + + return json.Marshal(&ppd) +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (f *PoolParams) UnmarshalJSON(data []byte) error { + ppd := poolParamsDisk{} + err := json.Unmarshal(data, &ppd) + if err != nil { + return err + } + + *f = PoolParams{ + MaxPoolSize: ppd.MaxPoolSize, + PoolSize: ppd.PoolSize, + ProxyAttempts: ppd.ProxyAttempts, + MaxPings: ppd.MaxPings, + ForceConnection: ppd.ForceConnection, + } + + return nil +} + // newHostPool builds and returns a new HostPool object. func newHostPool(poolParams PoolParams, rng *fastRNG.StreamGenerator, netDef *ndf.NetworkDefinition, getter HostManager, storage storage.Session, diff --git a/cmix/identity/receptionID/store/unknownRounds.go b/cmix/identity/receptionID/store/unknownRounds.go index 022fd252d..77816f555 100644 --- a/cmix/identity/receptionID/store/unknownRounds.go +++ b/cmix/identity/receptionID/store/unknownRounds.go @@ -24,21 +24,6 @@ const ( defaultMaxCheck = 3 ) -// UnknownRounds tracks data for unknown rounds. Should adhere to UnknownRounds -// interface. -type UnknownRounds struct { - // Maps an unknown round to how many times the round has been checked - rounds map[id.Round]*uint64 - - // Configurations of UnknownRounds - params UnknownRoundsParams - - // Key Value store to save data to disk - kv *versioned.KV - - mux sync.Mutex -} - // UnknownRoundsParams allows configuration of UnknownRounds parameters. type UnknownRoundsParams struct { // MaxChecks is the maximum amount of checks of a round before that round @@ -49,6 +34,12 @@ type UnknownRoundsParams struct { Stored bool } +// unknownRoundsParamsDisk will be the marshal-able and umarshal-able object. +type unknownRoundsParamsDisk struct { + MaxChecks uint64 + Stored bool +} + // DefaultUnknownRoundsParams returns a default set of UnknownRoundsParams. func DefaultUnknownRoundsParams() UnknownRoundsParams { return UnknownRoundsParams{ @@ -57,6 +48,60 @@ func DefaultUnknownRoundsParams() UnknownRoundsParams { } } +// GetParameters returns the default UnknownRoundsParams, +// or override with given parameters, if set. +func GetParameters(params string) (UnknownRoundsParams, error) { + p := DefaultUnknownRoundsParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return UnknownRoundsParams{}, err + } + } + return p, nil +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (f *UnknownRoundsParams) UnmarshalJSON(data []byte) error { + urpDisk := unknownRoundsParamsDisk{} + err := json.Unmarshal(data, &urpDisk) + if err != nil { + return err + } + + *f = UnknownRoundsParams{ + MaxChecks: urpDisk.MaxChecks, + Stored: urpDisk.Stored, + } + + return nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (f UnknownRoundsParams) MarshalJSON() ([]byte, error) { + urpDisk := unknownRoundsParamsDisk{ + MaxChecks: f.MaxChecks, + Stored: f.Stored, + } + + return json.Marshal(&urpDisk) +} + +// UnknownRounds tracks data for unknown rounds. Should adhere to UnknownRounds +// interface. +type UnknownRounds struct { + // Maps an unknown round to how many times the round has been checked + rounds map[id.Round]*uint64 + + // Configurations of UnknownRounds + params UnknownRoundsParams + + // Key Value store to save data to disk + kv *versioned.KV + + mux sync.Mutex +} + // NewUnknownRounds builds and returns a new UnknownRounds object. func NewUnknownRounds(kv *versioned.KV, params UnknownRoundsParams) *UnknownRounds { diff --git a/cmix/message/params.go b/cmix/message/params.go index 9a3a56cd5..c717a19cf 100644 --- a/cmix/message/params.go +++ b/cmix/message/params.go @@ -1,7 +1,18 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +//////////////////////////////////////////////////////////////////////////////// + package message -import "time" +import ( + "encoding/json" + "time" +) +// Params contains the parameters for the message package. type Params struct { MessageReceptionBuffLen uint MessageReceptionWorkerPoolSize uint @@ -10,6 +21,17 @@ type Params struct { RealtimeOnly bool } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + MessageReceptionBuffLen uint + MessageReceptionWorkerPoolSize uint + MaxChecksInProcessMessage uint + InProcessMessageWait time.Duration + RealtimeOnly bool +} + +// GetDefaultParams returns a Params object containing the +// default parameters. func GetDefaultParams() Params { return Params{ MessageReceptionBuffLen: 500, @@ -19,3 +41,49 @@ func GetDefaultParams() Params { RealtimeOnly: false, } } + +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + MessageReceptionBuffLen: r.MessageReceptionBuffLen, + MessageReceptionWorkerPoolSize: r.MessageReceptionWorkerPoolSize, + MaxChecksInProcessMessage: r.MaxChecksInProcessMessage, + InProcessMessageWait: r.InProcessMessageWait, + RealtimeOnly: r.RealtimeOnly, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{ + MessageReceptionBuffLen: pDisk.MessageReceptionBuffLen, + MessageReceptionWorkerPoolSize: pDisk.MessageReceptionWorkerPoolSize, + MaxChecksInProcessMessage: pDisk.MaxChecksInProcessMessage, + InProcessMessageWait: pDisk.InProcessMessageWait, + RealtimeOnly: pDisk.RealtimeOnly, + } + + return nil +} diff --git a/cmix/params.go b/cmix/params.go index d823632e1..4f8b8bb7a 100644 --- a/cmix/params.go +++ b/cmix/params.go @@ -1,3 +1,10 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +//////////////////////////////////////////////////////////////////////////////// + package cmix import ( @@ -57,6 +64,22 @@ type Params struct { Historical rounds.Params } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + TrackNetworkPeriod time.Duration + MaxCheckedRounds uint + RegNodesBufferLen uint + NetworkHealthTimeout time.Duration + ParallelNodeRegistrations uint + KnownRoundsThreshold uint + FastPolling bool + VerboseRoundTracking bool + RealtimeOnly bool + ReplayRequests bool +} + +// GetDefaultParams returns a Params object containing the +// default parameters. func GetDefaultParams() Params { n := Params{ TrackNetworkPeriod: 100 * time.Millisecond, @@ -78,18 +101,7 @@ func GetDefaultParams() Params { return n } -func (n Params) Marshal() ([]byte, error) { - return json.Marshal(n) -} - -func (n Params) SetRealtimeOnlyAll() Params { - n.RealtimeOnly = true - n.Pickup.RealtimeOnly = true - n.Message.RealtimeOnly = true - return n -} - -// GetParameters returns the default network parameters, or override with given +// GetParameters returns the default Params, or override with given // parameters, if set. func GetParameters(params string) (Params, error) { p := GetDefaultParams() @@ -102,7 +114,53 @@ func GetParameters(params string) (Params, error) { return p, nil } -type NodeMap map[id.ID]bool +// MarshalJSON adheres to the json.Marshaler interface. +func (n Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + TrackNetworkPeriod: n.TrackNetworkPeriod, + MaxCheckedRounds: n.MaxCheckedRounds, + RegNodesBufferLen: n.RegNodesBufferLen, + NetworkHealthTimeout: n.NetworkHealthTimeout, + ParallelNodeRegistrations: n.ParallelNodeRegistrations, + KnownRoundsThreshold: n.KnownRoundsThreshold, + FastPolling: n.FastPolling, + VerboseRoundTracking: n.VerboseRoundTracking, + RealtimeOnly: n.RealtimeOnly, + ReplayRequests: n.ReplayRequests, + } + return json.Marshal(&pDisk) +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (n *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *n = Params{ + TrackNetworkPeriod: pDisk.TrackNetworkPeriod, + MaxCheckedRounds: pDisk.MaxCheckedRounds, + RegNodesBufferLen: pDisk.RegNodesBufferLen, + NetworkHealthTimeout: pDisk.NetworkHealthTimeout, + ParallelNodeRegistrations: pDisk.ParallelNodeRegistrations, + KnownRoundsThreshold: pDisk.KnownRoundsThreshold, + FastPolling: pDisk.FastPolling, + VerboseRoundTracking: pDisk.VerboseRoundTracking, + RealtimeOnly: pDisk.RealtimeOnly, + ReplayRequests: pDisk.ReplayRequests, + } + + return nil +} + +func (n Params) SetRealtimeOnlyAll() Params { + n.RealtimeOnly = true + n.Pickup.RealtimeOnly = true + n.Message.RealtimeOnly = true + return n +} const DefaultDebugTag = "External" @@ -137,6 +195,16 @@ type CMIXParams struct { Critical bool } +// cMixParamsDisk will be the marshal-able and umarshal-able object. +type cMixParamsDisk struct { + RoundTries uint + Timeout time.Duration + RetryDelay time.Duration + SendTimeout time.Duration + DebugTag string + Critical bool +} + func GetDefaultCMIXParams() CMIXParams { return CMIXParams{ RoundTries: 10, @@ -150,6 +218,41 @@ func GetDefaultCMIXParams() CMIXParams { } } +// MarshalJSON adheres to the json.Marshaler interface. +func (r CMIXParams) MarshalJSON() ([]byte, error) { + pDisk := cMixParamsDisk{ + RoundTries: r.RoundTries, + Timeout: r.Timeout, + RetryDelay: r.RetryDelay, + SendTimeout: r.SendTimeout, + DebugTag: r.DebugTag, + Critical: r.Critical, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *CMIXParams) UnmarshalJSON(data []byte) error { + pDisk := cMixParamsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = CMIXParams{ + RoundTries: pDisk.RoundTries, + Timeout: pDisk.Timeout, + RetryDelay: pDisk.RetryDelay, + SendTimeout: pDisk.SendTimeout, + DebugTag: pDisk.DebugTag, + Critical: pDisk.Critical, + } + + return nil +} + // GetCMIXParameters obtains default CMIX parameters, or overrides with given // parameters if set. func GetCMIXParameters(params string) (CMIXParams, error) { @@ -163,6 +266,8 @@ func GetCMIXParameters(params string) (CMIXParams, error) { return p, nil } +type NodeMap map[id.ID]bool + // MarshalJSON adheres to the json.Marshaler interface. func (nm NodeMap) MarshalJSON() ([]byte, error) { stringMap := make(map[string]bool, len(nm)) diff --git a/cmix/pickup/params.go b/cmix/pickup/params.go index 95200674d..717f37212 100644 --- a/cmix/pickup/params.go +++ b/cmix/pickup/params.go @@ -1,7 +1,18 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +//////////////////////////////////////////////////////////////////////////////// + package pickup -import "time" +import ( + "encoding/json" + "time" +) +// Params contains the parameters for the pickup package. type Params struct { // Number of worker threads for retrieving messages from gateways NumMessageRetrievalWorkers uint @@ -31,6 +42,18 @@ type Params struct { ForceHistoricalRounds bool } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + NumMessageRetrievalWorkers uint + LookupRoundsBufferLen uint + MaxHistoricalRoundsRetries uint + UncheckRoundPeriod time.Duration + ForceMessagePickupRetry bool + SendTimeout time.Duration + RealtimeOnly bool + ForceHistoricalRounds bool +} + func GetDefaultParams() Params { return Params{ NumMessageRetrievalWorkers: 8, @@ -42,3 +65,55 @@ func GetDefaultParams() Params { RealtimeOnly: false, } } + +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + NumMessageRetrievalWorkers: r.NumMessageRetrievalWorkers, + LookupRoundsBufferLen: r.LookupRoundsBufferLen, + MaxHistoricalRoundsRetries: r.MaxHistoricalRoundsRetries, + UncheckRoundPeriod: r.UncheckRoundPeriod, + ForceMessagePickupRetry: r.ForceMessagePickupRetry, + SendTimeout: r.SendTimeout, + RealtimeOnly: r.RealtimeOnly, + ForceHistoricalRounds: r.ForceHistoricalRounds, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{ + NumMessageRetrievalWorkers: pDisk.NumMessageRetrievalWorkers, + LookupRoundsBufferLen: pDisk.LookupRoundsBufferLen, + MaxHistoricalRoundsRetries: pDisk.MaxHistoricalRoundsRetries, + UncheckRoundPeriod: pDisk.UncheckRoundPeriod, + ForceMessagePickupRetry: pDisk.ForceMessagePickupRetry, + SendTimeout: pDisk.SendTimeout, + RealtimeOnly: pDisk.RealtimeOnly, + ForceHistoricalRounds: pDisk.ForceHistoricalRounds, + } + + return nil +} diff --git a/cmix/rounds/params.go b/cmix/rounds/params.go index 1023f6022..dd9596c2f 100644 --- a/cmix/rounds/params.go +++ b/cmix/rounds/params.go @@ -1,7 +1,18 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +//////////////////////////////////////////////////////////////////////////////// + package rounds -import "time" +import ( + "encoding/json" + "time" +) +// Params contains the parameters for the rounds package. type Params struct { // MaxHistoricalRounds is the number of historical rounds required to // automatically send a historical rounds query. @@ -20,6 +31,15 @@ type Params struct { MaxHistoricalRoundsRetries uint } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + MaxHistoricalRounds uint + HistoricalRoundsPeriod time.Duration + HistoricalRoundsBufferLen uint + MaxHistoricalRoundsRetries uint +} + +// GetDefaultParams returns a default set of Params. func GetDefaultParams() Params { return Params{ MaxHistoricalRounds: 100, @@ -28,3 +48,47 @@ func GetDefaultParams() Params { MaxHistoricalRoundsRetries: 3, } } + +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + MaxHistoricalRounds: r.MaxHistoricalRounds, + HistoricalRoundsPeriod: r.HistoricalRoundsPeriod, + HistoricalRoundsBufferLen: r.HistoricalRoundsBufferLen, + MaxHistoricalRoundsRetries: r.MaxHistoricalRoundsRetries, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{ + MaxHistoricalRounds: pDisk.MaxHistoricalRounds, + HistoricalRoundsPeriod: pDisk.HistoricalRoundsPeriod, + HistoricalRoundsBufferLen: pDisk.HistoricalRoundsBufferLen, + MaxHistoricalRoundsRetries: pDisk.MaxHistoricalRoundsRetries, + } + + return nil +} diff --git a/connect/connect.go b/connect/connect.go index 1f0a6db74..d0c2c68e0 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -7,6 +7,7 @@ package connect import ( + "encoding/json" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/auth" @@ -69,7 +70,7 @@ type Callback func(connection Connection) type Params struct { Auth auth.Param Rekey rekey.Params - Event event.Reporter + Event event.Reporter `json:"-"` Timeout time.Duration } @@ -83,6 +84,19 @@ func GetDefaultParams() Params { } } +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + // Connect performs auth key negotiation with the given recipient, // and returns a Connection object for the newly-created partner.Manager // This function is to be used sender-side and will block until the diff --git a/e2e/params.go b/e2e/params.go index 23052727f..f98450a09 100644 --- a/e2e/params.go +++ b/e2e/params.go @@ -29,6 +29,16 @@ type Params struct { cmix.CMIXParams } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + ServiceTag string + LastServiceTag string + KeyGetRetryCount uint + KeyGeRetryDelay time.Duration + Rekey bool +} + +// GetDefaultParams returns a default set of Params. func GetDefaultParams() Params { return Params{ ServiceTag: catalog.Silent, @@ -41,12 +51,9 @@ func GetDefaultParams() Params { CMIXParams: cmix.GetDefaultCMIXParams(), } } -func (e Params) Marshal() ([]byte, error) { - return json.Marshal(e) -} -// GetParameters Obtain default E2E parameters, or override with -// given parameters if set +// GetParameters Obtain default Params, or override with +// given parameters if set. func GetParameters(params string) (Params, error) { p := GetDefaultParams() if len(params) > 0 { @@ -57,3 +64,36 @@ func GetParameters(params string) (Params, error) { } return p, nil } + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + ServiceTag: r.ServiceTag, + LastServiceTag: r.LastServiceTag, + KeyGetRetryCount: r.KeyGetRetryCount, + KeyGeRetryDelay: r.KeyGeRetryDelay, + Rekey: r.Rekey, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{ + ServiceTag: pDisk.ServiceTag, + LastServiceTag: pDisk.LastServiceTag, + KeyGetRetryCount: pDisk.KeyGetRetryCount, + KeyGeRetryDelay: pDisk.KeyGeRetryDelay, + Rekey: pDisk.Rekey, + } + + return nil +} diff --git a/e2e/ratchet/partner/session/params.go b/e2e/ratchet/partner/session/params.go index 8ccd45494..05de8567a 100644 --- a/e2e/ratchet/partner/session/params.go +++ b/e2e/ratchet/partner/session/params.go @@ -1,6 +1,9 @@ package session -import "fmt" +import ( + "encoding/json" + "fmt" +) type Params struct { // using the DH as a seed, both sides finalizeKeyNegotation a number @@ -31,6 +34,7 @@ const ( rekeyRatio float64 = 1 / 10 ) +// GetDefaultParams returns a default set of Params. func GetDefaultParams() Params { return Params{ MinKeys: minKeys, @@ -41,7 +45,38 @@ func GetDefaultParams() Params { } } -func (p Params) String() string { +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (s Params) MarshalJSON() ([]byte, error) { + return json.Marshal(s) +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (s *Params) UnmarshalJSON(data []byte) error { + p := GetDefaultParams() + err := json.Unmarshal(data, &p) + if err != nil { + return err + } + + *s = p + + return nil +} + +func (s Params) String() string { return fmt.Sprintf("SessionParams{ MinKeys: %d, MaxKeys: %d, NumRekeys: %d }", - p.MinKeys, p.MaxKeys, p.NumRekeys) + s.MinKeys, s.MaxKeys, s.NumRekeys) } diff --git a/e2e/rekey/params.go b/e2e/rekey/params.go index 0611e67e8..73f6b2333 100644 --- a/e2e/rekey/params.go +++ b/e2e/rekey/params.go @@ -1,6 +1,7 @@ package rekey import ( + "encoding/json" "gitlab.com/elixxir/client/catalog" "time" ) @@ -22,6 +23,36 @@ type Params struct { StoppableName string } +// GetParameters returns the default network parameters, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := GetDefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (c *Params) Marshal() ([]byte, error) { + return json.Marshal(c) +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (c *Params) UnmarshalJSON(data []byte) error { + p := GetDefaultParams() + err := json.Unmarshal(data, &p) + if err != nil { + return err + } + + *c = p + return nil +} + func GetDefaultParams() Params { return Params{ RoundTimeout: time.Minute, diff --git a/e2e/rekey/params_test.go b/e2e/rekey/params_test.go new file mode 100644 index 000000000..b1749f6de --- /dev/null +++ b/e2e/rekey/params_test.go @@ -0,0 +1 @@ +package rekey diff --git a/fileTransfer2/connect/params.go b/fileTransfer2/connect/params.go index 3b502637e..761716f37 100644 --- a/fileTransfer2/connect/params.go +++ b/fileTransfer2/connect/params.go @@ -7,6 +7,10 @@ package connect +import ( + "encoding/json" +) + const ( defaultNotifyUponCompletion = true ) @@ -18,9 +22,47 @@ type Params struct { NotifyUponCompletion bool } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + NotifyUponCompletion bool +} + // DefaultParams returns a Params object filled with the default values. func DefaultParams() Params { return Params{ NotifyUponCompletion: defaultNotifyUponCompletion, } } + +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := DefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{NotifyUponCompletion: r.NotifyUponCompletion} + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} + + return nil +} diff --git a/fileTransfer2/e2e/params.go b/fileTransfer2/e2e/params.go index 254e7d3a4..3ec766b58 100644 --- a/fileTransfer2/e2e/params.go +++ b/fileTransfer2/e2e/params.go @@ -7,6 +7,8 @@ package e2e +import "encoding/json" + const ( defaultNotifyUponCompletion = true ) @@ -18,9 +20,47 @@ type Params struct { NotifyUponCompletion bool } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + NotifyUponCompletion bool +} + // DefaultParams returns a Params object filled with the default values. func DefaultParams() Params { return Params{ NotifyUponCompletion: defaultNotifyUponCompletion, } } + +// GetParameters returns the default Params, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := DefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{NotifyUponCompletion: r.NotifyUponCompletion} + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} + + return nil +} diff --git a/fileTransfer2/params.go b/fileTransfer2/params.go index 3a71a6c5e..e671c2832 100644 --- a/fileTransfer2/params.go +++ b/fileTransfer2/params.go @@ -8,6 +8,7 @@ package fileTransfer2 import ( + "encoding/json" "gitlab.com/elixxir/client/cmix" "time" ) @@ -32,6 +33,12 @@ type Params struct { Cmix cmix.CMIXParams } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + MaxThroughput int + SendTimeout time.Duration +} + // DefaultParams returns a Params object filled with the default values. func DefaultParams() Params { return Params{ @@ -40,3 +47,43 @@ func DefaultParams() Params { Cmix: cmix.GetDefaultCMIXParams(), } } + +// GetParameters returns the default network parameters, or override with given +// parameters, if set. +func GetParameters(params string) (Params, error) { + p := DefaultParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return Params{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + MaxThroughput: r.MaxThroughput, + SendTimeout: r.SendTimeout, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = Params{ + MaxThroughput: pDisk.MaxThroughput, + SendTimeout: pDisk.SendTimeout, + } + + return nil +} diff --git a/single/params.go b/single/params.go index 10d60a908..0c33d548e 100644 --- a/single/params.go +++ b/single/params.go @@ -8,6 +8,7 @@ package single import ( + "encoding/json" "gitlab.com/elixxir/client/cmix" "time" ) @@ -32,6 +33,12 @@ type RequestParams struct { CmixParams cmix.CMIXParams } +// requestParamsDisk will be the marshal-able and umarshal-able object. +type requestParamsDisk struct { + Timeout time.Duration + MaxResponseMessages uint8 +} + // GetDefaultRequestParams returns a RequestParams with the default // configuration. func GetDefaultRequestParams() RequestParams { @@ -41,3 +48,43 @@ func GetDefaultRequestParams() RequestParams { CmixParams: cmix.GetDefaultCMIXParams(), } } + +// GetParameters returns the default network parameters, or override with given +// parameters, if set. +func GetParameters(params string) (RequestParams, error) { + p := GetDefaultRequestParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return RequestParams{}, err + } + } + return p, nil +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (r RequestParams) MarshalJSON() ([]byte, error) { + pDisk := requestParamsDisk{ + Timeout: r.Timeout, + MaxResponseMessages: r.MaxResponseMessages, + } + + return json.Marshal(&pDisk) + +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (r *RequestParams) UnmarshalJSON(data []byte) error { + pDisk := requestParamsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *r = RequestParams{ + Timeout: pDisk.Timeout, + MaxResponseMessages: pDisk.MaxResponseMessages, + } + + return nil +} -- GitLab