Documentation ¶
Overview ¶
Package discovery implements uses bitcoin-based addrbook to store network addresses and collects them by crawling the network using a simple protocol.
Index ¶
- Constants
- Variables
- func GroupKey(na net.IP) string
- func IsIPv4(na net.IP) bool
- func IsLocal(na net.IP) bool
- func IsOnionCatTor(na net.IP) bool
- func IsRFC1918(na net.IP) bool
- func IsRFC2544(na net.IP) bool
- func IsRFC3849(na net.IP) bool
- func IsRFC3927(na net.IP) bool
- func IsRFC3964(na net.IP) bool
- func IsRFC4193(na net.IP) bool
- func IsRFC4380(na net.IP) bool
- func IsRFC4843(na net.IP) bool
- func IsRFC4862(na net.IP) bool
- func IsRFC5737(na net.IP) bool
- func IsRFC6052(na net.IP) bool
- func IsRFC6145(na net.IP) bool
- func IsRFC6598(na net.IP) bool
- func IsRoutable(na net.IP) bool
- func IsValid(na net.IP) bool
- type Discovery
- func (d *Discovery) Attempt(key p2pcrypto.PublicKey)
- func (d *Discovery) Bootstrap(ctx context.Context) error
- func (d *Discovery) Good(key p2pcrypto.PublicKey)
- func (d *Discovery) IsLocalAddress(info *node.Info) bool
- func (d *Discovery) Lookup(key p2pcrypto.PublicKey) (*node.Info, error)
- func (d *Discovery) Remove(key p2pcrypto.PublicKey)
- func (d *Discovery) SelectPeers(ctx context.Context, qty int) []*node.Info
- func (d *Discovery) SetLocalAddresses(tcp, udp int)
- func (d *Discovery) Shutdown()
- func (d *Discovery) Size() int
- func (d *Discovery) Update(addr, src *node.Info)
- type KnownAddress
- type MockPeerStore
- func (m *MockPeerStore) Attempt(key p2pcrypto.PublicKey)
- func (m *MockPeerStore) Bootstrap(ctx context.Context) error
- func (m *MockPeerStore) BootstrapCount() int
- func (m *MockPeerStore) Good(key p2pcrypto.PublicKey)
- func (m *MockPeerStore) IsLocalAddress(info *node.Info) bool
- func (m *MockPeerStore) Lookup(pubkey p2pcrypto.PublicKey) (*node.Info, error)
- func (m *MockPeerStore) Remove(key p2pcrypto.PublicKey)
- func (m *MockPeerStore) SelectPeers(ctx context.Context, qty int) []*node.Info
- func (m *MockPeerStore) SetBootstrap(err error)
- func (m *MockPeerStore) SetLocalAddresses(tcp, udp int)
- func (m *MockPeerStore) SetLookupResult(node *node.Info, err error)
- func (m *MockPeerStore) SetUpdate(f func(n, addr *node.Info))
- func (m *MockPeerStore) Shutdown()
- func (m *MockPeerStore) Size() int
- func (m *MockPeerStore) Update(n, src *node.Info)
- func (m *MockPeerStore) UpdateCount() int
- type PeerStore
- type Protocol
Constants ¶
const GetAddresses = 1
GetAddresses is the findnode protocol ID
const MessageBufSize = 1000
MessageBufSize is the buf size we give to the messages channel
const MessageTimeout = time.Second * 5 // TODO: Parametrize
MessageTimeout is the timeout we tolerate when waiting for a message reply
const Name = "/udp/v2/discovery"
Name is the name if the protocol.
const PingPong = 0
PingPong is the ping protocol ID
Variables ¶
var ErrBootAbort = errors.New("bootstrap canceled by signal")
ErrBootAbort is returned when when bootstrap is canceled by context cancel
var ( // ErrLookupFailed determines that we could'nt lookup this node in the routing table or network ErrLookupFailed = errors.New("failed to lookup node in the network") )
Functions ¶
func GroupKey ¶
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 IsOnionCatTor ¶
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 ¶
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 ¶
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 ¶
IsRFC3849 returns whether or not the passed address is part of the IPv6 documentation range as defined by RFC3849 (2001:DB8::/32).
func IsRFC3927 ¶
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 ¶
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 ¶
IsRFC4193 returns whether or not the passed address is part of the IPv6 unique localNode range as defined by RFC4193 (FC00::/7).
func IsRFC4380 ¶
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 ¶
IsRFC4843 returns whether or not the passed address is part of the IPv6 ORCHID range as defined by RFC4843 (2001:10::/28).
func IsRFC4862 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
Types ¶
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery is struct that holds the protocol components, the protocol definition, the addr book data structure and more.
func New ¶
func New(ctx context.Context, ln node.LocalNode, config config.SwarmConfig, service server.Service, path string, logger log.Log) *Discovery
New creates a new Discovery
func (*Discovery) Bootstrap ¶
Bootstrap runs a refresh and tries to get a minimum number of nodes in the addrBook.
func (*Discovery) IsLocalAddress ¶ added in v0.1.1
IsLocalAddress checks info against the addrBook to see if it's a local address.
func (*Discovery) Lookup ¶
Lookup searched a node in the address book. *NOTE* this returns a `Node` with the udpAddress as `Address()`. this is because Lookup is only used in the udp mux.
func (*Discovery) SelectPeers ¶
SelectPeers asks routing table to randomly select a slice of nodes in size `qty`
func (*Discovery) SetLocalAddresses ¶
SetLocalAddresses sets the localNode addresses to be advertised.
type KnownAddress ¶
type KnownAddress struct {
// contains filtered or unexported fields
}
KnownAddress tracks information about a known network address that is used to determine how viable an address is.
func (*KnownAddress) LastAttempt ¶
func (ka *KnownAddress) LastAttempt() time.Time
LastAttempt returns the last time the known address was attempted.
func (*KnownAddress) NodeInfo ¶ added in v0.1.11
func (ka *KnownAddress) NodeInfo() *node.Info
NodeInfo returns the internal Info struct of this address.
type MockPeerStore ¶
type MockPeerStore struct { UpdateFunc func(n, src *node.Info) SelectPeersFunc func(ctx context.Context, qty int) []*node.Info LookupFunc func(p2pcrypto.PublicKey) (*node.Info, error) IsLocalAddressFunc func(info *node.Info) bool RemoveFunc func(key p2pcrypto.PublicKey) GoodFunc func(key p2pcrypto.PublicKey) AttemptFunc func(key p2pcrypto.PublicKey) // contains filtered or unexported fields }
MockPeerStore is a mocked discovery
func (*MockPeerStore) Attempt ¶
func (m *MockPeerStore) Attempt(key p2pcrypto.PublicKey)
Attempt is a mock.
func (*MockPeerStore) Bootstrap ¶
func (m *MockPeerStore) Bootstrap(ctx context.Context) error
Bootstrap is a discovery bootstrap operation function it update the bootstrap count
func (*MockPeerStore) BootstrapCount ¶
func (m *MockPeerStore) BootstrapCount() int
BootstrapCount returns the number of times bootstrap was called
func (*MockPeerStore) IsLocalAddress ¶ added in v0.1.1
func (m *MockPeerStore) IsLocalAddress(info *node.Info) bool
IsLocalAddress mock
func (*MockPeerStore) SelectPeers ¶
SelectPeers mocks selecting peers.
func (*MockPeerStore) SetBootstrap ¶
func (m *MockPeerStore) SetBootstrap(err error)
SetBootstrap set the bootstrap result
func (*MockPeerStore) SetLocalAddresses ¶
func (m *MockPeerStore) SetLocalAddresses(tcp, udp int)
SetLocalAddresses to satisfy the iface
func (*MockPeerStore) SetLookupResult ¶
func (m *MockPeerStore) SetLookupResult(node *node.Info, err error)
SetLookupResult sets the result ok a lookup operation
func (*MockPeerStore) SetUpdate ¶
func (m *MockPeerStore) SetUpdate(f func(n, addr *node.Info))
SetUpdate sets the function to run on an issued update
func (*MockPeerStore) Size ¶
func (m *MockPeerStore) Size() int
Size returns the size of peers in the discovery
func (*MockPeerStore) Update ¶
func (m *MockPeerStore) Update(n, src *node.Info)
Update is a discovery update operation it updates the updatecount
func (*MockPeerStore) UpdateCount ¶
func (m *MockPeerStore) UpdateCount() int
UpdateCount returns the number of times update was called
type PeerStore ¶
type PeerStore interface { Remove(pubkey p2pcrypto.PublicKey) Lookup(pubkey p2pcrypto.PublicKey) (*node.Info, error) Update(addr, src *node.Info) SelectPeers(ctx context.Context, qty int) []*node.Info Bootstrap(ctx context.Context) error Size() int Shutdown() IsLocalAddress(info *node.Info) bool SetLocalAddresses(tcp, udp int) Good(key p2pcrypto.PublicKey) Attempt(key p2pcrypto.PublicKey) }
PeerStore is an interface to the discovery protocol