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
No related branches found
No related tags found
4 merge requests!510Release,!227Have all Params objects adhere to json.Marshaler/Unmarshaler,!226WIP: Api2.0,!207WIP: Client Restructure
package api
package auth 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 ReplayRequests bool
RequestTag string RequestTag string
...@@ -11,8 +15,22 @@ type Param struct { ...@@ -11,8 +15,22 @@ type Param struct {
ResetConfirmTag string ResetConfirmTag string
} }
func GetDefaultParams() Param { // GetParameters Obtain default Params, or override with
return Param{ // 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, ReplayRequests: false,
RequestTag: catalog.Request, RequestTag: catalog.Request,
ConfirmTag: catalog.Confirm, ConfirmTag: catalog.Confirm,
...@@ -21,7 +39,7 @@ func GetDefaultParams() Param { ...@@ -21,7 +39,7 @@ func GetDefaultParams() Param {
} }
} }
func GetDefaultTemporaryParams() Param { func GetDefaultTemporaryParams() Params {
p := GetDefaultParams() p := GetDefaultParams()
p.RequestTag = catalog.RequestEphemeral p.RequestTag = catalog.RequestEphemeral
p.ConfirmTag = catalog.ConfirmEphemeral p.ConfirmTag = catalog.ConfirmEphemeral
...@@ -30,7 +48,47 @@ func GetDefaultTemporaryParams() Param { ...@@ -30,7 +48,47 @@ func GetDefaultTemporaryParams() Param {
return p 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 { if reset {
return p.ResetConfirmTag return p.ResetConfirmTag
} else { } else {
......
...@@ -41,7 +41,7 @@ type state struct { ...@@ -41,7 +41,7 @@ type state struct {
store *store.Store store *store.Store
event event.Reporter event event.Reporter
params Param params Params
backupTrigger func(reason string) backupTrigger func(reason string)
} }
...@@ -101,7 +101,7 @@ type Callbacks interface { ...@@ -101,7 +101,7 @@ type Callbacks interface {
// with a memory only versioned.KV) as well as a memory only versioned.KV for // with a memory only versioned.KV) as well as a memory only versioned.KV for
// NewState and use GetDefaultTemporaryParams() for the parameters // NewState and use GetDefaultTemporaryParams() for the parameters
func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, 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) { callbacks Callbacks, backupTrigger func(reason string)) (State, error) {
kv = kv.Prefix(makeStorePrefix(e2e.GetReceptionID())) kv = kv.Prefix(makeStorePrefix(e2e.GetReceptionID()))
return NewStateLegacy( return NewStateLegacy(
...@@ -114,7 +114,7 @@ func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, ...@@ -114,7 +114,7 @@ func NewState(kv *versioned.KV, net cmix.Client, e2e e2e.Handler,
// Does not modify the kv prefix for backwards compatibility // Does not modify the kv prefix for backwards compatibility
// Otherwise, acts the same as NewState // Otherwise, acts the same as NewState
func NewStateLegacy(kv *versioned.KV, net cmix.Client, e2e e2e.Handler, 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) { callbacks Callbacks, backupTrigger func(reason string)) (State, error) {
s := &state{ s := &state{
......
...@@ -141,7 +141,7 @@ func TestManager_ReplayRequests(t *testing.T) { ...@@ -141,7 +141,7 @@ func TestManager_ReplayRequests(t *testing.T) {
rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG), rng: fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG),
store: s, store: s,
event: &mockEventManager{}, event: &mockEventManager{},
params: Param{ params: Params{
ReplayRequests: true, ReplayRequests: true,
}, },
} }
......
...@@ -109,6 +109,8 @@ type PoolParams struct { ...@@ -109,6 +109,8 @@ type PoolParams struct {
ForceConnection bool ForceConnection bool
// HostParams is the parameters for the creation of new Host objects. // 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:"-"` HostParams connect.HostParams `json:"-"`
} }
...@@ -156,32 +158,35 @@ func GetParameters(params string) (PoolParams, error) { ...@@ -156,32 +158,35 @@ func GetParameters(params string) (PoolParams, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (f PoolParams) MarshalJSON() ([]byte, error) { func (pp PoolParams) MarshalJSON() ([]byte, error) {
ppd := poolParamsDisk{ ppd := poolParamsDisk{
MaxPoolSize: f.MaxPoolSize, MaxPoolSize: pp.MaxPoolSize,
PoolSize: f.PoolSize, PoolSize: pp.PoolSize,
ProxyAttempts: f.ProxyAttempts, ProxyAttempts: pp.ProxyAttempts,
MaxPings: f.MaxPings, MaxPings: pp.MaxPings,
ForceConnection: f.ForceConnection, ForceConnection: pp.ForceConnection,
} }
return json.Marshal(&ppd) return json.Marshal(&ppd)
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (f *PoolParams) UnmarshalJSON(data []byte) error { func (pp *PoolParams) UnmarshalJSON(data []byte) error {
ppd := poolParamsDisk{} ppDisk := poolParamsDisk{}
err := json.Unmarshal(data, &ppd) err := json.Unmarshal(data, &ppDisk)
if err != nil { if err != nil {
return err return err
} }
*f = PoolParams{ *pp = PoolParams{
MaxPoolSize: ppd.MaxPoolSize, MaxPoolSize: ppDisk.MaxPoolSize,
PoolSize: ppd.PoolSize, PoolSize: ppDisk.PoolSize,
ProxyAttempts: ppd.ProxyAttempts, ProxyAttempts: ppDisk.ProxyAttempts,
MaxPings: ppd.MaxPings, MaxPings: ppDisk.MaxPings,
ForceConnection: ppd.ForceConnection, ForceConnection: ppDisk.ForceConnection,
// Since this does not adhere to json.Marshaler yet,
// file it in manually assuming default values
HostParams: connect.GetDefaultHostParams(),
} }
return nil return nil
......
...@@ -61,15 +61,25 @@ func GetParameters(params string) (UnknownRoundsParams, error) { ...@@ -61,15 +61,25 @@ func GetParameters(params string) (UnknownRoundsParams, error) {
return p, nil 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. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (f *UnknownRoundsParams) UnmarshalJSON(data []byte) error { func (urp *UnknownRoundsParams) UnmarshalJSON(data []byte) error {
urpDisk := unknownRoundsParamsDisk{} urpDisk := unknownRoundsParamsDisk{}
err := json.Unmarshal(data, &urpDisk) err := json.Unmarshal(data, &urpDisk)
if err != nil { if err != nil {
return err return err
} }
*f = UnknownRoundsParams{ *urp = UnknownRoundsParams{
MaxChecks: urpDisk.MaxChecks, MaxChecks: urpDisk.MaxChecks,
Stored: urpDisk.Stored, Stored: urpDisk.Stored,
} }
...@@ -77,16 +87,6 @@ func (f *UnknownRoundsParams) UnmarshalJSON(data []byte) error { ...@@ -77,16 +87,6 @@ func (f *UnknownRoundsParams) UnmarshalJSON(data []byte) error {
return nil 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 // UnknownRounds tracks data for unknown rounds. Should adhere to UnknownRounds
// interface. // interface.
type UnknownRounds struct { type UnknownRounds struct {
......
...@@ -56,13 +56,13 @@ func GetParameters(params string) (Params, error) { ...@@ -56,13 +56,13 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{ pDisk := paramsDisk{
MessageReceptionBuffLen: r.MessageReceptionBuffLen, MessageReceptionBuffLen: p.MessageReceptionBuffLen,
MessageReceptionWorkerPoolSize: r.MessageReceptionWorkerPoolSize, MessageReceptionWorkerPoolSize: p.MessageReceptionWorkerPoolSize,
MaxChecksInProcessMessage: r.MaxChecksInProcessMessage, MaxChecksInProcessMessage: p.MaxChecksInProcessMessage,
InProcessMessageWait: r.InProcessMessageWait, InProcessMessageWait: p.InProcessMessageWait,
RealtimeOnly: r.RealtimeOnly, RealtimeOnly: p.RealtimeOnly,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
...@@ -70,14 +70,14 @@ func (r Params) MarshalJSON() ([]byte, error) { ...@@ -70,14 +70,14 @@ func (r Params) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = Params{ *p = Params{
MessageReceptionBuffLen: pDisk.MessageReceptionBuffLen, MessageReceptionBuffLen: pDisk.MessageReceptionBuffLen,
MessageReceptionWorkerPoolSize: pDisk.MessageReceptionWorkerPoolSize, MessageReceptionWorkerPoolSize: pDisk.MessageReceptionWorkerPoolSize,
MaxChecksInProcessMessage: pDisk.MaxChecksInProcessMessage, MaxChecksInProcessMessage: pDisk.MaxChecksInProcessMessage,
......
...@@ -76,6 +76,10 @@ type paramsDisk struct { ...@@ -76,6 +76,10 @@ type paramsDisk struct {
VerboseRoundTracking bool VerboseRoundTracking bool
RealtimeOnly bool RealtimeOnly bool
ReplayRequests bool ReplayRequests bool
Rounds rounds.Params
Pickup pickup.Params
Message message.Params
Historical rounds.Params
} }
// GetDefaultParams returns a Params object containing the // GetDefaultParams returns a Params object containing the
...@@ -115,31 +119,36 @@ func GetParameters(params string) (Params, error) { ...@@ -115,31 +119,36 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (n Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{ pDisk := paramsDisk{
TrackNetworkPeriod: n.TrackNetworkPeriod, TrackNetworkPeriod: p.TrackNetworkPeriod,
MaxCheckedRounds: n.MaxCheckedRounds, MaxCheckedRounds: p.MaxCheckedRounds,
RegNodesBufferLen: n.RegNodesBufferLen, RegNodesBufferLen: p.RegNodesBufferLen,
NetworkHealthTimeout: n.NetworkHealthTimeout, NetworkHealthTimeout: p.NetworkHealthTimeout,
ParallelNodeRegistrations: n.ParallelNodeRegistrations, ParallelNodeRegistrations: p.ParallelNodeRegistrations,
KnownRoundsThreshold: n.KnownRoundsThreshold, KnownRoundsThreshold: p.KnownRoundsThreshold,
FastPolling: n.FastPolling, FastPolling: p.FastPolling,
VerboseRoundTracking: n.VerboseRoundTracking, VerboseRoundTracking: p.VerboseRoundTracking,
RealtimeOnly: n.RealtimeOnly, RealtimeOnly: p.RealtimeOnly,
ReplayRequests: n.ReplayRequests, ReplayRequests: p.ReplayRequests,
Rounds: p.Rounds,
Pickup: p.Pickup,
Message: p.Message,
Historical: p.Historical,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (n *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*n = Params{ *p = Params{
TrackNetworkPeriod: pDisk.TrackNetworkPeriod, TrackNetworkPeriod: pDisk.TrackNetworkPeriod,
MaxCheckedRounds: pDisk.MaxCheckedRounds, MaxCheckedRounds: pDisk.MaxCheckedRounds,
RegNodesBufferLen: pDisk.RegNodesBufferLen, RegNodesBufferLen: pDisk.RegNodesBufferLen,
...@@ -150,16 +159,20 @@ func (n *Params) UnmarshalJSON(data []byte) error { ...@@ -150,16 +159,20 @@ func (n *Params) UnmarshalJSON(data []byte) error {
VerboseRoundTracking: pDisk.VerboseRoundTracking, VerboseRoundTracking: pDisk.VerboseRoundTracking,
RealtimeOnly: pDisk.RealtimeOnly, RealtimeOnly: pDisk.RealtimeOnly,
ReplayRequests: pDisk.ReplayRequests, ReplayRequests: pDisk.ReplayRequests,
Rounds: pDisk.Rounds,
Pickup: pDisk.Pickup,
Message: pDisk.Message,
Historical: pDisk.Historical,
} }
return nil return nil
} }
func (n Params) SetRealtimeOnlyAll() Params { func (p Params) SetRealtimeOnlyAll() Params {
n.RealtimeOnly = true p.RealtimeOnly = true
n.Pickup.RealtimeOnly = true p.Pickup.RealtimeOnly = true
n.Message.RealtimeOnly = true p.Message.RealtimeOnly = true
return n return p
} }
const DefaultDebugTag = "External" const DefaultDebugTag = "External"
...@@ -202,6 +215,7 @@ type cMixParamsDisk struct { ...@@ -202,6 +215,7 @@ type cMixParamsDisk struct {
RetryDelay time.Duration RetryDelay time.Duration
SendTimeout time.Duration SendTimeout time.Duration
DebugTag string DebugTag string
BlacklistedNodes NodeMap
Critical bool Critical bool
} }
...@@ -218,15 +232,29 @@ 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. // MarshalJSON adheres to the json.Marshaler interface.
func (r CMIXParams) MarshalJSON() ([]byte, error) { func (p CMIXParams) MarshalJSON() ([]byte, error) {
pDisk := cMixParamsDisk{ pDisk := cMixParamsDisk{
RoundTries: r.RoundTries, RoundTries: p.RoundTries,
Timeout: r.Timeout, Timeout: p.Timeout,
RetryDelay: r.RetryDelay, RetryDelay: p.RetryDelay,
SendTimeout: r.SendTimeout, SendTimeout: p.SendTimeout,
DebugTag: r.DebugTag, DebugTag: p.DebugTag,
Critical: r.Critical, Critical: p.Critical,
BlacklistedNodes: p.BlacklistedNodes,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
...@@ -234,38 +262,26 @@ func (r CMIXParams) MarshalJSON() ([]byte, error) { ...@@ -234,38 +262,26 @@ func (r CMIXParams) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *CMIXParams) UnmarshalJSON(data []byte) error { func (p *CMIXParams) UnmarshalJSON(data []byte) error {
pDisk := cMixParamsDisk{} pDisk := cMixParamsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = CMIXParams{ *p = CMIXParams{
RoundTries: pDisk.RoundTries, RoundTries: pDisk.RoundTries,
Timeout: pDisk.Timeout, Timeout: pDisk.Timeout,
RetryDelay: pDisk.RetryDelay, RetryDelay: pDisk.RetryDelay,
SendTimeout: pDisk.SendTimeout, SendTimeout: pDisk.SendTimeout,
DebugTag: pDisk.DebugTag, DebugTag: pDisk.DebugTag,
Critical: pDisk.Critical, Critical: pDisk.Critical,
BlacklistedNodes: pDisk.BlacklistedNodes,
} }
return nil 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 type NodeMap map[id.ID]bool
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
......
...@@ -80,16 +80,16 @@ func GetParameters(params string) (Params, error) { ...@@ -80,16 +80,16 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{ pDisk := paramsDisk{
NumMessageRetrievalWorkers: r.NumMessageRetrievalWorkers, NumMessageRetrievalWorkers: p.NumMessageRetrievalWorkers,
LookupRoundsBufferLen: r.LookupRoundsBufferLen, LookupRoundsBufferLen: p.LookupRoundsBufferLen,
MaxHistoricalRoundsRetries: r.MaxHistoricalRoundsRetries, MaxHistoricalRoundsRetries: p.MaxHistoricalRoundsRetries,
UncheckRoundPeriod: r.UncheckRoundPeriod, UncheckRoundPeriod: p.UncheckRoundPeriod,
ForceMessagePickupRetry: r.ForceMessagePickupRetry, ForceMessagePickupRetry: p.ForceMessagePickupRetry,
SendTimeout: r.SendTimeout, SendTimeout: p.SendTimeout,
RealtimeOnly: r.RealtimeOnly, RealtimeOnly: p.RealtimeOnly,
ForceHistoricalRounds: r.ForceHistoricalRounds, ForceHistoricalRounds: p.ForceHistoricalRounds,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
...@@ -97,14 +97,14 @@ func (r Params) MarshalJSON() ([]byte, error) { ...@@ -97,14 +97,14 @@ func (r Params) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = Params{ *p = Params{
NumMessageRetrievalWorkers: pDisk.NumMessageRetrievalWorkers, NumMessageRetrievalWorkers: pDisk.NumMessageRetrievalWorkers,
LookupRoundsBufferLen: pDisk.LookupRoundsBufferLen, LookupRoundsBufferLen: pDisk.LookupRoundsBufferLen,
MaxHistoricalRoundsRetries: pDisk.MaxHistoricalRoundsRetries, MaxHistoricalRoundsRetries: pDisk.MaxHistoricalRoundsRetries,
......
...@@ -85,7 +85,7 @@ type Callback func(connection Connection) ...@@ -85,7 +85,7 @@ type Callback func(connection Connection)
// Params for managing Connection objects. // Params for managing Connection objects.
type Params struct { type Params struct {
Auth auth.Param Auth auth.Params
Rekey rekey.Params Rekey rekey.Params
Event event.Reporter `json:"-"` Event event.Reporter `json:"-"`
Timeout time.Duration Timeout time.Duration
......
...@@ -36,6 +36,7 @@ type paramsDisk struct { ...@@ -36,6 +36,7 @@ type paramsDisk struct {
KeyGetRetryCount uint KeyGetRetryCount uint
KeyGeRetryDelay time.Duration KeyGeRetryDelay time.Duration
Rekey bool Rekey bool
cmix.CMIXParams
} }
// GetDefaultParams returns a default set of Params. // GetDefaultParams returns a default set of Params.
...@@ -66,13 +67,14 @@ func GetParameters(params string) (Params, error) { ...@@ -66,13 +67,14 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{ pDisk := paramsDisk{
ServiceTag: r.ServiceTag, ServiceTag: p.ServiceTag,
LastServiceTag: r.LastServiceTag, LastServiceTag: p.LastServiceTag,
KeyGetRetryCount: r.KeyGetRetryCount, KeyGetRetryCount: p.KeyGetRetryCount,
KeyGeRetryDelay: r.KeyGeRetryDelay, KeyGeRetryDelay: p.KeyGeRetryDelay,
Rekey: r.Rekey, Rekey: p.Rekey,
CMIXParams: p.CMIXParams,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
...@@ -80,19 +82,20 @@ func (r Params) MarshalJSON() ([]byte, error) { ...@@ -80,19 +82,20 @@ func (r Params) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = Params{ *p = Params{
ServiceTag: pDisk.ServiceTag, ServiceTag: pDisk.ServiceTag,
LastServiceTag: pDisk.LastServiceTag, LastServiceTag: pDisk.LastServiceTag,
KeyGetRetryCount: pDisk.KeyGetRetryCount, KeyGetRetryCount: pDisk.KeyGetRetryCount,
KeyGeRetryDelay: pDisk.KeyGeRetryDelay, KeyGeRetryDelay: pDisk.KeyGeRetryDelay,
Rekey: pDisk.Rekey, Rekey: pDisk.Rekey,
CMIXParams: pDisk.CMIXParams,
} }
return nil return nil
......
...@@ -5,6 +5,17 @@ import ( ...@@ -5,6 +5,17 @@ import (
"fmt" "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 { type Params struct {
// using the DH as a seed, both sides finalizeKeyNegotation a number // using the DH as a seed, both sides finalizeKeyNegotation a number
// of keys to use before they must rekey because // of keys to use before they must rekey because
...@@ -23,16 +34,14 @@ type Params struct { ...@@ -23,16 +34,14 @@ type Params struct {
UnconfirmedRetryRatio float64 UnconfirmedRetryRatio float64
} }
// DEFAULT KEY GENERATION PARAMETERS // paramsDisk will be the marshal-able and umarshal-able object.
// Hardcoded limits for keys type paramsDisk struct {
// 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 MinKeys uint16
const ( MaxKeys uint16
minKeys uint16 = 1000 RekeyThreshold float64
maxKeys uint16 = 2000 NumRekeys uint16
rekeyThrshold float64 = 0.05 UnconfirmedRetryRatio float64
numReKeys uint16 = 16 }
rekeyRatio float64 = 1 / 10
)
// GetDefaultParams returns a default set of Params. // GetDefaultParams returns a default set of Params.
func GetDefaultParams() Params { func GetDefaultParams() Params {
...@@ -59,24 +68,37 @@ func GetParameters(params string) (Params, error) { ...@@ -59,24 +68,37 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (s Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
return json.Marshal(s) 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. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (s *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
p := GetDefaultParams() pDisk := paramsDisk{}
err := json.Unmarshal(data, &p) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*s = p *p = Params{
MinKeys: pDisk.MinKeys,
MaxKeys: pDisk.MaxKeys,
RekeyThreshold: pDisk.RekeyThreshold,
NumRekeys: pDisk.NumRekeys,
UnconfirmedRetryRatio: pDisk.UnconfirmedRetryRatio,
}
return nil return nil
} }
func (s Params) String() string { func (p Params) String() string {
return fmt.Sprintf("SessionParams{ MinKeys: %d, MaxKeys: %d, NumRekeys: %d }", 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 { ...@@ -23,6 +23,40 @@ type Params struct {
StoppableName string 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 // GetParameters returns the default network parameters, or override with given
// parameters, if set. // parameters, if set.
func GetParameters(params string) (Params, error) { func GetParameters(params string) (Params, error) {
...@@ -37,39 +71,35 @@ func GetParameters(params string) (Params, error) { ...@@ -37,39 +71,35 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (c *Params) Marshal() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
return json.Marshal(c) 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. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (c *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
p := GetDefaultParams() pDisk := paramsDisk{}
err := json.Unmarshal(data, &p) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*c = p *p = Params{
return nil RoundTimeout: pDisk.RoundTimeout,
} TriggerName: pDisk.TriggerName,
Trigger: pDisk.Trigger,
func GetDefaultParams() Params { ConfirmName: pDisk.ConfirmName,
return Params{ Confirm: pDisk.Confirm,
RoundTimeout: time.Minute, StoppableName: pDisk.StoppableName,
TriggerName: keyExchangeTriggerName,
Trigger: catalog.KeyExchangeTrigger,
ConfirmName: keyExchangeConfirmName,
Confirm: catalog.KeyExchangeConfirm,
StoppableName: keyExchangeMulti,
}
} }
func GetDefaultEphemeralParams() Params { return nil
p := GetDefaultParams()
p.TriggerName = keyExchangeTriggerEphemeralName
p.Trigger = catalog.KeyExchangeTriggerEphemeral
p.ConfirmName = keyExchangeConfirmEphemeralName
p.Confirm = catalog.KeyExchangeConfirmEphemeral
p.StoppableName = keyExchangeEphemeralMulti
return p
} }
...@@ -48,21 +48,21 @@ func GetParameters(params string) (Params, error) { ...@@ -48,21 +48,21 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{NotifyUponCompletion: r.NotifyUponCompletion} pDisk := paramsDisk{NotifyUponCompletion: p.NotifyUponCompletion}
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} *p = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion}
return nil return nil
} }
...@@ -46,21 +46,21 @@ func GetParameters(params string) (Params, error) { ...@@ -46,21 +46,21 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{NotifyUponCompletion: r.NotifyUponCompletion} pDisk := paramsDisk{NotifyUponCompletion: p.NotifyUponCompletion}
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion} *p = Params{NotifyUponCompletion: pDisk.NotifyUponCompletion}
return nil return nil
} }
...@@ -37,6 +37,7 @@ type Params struct { ...@@ -37,6 +37,7 @@ type Params struct {
type paramsDisk struct { type paramsDisk struct {
MaxThroughput int MaxThroughput int
SendTimeout time.Duration SendTimeout time.Duration
Cmix cmix.CMIXParams
} }
// DefaultParams returns a Params object filled with the default values. // DefaultParams returns a Params object filled with the default values.
...@@ -62,10 +63,11 @@ func GetParameters(params string) (Params, error) { ...@@ -62,10 +63,11 @@ func GetParameters(params string) (Params, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r Params) MarshalJSON() ([]byte, error) { func (p Params) MarshalJSON() ([]byte, error) {
pDisk := paramsDisk{ pDisk := paramsDisk{
MaxThroughput: r.MaxThroughput, MaxThroughput: p.MaxThroughput,
SendTimeout: r.SendTimeout, SendTimeout: p.SendTimeout,
Cmix: p.Cmix,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
...@@ -73,16 +75,17 @@ func (r Params) MarshalJSON() ([]byte, error) { ...@@ -73,16 +75,17 @@ func (r Params) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *Params) UnmarshalJSON(data []byte) error { func (p *Params) UnmarshalJSON(data []byte) error {
pDisk := paramsDisk{} pDisk := paramsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = Params{ *p = Params{
MaxThroughput: pDisk.MaxThroughput, MaxThroughput: pDisk.MaxThroughput,
SendTimeout: pDisk.SendTimeout, SendTimeout: pDisk.SendTimeout,
Cmix: pDisk.Cmix,
} }
return nil return nil
......
...@@ -37,6 +37,7 @@ type RequestParams struct { ...@@ -37,6 +37,7 @@ type RequestParams struct {
type requestParamsDisk struct { type requestParamsDisk struct {
Timeout time.Duration Timeout time.Duration
MaxResponseMessages uint8 MaxResponseMessages uint8
CmixParams cmix.CMIXParams
} }
// GetDefaultRequestParams returns a RequestParams with the default // GetDefaultRequestParams returns a RequestParams with the default
...@@ -63,10 +64,11 @@ func GetParameters(params string) (RequestParams, error) { ...@@ -63,10 +64,11 @@ func GetParameters(params string) (RequestParams, error) {
} }
// MarshalJSON adheres to the json.Marshaler interface. // MarshalJSON adheres to the json.Marshaler interface.
func (r RequestParams) MarshalJSON() ([]byte, error) { func (rp RequestParams) MarshalJSON() ([]byte, error) {
pDisk := requestParamsDisk{ pDisk := requestParamsDisk{
Timeout: r.Timeout, Timeout: rp.Timeout,
MaxResponseMessages: r.MaxResponseMessages, MaxResponseMessages: rp.MaxResponseMessages,
CmixParams: rp.CmixParams,
} }
return json.Marshal(&pDisk) return json.Marshal(&pDisk)
...@@ -74,16 +76,17 @@ func (r RequestParams) MarshalJSON() ([]byte, error) { ...@@ -74,16 +76,17 @@ func (r RequestParams) MarshalJSON() ([]byte, error) {
} }
// UnmarshalJSON adheres to the json.Unmarshaler interface. // UnmarshalJSON adheres to the json.Unmarshaler interface.
func (r *RequestParams) UnmarshalJSON(data []byte) error { func (rp *RequestParams) UnmarshalJSON(data []byte) error {
pDisk := requestParamsDisk{} pDisk := requestParamsDisk{}
err := json.Unmarshal(data, &pDisk) err := json.Unmarshal(data, &pDisk)
if err != nil { if err != nil {
return err return err
} }
*r = RequestParams{ *rp = RequestParams{
Timeout: pDisk.Timeout, Timeout: pDisk.Timeout,
MaxResponseMessages: pDisk.MaxResponseMessages, MaxResponseMessages: pDisk.MaxResponseMessages,
CmixParams: pDisk.CmixParams,
} }
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment