ping

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PingSize = 32 // PingSize 定义了 Ping 数据包的大小为 32 字节。

	ID          = "/dep2p/ping/1.0.0" // ID 定义了 Ping 服务的协议标识为 "/dep2p/ping/1.0.0"。
	ServiceName = "dep2p.ping"        // ServiceName 定义了 Ping 服务的名称为 "dep2p.ping"。
)

Variables

This section is empty.

Functions

func Ping

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

Ping 是一个 Ping 方法,用于向远程对等节点发送 Ping 请求,直到上下文被取消,返回一个包含往返时间(RTT)或错误的结果流。

Types

type PingService

type PingService struct {
	Host host.Host // Host表示 Ping 服务所在的主机。
}

PingService 是一个实现了 dep2p.ping 协议的服务

func NewPingService

func NewPingService(h host.Host) *PingService

NewPingService 是创建 PingService 实例的函数 它接受一个 host.Host 参数 h,并返回一个指向 PingService 的指针

func (*PingService) Ping

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

Ping 是 PingService 的 Ping 方法,用于向指定的对等节点发送 Ping 请求,并返回一个结果通道。 它接受一个上下文对象 ctx,用于控制 Ping 操作的取消或超时。 参数 p 是要 Ping 的对等节点的 peer.ID。 返回一个只读的结果通道,用于接收 Ping 操作的结果。

func (*PingService) PingHandler

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

PingHandler 是 PingService 的 Ping 处理方法 它接受一个 network.Stream 参数 s,用于处理 Ping 请求

type Result

type Result struct {
	RTT   time.Duration // RTT 字段表示往返时间(Round-Trip Time),即从发送 Ping 请求到接收到响应的时间间隔。
	Error error         // Error 字段表示在 Ping 过程中可能发生的错误。
}

Result 是一个 Ping 尝试的结果,可以是往返时间(RTT)或错误。

Jump to

Keyboard shortcuts

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