dual

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: 18 Imported by: 0

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

View Source
const LanExtension protocol.ID = "/lan"

LanExtension 用于区分局域网协议请求和广域网DHT请求

Variables

This section is empty.

Functions

This section is empty.

Types

type DHT

type DHT struct {
	WAN *dht.IpfsDHT // 广域网DHT
	LAN *dht.IpfsDHT // 局域网DHT
}

DHT 实现了路由接口,提供两个具体的DHT实现,用于支持全局网络用户和局域网用户

func New

func New(ctx context.Context, h host.Host, options ...Option) (*DHT, error)

New 创建一个新的双重DHT实例。提供的选项将转发到两个具体的IpfsDHT内部构造,除了双重DHT用于强制区分局域网和广域网的附加选项。 注意:作为参数提供的查询或路由表功能选项将被此构造函数覆盖。 参数:

  • ctx: context.Context 上下文
  • h: host.Host libp2p主机
  • options: ...Option 配置选项

返回值:

  • *DHT DHT实例
  • error 错误信息

func (*DHT) Bootstrap

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

Bootstrap 允许调用者提示路由系统进入引导状态并保持该状态 参数:

  • ctx: context.Context 上下文

返回值:

  • err: error 错误信息

func (*DHT) Close

func (dht *DHT) Close() error

Close 关闭DHT上下文 返回值:

  • error 错误信息

func (*DHT) FindPeer

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

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

func (dht *DHT) GetPublicKey(ctx context.Context, pid peer.ID) (ci.PubKey, error)

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

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

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 错误信息

func (*DHT) SearchValue

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

SearchValue 从此值搜索更好的值 参数:

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

返回值:

  • ch: <-chan []byte 结果通道
  • err: error 错误信息

func (*DHT) WANActive

func (dht *DHT) WANActive() bool

WANActive 当广域网DHT活跃(有对等节点)时返回true 返回值:

  • bool 是否活跃

type Option

type Option func(*config) error

Option 用于配置双重DHT的选项类型

func DHTOption

func DHTOption(opts ...dht.Option) Option

DHTOption 将给定的DHT选项同时应用于广域网和局域网DHT 参数:

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

返回值:

  • Option 配置选项函数

func LanDHTOption

func LanDHTOption(opts ...dht.Option) Option

LanDHTOption 将给定的DHT选项应用于局域网DHT 参数:

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

返回值:

  • Option 配置选项函数

func WanDHTOption

func WanDHTOption(opts ...dht.Option) Option

WanDHTOption 将给定的DHT选项应用于广域网DHT 参数:

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

返回值:

  • Option 配置选项函数

Jump to

Keyboard shortcuts

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