Skip to content
Snippets Groups Projects
Commit 99ac4f81 authored by Josh Brooks's avatar Josh Brooks
Browse files

Finalize json.Marshaler/Unmarshaler adherence across Params objects

parent 431bccbc
Branches
Tags
4 merge requests!510Release,!227Have all Params objects adhere to json.Marshaler/Unmarshaler,!226WIP: Api2.0,!207WIP: Client Restructure
package api
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 {
......
......@@ -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{
......
......@@ -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,
},
}
......
......@@ -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
......
......@@ -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 {
......
......@@ -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,
......
......@@ -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"
......@@ -202,6 +215,7 @@ type cMixParamsDisk struct {
RetryDelay time.Duration
SendTimeout time.Duration
DebugTag string
BlacklistedNodes NodeMap
Critical bool
}
......@@ -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{
*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.
......
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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)
}
......@@ -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
}
......@@ -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
}
......@@ -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
}
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment