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

Have all Params objects adhere to json.Marshaler/Unmarshaler

parent 12f6f375
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
......@@ -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
}
......@@ -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,
......
......@@ -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 {
......
////////////////////////////////////////////////////////////////////////////////
// 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
}
////////////////////////////////////////////////////////////////////////////////
// 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))
......
////////////////////////////////////////////////////////////////////////////////
// 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
}
////////////////////////////////////////////////////////////////////////////////
// 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
}
......@@ -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
......
......@@ -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
}
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)
}
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,
......
package rekey
......@@ -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
}
......@@ -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
}
......@@ -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
}
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment