From 99ac4f81192e4e8d0518be80d1376a2de522a4e3 Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Wed, 25 May 2022 15:12:03 -0700 Subject: [PATCH] Finalize json.Marshaler/Unmarshaler adherence across Params objects --- api/params_test.go | 1 + auth/params.go | 70 +++++++++- auth/state.go | 6 +- auth/state_test.go | 2 +- cmix/gateway/hostPool.go | 35 ++--- .../receptionID/store/unknownRounds.go | 24 ++-- cmix/message/params.go | 16 +-- cmix/params.go | 120 ++++++++++-------- cmix/pickup/params.go | 22 ++-- connect/connect.go | 2 +- e2e/params.go | 19 +-- e2e/ratchet/partner/session/params.go | 60 ++++++--- e2e/rekey/params.go | 82 ++++++++---- fileTransfer2/connect/params.go | 8 +- fileTransfer2/e2e/params.go | 8 +- fileTransfer2/params.go | 13 +- single/params.go | 13 +- 17 files changed, 321 insertions(+), 180 deletions(-) create mode 100644 api/params_test.go diff --git a/api/params_test.go b/api/params_test.go new file mode 100644 index 000000000..778f64ec1 --- /dev/null +++ b/api/params_test.go @@ -0,0 +1 @@ +package api diff --git a/auth/params.go b/auth/params.go index 92cb6e57d..946f4ea05 100644 --- a/auth/params.go +++ b/auth/params.go @@ -1,8 +1,12 @@ package auth -import "gitlab.com/elixxir/client/catalog" +import ( + "encoding/json" + "gitlab.com/elixxir/client/catalog" +) -type Param struct { +// Params is are the parameters for the auth package. +type Params struct { ReplayRequests bool RequestTag string @@ -11,8 +15,22 @@ type Param struct { ResetConfirmTag string } -func GetDefaultParams() Param { - return Param{ +// GetParameters Obtain 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 +} + +// GetDefaultParams returns a default set of Params. +func GetDefaultParams() Params { + return Params{ ReplayRequests: false, RequestTag: catalog.Request, ConfirmTag: catalog.Confirm, @@ -21,7 +39,7 @@ func GetDefaultParams() Param { } } -func GetDefaultTemporaryParams() Param { +func GetDefaultTemporaryParams() Params { p := GetDefaultParams() p.RequestTag = catalog.RequestEphemeral p.ConfirmTag = catalog.ConfirmEphemeral @@ -30,7 +48,47 @@ func GetDefaultTemporaryParams() Param { return p } -func (p Param) getConfirmTag(reset bool) string { +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + ReplayRequests bool + RequestTag string + ConfirmTag string + ResetRequestTag string + ResetConfirmTag string +} + +// MarshalJSON adheres to the json.Marshaler interface. +func (p Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + ReplayRequests: p.ReplayRequests, + RequestTag: p.ResetRequestTag, + ConfirmTag: p.ConfirmTag, + ResetRequestTag: p.RequestTag, + ResetConfirmTag: p.ResetConfirmTag, + } + return json.Marshal(&pDisk) +} + +// UnmarshalJSON adheres to the json.Unmarshaler interface. +func (p *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) + if err != nil { + return err + } + + *p = Params{ + ReplayRequests: pDisk.ReplayRequests, + RequestTag: pDisk.ResetRequestTag, + ConfirmTag: pDisk.ConfirmTag, + ResetRequestTag: pDisk.RequestTag, + ResetConfirmTag: pDisk.ResetConfirmTag, + } + + return nil +} + +func (p Params) getConfirmTag(reset bool) string { if reset { return p.ResetConfirmTag } else { diff --git a/auth/state.go b/auth/state.go index 2be3d4d6b..859b4015e 100644 --- a/auth/state.go +++ b/auth/state.go @@ -41,7 +41,7 @@ type state struct { store *store.Store event event.Reporter - params Param + params Params backupTrigger func(reason string) } @@ -101,7 +101,7 @@ type Callbacks interface { // with a memory only versioned.KV) as well as a memory only versioned.KV for // NewState and use GetDefaultTemporaryParams() for the parameters func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, - rng *fastRNG.StreamGenerator, event event.Reporter, params Param, + rng *fastRNG.StreamGenerator, event event.Reporter, params Params, callbacks Callbacks, backupTrigger func(reason string)) (State, error) { kv = kv.Prefix(makeStorePrefix(e2e.GetReceptionID())) return NewStateLegacy( @@ -114,7 +114,7 @@ func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, // Does not modify the kv prefix for backwards compatibility // Otherwise, acts the same as NewState func NewStateLegacy(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, - rng *fastRNG.StreamGenerator, event event.Reporter, params Param, + rng *fastRNG.StreamGenerator, event event.Reporter, params Params, callbacks Callbacks, backupTrigger func(reason string)) (State, error) { s := &state{ diff --git a/auth/state_test.go b/auth/state_test.go index 211e3d654..d52c5ca9c 100644 --- a/auth/state_test.go +++ b/auth/state_test.go @@ -141,7 +141,7 @@ func TestManager_ReplayRequests(t *testing.T) { rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG), store: s, event: &mockEventManager{}, - params: Param{ + params: Params{ ReplayRequests: true, }, } diff --git a/cmix/gateway/hostPool.go b/cmix/gateway/hostPool.go index ebc8ede74..09f52d5bd 100644 --- a/cmix/gateway/hostPool.go +++ b/cmix/gateway/hostPool.go @@ -109,6 +109,8 @@ type PoolParams struct { ForceConnection bool // HostParams is the parameters for the creation of new Host objects. + //fixme params: have this adhere to json.Marshaler. + // This will allow the PoolParams object to have full adherence. HostParams connect.HostParams `json:"-"` } @@ -156,32 +158,35 @@ func GetParameters(params string) (PoolParams, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (f PoolParams) MarshalJSON() ([]byte, error) { +func (pp PoolParams) MarshalJSON() ([]byte, error) { ppd := poolParamsDisk{ - MaxPoolSize: f.MaxPoolSize, - PoolSize: f.PoolSize, - ProxyAttempts: f.ProxyAttempts, - MaxPings: f.MaxPings, - ForceConnection: f.ForceConnection, + MaxPoolSize: pp.MaxPoolSize, + PoolSize: pp.PoolSize, + ProxyAttempts: pp.ProxyAttempts, + MaxPings: pp.MaxPings, + ForceConnection: pp.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) +func (pp *PoolParams) UnmarshalJSON(data []byte) error { + ppDisk := poolParamsDisk{} + err := json.Unmarshal(data, &ppDisk) if err != nil { return err } - *f = PoolParams{ - MaxPoolSize: ppd.MaxPoolSize, - PoolSize: ppd.PoolSize, - ProxyAttempts: ppd.ProxyAttempts, - MaxPings: ppd.MaxPings, - ForceConnection: ppd.ForceConnection, + *pp = PoolParams{ + MaxPoolSize: ppDisk.MaxPoolSize, + PoolSize: ppDisk.PoolSize, + ProxyAttempts: ppDisk.ProxyAttempts, + MaxPings: ppDisk.MaxPings, + ForceConnection: ppDisk.ForceConnection, + // Since this does not adhere to json.Marshaler yet, + // file it in manually assuming default values + HostParams: connect.GetDefaultHostParams(), } return nil diff --git a/cmix/identity/receptionID/store/unknownRounds.go b/cmix/identity/receptionID/store/unknownRounds.go index 77816f555..b14c939ab 100644 --- a/cmix/identity/receptionID/store/unknownRounds.go +++ b/cmix/identity/receptionID/store/unknownRounds.go @@ -61,15 +61,25 @@ func GetParameters(params string) (UnknownRoundsParams, error) { return p, nil } +// MarshalJSON adheres to the json.Marshaler interface. +func (urp UnknownRoundsParams) MarshalJSON() ([]byte, error) { + urpDisk := unknownRoundsParamsDisk{ + MaxChecks: urp.MaxChecks, + Stored: urp.Stored, + } + + return json.Marshal(&urpDisk) +} + // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (f *UnknownRoundsParams) UnmarshalJSON(data []byte) error { +func (urp *UnknownRoundsParams) UnmarshalJSON(data []byte) error { urpDisk := unknownRoundsParamsDisk{} err := json.Unmarshal(data, &urpDisk) if err != nil { return err } - *f = UnknownRoundsParams{ + *urp = UnknownRoundsParams{ MaxChecks: urpDisk.MaxChecks, Stored: urpDisk.Stored, } @@ -77,16 +87,6 @@ func (f *UnknownRoundsParams) UnmarshalJSON(data []byte) error { 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 { diff --git a/cmix/message/params.go b/cmix/message/params.go index c717a19cf..cd2e6675b 100644 --- a/cmix/message/params.go +++ b/cmix/message/params.go @@ -56,13 +56,13 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r Params) MarshalJSON() ([]byte, error) { +func (p Params) MarshalJSON() ([]byte, error) { pDisk := paramsDisk{ - MessageReceptionBuffLen: r.MessageReceptionBuffLen, - MessageReceptionWorkerPoolSize: r.MessageReceptionWorkerPoolSize, - MaxChecksInProcessMessage: r.MaxChecksInProcessMessage, - InProcessMessageWait: r.InProcessMessageWait, - RealtimeOnly: r.RealtimeOnly, + MessageReceptionBuffLen: p.MessageReceptionBuffLen, + MessageReceptionWorkerPoolSize: p.MessageReceptionWorkerPoolSize, + MaxChecksInProcessMessage: p.MaxChecksInProcessMessage, + InProcessMessageWait: p.InProcessMessageWait, + RealtimeOnly: p.RealtimeOnly, } return json.Marshal(&pDisk) @@ -70,14 +70,14 @@ func (r Params) MarshalJSON() ([]byte, error) { } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = Params{ + *p = Params{ MessageReceptionBuffLen: pDisk.MessageReceptionBuffLen, MessageReceptionWorkerPoolSize: pDisk.MessageReceptionWorkerPoolSize, MaxChecksInProcessMessage: pDisk.MaxChecksInProcessMessage, diff --git a/cmix/params.go b/cmix/params.go index 4f8b8bb7a..23f8d7d6a 100644 --- a/cmix/params.go +++ b/cmix/params.go @@ -76,6 +76,10 @@ type paramsDisk struct { VerboseRoundTracking bool RealtimeOnly bool ReplayRequests bool + Rounds rounds.Params + Pickup pickup.Params + Message message.Params + Historical rounds.Params } // GetDefaultParams returns a Params object containing the @@ -115,31 +119,36 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (n Params) MarshalJSON() ([]byte, error) { +func (p 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, + TrackNetworkPeriod: p.TrackNetworkPeriod, + MaxCheckedRounds: p.MaxCheckedRounds, + RegNodesBufferLen: p.RegNodesBufferLen, + NetworkHealthTimeout: p.NetworkHealthTimeout, + ParallelNodeRegistrations: p.ParallelNodeRegistrations, + KnownRoundsThreshold: p.KnownRoundsThreshold, + FastPolling: p.FastPolling, + VerboseRoundTracking: p.VerboseRoundTracking, + RealtimeOnly: p.RealtimeOnly, + ReplayRequests: p.ReplayRequests, + Rounds: p.Rounds, + Pickup: p.Pickup, + Message: p.Message, + Historical: p.Historical, } + return json.Marshal(&pDisk) } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (n *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *n = Params{ + *p = Params{ TrackNetworkPeriod: pDisk.TrackNetworkPeriod, MaxCheckedRounds: pDisk.MaxCheckedRounds, RegNodesBufferLen: pDisk.RegNodesBufferLen, @@ -150,16 +159,20 @@ func (n *Params) UnmarshalJSON(data []byte) error { VerboseRoundTracking: pDisk.VerboseRoundTracking, RealtimeOnly: pDisk.RealtimeOnly, ReplayRequests: pDisk.ReplayRequests, + Rounds: pDisk.Rounds, + Pickup: pDisk.Pickup, + Message: pDisk.Message, + Historical: pDisk.Historical, } return nil } -func (n Params) SetRealtimeOnlyAll() Params { - n.RealtimeOnly = true - n.Pickup.RealtimeOnly = true - n.Message.RealtimeOnly = true - return n +func (p Params) SetRealtimeOnlyAll() Params { + p.RealtimeOnly = true + p.Pickup.RealtimeOnly = true + p.Message.RealtimeOnly = true + return p } const DefaultDebugTag = "External" @@ -197,12 +210,13 @@ type CMIXParams struct { // 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 + RoundTries uint + Timeout time.Duration + RetryDelay time.Duration + SendTimeout time.Duration + DebugTag string + BlacklistedNodes NodeMap + Critical bool } func GetDefaultCMIXParams() CMIXParams { @@ -218,15 +232,29 @@ func GetDefaultCMIXParams() CMIXParams { } } +// GetCMIXParameters obtains default CMIX parameters, or overrides with given +// parameters if set. +func GetCMIXParameters(params string) (CMIXParams, error) { + p := GetDefaultCMIXParams() + if len(params) > 0 { + err := json.Unmarshal([]byte(params), &p) + if err != nil { + return CMIXParams{}, err + } + } + return p, nil +} + // MarshalJSON adheres to the json.Marshaler interface. -func (r CMIXParams) MarshalJSON() ([]byte, error) { +func (p CMIXParams) MarshalJSON() ([]byte, error) { pDisk := cMixParamsDisk{ - RoundTries: r.RoundTries, - Timeout: r.Timeout, - RetryDelay: r.RetryDelay, - SendTimeout: r.SendTimeout, - DebugTag: r.DebugTag, - Critical: r.Critical, + RoundTries: p.RoundTries, + Timeout: p.Timeout, + RetryDelay: p.RetryDelay, + SendTimeout: p.SendTimeout, + DebugTag: p.DebugTag, + Critical: p.Critical, + BlacklistedNodes: p.BlacklistedNodes, } return json.Marshal(&pDisk) @@ -234,38 +262,26 @@ func (r CMIXParams) MarshalJSON() ([]byte, error) { } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *CMIXParams) UnmarshalJSON(data []byte) error { +func (p *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, + *p = CMIXParams{ + RoundTries: pDisk.RoundTries, + Timeout: pDisk.Timeout, + RetryDelay: pDisk.RetryDelay, + SendTimeout: pDisk.SendTimeout, + DebugTag: pDisk.DebugTag, + Critical: pDisk.Critical, + BlacklistedNodes: pDisk.BlacklistedNodes, } return nil } -// GetCMIXParameters obtains default CMIX parameters, or overrides with given -// parameters if set. -func GetCMIXParameters(params string) (CMIXParams, error) { - p := GetDefaultCMIXParams() - if len(params) > 0 { - err := json.Unmarshal([]byte(params), &p) - if err != nil { - return CMIXParams{}, err - } - } - return p, nil -} - type NodeMap map[id.ID]bool // MarshalJSON adheres to the json.Marshaler interface. diff --git a/cmix/pickup/params.go b/cmix/pickup/params.go index 717f37212..9edf0f029 100644 --- a/cmix/pickup/params.go +++ b/cmix/pickup/params.go @@ -80,16 +80,16 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r Params) MarshalJSON() ([]byte, error) { +func (p 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, + NumMessageRetrievalWorkers: p.NumMessageRetrievalWorkers, + LookupRoundsBufferLen: p.LookupRoundsBufferLen, + MaxHistoricalRoundsRetries: p.MaxHistoricalRoundsRetries, + UncheckRoundPeriod: p.UncheckRoundPeriod, + ForceMessagePickupRetry: p.ForceMessagePickupRetry, + SendTimeout: p.SendTimeout, + RealtimeOnly: p.RealtimeOnly, + ForceHistoricalRounds: p.ForceHistoricalRounds, } return json.Marshal(&pDisk) @@ -97,14 +97,14 @@ func (r Params) MarshalJSON() ([]byte, error) { } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = Params{ + *p = Params{ NumMessageRetrievalWorkers: pDisk.NumMessageRetrievalWorkers, LookupRoundsBufferLen: pDisk.LookupRoundsBufferLen, MaxHistoricalRoundsRetries: pDisk.MaxHistoricalRoundsRetries, diff --git a/connect/connect.go b/connect/connect.go index e2099a20a..310ef304a 100644 --- a/connect/connect.go +++ b/connect/connect.go @@ -85,7 +85,7 @@ type Callback func(connection Connection) // Params for managing Connection objects. type Params struct { - Auth auth.Param + Auth auth.Params Rekey rekey.Params Event event.Reporter `json:"-"` Timeout time.Duration diff --git a/e2e/params.go b/e2e/params.go index f98450a09..2702d4906 100644 --- a/e2e/params.go +++ b/e2e/params.go @@ -36,6 +36,7 @@ type paramsDisk struct { KeyGetRetryCount uint KeyGeRetryDelay time.Duration Rekey bool + cmix.CMIXParams } // GetDefaultParams returns a default set of Params. @@ -66,13 +67,14 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r Params) MarshalJSON() ([]byte, error) { +func (p Params) MarshalJSON() ([]byte, error) { pDisk := paramsDisk{ - ServiceTag: r.ServiceTag, - LastServiceTag: r.LastServiceTag, - KeyGetRetryCount: r.KeyGetRetryCount, - KeyGeRetryDelay: r.KeyGeRetryDelay, - Rekey: r.Rekey, + ServiceTag: p.ServiceTag, + LastServiceTag: p.LastServiceTag, + KeyGetRetryCount: p.KeyGetRetryCount, + KeyGeRetryDelay: p.KeyGeRetryDelay, + Rekey: p.Rekey, + CMIXParams: p.CMIXParams, } return json.Marshal(&pDisk) @@ -80,19 +82,20 @@ func (r Params) MarshalJSON() ([]byte, error) { } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = Params{ + *p = Params{ ServiceTag: pDisk.ServiceTag, LastServiceTag: pDisk.LastServiceTag, KeyGetRetryCount: pDisk.KeyGetRetryCount, KeyGeRetryDelay: pDisk.KeyGeRetryDelay, Rekey: pDisk.Rekey, + CMIXParams: pDisk.CMIXParams, } return nil diff --git a/e2e/ratchet/partner/session/params.go b/e2e/ratchet/partner/session/params.go index 05de8567a..2782578e9 100644 --- a/e2e/ratchet/partner/session/params.go +++ b/e2e/ratchet/partner/session/params.go @@ -5,6 +5,17 @@ import ( "fmt" ) +// DEFAULT KEY GENERATION PARAMETERS +// Hardcoded limits for keys +// sets the number of keys very high, but with a low rekey threshold. In this case, if the other party is online, you will read +const ( + minKeys uint16 = 1000 + maxKeys uint16 = 2000 + rekeyThrshold float64 = 0.05 + numReKeys uint16 = 16 + rekeyRatio float64 = 1 / 10 +) + type Params struct { // using the DH as a seed, both sides finalizeKeyNegotation a number // of keys to use before they must rekey because @@ -23,16 +34,14 @@ type Params struct { UnconfirmedRetryRatio float64 } -// DEFAULT KEY GENERATION PARAMETERS -// Hardcoded limits for keys -// sets the number of keys very high, but with a low rekey threshold. In this case, if the other party is online, you will read -const ( - minKeys uint16 = 1000 - maxKeys uint16 = 2000 - rekeyThrshold float64 = 0.05 - numReKeys uint16 = 16 - rekeyRatio float64 = 1 / 10 -) +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + MinKeys uint16 + MaxKeys uint16 + RekeyThreshold float64 + NumRekeys uint16 + UnconfirmedRetryRatio float64 +} // GetDefaultParams returns a default set of Params. func GetDefaultParams() Params { @@ -59,24 +68,37 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (s Params) MarshalJSON() ([]byte, error) { - return json.Marshal(s) +func (p Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + MinKeys: p.MinKeys, + MaxKeys: p.MaxKeys, + RekeyThreshold: p.RekeyThreshold, + NumRekeys: p.NumRekeys, + UnconfirmedRetryRatio: p.UnconfirmedRetryRatio, + } + return json.Marshal(&pDisk) + } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (s *Params) UnmarshalJSON(data []byte) error { - p := GetDefaultParams() - err := json.Unmarshal(data, &p) +func (p *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *s = p - + *p = Params{ + MinKeys: pDisk.MinKeys, + MaxKeys: pDisk.MaxKeys, + RekeyThreshold: pDisk.RekeyThreshold, + NumRekeys: pDisk.NumRekeys, + UnconfirmedRetryRatio: pDisk.UnconfirmedRetryRatio, + } return nil } -func (s Params) String() string { +func (p Params) String() string { return fmt.Sprintf("SessionParams{ MinKeys: %d, MaxKeys: %d, NumRekeys: %d }", - s.MinKeys, s.MaxKeys, s.NumRekeys) + p.MinKeys, p.MaxKeys, p.NumRekeys) } diff --git a/e2e/rekey/params.go b/e2e/rekey/params.go index 73f6b2333..274770c11 100644 --- a/e2e/rekey/params.go +++ b/e2e/rekey/params.go @@ -23,6 +23,40 @@ type Params struct { StoppableName string } +// paramsDisk will be the marshal-able and umarshal-able object. +type paramsDisk struct { + RoundTimeout time.Duration + TriggerName string + Trigger catalog.MessageType + ConfirmName string + Confirm catalog.MessageType + StoppableName string +} + +// GetDefaultParams returns a default set of Params. +func GetDefaultParams() Params { + return Params{ + RoundTimeout: time.Minute, + TriggerName: keyExchangeTriggerName, + Trigger: catalog.KeyExchangeTrigger, + ConfirmName: keyExchangeConfirmName, + Confirm: catalog.KeyExchangeConfirm, + StoppableName: keyExchangeMulti, + } +} + +// GetDefaultEphemeralParams returns a default set of Params for +// ephemeral re-keying. +func GetDefaultEphemeralParams() Params { + p := GetDefaultParams() + p.TriggerName = keyExchangeTriggerEphemeralName + p.Trigger = catalog.KeyExchangeTriggerEphemeral + p.ConfirmName = keyExchangeConfirmEphemeralName + p.Confirm = catalog.KeyExchangeConfirmEphemeral + p.StoppableName = keyExchangeEphemeralMulti + return p +} + // GetParameters returns the default network parameters, or override with given // parameters, if set. func GetParameters(params string) (Params, error) { @@ -37,39 +71,35 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (c *Params) Marshal() ([]byte, error) { - return json.Marshal(c) +func (p Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{ + RoundTimeout: p.RoundTimeout, + TriggerName: p.TriggerName, + Trigger: p.Trigger, + ConfirmName: p.ConfirmName, + Confirm: p.Confirm, + StoppableName: p.StoppableName, + } + return json.Marshal(&pDisk) + } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (c *Params) UnmarshalJSON(data []byte) error { - p := GetDefaultParams() - err := json.Unmarshal(data, &p) +func (p *Params) UnmarshalJSON(data []byte) error { + pDisk := paramsDisk{} + err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *c = p - return nil -} - -func GetDefaultParams() Params { - return Params{ - RoundTimeout: time.Minute, - TriggerName: keyExchangeTriggerName, - Trigger: catalog.KeyExchangeTrigger, - ConfirmName: keyExchangeConfirmName, - Confirm: catalog.KeyExchangeConfirm, - StoppableName: keyExchangeMulti, + *p = Params{ + RoundTimeout: pDisk.RoundTimeout, + TriggerName: pDisk.TriggerName, + Trigger: pDisk.Trigger, + ConfirmName: pDisk.ConfirmName, + Confirm: pDisk.Confirm, + StoppableName: pDisk.StoppableName, } -} -func GetDefaultEphemeralParams() Params { - p := GetDefaultParams() - p.TriggerName = keyExchangeTriggerEphemeralName - p.Trigger = catalog.KeyExchangeTriggerEphemeral - p.ConfirmName = keyExchangeConfirmEphemeralName - p.Confirm = catalog.KeyExchangeConfirmEphemeral - p.StoppableName = keyExchangeEphemeralMulti - return p + return nil } diff --git a/fileTransfer2/connect/params.go b/fileTransfer2/connect/params.go index 761716f37..93a3a44a1 100644 --- a/fileTransfer2/connect/params.go +++ b/fileTransfer2/connect/params.go @@ -48,21 +48,21 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r Params) MarshalJSON() ([]byte, error) { - pDisk := paramsDisk{NotifyUponCompletion: r.NotifyUponCompletion} +func (p Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{NotifyUponCompletion: p.NotifyUponCompletion} return json.Marshal(&pDisk) } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} + *p = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} return nil } diff --git a/fileTransfer2/e2e/params.go b/fileTransfer2/e2e/params.go index 3ec766b58..819e963f5 100644 --- a/fileTransfer2/e2e/params.go +++ b/fileTransfer2/e2e/params.go @@ -46,21 +46,21 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r Params) MarshalJSON() ([]byte, error) { - pDisk := paramsDisk{NotifyUponCompletion: r.NotifyUponCompletion} +func (p Params) MarshalJSON() ([]byte, error) { + pDisk := paramsDisk{NotifyUponCompletion: p.NotifyUponCompletion} return json.Marshal(&pDisk) } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} + *p = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} return nil } diff --git a/fileTransfer2/params.go b/fileTransfer2/params.go index e671c2832..bc6ce38f5 100644 --- a/fileTransfer2/params.go +++ b/fileTransfer2/params.go @@ -37,6 +37,7 @@ type Params struct { type paramsDisk struct { MaxThroughput int SendTimeout time.Duration + Cmix cmix.CMIXParams } // DefaultParams returns a Params object filled with the default values. @@ -62,10 +63,11 @@ func GetParameters(params string) (Params, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r Params) MarshalJSON() ([]byte, error) { +func (p Params) MarshalJSON() ([]byte, error) { pDisk := paramsDisk{ - MaxThroughput: r.MaxThroughput, - SendTimeout: r.SendTimeout, + MaxThroughput: p.MaxThroughput, + SendTimeout: p.SendTimeout, + Cmix: p.Cmix, } return json.Marshal(&pDisk) @@ -73,16 +75,17 @@ func (r Params) MarshalJSON() ([]byte, error) { } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *Params) UnmarshalJSON(data []byte) error { +func (p *Params) UnmarshalJSON(data []byte) error { pDisk := paramsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = Params{ + *p = Params{ MaxThroughput: pDisk.MaxThroughput, SendTimeout: pDisk.SendTimeout, + Cmix: pDisk.Cmix, } return nil diff --git a/single/params.go b/single/params.go index 0c33d548e..889581844 100644 --- a/single/params.go +++ b/single/params.go @@ -37,6 +37,7 @@ type RequestParams struct { type requestParamsDisk struct { Timeout time.Duration MaxResponseMessages uint8 + CmixParams cmix.CMIXParams } // GetDefaultRequestParams returns a RequestParams with the default @@ -63,10 +64,11 @@ func GetParameters(params string) (RequestParams, error) { } // MarshalJSON adheres to the json.Marshaler interface. -func (r RequestParams) MarshalJSON() ([]byte, error) { +func (rp RequestParams) MarshalJSON() ([]byte, error) { pDisk := requestParamsDisk{ - Timeout: r.Timeout, - MaxResponseMessages: r.MaxResponseMessages, + Timeout: rp.Timeout, + MaxResponseMessages: rp.MaxResponseMessages, + CmixParams: rp.CmixParams, } return json.Marshal(&pDisk) @@ -74,16 +76,17 @@ func (r RequestParams) MarshalJSON() ([]byte, error) { } // UnmarshalJSON adheres to the json.Unmarshaler interface. -func (r *RequestParams) UnmarshalJSON(data []byte) error { +func (rp *RequestParams) UnmarshalJSON(data []byte) error { pDisk := requestParamsDisk{} err := json.Unmarshal(data, &pDisk) if err != nil { return err } - *r = RequestParams{ + *rp = RequestParams{ Timeout: pDisk.Timeout, MaxResponseMessages: pDisk.MaxResponseMessages, + CmixParams: pDisk.CmixParams, } return nil -- GitLab