p2p/protocols: accounting api documentation added (#847)

This commit is contained in:
Jerzy 2018-12-06 08:18:22 +01:00
parent d545bb74ba
commit b8454e6d9e

View file

@ -6,7 +6,7 @@ import (
const AccountingVersion = "1.0"
var errNoAccountingMetrics = errors.New("no accounting metrics")
var errNoAccountingMetrics = errors.New("accounting metrics not enabled")
type AccountingApi struct {
metrics *AccountingMetrics
@ -16,6 +16,7 @@ func NewAccountingApi(m *AccountingMetrics) *AccountingApi {
return &AccountingApi{m}
}
// BalanceCredit returns total amount of units credited by local node
func (self *AccountingApi) BalanceCredit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -23,6 +24,7 @@ func (self *AccountingApi) BalanceCredit() (int64, error) {
return mBalanceCredit.Count(), nil
}
// BalanceCredit returns total amount of units debited by local node
func (self *AccountingApi) BalanceDebit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -30,6 +32,7 @@ func (self *AccountingApi) BalanceDebit() (int64, error) {
return mBalanceDebit.Count(), nil
}
// BytesCredit returns total amount of bytes credited by local node
func (self *AccountingApi) BytesCredit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -37,6 +40,7 @@ func (self *AccountingApi) BytesCredit() (int64, error) {
return mBytesCredit.Count(), nil
}
// BalanceCredit returns total amount of bytes debited by local node
func (self *AccountingApi) BytesDebit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -44,6 +48,7 @@ func (self *AccountingApi) BytesDebit() (int64, error) {
return mBytesDebit.Count(), nil
}
// MsgCredit returns total amount of messages credited by local node
func (self *AccountingApi) MsgCredit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -51,6 +56,7 @@ func (self *AccountingApi) MsgCredit() (int64, error) {
return mMsgCredit.Count(), nil
}
// MsgDebit returns total amount of messages debited by local node
func (self *AccountingApi) MsgDebit() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -58,6 +64,7 @@ func (self *AccountingApi) MsgDebit() (int64, error) {
return mMsgDebit.Count(), nil
}
// PeerDrops returns number of times when local node had to drop remote peers
func (self *AccountingApi) PeerDrops() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics
@ -65,6 +72,7 @@ func (self *AccountingApi) PeerDrops() (int64, error) {
return mPeerDrops.Count(), nil
}
// SelfDrops returns number of times when local node was overdrafted and dropped
func (self *AccountingApi) SelfDrops() (int64, error) {
if self.metrics == nil {
return 0, errNoAccountingMetrics