diff --git a/api/params.go b/api/params.go index 6430eb60c5860be420c11b0715da0c960ddbc5e5..39f9d8db3768ac00c454bf89d2ba8b5326c9fb4e 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 25dc7192ed9933dcf323190a526c772a1548e8a3..ebc8ede746c92f8c6536593d0eb939868ea3a87f 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 022fd252dba2d7dbaaec14a072e5dbac6623ff25..77816f5559d2008d8d0b8fe6cff6c1266c1649a8 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 9a3a56cd599860416ebe2951048c2c5ac7767987..c717a19cff304d4f9de7c69dbe532bc8ded64946 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 d823632e199e021606a3414bc2403babcc3d17b9..4f8b8bb7a86636e1e929d8a0300ecb4df6aadfcd 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 95200674d0e0e8a791a0236e1a5dc019b4b59225..717f3721281501c2415bc073061a9316443a80dc 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 1023f6022acce31a971747c5f31bfebdec724c03..dd9596c2fcf6809010ceb9fbeda609f2ef3b6645 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 1f0a6db7449f9c3fac9db297114997bce803fdd1..d0c2c68e0240f0779365d5d731cb688e05811588 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 23052727ffcc103f62e14c5d41fad2fbcabfe244..f98450a0989da42e489f576fab0f1b3c08cf6d04 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 8ccd454947ff281471cd77d79fa15ea826efec9d..05de8567a0592175b6c40eeb009ed8c6e2a085bf 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 0611e67e84b4875bae35f29855fbddc0e007fe83..73f6b23335a9e4c623ff6d0b766f3940b3d4333f 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 0000000000000000000000000000000000000000..b1749f6de2935ce044dcee8b5afdd55b385f8221 --- /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 3b502637e895a852b8ab11c0118d0806659c073a..761716f37c2eb18c320ce8c1d24a0885d955b4bd 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 254e7d3a40777ec48c8ad33c89b95ccacaf5d2d9..3ec766b580573c1bd42afb9f708fcf3213649a74 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 3a71a6c5edd082a0debfa8041e214004ba160099..e671c283288ec7d2edd7b24f64fc9057c01630c1 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 10d60a908022f6d7c0e4857133a8e7a7b8444306..0c33d548ec18072363e9fa4579f15386741a4e4c 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 +}