routinghelpers

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

Documentation

Index

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) Bootstrap

func (cr *Compose) Bootstrap(ctx context.Context) (err error)

Bootstrap 引导路由器 参数:

  • ctx: context.Context 上下文

返回值:

  • error 错误信息

func (*Compose) FindPeer

func (cr *Compose) FindPeer(ctx context.Context, p peer.ID) (info peer.AddrInfo, err error)

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

func (cr *Compose) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

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

func (cr *Compose) Provide(ctx context.Context, c cid.Cid, local bool) (err error)

Provide 将给定的CID添加到内容路由系统中 如果传入'true',它还会公告它,否则仅保留在本地记录中 参数:

  • ctx: context.Context 上下文
  • c: cid.Cid 内容标识符
  • local: bool 是否本地提供

返回值:

  • error 错误信息

func (*Compose) PutValue

func (cr *Compose) 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 (*Compose) SearchValue

func (cr *Compose) 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 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

func (lvs *LimitedValueStore) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

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) Bootstrap

func (nr Null) Bootstrap(context.Context) error

Bootstrap 总是立即成功返回 参数:

  • ctx: context.Context 上下文

返回值:

  • error 错误信息

func (Null) Close

func (nr Null) Close() error

Close 总是立即成功返回 返回值:

  • error 错误信息

func (Null) FindPeer

func (nr Null) FindPeer(context.Context, peer.ID) (peer.AddrInfo, error)

FindPeer 总是返回 ErrNotFound 参数:

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

返回值:

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

func (Null) FindProvidersAsync

func (nr Null) FindProvidersAsync(context.Context, cid.Cid, int) <-chan peer.AddrInfo

FindProvidersAsync 总是返回一个已关闭的通道 参数:

  • ctx: context.Context 上下文
  • c: cid.Cid 内容标识符
  • count: int 最大提供者数量

返回值:

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

func (Null) GetValue

func (nr Null) GetValue(context.Context, string, ...routing.Option) ([]byte, error)

GetValue 总是返回 ErrNotFound 参数:

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

返回值:

  • []byte 值
  • error 错误信息

func (Null) Provide

func (nr Null) Provide(context.Context, cid.Cid, bool) error

Provide 总是返回 ErrNotSupported 参数:

  • ctx: context.Context 上下文
  • c: cid.Cid 内容标识符
  • provide: bool 是否提供

返回值:

  • error 错误信息

func (Null) PutValue

func (nr Null) PutValue(context.Context, string, []byte, ...routing.Option) error

PutValue 总是返回 ErrNotSupported 参数:

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

返回值:

  • error 错误信息

func (Null) SearchValue

func (nr Null) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)

SearchValue 总是返回 ErrNotFound 参数:

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

返回值:

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

type Parallel

type Parallel struct {
	Routers   []routing.Routing // 路由器切片
	Validator record.Validator  // 验证器
}

Parallel 并行操作路由器切片

func (Parallel) Bootstrap

func (r Parallel) Bootstrap(ctx context.Context) error

Bootstrap 通知所有子路由器进行引导 参数:

  • ctx: context.Context 上下文

返回值:

  • error 错误信息

func (Parallel) Close

func (r Parallel) Close() error

Close 关闭所有实现了 io.Closer 接口的子路由器 返回值:

  • error 错误信息

func (Parallel) FindPeer

func (r Parallel) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)

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

func (r Parallel) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

GetPublicKey 并行从所有子路由器中检索公钥,返回第一个结果 参数:

  • ctx: context.Context 上下文
  • p: peer.ID 对等节点ID

返回值:

  • ci.PubKey 公钥
  • error 错误信息

func (Parallel) GetValue

func (r Parallel) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)

GetValue 在所有子路由器中搜索给定的键,返回第一个完成查询的子路由器的结果 参数:

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

返回值:

  • []byte 值
  • error 错误信息

func (Parallel) Provide

func (r Parallel) Provide(ctx context.Context, c cid.Cid, local bool) error

Provide 并行向所有子路由器宣告此对等节点提供指定的内容 只要有一个子路由器成功,就视为成功,但仍会等待所有子路由器完成后再返回 参数:

  • ctx: context.Context 上下文
  • c: cid.Cid 内容标识符
  • local: bool 是否为本地提供

返回值:

  • error 错误信息

func (Parallel) PutValue

func (r Parallel) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error

PutValue 并行将给定的键值对存储到所有子路由器中 只要至少有一个子路由器成功,就视为成功,但会等待所有存储操作完成 参数:

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

返回值:

  • error 错误信息

func (Parallel) SearchValue

func (r Parallel) 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 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

type Tiered struct {
	Routers   []routing.Routing
	Validator record.Validator
}

Tiered 类似于 Parallel,但 GetValue 和 FindPeer 是按顺序调用的。

func (Tiered) Bootstrap

func (r Tiered) Bootstrap(ctx context.Context) error

Bootstrap 通知所有子路由器进行引导。 参数:

  • ctx: context.Context 上下文

返回值:

  • error 错误信息

func (Tiered) Close

func (r Tiered) Close() error

Close 关闭所有实现了 io.Closer 接口的子路由器。 返回值:

  • error 错误信息

func (Tiered) FindPeer

func (r Tiered) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error)

FindPeer 按顺序使用每个子路由器搜索给定的对等节点,返回第一个结果。 参数:

  • ctx: context.Context 上下文
  • p: peer.ID 对等节点ID

返回值:

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

func (Tiered) FindProvidersAsync

func (r Tiered) 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 (Tiered) GetPublicKey

func (r Tiered) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, error)

GetPublicKey 按顺序在每个子路由器中搜索公钥,返回第一个结果。 参数:

  • ctx: context.Context 上下文
  • p: peer.ID 对等节点ID

返回值:

  • ci.PubKey 公钥
  • error 错误信息

func (Tiered) GetValue

func (r Tiered) GetValue(ctx context.Context, key string, opts ...routing.Option) ([]byte, error)

GetValue 按顺序在每个子路由器中搜索给定的键,返回第一个完成查询的子路由器的值。 参数:

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

返回值:

  • []byte 获取的值
  • error 错误信息

func (Tiered) Provide

func (r Tiered) Provide(ctx context.Context, c cid.Cid, local bool) error

Provide 向所有子路由器并行地宣告此对等节点提供指定的内容。 只要有一个子路由器成功就返回成功,但会等待所有子路由器完成后才返回。 参数:

  • ctx: context.Context 上下文
  • c: cid.Cid 内容标识符
  • local: bool 是否本地提供

返回值:

  • error 错误信息

func (Tiered) PutValue

func (r Tiered) PutValue(ctx context.Context, key string, value []byte, opts ...routing.Option) error

PutValue 并行地将给定的键值对写入所有子路由器。 只要至少有一个子路由器成功写入就算成功,但会等待所有写入操作完成后才返回。 参数:

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

返回值:

  • error 错误信息

func (Tiered) SearchValue

func (r Tiered) SearchValue(ctx context.Context, key string, opts ...routing.Option) (<-chan []byte, error)

SearchValue 并行地在所有子路由器中搜索给定的键,从所有子路由器返回按"新鲜度"单调递增的结果。 参数:

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

返回值:

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

Directories

Path Synopsis
tracing 为 routing.Routing API 提供高级方法追踪。
tracing 为 routing.Routing API 提供高级方法追踪。

Jump to

Keyboard shortcuts

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