Documentation ¶
Index ¶
- type Metric
- func (tm *Metric) BadEvents(num int)
- func (tm *Metric) Copy() *Metric
- func (tm *Metric) GoodEvents(num int)
- func (tm *Metric) HistoryJSON() MetricHistoryJSON
- func (tm *Metric) Init(hist MetricHistoryJSON)
- func (tm *Metric) NextTimeInterval()
- func (tm *Metric) OnStart() error
- func (tm *Metric) OnStop()
- func (tm *Metric) Pause()
- func (tm *Metric) SetTicker(ticker MetricTicker)
- func (tm *Metric) TrustScore() int
- func (tm *Metric) TrustValue() float64
- type MetricConfig
- type MetricHistoryJSON
- type MetricStore
- func (tms *MetricStore) AddPeerTrustMetric(key string, tm *Metric)
- func (tms *MetricStore) GetPeerTrustMetric(key string) *Metric
- func (tms *MetricStore) OnStart() error
- func (tms *MetricStore) OnStop()
- func (tms *MetricStore) PeerDisconnected(key string)
- func (tms *MetricStore) SaveToDB()
- func (tms *MetricStore) Size() int
- type MetricTicker
- type TestTicker
- type Ticker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metric ¶
type Metric struct { service.BaseService // contains filtered or unexported fields }
Metric - keeps track of peer reliability See candy/docs/architecture/adr-006-trust-metric.md for details
func NewMetric ¶
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 ¶
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) GoodEvents ¶
GoodEvents indicates that a desirable event(s) took place
func (*Metric) HistoryJSON ¶
func (tm *Metric) HistoryJSON() MetricHistoryJSON
Returns a snapshot of the trust metric history data
func (*Metric) Init ¶
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 ¶
func (tm *Metric) NextTimeInterval()
NextTimeInterval saves current time interval data and prepares for the following interval
func (*Metric) OnStop ¶
func (tm *Metric) OnStop()
OnStop implements Service Nothing to do since the goroutine shuts down by itself via BaseService.Quit()
func (*Metric) Pause ¶
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 ¶
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 ¶
TrustScore gets a score based on the trust value always between 0 and 100
func (*Metric) TrustValue ¶
TrustValue gets the dependable trust value; always between 0 and 1
type MetricConfig ¶
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 ¶
func DefaultConfig() MetricConfig
DefaultConfig returns a config with values that have been tested and produce desirable results
type MetricHistoryJSON ¶
type MetricHistoryJSON struct { NumIntervals int `json:"intervals"` History []float64 `json:"history"` }
MetricHistoryJSON - history data necessary to save the trust metric
type MetricStore ¶
type MetricStore struct { service.BaseService // contains filtered or unexported fields }
MetricStore - Manages all trust metrics for peers
func NewTrustMetricStore ¶
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 ¶
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 ¶
func (tms *MetricStore) GetPeerTrustMetric(key string) *Metric
GetPeerTrustMetric returns a trust metric by peer key
func (*MetricStore) PeerDisconnected ¶
func (tms *MetricStore) PeerDisconnected(key string)
PeerDisconnected pauses the trust metric associated with the peer identified by the key
func (*MetricStore) SaveToDB ¶
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 ¶
func (tms *MetricStore) Size() int
Size returns the number of entries in the trust metric store
type MetricTicker ¶
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 ¶
The ticker used during testing that provides manual control over time intervals
func NewTestTicker ¶
func NewTestTicker() *TestTicker
NewTestTicker returns our ticker used within test routines
func (*TestTicker) GetChannel ¶
func (t *TestTicker) GetChannel() <-chan time.Time
func (*TestTicker) NextTick ¶
func (t *TestTicker) NextTick()
NextInterval manually sends Time on the ticker channel
func (*TestTicker) Stop ¶
func (t *TestTicker) Stop()