Documentation
¶
Index ¶
- Constants
- Variables
- type Accounting
- type AccountingApi
- func (self *AccountingApi) Balance() (int64, error)
- func (self *AccountingApi) BalanceCredit() (int64, error)
- func (self *AccountingApi) BalanceDebit() (int64, error)
- func (self *AccountingApi) BytesCredit() (int64, error)
- func (self *AccountingApi) BytesDebit() (int64, error)
- func (self *AccountingApi) MsgCredit() (int64, error)
- func (self *AccountingApi) MsgDebit() (int64, error)
- func (self *AccountingApi) PeerDrops() (int64, error)
- func (self *AccountingApi) SelfDrops() (int64, error)
- type AccountingMetrics
- type Balance
- type Error
- type Hook
- type Payer
- type Peer
- func (p *Peer) Drop(err error)
- func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interface{}) error) (rhs interface{}, err error)
- func (p *Peer) Run(handler func(ctx context.Context, msg interface{}) error) error
- func (p *Peer) Send(ctx context.Context, msg interface{}) error
- type Price
- type Prices
- type Spec
- type WrappedMsg
Constants ¶
const ( Sender = Payer(true) Receiver = Payer(false) )
const ( ErrMsgTooLong = iota ErrDecode ErrWrite ErrInvalidMsgCode ErrInvalidMsgType ErrHandshake ErrNoHandler ErrHandler )
此协议方案使用的错误代码
const AccountingVersion = "1.0"
会计API文本版本号
Variables ¶
var (
MetricsRegistry metrics.Registry
)
定义一些指标
Functions ¶
This section is empty.
Types ¶
type Accounting ¶
会计实现钩子接口 它通过余额接口与余额接口连接, 通过价格接口与协议及其价格进行接口时
func NewAccounting ¶
func NewAccounting(balance Balance, po Prices) *Accounting
type AccountingApi ¶
type AccountingApi struct {
// contains filtered or unexported fields
}
AccountingAPI提供了一个API来访问与帐户相关的信息
func NewAccountingApi ¶
func NewAccountingApi(m *AccountingMetrics) *AccountingApi
new accountingapi创建新的accountingapi m将用于检查会计指标是否启用
func (*AccountingApi) Balance ¶
func (self *AccountingApi) Balance() (int64, error)
余额返回本地节点余额(贷记单位-借记单位)
func (*AccountingApi) BalanceCredit ¶
func (self *AccountingApi) BalanceCredit() (int64, error)
BalanceCredit返回本地节点贷记的单位总数
func (*AccountingApi) BalanceDebit ¶
func (self *AccountingApi) BalanceDebit() (int64, error)
BalanceCredit返回本地节点借记的单位总数
func (*AccountingApi) BytesCredit ¶
func (self *AccountingApi) BytesCredit() (int64, error)
BytesCredit返回本地节点贷记的字节总数
func (*AccountingApi) BytesDebit ¶
func (self *AccountingApi) BytesDebit() (int64, error)
BalanceCredit返回本地节点借记的字节总数
func (*AccountingApi) MsgCredit ¶
func (self *AccountingApi) MsgCredit() (int64, error)
msgcredit返回本地节点贷记的消息总数
func (*AccountingApi) MsgDebit ¶
func (self *AccountingApi) MsgDebit() (int64, error)
func (*AccountingApi) PeerDrops ¶
func (self *AccountingApi) PeerDrops() (int64, error)
func (*AccountingApi) SelfDrops ¶
func (self *AccountingApi) SelfDrops() (int64, error)
type AccountingMetrics ¶
type AccountingMetrics struct {
// contains filtered or unexported fields
}
AccountMetrics提取了度量数据库,并 报告者坚持标准
func NewAccountingMetrics ¶
NewMetricsDB创建一个新的LevelDB实例,用于持久化定义的度量 在p2p/protocols/accounting.go中
func SetupAccountingMetrics ¶
func SetupAccountingMetrics(reportInterval time.Duration, path string) *AccountingMetrics
SetupAccountingMetrics为P2P会计指标创建单独的注册表; 这个注册表应该独立于任何其他指标,因为它在不同的端点上持续存在。 它还实例化给定的度量并启动持续执行例程,该例程 在经过的时间间隔内,将度量值写入级别数据库
type Balance ¶
type Balance interface { //使用远程节点“peer”将金额添加到本地余额中; //正数=贷方本地节点 //负金额=借方本地节点 Add(amount int64, peer *Peer) error }
余额是实际的会计实例 余额定义了会计所需的操作 实现在内部维护每个对等点的平衡
type Hook ¶
type Hook interface { //发送信息的钩子 Send(peer *Peer, size uint32, msg interface{}) error //接收信息的钩子 Receive(peer *Peer, size uint32, msg interface{}) error }
对于会计,设计是允许规范描述消息的定价方式和内容。 为了访问这个功能,我们提供了一个钩子接口,它将调用会计方法 注意:将来可能会有更多这样的(水平)钩子
type Peer ¶
对等机表示在与的对等连接上运行的远程对等机或协议实例 远程对等体
func NewPeer ¶
new peer构造新的peer 此构造函数由p2p.protocol run函数调用 前两个参数是传递给p2p.protocol.run函数的参数 第三个参数是描述协议的规范
func (*Peer) Handshake ¶
func (p *Peer) Handshake(ctx context.Context, hs interface{}, verify func(interface{}) error) (rhs interface{}, err error)
握手在对等连接上协商握手 *参数 *上下文 *要发送到远程对等机的本地握手 *在远程握手时要调用的函数(可以为零) *需要相同类型的远程握手 *拨号对等端需要先发送握手,然后等待远程 *侦听对等机等待远程握手,然后发送它 返回远程握手和错误
type Spec ¶
type Spec struct { //名称是协议的名称,通常是三个字母的单词 Name string //version是协议的版本号 Version uint //maxmsgsize是消息有效负载的最大可接受长度 MaxMsgSize uint32 //messages是此协议使用的消息数据类型的列表, //发送的每个消息类型及其数组索引作为代码(因此 //[&foo,&bar,&baz]将发送带有代码的foo、bar和baz //分别为0、1和2) //每条消息必须有一个唯一的数据类型 Messages []interface{} //会计挂钩(将来可扩展到多个挂钩) Hook Hook // contains filtered or unexported fields }
规范是一种协议规范,包括其名称和版本以及 交换的消息类型
type WrappedMsg ¶
wrappedmsg用于在消息有效负载旁边传播已封送的上下文