Documentation
¶
Overview ¶
Package dual provides an implementation of a split or "dual" dht, where two parallel instances are maintained for the global internet and the local LAN respectively.
Index ¶
- Constants
- type DHT
- func (dht *DHT) Bootstrap(ctx context.Context) (err error)
- func (dht *DHT) Close() error
- func (dht *DHT) FindPeer(ctx context.Context, pid peer.ID) (pi peer.AddrInfo, err error)
- func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) (ch <-chan peer.AddrInfo)
- func (dht *DHT) GetPublicKey(ctx context.Context, pid peer.ID) (ci.PubKey, error)
- func (dht *DHT) GetRoutingTableDiversityStats() []peerdiversity.CplDiversityStats
- func (d *DHT) GetValue(ctx context.Context, key string, opts ...routing.Option) (result []byte, err error)
- func (dht *DHT) Provide(ctx context.Context, key cid.Cid, announce bool) (err error)
- func (dht *DHT) PutValue(ctx context.Context, key string, val []byte, opts ...routing.Option) (err error)
- func (dht *DHT) SearchValue(ctx context.Context, key string, opts ...routing.Option) (ch <-chan []byte, err error)
- func (dht *DHT) WANActive() bool
- type Option
Constants ¶
const LanExtension protocol.ID = "/lan"
LanExtension 用于区分局域网协议请求和广域网DHT请求
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DHT ¶
DHT 实现了路由接口,提供两个具体的DHT实现,用于支持全局网络用户和局域网用户
func New ¶
New 创建一个新的双重DHT实例。提供的选项将转发到两个具体的IpfsDHT内部构造,除了双重DHT用于强制区分局域网和广域网的附加选项。 注意:作为参数提供的查询或路由表功能选项将被此构造函数覆盖。 参数:
- ctx: context.Context 上下文
- h: host.Host libp2p主机
- options: ...Option 配置选项
返回值:
- *DHT DHT实例
- error 错误信息
func (*DHT) Bootstrap ¶
Bootstrap 允许调用者提示路由系统进入引导状态并保持该状态 参数:
- ctx: context.Context 上下文
返回值:
- err: error 错误信息
func (*DHT) FindPeer ¶
FindPeer 搜索具有给定ID的对等节点 注意: 使用签名的对等节点记录时,我们可以在任一DHT返回时短路 参数:
- ctx: context.Context 上下文
- pid: peer.ID 对等节点ID
返回值:
- pi: peer.AddrInfo 对等节点地址信息
- err: error 错误信息
func (*DHT) FindProvidersAsync ¶
func (dht *DHT) FindProvidersAsync(ctx context.Context, key cid.Cid, count int) (ch <-chan peer.AddrInfo)
FindProvidersAsync 异步搜索能够提供给定键的对等节点 参数:
- ctx: context.Context 上下文
- key: cid.Cid 内容标识符
- count: int 需要的提供者数量
返回值:
- <-chan peer.AddrInfo 提供者信息通道
func (*DHT) GetPublicKey ¶
GetPublicKey 返回给定对等节点的公钥 参数:
- ctx: context.Context 上下文
- pid: peer.ID 对等节点ID
返回值:
- ci.PubKey 公钥
- error 错误信息
func (*DHT) GetRoutingTableDiversityStats ¶
func (dht *DHT) GetRoutingTableDiversityStats() []peerdiversity.CplDiversityStats
GetRoutingTableDiversityStats 获取路由表多样性统计信息 返回值:
- []peerdiversity.CplDiversityStats 多样性统计信息
func (*DHT) GetValue ¶
func (d *DHT) GetValue(ctx context.Context, key string, opts ...routing.Option) (result []byte, err error)
GetValue 搜索与给定键对应的值 参数:
- ctx: context.Context 上下文
- key: string 键
- opts: ...routing.Option 选项
返回值:
- result: []byte 结果值
- err: error 错误信息
func (*DHT) Provide ¶
Provide 将给定的CID添加到内容路由系统 参数:
- ctx: context.Context 上下文
- key: cid.Cid 内容标识符
- announce: bool 是否公告
返回值:
- error 错误信息
func (*DHT) PutValue ¶
func (dht *DHT) PutValue(ctx context.Context, key string, val []byte, opts ...routing.Option) (err error)
PutValue 添加与给定键对应的值 参数:
- ctx: context.Context 上下文
- key: string 键
- val: []byte 值
- opts: ...routing.Option 选项
返回值:
- err: error 错误信息
type Option ¶
type Option func(*config) error
Option 用于配置双重DHT的选项类型
func DHTOption ¶
DHTOption 将给定的DHT选项同时应用于广域网和局域网DHT 参数:
- opts: ...dht.Option DHT选项列表
返回值:
- Option 配置选项函数
func LanDHTOption ¶
LanDHTOption 将给定的DHT选项应用于局域网DHT 参数:
- opts: ...dht.Option DHT选项列表
返回值:
- Option 配置选项函数
func WanDHTOption ¶
WanDHTOption 将给定的DHT选项应用于广域网DHT 参数:
- opts: ...dht.Option DHT选项列表
返回值:
- Option 配置选项函数