Documentation
¶
Index ¶
- func NewComposableParallel(routers []*ParallelRouter) *composableParallel
- func NewComposableSequential(routers []*SequentialRouter) *composableSequential
- type Bootstrap
- type ComposableRouter
- type Compose
- func (cr *Compose) Bootstrap(ctx context.Context) (err error)
- func (cr *Compose) FindPeer(ctx context.Context, p peer.ID) (info peer.AddrInfo, err error)
- func (cr *Compose) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo
- func (cr *Compose) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)
- func (cr *Compose) GetValue(ctx context.Context, key string, opts ...routing.Option) (value []byte, err error)
- func (cr *Compose) Provide(ctx context.Context, c cid.Cid, local bool) (err error)
- func (cr *Compose) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) (err error)
- func (cr *Compose) SearchValue(ctx context.Context, key string, opts ...routing.Option) (ch <-chan []byte, err error)
- type LimitedValueStore
- func (lvs *LimitedValueStore) Bootstrap(ctx context.Context) error
- func (lvs *LimitedValueStore) Close() error
- func (lvs *LimitedValueStore) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)
- func (lvs *LimitedValueStore) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)
- func (lvs *LimitedValueStore) KeySupported(key string) bool
- func (lvs *LimitedValueStore) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error
- func (lvs *LimitedValueStore) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)
- type Null
- func (nr Null) Bootstrap(context.Context) error
- func (nr Null) Close() error
- func (nr Null) FindPeer(context.Context, peer.ID) (peer.AddrInfo, error)
- func (nr Null) FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo
- func (nr Null) GetValue(context.Context, string, ...routing.Option) ([]byte, error)
- func (nr Null) Provide(context.Context, cid.Cid, bool) error
- func (nr Null) PutValue(context.Context, string, []byte, ...routing.Option) error
- func (nr Null) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)
- type Parallel
- func (r Parallel) Bootstrap(ctx context.Context) error
- func (r Parallel) Close() error
- func (r Parallel) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)
- func (r Parallel) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo
- func (r Parallel) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)
- func (r Parallel) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)
- func (r Parallel) Provide(ctx context.Context, c cid.Cid, local bool) error
- func (r Parallel) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error
- func (r Parallel) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)
- type ParallelRouter
- type ProvideManyRouter
- type ReadyAbleRouter
- type SequentialRouter
- type Tiered
- func (r Tiered) Bootstrap(ctx context.Context) error
- func (r Tiered) Close() error
- func (r Tiered) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)
- func (r Tiered) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo
- func (r Tiered) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)
- func (r Tiered) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)
- func (r Tiered) Provide(ctx context.Context, c cid.Cid, local bool) error
- func (r Tiered) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error
- func (r Tiered) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewComposableParallel ¶
func NewComposableParallel(routers []*ParallelRouter) *composableParallel
NewComposableParallel 创建一个并行执行多个路由器方法的路由器 对于所有方法,如果设置了 IgnoreError 标志,该路由器不会停止整个执行 对于所有方法,如果设置了 ExecuteAfter,该路由器将在计时器之后执行 路由器特定的超时将在 ExecuteAfter 计时器之后开始计数 参数:
- routers: []*ParallelRouter 路由器列表
返回值:
- *composableParallel 并行组合路由器实例
func NewComposableSequential ¶
func NewComposableSequential(routers []*SequentialRouter) *composableSequential
NewComposableSequential 创建一个新的顺序组合路由器 参数:
- routers: []*SequentialRouter 路由器列表
返回值:
- *composableSequential 顺序组合路由器实例
Types ¶
type Bootstrap ¶
type Bootstrap interface {
// Bootstrap 引导路由器
// 参数:
// - ctx: context.Context 上下文
//
// 返回值:
// - error 错误信息
Bootstrap(ctx context.Context) error
}
Bootstrap 需要被引导的路由器应该实现的接口
type ComposableRouter ¶
type ComposableRouter interface {
// Routers 获取路由器列表
// 返回值:
// - []routing.Routing 路由器列表
Routers() []routing.Routing
}
ComposableRouter 可组合路由器接口
type Compose ¶
type Compose struct {
ValueStore routing.ValueStore
PeerRouting routing.PeerRouting
ContentRouting routing.ContentRouting
}
Compose 将组件组合成单个路由器。未指定组件(保留为nil)等同于指定Null路由器。
它还实现了Bootstrap接口。所有实现Bootstrap的不同组件将并行引导。 相同的组件不会被引导两次。
func (*Compose) FindPeer ¶
FindPeer 搜索具有给定ID的对等节点,返回包含相关地址的peer.AddrInfo 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- peer.AddrInfo 对等节点地址信息
- error 错误信息
func (*Compose) FindProvidersAsync ¶
func (cr *Compose) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo
FindProvidersAsync 搜索能够提供给定键的对等节点
如果count > 0,它最多返回count个提供者。如果count == 0,它返回无限数量的提供者。 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- count: int 最大提供者数量
返回值:
- <-chan peer.AddrInfo 提供者地址信息通道
func (*Compose) GetPublicKey ¶
GetPublicKey 返回给定对等节点的公钥 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- ci.PubKey 公钥
- error 错误信息
func (*Compose) GetValue ¶
func (cr *Compose) GetValue(ctx context.Context, key string, opts ...routing.Option) (value []byte, err error)
GetValue 搜索与给定键对应的值 参数:
- ctx: context.Context 上下文
- key: string 键
- opts: ...routing.Option 路由选项
返回值:
- []byte 值
- error 错误信息
func (*Compose) Provide ¶
Provide 将给定的CID添加到内容路由系统中 如果传入'true',它还会公告它,否则仅保留在本地记录中 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- local: bool 是否本地提供
返回值:
- error 错误信息
type LimitedValueStore ¶
type LimitedValueStore struct {
routing.ValueStore
Namespaces []string
}
LimitedValueStore 限制内部值存储到指定的命名空间
func (*LimitedValueStore) Bootstrap ¶
func (lvs *LimitedValueStore) Bootstrap(ctx context.Context) error
Bootstrap 使底层值存储进入"已引导"状态 仅当它实现了Bootstrap接口时才执行 参数:
- ctx: context.Context 上下文
返回值:
- error 错误信息
func (*LimitedValueStore) Close ¶
func (lvs *LimitedValueStore) Close() error
Close 关闭底层值存储 仅当它实现了io.Closer接口时才执行 返回值:
- error 错误信息
func (*LimitedValueStore) GetPublicKey ¶
GetPublicKey 获取指定对等节点的公钥 仅当路由器支持/pk命名空间时才返回公钥,否则返回routing.ErrNotFound 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- ci.PubKey 公钥
- error 错误信息
func (*LimitedValueStore) GetValue ¶
func (lvs *LimitedValueStore) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)
GetValue 从底层值存储中获取给定键的值 仅当命名空间受支持时才获取,否则返回routing.ErrNotFound 参数:
- ctx: context.Context 上下文
- key: string 键
- opts: ...routing.Option 选项
返回值:
- []byte 值
- error 错误信息
func (*LimitedValueStore) KeySupported ¶
func (lvs *LimitedValueStore) KeySupported(key string) bool
KeySupported 检查给定的键是否被此值存储支持 参数:
- key: string 键
返回值:
- bool 是否支持
func (*LimitedValueStore) PutValue ¶
func (lvs *LimitedValueStore) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error
PutValue 将给定的键值对存储到底层值存储中 仅当命名空间受支持时才存储,否则返回routing.ErrNotSupported 参数:
- ctx: context.Context 上下文
- key: string 键
- value: []byte 值
- opts: ...routing.Option 选项
返回值:
- error 错误信息
func (*LimitedValueStore) SearchValue ¶
func (lvs *LimitedValueStore) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)
SearchValue 在底层值存储中搜索给定的键 仅当命名空间受支持时才搜索,否则返回一个空的已关闭通道表示未找到值 参数:
- ctx: context.Context 上下文
- key: string 键
- opts: ...routing.Option 选项
返回值:
- <-chan []byte 结果通道
- error 错误信息
type Null ¶
type Null struct{}
Null 是一个不执行任何操作的路由器
func (Null) FindPeer ¶
FindPeer 总是返回 ErrNotFound 参数:
- ctx: context.Context 上下文
- id: peer.ID 对等节点ID
返回值:
- peer.AddrInfo 对等节点信息
- error 错误信息
func (Null) FindProvidersAsync ¶
FindProvidersAsync 总是返回一个已关闭的通道 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- count: int 最大提供者数量
返回值:
- <-chan peer.AddrInfo 提供者信息通道
func (Null) GetValue ¶
GetValue 总是返回 ErrNotFound 参数:
- ctx: context.Context 上下文
- key: string 键
- opts: ...routing.Option 选项
返回值:
- []byte 值
- error 错误信息
func (Null) Provide ¶
Provide 总是返回 ErrNotSupported 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- provide: bool 是否提供
返回值:
- error 错误信息
type Parallel ¶
Parallel 并行操作路由器切片
func (Parallel) FindPeer ¶
FindPeer 并行在所有子路由器中查找给定的对等节点,返回第一个结果 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- peer.AddrInfo 对等节点地址信息
- error 错误信息
func (Parallel) FindProvidersAsync ¶
func (r Parallel) FindProvidersAsync(ctx context.Context, c cid.Cid, count int) <-chan peer.AddrInfo
FindProvidersAsync 并行在所有子路由器中搜索能够提供给定键的对等节点 如果 count > 0,最多返回 count 个提供者。如果 count == 0,返回无限数量的提供者 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- count: int 最大提供者数量
返回值:
- <-chan peer.AddrInfo 提供者通道
func (Parallel) GetPublicKey ¶
GetPublicKey 并行从所有子路由器中检索公钥,返回第一个结果 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- ci.PubKey 公钥
- error 错误信息
func (Parallel) GetValue ¶
GetValue 在所有子路由器中搜索给定的键,返回第一个完成查询的子路由器的结果 参数:
- ctx: context.Context 上下文
- key: string 键名
- opts: ...routing.Option 选项
返回值:
- []byte 值
- error 错误信息
func (Parallel) Provide ¶
Provide 并行向所有子路由器宣告此对等节点提供指定的内容 只要有一个子路由器成功,就视为成功,但仍会等待所有子路由器完成后再返回 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- local: bool 是否为本地提供
返回值:
- error 错误信息
type ParallelRouter ¶
type ParallelRouter struct {
// 超时时间
Timeout time.Duration
// 路由器实例
Router routing.Routing
// 执行延迟时间
ExecuteAfter time.Duration
// DoNotWaitForSearchValue 是实验性的,等待更好的解决方案
DoNotWaitForSearchValue bool
// 是否忽略错误
IgnoreError bool
}
ParallelRouter 并行路由器结构体
type ProvideManyRouter ¶
type ProvideManyRouter interface {
// ProvideMany 批量提供多个键
// 参数:
// - ctx: context.Context 上下文
// - keys: []multihash.Multihash 多个键的哈希值
//
// 返回值:
// - error 错误信息
ProvideMany(ctx context.Context, keys []multihash.Multihash) error
}
ProvideManyRouter 批量提供者路由器接口
type ReadyAbleRouter ¶
type ReadyAbleRouter interface {
// Ready 检查路由器是否就绪
// 返回值:
// - bool 是否就绪
Ready() bool
}
ReadyAbleRouter 可就绪路由器接口
type SequentialRouter ¶
type SequentialRouter struct {
// 超时时间
Timeout time.Duration
// 是否忽略错误
IgnoreError bool
// 路由器实例
Router routing.Routing
}
SequentialRouter 顺序路由器结构体
type Tiered ¶
Tiered 类似于 Parallel,但 GetValue 和 FindPeer 是按顺序调用的。
func (Tiered) FindPeer ¶
FindPeer 按顺序使用每个子路由器搜索给定的对等节点,返回第一个结果。 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- peer.AddrInfo 对等节点地址信息
- error 错误信息
func (Tiered) FindProvidersAsync ¶
FindProvidersAsync 并行地在所有子路由器中搜索能够提供给定键的对等节点。
如果 count > 0,最多返回 count 个提供者。如果 count == 0,返回无限数量的提供者。 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- count: int 提供者数量限制
返回值:
- <-chan peer.AddrInfo 提供者地址信息通道
func (Tiered) GetPublicKey ¶
GetPublicKey 按顺序在每个子路由器中搜索公钥,返回第一个结果。 参数:
- ctx: context.Context 上下文
- p: peer.ID 对等节点ID
返回值:
- ci.PubKey 公钥
- error 错误信息
func (Tiered) GetValue ¶
GetValue 按顺序在每个子路由器中搜索给定的键,返回第一个完成查询的子路由器的值。 参数:
- ctx: context.Context 上下文
- key: string 键
- opts: ...routing.Option 路由选项
返回值:
- []byte 获取的值
- error 错误信息
func (Tiered) Provide ¶
Provide 向所有子路由器并行地宣告此对等节点提供指定的内容。 只要有一个子路由器成功就返回成功,但会等待所有子路由器完成后才返回。 参数:
- ctx: context.Context 上下文
- c: cid.Cid 内容标识符
- local: bool 是否本地提供
返回值:
- error 错误信息