trust

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricHistoryJSON

type MetricHistoryJSON struct {
	NumIntervals int       `json:"intervals"`
	History      []float64 `json:"history"`
}

MetricHistoryJSON - history data necessary to save the trust metric

type MetricTicker added in v0.15.0

type MetricTicker interface {
	// GetChannel returns the receive only channel that fires at each time interval
	GetChannel() <-chan time.Time

	// Stop will halt further activity on the ticker channel
	Stop()
}

MetricTicker provides a single ticker interface for the trust metric

type TestTicker added in v0.15.0

type TestTicker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

The ticker used during testing that provides manual control over time intervals

func NewTestTicker added in v0.15.0

func NewTestTicker() *TestTicker

NewTestTicker returns our ticker used within test routines

func (*TestTicker) GetChannel added in v0.15.0

func (t *TestTicker) GetChannel() <-chan time.Time

func (*TestTicker) NextTick added in v0.15.0

func (t *TestTicker) NextTick()

NextInterval manually sends Time on the ticker channel

func (*TestTicker) Stop added in v0.15.0

func (t *TestTicker) Stop()

type Ticker added in v0.15.0

type Ticker struct {
	*time.Ticker
}

Ticker is just a wrap around time.Ticker that allows it to meet the requirements of our interface

func NewTicker added in v0.15.0

func NewTicker(d time.Duration) *Ticker

NewTicker returns a normal time.Ticker wrapped to meet our interface

func (*Ticker) GetChannel added in v0.15.0

func (t *Ticker) GetChannel() <-chan time.Time

type TrustMetric

type TrustMetric struct {
	cmn.BaseService
	// contains filtered or unexported fields
}

TrustMetric - keeps track of peer reliability See tendermint/docs/architecture/adr-006-trust-metric.md for details

func NewMetric

func NewMetric() *TrustMetric

NewMetric returns a trust metric with the default configuration. Use Start to begin tracking the quality of peer behavior over time

func NewMetricWithConfig

func NewMetricWithConfig(tmc TrustMetricConfig) *TrustMetric

NewMetricWithConfig returns a trust metric with a custom configuration. Use Start to begin tracking the quality of peer behavior over time

func (*TrustMetric) BadEvents

func (tm *TrustMetric) BadEvents(num int)

BadEvents indicates that an undesirable event(s) took place

func (*TrustMetric) Copy

func (tm *TrustMetric) Copy() *TrustMetric

Copy returns a new trust metric with members containing the same values

func (*TrustMetric) GoodEvents

func (tm *TrustMetric) GoodEvents(num int)

GoodEvents indicates that a desirable event(s) took place

func (*TrustMetric) HistoryJSON

func (tm *TrustMetric) HistoryJSON() MetricHistoryJSON

Returns a snapshot of the trust metric history data

func (*TrustMetric) Init

func (tm *TrustMetric) Init(hist MetricHistoryJSON)

Instantiates a trust metric by loading the history data for a single peer. This is called only once and only right after creation, which is why the lock is not held while accessing the trust metric struct members

func (*TrustMetric) NextTimeInterval

func (tm *TrustMetric) NextTimeInterval()

NextTimeInterval saves current time interval data and prepares for the following interval

func (*TrustMetric) OnStart added in v0.15.0

func (tm *TrustMetric) OnStart() error

OnStart implements Service

func (*TrustMetric) OnStop added in v0.15.0

func (tm *TrustMetric) OnStop()

OnStop implements Service Nothing to do since the goroutine shuts down by itself via BaseService.Quit()

func (*TrustMetric) Pause

func (tm *TrustMetric) Pause()

Pause tells the metric to pause recording data over time intervals. All method calls that indicate events will unpause the metric

func (*TrustMetric) SetTicker added in v0.15.0

func (tm *TrustMetric) SetTicker(ticker MetricTicker)

SetTicker allows a TestTicker to be provided that will manually control the passing of time from the perspective of the TrustMetric. The ticker must be set before Start is called on the metric

func (*TrustMetric) TrustScore

func (tm *TrustMetric) TrustScore() int

TrustScore gets a score based on the trust value always between 0 and 100

func (*TrustMetric) TrustValue

func (tm *TrustMetric) TrustValue() float64

TrustValue gets the dependable trust value; always between 0 and 1

type TrustMetricConfig

type TrustMetricConfig struct {
	// Determines the percentage given to current behavior
	ProportionalWeight float64

	// Determines the percentage given to prior behavior
	IntegralWeight float64

	// The window of time that the trust metric will track events across.
	// This can be set to cover many days without issue
	TrackingWindow time.Duration

	// Each interval should be short for adapability.
	// Less than 30 seconds is too sensitive,
	// and greater than 5 minutes will make the metric numb
	IntervalLength time.Duration
}

TrustMetricConfig - Configures the weight functions and time intervals for the metric

func DefaultConfig

func DefaultConfig() TrustMetricConfig

DefaultConfig returns a config with values that have been tested and produce desirable results

type TrustMetricStore

type TrustMetricStore struct {
	cmn.BaseService
	// contains filtered or unexported fields
}

TrustMetricStore - Manages all trust metrics for peers

func NewTrustMetricStore

func NewTrustMetricStore(db dbm.DB, tmc TrustMetricConfig) *TrustMetricStore

NewTrustMetricStore returns a store that saves data to the DB and uses the config when creating new trust metrics. Use Start to to initialize the trust metric store

func (*TrustMetricStore) AddPeerTrustMetric added in v0.15.0

func (tms *TrustMetricStore) AddPeerTrustMetric(key string, tm *TrustMetric)

AddPeerTrustMetric takes an existing trust metric and associates it with a peer key. The caller is expected to call Start on the TrustMetric being added

func (*TrustMetricStore) GetPeerTrustMetric

func (tms *TrustMetricStore) GetPeerTrustMetric(key string) *TrustMetric

GetPeerTrustMetric returns a trust metric by peer key

func (*TrustMetricStore) OnStart

func (tms *TrustMetricStore) OnStart() error

OnStart implements Service

func (*TrustMetricStore) OnStop

func (tms *TrustMetricStore) OnStop()

OnStop implements Service

func (*TrustMetricStore) PeerDisconnected

func (tms *TrustMetricStore) PeerDisconnected(key string)

PeerDisconnected pauses the trust metric associated with the peer identified by the key

func (*TrustMetricStore) SaveToDB

func (tms *TrustMetricStore) SaveToDB()

Saves the history data for all peers to the store DB. This public method acquires the trust metric store lock

func (*TrustMetricStore) Size

func (tms *TrustMetricStore) Size() int

Size returns the number of entries in the trust metric store

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL