ping

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ping 消息的大小(字节)
	PingSize = 32

	// ping 协议标识符
	ID = "/ipfs/ping/1.0.0"

	// ping 服务名称
	ServiceName = "libp2p.ping"
)

Variables

This section is empty.

Functions

func Ping

func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result

Ping 持续向远程节点发送 ping 请求直到上下文被取消 参数:

  • ctx: context.Context 上下文对象
  • h: host.Host libp2p 主机实例
  • p: peer.ID 目标节点 ID

返回值:

  • <-chan Result RTT 或错误的结果流

Types

type PingService

type PingService struct {
	// libp2p 主机实例
	Host host.Host
}

PingService ping 服务结构体

func NewPingService

func NewPingService(h host.Host) *PingService

NewPingService 创建一个新的 ping 服务 参数:

  • h: host.Host libp2p 主机实例

返回值:

  • *PingService ping 服务实例

func (*PingService) Ping

func (ps *PingService) Ping(ctx context.Context, p peer.ID) <-chan Result

Ping 向指定节点发送 ping 请求 参数:

  • ctx: context.Context 上下文对象
  • p: peer.ID 目标节点 ID

返回值:

  • <-chan Result ping 结果通道

func (*PingService) PingHandler

func (p *PingService) PingHandler(s network.Stream)

PingHandler 处理接收到的 ping 请求 参数:

  • s: network.Stream 网络流对象

type Result

type Result struct {
	// RTT 往返时间
	RTT time.Duration
	// Error 错误信息
	Error error
}

Result ping 操作的结果

Jump to

Keyboard shortcuts

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