addressbook

package
v0.2.22-beta.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupKey

func GroupKey(na net.IP) string

GroupKey returns a string representing the network group an address is part of. This is the /16 for IPv4, the /32 (/36 for he.net) for IPv6, the string "localNode" for a localNode address, the string "tor:key" where key is the /4 of the onion address for Tor address, and the string "unroutable" for an unroutable address.

func IsDNSAddress

func IsDNSAddress(rawAddr string) bool

IsDNSAddress returns whether or not the passed address is an intended DNS.

func IsIPv4

func IsIPv4(na net.IP) bool

IsIPv4 returns whether or not the given address is an IPv4 address.

func IsLocal

func IsLocal(na net.IP) bool

IsLocal returns whether or not the given address is a localNode address.

func IsOnionCatTor

func IsOnionCatTor(na net.IP) bool

IsOnionCatTor returns whether or not the passed address is in the IPv6 range used by bitcoin to support Tor (fd87:d87e:eb43::/48). Note that this range is the same range used by OnionCat, which is part of the RFC4193 unique localNode IPv6 range.

func IsRFC1918

func IsRFC1918(na net.IP) bool

IsRFC1918 returns whether or not the passed address is part of the IPv4 private network address space as defined by RFC1918 (10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16).

func IsRFC2544

func IsRFC2544(na net.IP) bool

IsRFC2544 returns whether or not the passed address is part of the IPv4 address space as defined by RFC2544 (198.18.0.0/15).

func IsRFC3849

func IsRFC3849(na net.IP) bool

IsRFC3849 returns whether or not the passed address is part of the IPv6 documentation range as defined by RFC3849 (2001:DB8::/32).

func IsRFC3927

func IsRFC3927(na net.IP) bool

IsRFC3927 returns whether or not the passed address is part of the IPv4 autoconfiguration range as defined by RFC3927 (169.254.0.0/16).

func IsRFC3964

func IsRFC3964(na net.IP) bool

IsRFC3964 returns whether or not the passed address is part of the IPv6 to IPv4 encapsulation range as defined by RFC3964 (2002::/16).

func IsRFC4193

func IsRFC4193(na net.IP) bool

IsRFC4193 returns whether or not the passed address is part of the IPv6 unique localNode range as defined by RFC4193 (FC00::/7).

func IsRFC4380

func IsRFC4380(na net.IP) bool

IsRFC4380 returns whether or not the passed address is part of the IPv6 teredo tunneling over UDP range as defined by RFC4380 (2001::/32).

func IsRFC4843

func IsRFC4843(na net.IP) bool

IsRFC4843 returns whether or not the passed address is part of the IPv6 ORCHID range as defined by RFC4843 (2001:10::/28).

func IsRFC4862

func IsRFC4862(na net.IP) bool

IsRFC4862 returns whether or not the passed address is part of the IPv6 stateless address autoconfiguration range as defined by RFC4862 (FE80::/64).

func IsRFC5737

func IsRFC5737(na net.IP) bool

IsRFC5737 returns whether or not the passed address is part of the IPv4 documentation address space as defined by RFC5737 (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24).

func IsRFC6052

func IsRFC6052(na net.IP) bool

IsRFC6052 returns whether or not the passed address is part of the IPv6 well-known prefix range as defined by RFC6052 (64:FF9B::/96).

func IsRFC6145

func IsRFC6145(na net.IP) bool

IsRFC6145 returns whether or not the passed address is part of the IPv6 to IPv4 translated address range as defined by RFC6145 (::FFFF:0:0:0/96).

func IsRFC6598

func IsRFC6598(na net.IP) bool

IsRFC6598 returns whether or not the passed address is part of the IPv4 shared address space specified by RFC6598 (100.64.0.0/10).

func IsRoutable

func IsRoutable(na net.IP) bool

IsRoutable returns whether or not the passed address is routable over the public internet. This is true as long as the address is valid and is not in any reserved ranges.

func IsValid

func IsValid(na net.IP) bool

IsValid returns whether or not the passed address is valid. The address is considered invalid under the following circumstances: IPv4: It is either a zero or all bits set address. IPv6: It is either a zero or RFC3849 documentation address.

Types

type AddrBook

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

AddrBook provides a concurrency safe address manager for caching potential peers on the network. based on bitcoin's AddrBook.

func NewAddrBook

func NewAddrBook(cfg *Config, logger log.Log) *AddrBook

NewAddrBook returns a new address manager. Use Start to begin processing asynchronous address updates.

func (*AddrBook) AddAddress

func (a *AddrBook) AddAddress(addr, src *AddrInfo)

AddAddress adds a new address to the address manager. It enforces a max number of addresses and silently ignores duplicate addresses. It is safe for concurrent access.

func (*AddrBook) AddAddresses

func (a *AddrBook) AddAddresses(addrs []*AddrInfo, src *AddrInfo)

AddAddresses adds new addresses to the address manager. It enforces a max number of addresses and silently ignores duplicate addresses. It is safe for concurrent access.

func (*AddrBook) AddressCache

func (a *AddrBook) AddressCache() []*AddrInfo

AddressCache returns the current address cache. It must be treated as read-only (but since it is a copy now, this is not as dangerous).

func (*AddrBook) Attempt

