config

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

Documentation

Index

Constants

View Source
const DefaultPrefix protocol.ID = amino.ProtocolPrefix

DefaultPrefix 是默认情况下附加到所有DHT协议的应用程序特定前缀

Variables

View Source
var Defaults = func(o *Config) error {
	o.Validator = record.NamespacedValidator{}
	o.Datastore = dssync.MutexWrap(ds.NewMapDatastore())
	o.ProtocolPrefix = DefaultPrefix
	o.EnableProviders = true
	o.EnableValues = true
	o.QueryPeerFilter = EmptyQueryFilter
	o.MsgSenderBuilder = net.NewMessageSenderImpl

	o.RoutingTable.LatencyTolerance = 10 * time.Second
	o.RoutingTable.RefreshQueryTimeout = 10 * time.Second
	o.RoutingTable.RefreshInterval = 10 * time.Minute
	o.RoutingTable.AutoRefresh = true
	o.RoutingTable.PeerFilter = EmptyRTFilter

	o.MaxRecordAge = providers.ProvideValidity

	o.BucketSize = amino.DefaultBucketSize
	o.Concurrency = amino.DefaultConcurrency
	o.Resiliency = amino.DefaultResiliency
	o.LookupCheckConcurrency = 256

	o.OptimisticProvideJobsPoolSize = 60

	return nil
}

Defaults 是默认的DHT选项。此选项将自动添加到传递给DHT构造函数的任何选项之前

Functions

func EmptyQueryFilter

func EmptyQueryFilter(_ interface{}, ai peer.AddrInfo) bool

EmptyQueryFilter 空的查询过滤器 参数:

  • _: interface{} DHT实例(未使用)
  • ai: peer.AddrInfo 对等点地址信息(未使用)

返回值:

  • bool 总是返回true

func EmptyRTFilter

func EmptyRTFilter(_ interface{}, p peer.ID) bool

EmptyRTFilter 空的路由表过滤器 参数:

  • _: interface{} DHT实例(未使用)
  • p: peer.ID 对等点ID(未使用)

返回值:

  • bool 总是返回true

func GetQuorum

func GetQuorum(opts *routing.Options) int

GetQuorum 获取所需响应数,如果未找到选项则默认为0 参数:

  • opts: *routing.Options 路由选项

返回值:

  • int 所需响应数

Types

type Config

type Config struct {
	Datastore              ds.Batching
	Validator              record.Validator
	ValidatorChanged       bool // 如果为true,表示验证器已更改,不应使用默认值
	Mode                   ModeOpt
	ProtocolPrefix         protocol.ID
	V1ProtocolOverride     protocol.ID
	BucketSize             int
	Concurrency            int
	Resiliency             int
	MaxRecordAge           time.Duration
	EnableProviders        bool
	EnableValues           bool
	ProviderStore          providers.ProviderStore
	QueryPeerFilter        QueryFilterFunc
	LookupCheckConcurrency int
	MsgSenderBuilder       func(h host.Host, protos []protocol.ID) pb.MessageSenderWithDisconnect

	RoutingTable struct {
		RefreshQueryTimeout time.Duration
		RefreshInterval     time.Duration
		AutoRefresh         bool
		LatencyTolerance    time.Duration
		CheckInterval       time.Duration
		PeerFilter          RouteTableFilterFunc
		DiversityFilter     peerdiversity.PeerIPGroupFilter
	}

	BootstrapPeers func() []peer.AddrInfo
	AddressFilter  func([]ma.Multiaddr) []ma.Multiaddr

	// 测试特定的配置选项
	DisableFixLowPeers          bool
	TestAddressUpdateProcessing bool

	EnableOptimisticProvide       bool
	OptimisticProvideJobsPoolSize int
}

Config 是构造DHT时可以使用的所有选项的结构

func (*Config) Apply

func (c *Config) Apply(opts ...Option) error

Apply 将给定的选项应用到此配置 参数:

  • opts: ...Option 要应用的选项列表

返回值:

  • error 错误信息

func (*Config) ApplyFallbacks

func (c *Config) ApplyFallbacks(h host.Host) error

ApplyFallbacks 设置在配置创建期间无法应用的默认值,因为它们依赖于其他配置参数(例如optA默认为optB的2倍)和/或主机 参数:

  • h: host.Host 主机实例

返回值:

  • error 错误信息

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证配置 返回值:

  • error 错误信息

type ModeOpt

type ModeOpt int

ModeOpt 描述DHT应该在什么模式下运行

type Option

type Option func(*Config) error

Option DHT选项类型

type QueryFilterFunc

type QueryFilterFunc func(dht interface{}, ai peer.AddrInfo) bool

QueryFilterFunc 是在查询时考虑要拨号的对等点时应用的过滤器 参数:

  • dht: interface{} DHT实例
  • ai: peer.AddrInfo 对等点地址信息

返回值:

  • bool 是否允许该对等点

type QuorumOptionKey

type QuorumOptionKey struct{}

type RouteTableFilterFunc

type RouteTableFilterFunc func(dht interface{}, p peer.ID) bool

RouteTableFilterFunc 是在考虑要保留在本地路由表中的连接时应用的过滤器 参数:

  • dht: interface{} DHT实例
  • p: peer.ID 对等点ID

返回值:

  • bool 是否保留该连接

Jump to

Keyboard shortcuts

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