Documentation
¶
Index ¶
- func Filter(addrs []ma.Multiaddr) []ma.Multiaddr
- type AutoRelay
- type ClockWithInstantTimer
- type InstantTimer
- type MetricsTracer
- type MetricsTracerOption
- type Option
- func WithBackoff(d time.Duration) Option
- func WithBootDelay(d time.Duration) Option
- func WithClock(cl ClockWithInstantTimer) Option
- func WithMaxCandidateAge(d time.Duration) Option
- func WithMaxCandidates(n int) Option
- func WithMetricsTracer(mt MetricsTracer) Option
- func WithMinCandidates(n int) Option
- func WithMinInterval(interval time.Duration) Option
- func WithNumRelays(n int) Option
- func WithPeerSource(f PeerSource) Option
- func WithStaticRelays(static []peer.AddrInfo) Option
- type PeerSource
- type RealClock
- type RealTimer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AutoRelay ¶
type AutoRelay struct {
// contains filtered or unexported fields
}
AutoRelay 自动中继服务结构体
func NewAutoRelay ¶
NewAutoRelay 创建一个新的自动中继服务实例 参数:
- bhost: *basic.BasicHost 基础主机实例
- opts: ...Option 可选配置项
返回值:
- *AutoRelay: 返回创建的自动中继服务实例
- error: 如果发生错误则返回错误信息
type ClockWithInstantTimer ¶
type ClockWithInstantTimer interface { Now() time.Time // 获取当前时间 Since(t time.Time) time.Duration // 计算自指定时间以来的持续时间 InstantTimer(when time.Time) InstantTimer // 创建即时计时器 }
ClockWithInstantTimer 定义了带即时计时器的时钟接口
type InstantTimer ¶
type InstantTimer interface { Reset(d time.Time) bool // 重置计时器到指定时间 Stop() bool // 停止计时器 Ch() <-chan time.Time // 获取计时器通道 }
InstantTimer 定义了在特定时刻触发的计时器接口
type MetricsTracer ¶
type MetricsTracer interface { // RelayFinderStatus 更新中继查找器状态 RelayFinderStatus(isActive bool) // ReservationEnded 记录已结束的预约数量 ReservationEnded(cnt int) // ReservationOpened 记录已打开的预约数量 ReservationOpened(cnt int) // ReservationRequestFinished 记录预约请求完成情况 ReservationRequestFinished(isRefresh bool, err error) // RelayAddressCount 更新中继地址数量 RelayAddressCount(int) // RelayAddressUpdated 记录中继地址更新 RelayAddressUpdated() // CandidateChecked 记录候选节点检查结果 CandidateChecked(supportsCircuitV2 bool) // CandidateAdded 记录添加的候选节点数量 CandidateAdded(cnt int) // CandidateRemoved 记录移除的候选节点数量 CandidateRemoved(cnt int) // CandidateLoopState 更新候选循环状态 CandidateLoopState(state candidateLoopState) // ScheduledWorkUpdated 更新计划工作时间 ScheduledWorkUpdated(scheduledWork *scheduledWorkTimes) // DesiredReservations 更新期望的预约数量 DesiredReservations(int) }
MetricsTracer 定义了自动中继的指标跟踪接口
func NewMetricsTracer ¶
func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer
NewMetricsTracer 创建新的指标跟踪器 @param opts 可选的配置选项 @return MetricsTracer 返回指标跟踪器实例
type MetricsTracerOption ¶
type MetricsTracerOption func(*metricsTracerSetting)
MetricsTracerOption 定义指标跟踪器选项函数类型
func WithRegisterer ¶
func WithRegisterer(reg prometheus.Registerer) MetricsTracerOption
WithRegisterer 设置指标注册器的选项函数
type Option ¶
type Option func(*config) error
Option 定义配置函数类型 参数:
- *config: 配置对象指针
返回值:
- error: 返回可能的错误
func WithClock ¶
func WithClock(cl ClockWithInstantTimer) Option
WithClock 配置使用指定的时钟实例 参数:
- cl: ClockWithInstantTimer 时钟实例
返回值:
- Option: 返回配置函数
func WithMaxCandidateAge ¶
WithMaxCandidateAge 设置候选节点的最大年龄 参数:
- d: time.Duration 最大存活时间
返回值:
- Option: 返回配置函数
func WithMetricsTracer ¶
func WithMetricsTracer(mt MetricsTracer) Option
WithMetricsTracer 配置 autorelay 使用指定的指标追踪器 参数:
- mt: MetricsTracer 指标追踪器实例
返回值:
- Option: 返回配置函数
func WithMinCandidates ¶
WithMinCandidates 设置在与任何候选节点获取预约之前收集的最小候选节点数量 参数:
- n: int 最小候选节点数量
返回值:
- Option: 返回配置函数
func WithMinInterval ¶
WithMinInterval 设置调用 peerSource 回调的最小间隔时间 参数:
- interval: time.Duration 最小间隔时间
返回值:
- Option: 返回配置函数
func WithPeerSource ¶
func WithPeerSource(f PeerSource) Option
WithPeerSource 为 AutoRelay 定义一个回调函数,用于查询更多的中继候选节点 参数:
- f: PeerSource 节点源函数
返回值:
- Option: 返回配置函数
func WithStaticRelays ¶
WithStaticRelays 配置使用静态中继节点列表 参数:
- static: []peer.AddrInfo 静态中继节点列表
返回值:
- Option: 返回配置函数
type PeerSource ¶
PeerSource 定义了一个函数类型,用于获取中继候选节点 参数:
- ctx: context.Context 上下文对象,用于取消操作
- num: int 请求的节点数量
返回值:
- <-chan peer.AddrInfo: 返回一个只读通道,用于接收节点地址信息
AutoRelay 在需要新的候选节点时会调用此函数,原因可能是: 1. 未连接到期望数量的中继节点 2. 与某个中继节点断开连接 实现必须最多发送 numPeers 个节点,并在不打算提供更多节点时关闭通道。 在通道关闭之前,AutoRelay 不会再次调用回调。 实现应该发送新节点,但也可以发送之前发送过的节点。 AutoRelay 实现了每个节点的退避机制(参见 WithBackoff)。 使用 WithMinInterval 设置回调调用的最小间隔。 当 AutoRelay 认为满意时,传入的 context.Context 可能会被取消, 当节点关闭时它也会被取消。如果上下文被取消,您必须在某个时候关闭输出通道。
type RealClock ¶
type RealClock struct{}
RealClock 实现了 ClockWithInstantTimer 接口
func (RealClock) InstantTimer ¶
func (RealClock) InstantTimer(when time.Time) InstantTimer
InstantTimer 创建即时计时器 参数:
- when: time.Time 触发时间
返回值:
- InstantTimer: 返回即时计时器实例