dht

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConnThreshold represents the minimum number of bootstrap peers we need a connection to.
	ConnThreshold = 3

	// TruncateDuration represents the time slot to which the current time is truncated.
	TruncateDuration = 5 * time.Minute
)

Functions

This section is empty.

Types

type Advertiser

type Advertiser struct {
	// contains filtered or unexported fields
}

Advertiser is responsible for writing and renewing the DHT entry.

func NewAdvertiser

func NewAdvertiser(h host.Host, dht wrap.IpfsDHT) *Advertiser

NewAdvertiser creates a new Advertiser.

func (*Advertiser) Advertise

func (a *Advertiser) Advertise(chanID int) error

Advertise establishes a connection to a set of bootstrap peers that we're using to connect to the DHT. Then it puts the discovery identifier into the DHT (timeout 1 minute - provideTimeout) and renews the identifier when a new time slot is reached. Time slots are used as a kind of sharding for peer discovery. pcp nodes says: "Hey, you can find me with channel ID 123". Then, one hour later another, completely unrelated pcp node comes along and says "Hey, you can find me with channel ID 123". A peer searching for 123 would find the new and the stale entry. To avoid finding the stale entry we use the current time truncated to 5 minute intervals (TruncateDuration). When pcp is advertising its own channel-id + time slot it can happen that it rolls over to the next time slot. Than pcp just advertises the new time slot as well. It can still be found with the old one.

func (Advertiser) Bootstrap

func (p Advertiser) Bootstrap() (err error)

Bootstrap connects to a set of bootstrap nodes to connect to the DHT.

func (Advertiser) DiscoveryID added in v0.3.1

func (p Advertiser) DiscoveryID(chanID int) string

DiscoveryID returns the string, that we use to advertise via mDNS and the DHT. See chanID above for more information. Using UnixNano for testing.

func (*Advertiser) HasPublicAddr added in v0.3.1

func (a *Advertiser) HasPublicAddr() bool

HasPublicAddr returns true if there is at least one public address associated with the current node - aka we got at least three confirmations from peers through the identify protocol.

func (*Advertiser) Shutdown

func (a *Advertiser) Shutdown()

Shutdown stops the advertise mechanics.

func (Advertiser) TimeSlotStart added in v0.3.1

func (p Advertiser) TimeSlotStart() time.Time

TimeSlotStart returns the time when the current time slot started.f

type Discoverer

type Discoverer struct {
	// contains filtered or unexported fields
}

Discoverer is responsible for reading the DHT for an entry with the channel ID given below.

func NewDiscoverer

func NewDiscoverer(h host.Host, dht wrap.IpfsDHT) *Discoverer

NewDiscoverer creates a new Discoverer.

func (Discoverer) Bootstrap

func (p Discoverer) Bootstrap() (err error)

Bootstrap connects to a set of bootstrap nodes to connect to the DHT.

func (*Discoverer) Discover

func (d *Discoverer) Discover(chanID int, handler func(info peer.AddrInfo)) error

Discover establishes a connection to a set of bootstrap peers that we're using to connect to the DHT. It tries to find

func (Discoverer) DiscoveryID added in v0.3.1

func (p Discoverer) DiscoveryID(chanID int) string

DiscoveryID returns the string, that we use to advertise via mDNS and the DHT. See chanID above for more information. Using UnixNano for testing.

func (*Discoverer) SetOffset added in v0.3.1

func (d *Discoverer) SetOffset(offset time.Duration) *Discoverer

func (*Discoverer) Shutdown

func (d *Discoverer) Shutdown()

func (Discoverer) TimeSlotStart added in v0.3.1

func (p Discoverer) TimeSlotStart() time.Time

TimeSlotStart returns the time when the current time slot started.f

type ErrConnThresholdNotReached added in v0.3.1

type ErrConnThresholdNotReached struct {
	BootstrapErrs []error
}

func (ErrConnThresholdNotReached) Error added in v0.3.1

func (ErrConnThresholdNotReached) Log added in v0.3.1

Jump to

Keyboard shortcuts

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