长安链源码分析之网络模块 net-liquid(6)
作者:李
- 2022-10-19 湖南
本文字数:1918 字
阅读完需:约 1 分钟
本文已参与「开源摘星计划」,欢迎正在阅读的你加入。活动链接:https://github.com/weopenprojects/WeOpen-Star
core/handler 用于回调的处理器函数类型定义。
// MsgPayloadHandler is a function to handle the msg payload received from sender.
//MsgPayloadHandler 用于处理接收指定发送者的消息
type MsgPayloadHandler func(senderPID peer.ID, msgPayload []byte)
// SubMsgHandler is a function to handle the msg payload received from the PubSub topic network.
//SubMsgHandler 用于处理接收指定发布者发布指定topic的消息
type SubMsgHandler func(publisher peer.ID, topic string, msg []byte)
复制代码
core/host 网络 Host 接口定义、网络活动事件通知接口定义。
// PeerProtocols store the peer.ID and the protocol.ID list that supported by peer.
//存储节点支持的协议
type PeerProtocols struct {
PID peer.ID
Protocols []protocol.ID
}
// Host provides the capabilities of network.
//host
type Host interface {
//开关 支持启动和关闭方法
basic.Switcher
// Context of the host instance.
//上下文
Context() context.Context
// PrivateKey of the crypto private key.
//加密私钥
PrivateKey() crypto.PrivateKey
// ID is local peer id.
//本地节点id
ID() peer.ID
// RegisterMsgPayloadHandler register a handler.MsgPayloadHandler for handling
// the msg received with the protocol which id is the given protocolID.
//注册指定协议消息的处理器
RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
// UnregisterMsgPayloadHandler unregister the handler.MsgPayloadHandler for
// handling the msg received with the protocol which id is the given protocolID.
//注销处理器
UnregisterMsgPayloadHandler(protocolID protocol.ID) error
// SendMsg will send a msg with the protocol which id is the given protocolID
// to the receiver whose peer.ID is the given receiverPID.
//发送指定协议消息给接收者
SendMsg(protocolID protocol.ID, receiverPID peer.ID, msgPayload []byte) error
// Dial try to establish a connection with peer whose address is the given.
//拨号建立连接
Dial(remoteAddr ma.Multiaddr) (network.Conn, error)
// CheckClosedConnWithErr return whether the connection has closed.
// If conn.IsClosed() is true, return true.
// If err contains closed info, return true.
// Otherwise, return false.
//检查连接是否关闭
CheckClosedConnWithErr(conn network.Conn, err error) bool
// PeerStore return the store.PeerStore instance of the host.
//返回host的 节点存储器
PeerStore() store.PeerStore
// ConnMgr return the mgr.ConnMgr instance of the host.
//返回 host的连接管理器
ConnMgr() mgr.ConnMgr
// ProtocolMgr return the mgr.ProtocolManager instance of the host.
// 返回host的协议管理器
ProtocolMgr() mgr.ProtocolManager
// Blacklist return the blacklist.BlackList instance of the host.
//返回host的黑名单
Blacklist() blacklist.BlackList
// PeerProtocols query peer.ID and the protocol.ID list supported by peer.
// If protocolIDs is nil ,return the list of all connected to us.
// Otherwise, return the list of part of all which support the protocols
// that id contains in the given protocolIDs.
//返回执行协议的,所有(节点-协议) ,如果没有指定协议。 这返回所有节点的(节点-协议)
PeerProtocols(protocolIDs []protocol.ID) ([]*PeerProtocols, error)
// IsPeerSupportProtocol return true if peer which id is the given pid
// support the given protocol. Otherwise, return false.
//返回这个节点知否支持指定的协议
IsPeerSupportProtocol(pid peer.ID, protocolID protocol.ID) bool
// Notify registers a Notifiee to host.
//注册一个通知器
Notify(notifiee Notifiee)
// AddDirectPeer append a direct peer.
//添加一个直接节点
AddDirectPeer(dp ma.Multiaddr)
// ClearDirectPeers remove all direct peers.
//清除所有的远程连接
ClearDirectPeers()
// LocalAddresses return the list of net addresses for listener listening.
//返回监听的网络地址
LocalAddresses() []ma.Multiaddr
}
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 4
李
关注
还未添加个人签名 2018-05-04 加入
还未添加个人简介
评论