func (a *AddrBook) Attempt(pid peer.ID)

Attempt increases the given address' attempt counter and updates the last attempt time.

func (*AddrBook) BootstrapAddressCache

func (a *AddrBook) BootstrapAddressCache() (addresses []*AddrInfo)

BootstrapAddressCache run AddressCache and add Config.AnchorPeersCount addresses from anchor peers.

func (*AddrBook) Connected

func (a *AddrBook) Connected(peerID peer.ID)

Connected adds the given address to anchor list. Will take some addresses this when node will start.

func (*AddrBook) GetAddresses

func (a *AddrBook) GetAddresses() []*AddrInfo

GetAddresses returns all the addresses currently found within the manager's address cache.

func (*AddrBook) GetAddressesNotConnectedSince

func (a *AddrBook) GetAddressesNotConnectedSince(date time.Time) []*AddrInfo

GetAddressesNotConnectedSince returns all the addresses which have not been successfully connected to since `date`.

func (*AddrBook) GetKnownAddressesCache

func (a *AddrBook) GetKnownAddressesCache() []knownAddress

func (*AddrBook) Good

func (a *AddrBook) Good(pid peer.ID)

Good marks the given address as good. To be called after a successful connection and version exchange. If the address is unknown to the address manager it will be ignored.

func (*AddrBook) Lookup

func (a *AddrBook) Lookup(addr peer.ID) *AddrInfo

Lookup searches for an address using a public key. returns *Info.

func (*AddrBook) NumAddresses

func (a *AddrBook) NumAddresses() int

NumAddresses returns the number of addresses known to the address manager.

func (*AddrBook) Persist

func (a *AddrBook) Persist(ctx context.Context)

Persist runs a loop that periodically persists address book on disk. If started with canceled context it will persist exactly once.

func (*AddrBook) RemoveAddress

func (a *AddrBook) RemoveAddress(pid peer.ID)

RemoveAddress removes the address from the manager.

func (*AddrBook) WasRecentlyRemoved

func (a *AddrBook) WasRecentlyRemoved(id peer.ID) (removedAt *time.Time, wasRemoved bool)

WasRecentlyRemoved checks if peer ID was recently removed. If peer is in the cache, then it returns the time when peer was removed. If the peer was not in the cache, returns (nil, false).

type AddrInfo

type AddrInfo struct {
	IP      net.IP
	ID      peer.ID
	RawAddr string
	// contains filtered or unexported fields
}

AddrInfo stores relevant information for discovery.

func ParseAddrInfo

func ParseAddrInfo(raw string) (*AddrInfo, error)

ParseAddrInfo parses required info from string in multiaddr format.

func (*AddrInfo) Addr

func (a *AddrInfo) Addr() ma.Multiaddr

Addr returns pointer to multiaddr.

func (*AddrInfo) SetAddr

func (a *AddrInfo) SetAddr(addr ma.Multiaddr)

SetAddr sets the multiaddr for the AddrInfo.

func (*AddrInfo) String

func (a *AddrInfo) String() string

type Config

type Config struct {
	// DataDir path to directory where store files
	DataDir string

	// NeedAddressThreshold is the number of addresses under which the
	// address manager will claim to need more addresses.
	NeedAddressThreshold int

	// TriedBucketSize is the maximum number of addresses in each tried address bucket.
	TriedBucketSize int

	// TriedBucketCount is the number of buckets we split tried addresses over.
	TriedBucketCount uint64

	// NewBucketSize is the maximum number of addresses in each new address bucket.
	NewBucketSize int

	// NewBucketCount is the number of buckets that we spread new addresses over.
	NewBucketCount uint64

	// TriedBucketsPerGroup is the number of tried buckets over which an address group will be spread.
	TriedBucketsPerGroup uint64

	// NewBucketsPerGroup is the number of new buckets over which an source address group will be spread.
	NewBucketsPerGroup uint64

	// NewBucketsPerAddress is the number of buckets a frequently seen new address may end up in.
	NewBucketsPerAddress int

	// NumMissingDays is the number of days before which we assume an
	// address has vanished if we have not seen it announced  in that long.
	NumMissingDays time.Duration

	// NumRetries is the number of tried without a single success before
	// we assume an address is bad.
	NumRetries int

	// MaxFailures is the maximum number of failures we will accept without
	// a success before considering an address bad.
	MaxFailures int

	// MinBadDays is the number of days since the last success before we
	// will consider evicting an address.
	MinBadDays time.Duration

	// GetAddrMax is the most addresses that we will send in response
	// to a getAddr (in practice the most addresses we will return from a
	// call to AddressCache()).
	GetAddrMax int

	// GetAddrPercent is the percentage of total addresses known that we
	// will share with a call to AddressCache.
	GetAddrPercent int

	// AnchorPeersCount is the number of anchor peers to use when node starting.
	AnchorPeersCount int

	// Size of the evicted peers cache. Controls how many evicted peers are remembered.
	RemovedPeersCacheSize int
}

Config is the configuration for the address book.

func DefaultAddressBookConfigWithDataDir

func DefaultAddressBookConfigWithDataDir(dataDir string) *Config

DefaultAddressBookConfigWithDataDir returns a default configuration for the address book.

Jump to

Keyboard shortcuts

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