Skip to content
Snippets Groups Projects
Select Git revision
  • e58c031b1b48e0c5e36c8c7eb79e3996c836d7cd
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

params.go

Blame
  • params.go 2.47 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package fileTransfer
    
    import (
    	"encoding/json"
    	"gitlab.com/elixxir/client/cmix"
    	"time"
    )
    
    const (
    	defaultMaxThroughput = 150_000 // 150 kB per second
    	defaultSendTimeout   = 500 * time.Millisecond
    )
    
    // Params contains parameters used for file transfer.
    type Params struct {
    	// MaxThroughput is the maximum data transfer speed to send file parts (in
    	// bytes per second). If set to 0, rate limiting will be disabled.
    	MaxThroughput int
    
    	// SendTimeout is the duration, in nanoseconds, before sending on a round
    	// times out. It is recommended that SendTimeout is not changed from its
    	// default.
    	SendTimeout time.Duration
    
    	// Cmix are the parameters used when sending a cMix message.
    	Cmix cmix.CMIXParams
    }
    
    // paramsDisk will be the marshal-able and umarshal-able object.
    type paramsDisk struct {
    	MaxThroughput int
    	SendTimeout   time.Duration
    	Cmix          cmix.CMIXParams
    }
    
    // DefaultParams returns a Params object filled with the default values.
    func DefaultParams() Params {
    	return Params{
    		MaxThroughput: defaultMaxThroughput,
    		SendTimeout:   defaultSendTimeout,
    		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 (p Params) MarshalJSON() ([]byte, error) {
    	pDisk := paramsDisk{
    		MaxThroughput: p.MaxThroughput,
    		SendTimeout:   p.SendTimeout,
    		Cmix:          p.Cmix,
    	}
    
    	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{
    		MaxThroughput: pDisk.MaxThroughput,
    		SendTimeout:   pDisk.SendTimeout,
    		Cmix:          pDisk.Cmix,
    	}
    
    	return nil
    }