Documentation
¶
Index ¶
- type FullRT
- func (dht *FullRT) Bootstrap(ctx context.Context) (err error)
- func (dht *FullRT) CheckPeers(ctx context.Context, peers ...peer.ID) (int, int)
- func (dht *FullRT) Close() error
- func (dht *FullRT) FindLocal(id peer.ID) peer.AddrInfo
- func (dht *FullRT) FindPeer(ctx context.Context, id peer.ID) (pi peer.AddrInfo, err error)
- func (dht *FullRT) FindProviders(ctx context.Context, c cid.Cid) ([]peer.AddrInfo, error)
- func (dht *FullRT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) (ch <-chan peer.AddrInfo)
- func (dht *FullRT) GetClosestPeers(ctx context.Context, key string) ([]peer.ID, error)
- func (dht *FullRT) GetValue(ctx context.Context, key string, opts ...routing.Option) (result []byte, err error)
- func (dht *FullRT) Host() host.Host
- func (dht *FullRT) Provide(ctx context.Context, key cid.Cid, brdcst bool) (err error)
- func (dht *FullRT) ProvideMany(ctx context.Context, keys []multihash.Multihash) (err error)
- func (dht *FullRT) PutMany(ctx context.Context, keys []string, values [][]byte) error
- func (dht *FullRT) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) (err error)
- func (dht *FullRT) Ready() bool
- func (dht *FullRT) SearchValue(ctx context.Context, key string, opts ...routing.Option) (ch <-chan []byte, err error)
- func (dht *FullRT) Stat() map[string]peer.ID
- func (dht *FullRT) TriggerRefresh(ctx context.Context) error
- type Option
- func DHTOption(opts ...kaddht.Option) Option
- func WithBulkSendParallelism(b int) Option
- func WithCrawlInterval(i time.Duration) Option
- func WithCrawler(c crawler.Crawler) Option
- func WithProviderManagerOptions(pmOpts ...providers.Option) Option
- func WithSuccessWaitFraction(f float64) Option
- func WithTimeoutPerOperation(t time.Duration) Option
- type RecvdVal
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 ¶
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) CheckPeers ¶
CheckPeers 检查节点连接状态 参数:
- ctx: context.Context 上下文
- peers: ...peer.ID 要检查的节点ID列表
返回值:
- int 成功连接的节点数
- int 总节点数
func (*FullRT) FindLocal ¶
FindLocal 查找连接到此DHT的具有给定ID的对等节点,并返回对等节点和找到它的表 参数:
- id: peer.ID 要查找的对等节点ID
返回值:
- peer.AddrInfo 对等节点地址信息
func (*FullRT) FindPeer ¶
FindPeer 搜索具有给定ID的对等节点 参数:
- ctx: context.Context 上下文
- id: peer.ID 要查找的对等节点ID
返回值:
- peer.AddrInfo 对等节点地址信息
- error 错误信息
func (*FullRT) FindProviders ¶
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 ¶
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) Provide ¶
Provide 宣告此节点可以为给定的键提供值 参数:
- ctx: context.Context 上下文
- key: cid.Cid 内容标识符
- brdcst: bool 是否广播
返回值:
- error 错误信息
func (*FullRT) ProvideMany ¶
ProvideMany 为多个键提供记录 参数:
- ctx: context.Context 上下文
- keys: []multihash.Multihash 要提供的键列表
返回值:
- error 错误信息
func (*FullRT) PutMany ¶
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) 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 错误信息
type Option ¶
type Option func(opt *config) error
Option 配置选项函数类型
func WithBulkSendParallelism ¶
WithBulkSendParallelism 设置向其他对等节点发送消息的最大并行度,必须大于等于1 如果未指定,默认为20 参数:
- b: int 并行度
返回值:
- Option 配置选项
func WithCrawlInterval ¶
WithCrawlInterval 设置爬取DHT以刷新对等节点存储的时间间隔 如果未指定,默认为1小时 参数:
- i: time.Duration 时间间隔
返回值:
- Option 配置选项
func WithCrawler ¶
WithCrawler 设置用于爬取DHT网络的爬虫 如果未指定,默认使用parallelism为200的crawler.DefaultCrawler 参数:
- c: crawler.Crawler 爬虫实例
返回值:
- Option 配置选项
func WithProviderManagerOptions ¶
WithProviderManagerOptions 设置实例化providers.ProviderManager时使用的选项 参数:
- pmOpts: ...providers.Option 提供者管理器选项列表
返回值:
- Option 配置选项
func WithSuccessWaitFraction ¶
WithSuccessWaitFraction 设置将操作视为成功前需要等待的对等节点比例,取值范围(0,1] 如果未指定,默认为30% 参数:
- f: float64 等待比例
返回值:
- Option 配置选项
func WithTimeoutPerOperation ¶
WithTimeoutPerOperation 设置每个操作的超时时间,包括设置提供者和查询DHT 如果未指定,默认为5秒 参数:
- t: time.Duration 超时时间
返回值:
- Option 配置选项