dhtopts

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolDHTOld protocol.ID = "/ipfs/dht"

Deprecated: The old format did not support more than one message per stream, and is not supported or relevant with stream pooling. ProtocolDHT should be used instead.

Variables

View Source
var (
	ProtocolDHT      protocol.ID = "/ipfs/kad/1.0.0"
	DefaultProtocols             = []protocol.ID{ProtocolDHT}
)
View Source
var Defaults = func(o *Options) error {
	o.Validator = record.NamespacedValidator{
		"pk": record.PublicKeyValidator{},
	}
	o.Datastore = dssync.MutexWrap(ds.NewMapDatastore())
	o.Protocols = DefaultProtocols
	o.EnableProviders = true
	o.EnableValues = true

	o.RoutingTable.RefreshQueryTimeout = 10 * time.Second
	o.RoutingTable.RefreshPeriod = 1 * time.Hour
	o.RoutingTable.AutoRefresh = true
	o.MaxRecordAge = time.Hour * 36

	return nil
}

Defaults are the default DHT options. This option will be automatically prepended to any options you pass to the DHT constructor.

Functions

This section is empty.

Types

type Option

type Option func(*Options) error

Option DHT option type.

func BucketSize

func BucketSize(bucketSize int) Option

BucketSize configures the bucket size of the routing table.

The default value is 20.

func Client

func Client(only bool) Option

Client configures whether or not the DHT operates in client-only mode.

Defaults to false.

func Datastore

func Datastore(ds ds.Batching) Option

Datastore configures the DHT to use the specified datastore.

Defaults to an in-memory (temporary) map.

func DisableAutoRefresh

func DisableAutoRefresh() Option

DisableAutoRefresh completely disables 'auto-refresh' on the DHT routing table. This means that we will neither refresh the routing table periodically nor when the routing table size goes below the minimum threshold.

func DisableProviders

func DisableProviders() Option

DisableProviders disables storing and retrieving provider records.

Defaults to enabled.

WARNING: do not change this unless you're using a forked DHT (i.e., a private network and/or distinct DHT protocols with the `Protocols` option).

func DisableValues

func DisableValues() Option

DisableProviders disables storing and retrieving value records (including public keys).

Defaults to enabled.

WARNING: do not change this unless you're using a forked DHT (i.e., a private network and/or distinct DHT protocols with the `Protocols` option).

func MaxRecordAge

func MaxRecordAge(maxAge time.Duration) Option

MaxRecordAge specifies the maximum time that any node will hold onto a record ("PutValue record") from the time its received. This does not apply to any other forms of validity that the record may contain. For example, a record may contain an ipns entry with an EOL saying its valid until the year 2020 (a great time in the future). For that record to stick around it must be rebroadcasted more frequently than once every 'MaxRecordAge'

func NamespacedValidator

func NamespacedValidator(ns string, v record.Validator) Option

NamespacedValidator adds a validator namespaced under `ns`. This option fails if the DHT is not using a `record.NamespacedValidator` as it's validator (it uses one by default but this can be overridden with the `Validator` option).

Example: Given a validator registered as `NamespacedValidator("ipns", myValidator)`, all records with keys starting with `/ipns/` will be validated with `myValidator`.

func Protocols

func Protocols(protocols ...protocol.ID) Option

Protocols sets the protocols for the DHT

Defaults to dht.DefaultProtocols

func RoutingTableRefreshPeriod

func RoutingTableRefreshPeriod(period time.Duration) Option

RoutingTableRefreshPeriod sets the period for refreshing buckets in the routing table. The DHT will refresh buckets every period by:

  1. First searching for nearby peers to figure out how many buckets we should try to fill.
  2. Then searching for a random key in each bucket that hasn't been queried in the last refresh period.

func RoutingTableRefreshQueryTimeout

func RoutingTableRefreshQueryTimeout(timeout time.Duration) Option

RoutingTableRefreshQueryTimeout sets the timeout for routing table refresh queries.

func Validator

func Validator(v record.Validator) Option

Validator configures the DHT to use the specified validator.

Defaults to a namespaced validator that can only validate public keys.

type Options

type Options struct {
	Datastore       ds.Batching
	Validator       record.Validator
	Client          bool
	Protocols       []protocol.ID
	BucketSize      int
	MaxRecordAge    time.Duration
	EnableProviders bool
	EnableValues    bool

	RoutingTable struct {
		RefreshQueryTimeout time.Duration
		RefreshPeriod       time.Duration
		AutoRefresh         bool
	}
}

Options is a structure containing all the options that can be used when constructing a DHT.

func (*Options) Apply

func (o *Options) Apply(opts ...Option) error

Apply applies the given options to this Option

Jump to

Keyboard shortcuts

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