Documentation
¶
Index ¶
- Constants
- type Error
- 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 Spec
- type WrappedMsg
Constants ¶
View Source
const ( ErrMsgTooLong = iota ErrDecode ErrWrite ErrInvalidMsgCode ErrInvalidMsgType ErrHandshake ErrNoHandler ErrHandler )
此协议方案使用的错误代码
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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{} // contains filtered or unexported fields }
规范是一种协议规范,包括其名称和版本以及 交换的消息类型
type WrappedMsg ¶
wrappedmsg用于在消息有效负载旁边传播已封送的上下文
Click to show internal directories.
Click to hide internal directories.