blankhost

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlankHost

type BlankHost struct {
	// contains filtered or unexported fields
}

BlankHost 是 host.Host 接口的最简实现

func NewBlankHost

func NewBlankHost(n network.Network, options ...Option) *BlankHost

NewBlankHost 创建新的空白主机实例 参数:

  • n: network.Network 网络实例
  • options: ...Option 配置选项

返回:

  • *BlankHost 空白主机实例

func (*BlankHost) Addrs

func (bh *BlankHost) Addrs() []ma.Multiaddr

Addrs 返回主机的监听地址列表 返回:

  • []ma.Multiaddr 监听地址列表

func (*BlankHost) Close

func (bh *BlankHost) Close() error

Close 关闭主机 返回:

  • error 错误信息

func (*BlankHost) ConnManager

func (bh *BlankHost) ConnManager() connmgr.ConnManager

ConnManager 返回连接管理器 返回:

  • connmgr.ConnManager 连接管理器

func (*BlankHost) Connect

func (bh *BlankHost) Connect(ctx context.Context, ai peer.AddrInfo) error

Connect 连接到指定的对等节点 参数:

  • ctx: context.Context 上下文
  • ai: peer.AddrInfo 对等节点信息

返回:

  • error 错误信息

func (*BlankHost) EventBus

func (bh *BlankHost) EventBus() event.Bus

EventBus 返回事件总线 返回:

  • event.Bus 事件总线

func (*BlankHost) ID

func (bh *BlankHost) ID() peer.ID

ID 返回本地对等节点ID 返回:

  • peer.ID 对等节点ID

func (*BlankHost) Mux

func (bh *BlankHost) Mux() protocol.Switch

Mux 返回协议切换器 返回:

  • protocol.Switch 协议切换器

func (*BlankHost) Network

func (bh *BlankHost) Network() network.Network

Network 返回网络实例 返回:

  • network.Network 网络实例

func (*BlankHost) NewStream

func (bh *BlankHost) NewStream(ctx context.Context, p peer.ID, protos ...protocol.ID) (network.Stream, error)

NewStream 创建新的流 参数:

  • ctx: context.Context 上下文
  • p: peer.ID 对等节点ID
  • protos: ...protocol.ID 协议ID列表

返回:

  • network.Stream 网络流
  • error 错误信息

func (*BlankHost) Peerstore

func (bh *BlankHost) Peerstore() peerstore.Peerstore

Peerstore 返回对等存储 返回:

  • peerstore.Peerstore 对等存储实例

func (*BlankHost) RemoveStreamHandler

func (bh *BlankHost) RemoveStreamHandler(pid protocol.ID)

RemoveStreamHandler 移除流处理器 参数:

  • pid: protocol.ID 协议ID

func (*BlankHost) SetStreamHandler

func (bh *BlankHost) SetStreamHandler(pid protocol.ID, handler network.StreamHandler)

SetStreamHandler 设置流处理器 参数:

  • pid: protocol.ID 协议ID
  • handler: network.StreamHandler 流处理器

func (*BlankHost) SetStreamHandlerMatch

func (bh *BlankHost) SetStreamHandlerMatch(pid protocol.ID, m func(protocol.ID) bool, handler network.StreamHandler)

SetStreamHandlerMatch 设置带匹配函数的流处理器 参数:

  • pid: protocol.ID 协议ID
  • m: func(protocol.ID) bool 匹配函数
  • handler: network.StreamHandler 流处理器

type Option

type Option = func(cfg *config)

Option 定义配置选项函数类型

func WithConnectionManager

func WithConnectionManager(cmgr connmgr.ConnManager) Option

WithConnectionManager 设置连接管理器选项 参数:

  • cmgr: connmgr.ConnManager 连接管理器实例

返回:

  • Option 配置选项函数

func WithEventBus

func WithEventBus(eventBus event.Bus) Option

WithEventBus 设置事件总线选项 参数:

  • eventBus: event.Bus 事件总线实例

返回:

  • Option 配置选项函数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL