写点什么

长安链源码分析之网络模块 net-liquid(4)

作者:
  • 2022-10-19
    湖南
  • 本文字数:1627 字

    阅读完需:约 1 分钟

本文已参与「开源摘星计划」,欢迎正在阅读的你加入。活动链接:https://github.com/weopenprojects/WeOpen-Star


核心模块分析

  • core/basic 基础接口包,包含 Starter、Stopper 以及两者组合封装接口 Switcher。

启动、关闭方法

  • core/blacklist 黑名单接口定义。

// BlackList is a blacklist implementation for net addresses or peer ids .type BlackList interface {	// AddPeer append a peer id to blacklist.	//添加一个节点id到黑名单	AddPeer(pid peer.ID)	// RemovePeer delete a peer id from blacklist. If pid not exist in blacklist, it is a no-op.	//黑名单中移除一个节点	RemovePeer(pid peer.ID)	// AddIPAndPort append a string contains an ip or a net.Addr string with an ip and a port to blacklist.	// The string should be in the following format:	// "192.168.1.2:9000" or "192.168.1.2" or "[::1]:9000" or "[::1]"	//添加一个ip:port到黑明单	AddIPAndPort(ipAndPort string)	// RemoveIPAndPort delete a string contains an ip or a net.Addr string with an ip and a port from blacklist.	// If the string not exist in blacklist, it is a no-op.	//黑名单中移除一个ip:port	RemoveIPAndPort(ipAndPort string)	// IsBlack check whether the remote peer id or the remote net address of the connection given exist in blacklist.	//检测连接(peer id或者ip:port)是否在黑名单中	IsBlack(conn network.Conn) bool}
复制代码


  • core/broadcast PubSub 消息发布/订阅功能接口定义。

// PubSub provides the functions of broadcasting and subscribing messages to the network.// 提供在网络中广播和发送消息的接口type PubSub interface {	// AllMetadataOnlyPeers return a list of peer.ID who communicates with us in a metadata-only link.	// 返回只是传递元数据连接的节点id	AllMetadataOnlyPeers() []peer.ID	// Subscribe register a sub-msg handler for handling the msg listened from the topic given.	//定义个消息处理器用例处理监听指定topic的消息	Subscribe(topic string, msgHandler handler.SubMsgHandler)	// Unsubscribe cancels listening the topic given and unregister the sub-msg handler registered for this topic.	//注销topic的消息处理器	Unsubscribe(topic string)	// Publish will push a msg to the network of the topic given.	//发送消息到网络指定的topic上	Publish(topic string, msg []byte)	// ProtocolID return the protocol.ID of the PubSub service.	// The protocol id will be registered in host.RegisterMsgPayloadHandler method.	//返回该PubSub service的协议id	ProtocolID() protocol.ID	// ProtocolMsgHandler return a function which type is handler.MsgPayloadHandler.	// It will be registered in host.Host.RegisterMsgPayloadHandler method.	//返回协议消息处理器	ProtocolMsgHandler() handler.MsgPayloadHandler	// HostNotifiee return an implementation of host.Notifiee interface.	// It will be registered in host.Host.Notify method.	//返回通知的实现	HostNotifiee() host.Notifiee	// AttachHost will set up the host given to PubSub service.	//把host关联到该PubSub service	AttachHost(h host.Host) error	// ID return the local peer id.	//返回本地peer 的id	ID() peer.ID	// Stop the pub-sub service.	//停止pub-sub service.	Stop() error	// SetBlackPeer add a peer id into the blacklist of PubSub.	//添加一个节点到PubSub的黑名单中	SetBlackPeer(pid peer.ID)	// RemoveBlackPeer remove a peer id from the blacklist of PubSub.	//移除一个黑名单的节点	RemoveBlackPeer(pid peer.ID)}
复制代码


用户头像

关注

还未添加个人签名 2018-05-04 加入

还未添加个人简介

评论

发布
暂无评论
长安链源码分析之网络模块 net-liquid(4)_李_InfoQ写作社区