fullrt

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FullRT

type FullRT struct {
	Validator       record.Validator
	ProviderManager *providers.ProviderManager
	// contains filtered or unexported fields
}

FullRT 是一个正在开发中的实验性DHT客户端。在稳定之前,此客户端可能会发生重大变更。

func NewFullRT

func NewFullRT(h host.Host, protocolPrefix protocol.ID, options ...Option) (*FullRT, error)

NewFullRT 创建一个跟踪整个网络的DHT客户端 参数:

  • h: host.Host 主机实例
  • protocolPrefix: protocol.ID 协议前缀,例如/ipfs/kad/1.0.0的前缀是/ipfs
  • options: ...Option 配置选项

返回值:

  • *FullRT DHT客户端实例
  • error 错误信息

注意: FullRT是一个正在开发中的实验性DHT客户端。在稳定之前,此客户端可能会发生重大变更。 并非所有标准DHT选项都在此DHT中受支持。

func (*FullRT) Bootstrap

func (dht *FullRT) Bootstrap(ctx context.Context) (err error)

Bootstrap 引导DHT客户端 参数:

  • ctx: context.Context 上下文

返回值:

  • error 错误信息

func (*FullRT) CheckPeers

func (dht *FullRT) CheckPeers(ctx context.Context, peers ...peer.ID) (int, int)

CheckPeers 检查节点连接状态 参数:

  • ctx: context.Context 上下文
  • peers: ...peer.ID 要检查的节点ID列表

返回值:

  • int 成功连接的节点数
  • int 总节点数

func (*FullRT) Close

func (dht *FullRT) Close() error

Close 关闭DHT客户端 返回值:

  • error 错误信息

func (*FullRT) FindLocal

func (dht *FullRT) FindLocal(id peer.ID) peer.AddrInfo

FindLocal 查找连接到此DHT的具有给定ID的对等节点,并返回对等节点和找到它的表 参数:

  • id: peer.ID 要查找的对等节点ID

返回值:

  • peer.AddrInfo 对等节点地址信息

func (*FullRT) FindPeer

func (dht *FullRT) FindPeer(ctx context.Context, id peer.ID) (pi peer.AddrInfo, err error)

FindPeer 搜索具有给定ID的对等节点 参数:

  • ctx: context.Context 上下文
  • id: peer.ID 要查找的对等节点ID

返回值:

  • peer.AddrInfo 对等节点地址信息
  • error 错误信息

func (*FullRT) FindProviders

func (dht *FullRT) FindProviders(ctx context.Context, c cid.Cid) ([]peer.AddrInfo, error)

FindProviders 搜索直到上下文过期。 参数:

  • ctx: context.Context 上下文
  • c: cid.Cid 要查找的内容标识符

返回值:

  • []peer.AddrInfo 提供者地址信息列表
  • error 错误信息

func (*FullRT) FindProvidersAsync

func (dht *FullRT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) (ch <-chan peer.AddrInfo)

FindProvidersAsync 与 FindProviders 相同,但返回一个通道。 一旦找到对等节点,即使在搜索查询完成之前,也会立即在通道上返回它们。 如果 count 为零,则查询将一直运行到完成。 注意:不从返回的通道读取可能会阻塞查询的进度。 参数:

  • ctx: context.Context 上下文
  • key: cid.Cid 要查找的内容标识符
  • count: int 要查找的提供者数量

返回值:

  • <-chan peer.AddrInfo 提供者地址信息通道

func (*FullRT) GetClosestPeers

func (dht *FullRT) GetClosestPeers(ctx context.Context, key string) ([]peer.ID, error)

GetClosestPeers 获取与给定键最近的节点 参数:

  • ctx: context.Context 上下文
  • key: string 键

返回值:

  • []peer.ID 最近节点的ID列表
  • error 错误信息

func (*FullRT) GetValue

func (dht *FullRT) GetValue(ctx context.Context, key string, opts ...routing.Option) (result []byte, err error)

GetValue 搜索与给定键对应的值 参数:

  • ctx: context.Context 上下文
  • key: string 键
  • opts: ...routing.Option 路由选项

返回值:

  • []byte 找到的值
  • error 错误信息

func (*FullRT) Host

func (dht *FullRT) Host() host.Host

Host 返回主机实例 返回值:

  • host.Host 主机实例

func (*FullRT) Provide

func (dht *FullRT) Provide(ctx context.Context, key cid.Cid, brdcst bool) (err error)

