tendermint: github.com/tendermint/tendermint/p2p/trust Index | Files

package trust

import "github.com/tendermint/tendermint/p2p/trust"


Package Files

config.go metric.go store.go ticker.go

type Metric Uses

type Metric struct {
    // contains filtered or unexported fields

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

func NewMetric Uses

func NewMetric() *Metric

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

func NewMetricWithConfig Uses

func NewMetricWithConfig(tmc MetricConfig) *Metric

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

func (*Metric) BadEvents Uses

func (tm *Metric) BadEvents(num int)

BadEvents indicates that an undesirable event(s) took place

func (*Metric) Copy Uses

func (tm *Metric) Copy() *Metric

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

func (*Metric) GoodEvents Uses

func (tm *Metric) GoodEvents(num int)

GoodEvents indicates that a desirable event(s) took place

func (*Metric) HistoryJSON Uses

func (tm *Metric) HistoryJSON() MetricHistoryJSON

Returns a snapshot of the trust metric history data

func (*Metric) Init Uses

func (tm *Metric) 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 (*Metric) NextTimeInterval Uses

func (tm *Metric) NextTimeInterval()

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

func (*Metric) OnStart Uses

func (tm *Metric) OnStart() error

OnStart implements Service

func (*Metric) OnStop Uses

func (tm *Metric) OnStop()

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

func (*Metric) Pause Uses

func (tm *Metric) Pause()

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

func (*Metric) SetTicker Uses

func (tm *Metric) SetTicker(ticker MetricTicker)

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

func (*Metric) TrustScore Uses

func (tm *Metric) TrustScore() int

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

func (*Metric) TrustValue Uses

func (tm *Metric) TrustValue() float64

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

type MetricConfig Uses

type MetricConfig 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

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

func DefaultConfig Uses

func DefaultConfig() MetricConfig

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

type MetricHistoryJSON Uses

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

MetricHistoryJSON - history data necessary to save the trust metric

type MetricStore Uses

type MetricStore struct {
    // contains filtered or unexported fields

MetricStore - Manages all trust metrics for peers

func NewTrustMetricStore Uses

func NewTrustMetricStore(db dbm.DB, tmc MetricConfig) *MetricStore

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 (*MetricStore) AddPeerTrustMetric Uses

func (tms *MetricStore) AddPeerTrustMetric(key string, tm *Metric)

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 (*MetricStore) GetPeerTrustMetric Uses

func (tms *MetricStore) GetPeerTrustMetric(key string) *Metric

GetPeerTrustMetric returns a trust metric by peer key

func (*MetricStore) OnStart Uses

func (tms *MetricStore) OnStart() error

OnStart implements Service

func (*MetricStore) OnStop Uses

func (tms *MetricStore) OnStop()

OnStop implements Service

func (*MetricStore) PeerDisconnected Uses

func (tms *MetricStore) PeerDisconnected(key string)

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

func (*MetricStore) SaveToDB Uses

func (tms *MetricStore) SaveToDB()

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

func (*MetricStore) Size Uses

func (tms *MetricStore) Size() int

Size returns the number of entries in the trust metric store

type MetricTicker Uses

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

MetricTicker provides a single ticker interface for the trust metric

type TestTicker Uses

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 Uses

func NewTestTicker() *TestTicker

NewTestTicker returns our ticker used within test routines

func (*TestTicker) GetChannel Uses

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

func (*TestTicker) NextTick Uses

func (t *TestTicker) NextTick()

NextInterval manually sends Time on the ticker channel

func (*TestTicker) Stop Uses

func (t *TestTicker) Stop()

type Ticker Uses

type Ticker struct {

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

func NewTicker Uses

func NewTicker(d time.Duration) *Ticker

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

func (*Ticker) GetChannel Uses

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

Package trust imports 7 packages (graph) and is imported by 4 packages. Updated 2020-01-14. Refresh now. Tools for package owners.