长安链源码分析之网络模块 net-liquid(8)
作者:李
- 2022-10-20 湖南
本文字数:683 字
阅读完需:约 1 分钟
本文已参与「开源摘星计划」,欢迎正在阅读的你加入。活动链接:https://github.com/weopenprojects/WeOpen-Star
连接管理(ConnMgr)
// ConnMgr provides a connection manager.//连接管理提供一个连接管理器type ConnMgr interface { io.Closer //添加节点连接 AddPeerConn(pid peer.ID, conn network.Conn) bool //移除节点连接 RemovePeerConn(pid peer.ID, conn network.Conn) bool //检测节点连接 ExistPeerConn(pid peer.ID, conn network.Conn) bool //获取节点连接 GetPeerConn(pid peer.ID) network.Conn //获取节点所有连接 GetPeerAllConn(pid peer.ID) []network.Conn //节点是否连接上了 IsConnected(pid peer.ID) bool //节点是否允许连接 IsAllowed(pid peer.ID) bool // 如果没有达到最大节点连接数,尝试建立一个新连接 ExpendConn(pid peer.ID) //允许的最大节点数 MaxPeerCountAllowed() int //节点数量 PeerCount() int //所有节点 AllPeer() []peer.ID}
// ConnSupervisor maintains the connection state of the necessary peers.// If a necessary peer is not connected to us, supervisor will try to dial to it.type ConnSupervisor interface { //开关 basic.Switcher // SetPeerAddr will set a peer as a necessary peer and store the peer's address. //设置节点和地址 SetPeerAddr(pid peer.ID, addr ma.Multiaddr) // RemovePeerAddr will unset a necessary peer. //移除节点 RemovePeerAddr(pid peer.ID) // RemoveAllPeer clean all necessary peers. //移除所有节点 RemoveAllPeer()}
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 3
李
关注
还未添加个人签名 2018-05-04 加入
还未添加个人简介










评论