Provide 宣告此节点可以为给定的键提供值 参数:

  • ctx: context.Context 上下文
  • key: cid.Cid 内容标识符
  • brdcst: bool 是否广播

返回值:

  • error 错误信息

func (*FullRT) ProvideMany

func (dht *FullRT) ProvideMany(ctx context.Context, keys []multihash.Multihash) (err error)

ProvideMany 为多个键提供记录 参数:

  • ctx: context.Context 上下文
  • keys: []multihash.Multihash 要提供的键列表

返回值:

  • error 错误信息

func (*FullRT) PutMany

func (dht *FullRT) PutMany(ctx context.Context, keys []string, values [][]byte) error

PutMany 存储多个键值对 参数:

  • ctx: context.Context 上下文
  • keys: []string 键列表
  • values: [][]byte 值列表

返回值:

  • error 错误信息

func (*FullRT) PutValue

func (dht *FullRT) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) (err error)

PutValue 添加与给定键对应的值 参数:

  • ctx: context.Context 上下文
  • key: string 键
  • value: []byte 值
  • opts: ...routing.Option 路由选项

返回值:

  • error 错误信息

func (*FullRT) Ready

func (dht *FullRT) Ready() bool

Ready 检查DHT客户端是否就绪 返回值:

  • bool 是否就绪

func (*FullRT) SearchValue

func (dht *FullRT) SearchValue(ctx context.Context, key string, opts ...routing.Option) (ch <-chan []byte, err error)

SearchValue 搜索与给定键对应的值并流式返回结果 参数:

  • ctx: context.Context 上下文
  • key: string 键
  • opts: ...routing.Option 路由选项

返回值:

  • <-chan []byte 值的通道
  • error 错误信息

func (*FullRT) Stat

func (dht *FullRT) Stat() map[string]peer.ID

Stat 返回当前路由表状态 返回值:

  • map[string]peer.ID 键到节点ID的映射

func (*FullRT) TriggerRefresh

func (dht *FullRT) TriggerRefresh(ctx context.Context) error

TriggerRefresh 触发路由表刷新 参数:

  • ctx: context.Context 上下文

返回值:

  • error 错误信息

type Option

type Option func(opt *config) error

Option 配置选项函数类型

func DHTOption

func DHTOption(opts ...kaddht.Option) Option

DHTOption 设置DHT选项 参数:

  • opts: ...kaddht.Option DHT选项列表

返回值:

  • Option 配置选项

func WithBulkSendParallelism

func WithBulkSendParallelism(b int) Option

WithBulkSendParallelism 设置向其他对等节点发送消息的最大并行度,必须大于等于1 如果未指定,默认为20 参数:

  • b: int 并行度

返回值:

  • Option 配置选项

func WithCrawlInterval

func WithCrawlInterval(i time.Duration) Option

WithCrawlInterval 设置爬取DHT以刷新对等节点存储的时间间隔 如果未指定,默认为1小时 参数:

  • i: time.Duration 时间间隔

返回值:

  • Option 配置选项

func WithCrawler

func WithCrawler(c crawler.Crawler) Option

WithCrawler 设置用于爬取DHT网络的爬虫 如果未指定,默认使用parallelism为200的crawler.DefaultCrawler 参数:

  • c: crawler.Crawler 爬虫实例

返回值:

  • Option 配置选项

func WithProviderManagerOptions

func WithProviderManagerOptions(pmOpts ...providers.Option) Option

WithProviderManagerOptions 设置实例化providers.ProviderManager时使用的选项 参数:

  • pmOpts: ...providers.Option 提供者管理器选项列表

返回值:

  • Option 配置选项

func WithSuccessWaitFraction

func WithSuccessWaitFraction(f float64) Option

WithSuccessWaitFraction 设置将操作视为成功前需要等待的对等节点比例,取值范围(0,1] 如果未指定,默认为30% 参数:

  • f: float64 等待比例

返回值:

  • Option 配置选项

func WithTimeoutPerOperation

func WithTimeoutPerOperation(t time.Duration) Option

WithTimeoutPerOperation 设置每个操作的超时时间,包括设置提供者和查询DHT 如果未指定,默认为5秒 参数:

  • t: time.Duration 超时时间

返回值:

  • Option 配置选项

type RecvdVal

type RecvdVal struct {
	Val  []byte
	From peer.ID
}

RecvdVal 存储值及其来源节点

Jump to

Keyboard shortcuts

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