Documentation
¶
Overview ¶
Package PointSub 提供了基于 libp2p 的流式处理功能
Package pointsub 提供点对点订阅功能的实现 ¶
Package PointSub 提供了基于 libp2p 的流式处理功能 ¶
Package PointSub 提供了基于 libp2p 的流式处理功能 ¶
Package PointSub 提供了使用 LibP2P streams 替换 Go 标准网络栈的功能 ¶
主要功能: - 接收一个 libp2p.Host 参数 - 提供 Dial() 和 Listen() 方法,返回 net.Conn 和 net.Listener 的实现
网络寻址: - 不使用传统的 "host:port" 寻址方式 - 使用 Peer ID 进行寻址 - 使用 libp2p 的 net.Stream 替代原始 TCP 连接 - 支持 LibP2P 的多路由、NAT 穿透和流复用功能
使用限制: - LibP2P hosts 不能自己连接自己 - 同一个 Host 不能同时作为服务端和客户端使用
Index ¶
- Variables
- func Dial(ctx context.Context, h host.Host, pid peer.ID, tag protocol.ID) (net.Conn, error)
- func Listen(h host.Host, tag protocol.ID) (net.Listener, error)
- func NewLimitedConn(conn net.Conn, maxSize int) net.Conn
- type Client
- type ClientConfig
- type ConnectionInfo
- type LimitedConn
- type Server
- type ServerConfig
- type StreamHandler
Constants ¶
This section is empty.
Variables ¶
var (
ErrServerAlreadyStarted = errors.New("服务器已经启动") // 服务器已启动错误
)
错误定义
var Network = "pointsub"
Network 定义了 PointSub 连接使用的网络类型名称 用于在调用 net.Addr.Network() 时返回 对应的 net.Addr.String() 将返回 peer ID
Functions ¶
func Dial ¶
Dial 使用给定的主机打开到目标地址的流 参数:
- ctx: 上下文对象,用于控制操作的生命周期
- h: libp2p 主机对象
- pid: 目标对等节点的 ID
- tag: 协议标识符
返回值:
- net.Conn: 标准网络连接接口
- error: 错误信息
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 定义客户端结构体
type ClientConfig ¶
type ClientConfig struct {
ReadTimeout time.Duration // 读取超时时间
WriteTimeout time.Duration // 写入超时时间
ConnectTimeout time.Duration // 连接超时时间
MaxRetries int // 最大重试次数
RetryInterval time.Duration // 重试间隔时间
MaxBlockSize int // 最大数据块大小
EnableCompression bool // 是否启用压缩
MaxIdleConns int // 最大空闲连接数
IdleConnTimeout time.Duration // 空闲连接超时时间
}
ClientConfig 定义客户端配置参数
func DefaultClientConfig ¶
func DefaultClientConfig() *ClientConfig
DefaultClientConfig 返回默认的客户端配置 返回值: - *ClientConfig: 包含默认配置值的ClientConfig实例
type ConnectionInfo ¶
type ConnectionInfo struct {
RemoteAddr string // 远程地址
LastActive time.Time // 最后活跃时间
IdleTime time.Duration // 空闲时间
}
ConnectionInfo 连接信息结构体
type LimitedConn ¶
LimitedConn 包装了一个带有大小限制的连接
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server 定义服务结构 包含服务器运行所需的各种组件
func NewServer ¶
func NewServer(h host.Host, config *ServerConfig) (*Server, error)
NewServer 创建新的服务器实例 参数:
- h: libp2p 主机实例
- config: 服务器配置,如果为nil则使用默认配置
返回值:
- *Server: 新创建的服务器实例
- error: 错误信息
func (*Server) GetConnectionsInfo ¶
func (s *Server) GetConnectionsInfo() []ConnectionInfo
GetConnectionsInfo 获取当前活跃连接信息 返回值:
- []ConnectionInfo: 连接信息列表
type ServerConfig ¶
type ServerConfig struct {
// 连接相关配置
ReadTimeout time.Duration // 读取超时时间
WriteTimeout time.Duration // 写入超时时间
MaxBlockSize int // 最大消息大小
// 并发控制
MaxConcurrentConns int // 最大并发连接数
ConnectTimeout time.Duration // 连接建立超时时间
// 资源控制
MaxRequestsPerConn int // 每个连接最大请求数
IdleTimeout time.Duration // 空闲连接超时时间
// 内存控制
BufferPoolSize int // 缓冲池大小
EnableCompression bool // 是否启用压缩
// 连接清理相关配置
CleanupInterval time.Duration // 清理检查间隔
MaxIdleTime time.Duration // 最大空闲时间
// 告警相关配置
MaxMemoryUsage uint64 // 最大内存使用量
}
ServerConfig 定义服务器配置 包含连接、并发、资源、内存和监控等相关配置项
func DefaultServerConfig ¶
func DefaultServerConfig() *ServerConfig
DefaultServerConfig 返回默认的服务器配置 返回值:
- *ServerConfig: 包含默认值的配置对象
func (*ServerConfig) Validate ¶
func (c *ServerConfig) Validate() error
Validate 验证配置是否有效 返回值:
- error: 错误信息