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

package trust

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

Index

Package Files

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

type MetricHistoryJSON Uses

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

MetricHistoryJSON - history data necessary to save the trust metric

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
    Stop()
}

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 {
    *time.Ticker
}

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

type TrustMetric Uses

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 Uses

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 Uses

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 Uses

func (tm *TrustMetric) BadEvents(num int)

BadEvents indicates that an undesirable event(s) took place

func (*TrustMetric) Copy Uses

func (tm *TrustMetric) Copy() *TrustMetric

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

func (*TrustMetric) GoodEvents Uses

func (tm *TrustMetric) GoodEvents(num int)

GoodEvents indicates that a desirable event(s) took place

func (*TrustMetric) HistoryJSON Uses

func (tm *TrustMetric) HistoryJSON() MetricHistoryJSON

Returns a snapshot of the trust metric history data

func (*TrustMetric) Init Uses

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 Uses

func (tm *TrustMetric) NextTimeInterval()

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

func (*TrustMetric) OnStart Uses

func (tm *TrustMetric) OnStart() error

OnStart implements Service

func (*TrustMetric) OnStop Uses

func (tm *TrustMetric) OnStop()

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

func (*TrustMetric) Pause Uses

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 Uses

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 Uses

func (tm *TrustMetric) TrustScore() int

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

func (*TrustMetric) TrustValue Uses

func (tm *TrustMetric) TrustValue() float64

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

type TrustMetricConfig Uses

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 Uses

func DefaultConfig() TrustMetricConfig

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

type TrustMetricStore Uses

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

TrustMetricStore - Manages all trust metrics for peers

func NewTrustMetricStore Uses

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 Uses

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 Uses

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

GetPeerTrustMetric returns a trust metric by peer key

func (*TrustMetricStore) OnStart Uses

func (tms *TrustMetricStore) OnStart() error

OnStart implements Service

func (*TrustMetricStore) OnStop Uses

func (tms *TrustMetricStore) OnStop()

OnStop implements Service

func (*TrustMetricStore) PeerDisconnected Uses

func (tms *TrustMetricStore) PeerDisconnected(key string)

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

func (*TrustMetricStore) SaveToDB Uses

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 Uses

func (tms *TrustMetricStore) Size() int

Size returns the number of entries in the trust metric store

Package trust imports 7 packages (graph) and is imported by 3 packages. Updated 2019-08-01. Refresh now. Tools for package owners.