discovery

package
v1.0.0-...-b07499f Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxUndelayedQueryReplies specifies how many gossip queries we
	// will respond to immediately before starting to delay responses.
	DefaultMaxUndelayedQueryReplies = 10

	// DefaultDelayedQueryReplyInterval is the length of time we will wait
	// before responding to gossip queries after replying to
	// maxUndelayedQueryReplies queries.
	DefaultDelayedQueryReplyInterval = 5 * time.Second
)

Variables

View Source
var (

	// ErrGossiperShuttingDown is an error that is returned if the gossiper
	// is in the process of being shut down.
	ErrGossiperShuttingDown = errors.New("gossiper is shutting down")

	// ErrGossipSyncerNotFound signals that we were unable to find an active
	// gossip syncer corresponding to a gossip query message received from
	// the remote peer.
	ErrGossipSyncerNotFound = errors.New("gossip syncer not found")
)
View Source
var (

	// ErrGossipSyncerExiting signals that the syncer has been killed.
	ErrGossipSyncerExiting = errors.New("gossip syncer exiting")
)

Functions

func CreateChanAnnouncement

CreateChanAnnouncement is a helper function which creates all channel announcements given the necessary channel related database items. This function is used to transform out database structs into the corresponding wire structs for announcing new channels to other peers, or simply syncing up a peer's initial routing table upon connect.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func MultiSourceBootstrap

func MultiSourceBootstrap(ignore map[autopilot.NodeID]struct{}, numAddrs uint32,
	bootstrappers ...NetworkPeerBootstrapper) ([]*lnwire.NetAddress, error)

MultiSourceBootstrap attempts to utilize a set of NetworkPeerBootstrapper passed in to return the target (numAddrs) number of peer addresses that can be used to bootstrap a peer just joining the Lightning Network. Each bootstrapper will be queried successively until the target amount is met. If the ignore map is populated, then the bootstrappers will be instructed to skip those nodes.

func SignAnnouncement

func SignAnnouncement(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey,
	msg lnwire.Message) (*btcec.Signature, error)

SignAnnouncement is a helper function which is used to sign any outgoing channel node node announcement messages.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type AuthenticatedGossiper

type AuthenticatedGossiper struct {
	sync.Mutex
	// contains filtered or unexported fields
}

AuthenticatedGossiper is a subsystem which is responsible for receiving announcements, validating them and applying the changes to router, syncing lightning network with newly connected nodes, broadcasting announcements after validation, negotiating the channel announcement proofs exchange and handling the premature announcements. All outgoing announcements are expected to be properly signed as dictated in BOLT#7, additionally, all incoming message are expected to be well formed and signed. Invalid messages will be rejected by this struct.

func New

func New(cfg Config, selfKey *btcec.PublicKey) (*AuthenticatedGossiper, error)

New creates a new AuthenticatedGossiper instance, initialized with the passed configuration parameters.

func (*AuthenticatedGossiper) InitSyncState

func (d *AuthenticatedGossiper) InitSyncState(syncPeer lnpeer.Peer,
	recvUpdates bool)

InitSyncState is called by outside sub-systems when a connection is established to a new peer that understands how to perform channel range queries. We'll allocate a new gossip syncer for it, and start any goroutines needed to handle new queries. The recvUpdates bool indicates if we should continue to receive real-time updates from the remote peer once we've synced channel state.

func (*AuthenticatedGossiper) ProcessLocalAnnouncement

func (d *AuthenticatedGossiper) ProcessLocalAnnouncement(msg lnwire.Message,
	source *btcec.PublicKey) chan error

ProcessLocalAnnouncement sends a new remote announcement message along with the peer that sent the routing message. The announcement will be processed then added to a queue for batched trickled announcement to all connected peers. Local channel announcements don't contain the announcement proof and will not be fully validated. Once the channel proofs are received, the entire channel announcement and update messages will be re-constructed and broadcast to the rest of the network.

func (*AuthenticatedGossiper) ProcessRemoteAnnouncement

func (d *AuthenticatedGossiper) ProcessRemoteAnnouncement(msg lnwire.Message,
	peer lnpeer.Peer) chan error

ProcessRemoteAnnouncement sends a new remote announcement message along with the peer that sent the routing message. The announcement will be processed then added to a queue for batched trickled announcement to all connected peers. Remote channel announcements should contain the announcement proof and be fully validated.

func (*AuthenticatedGossiper) PropagateChanPolicyUpdate

func (d *AuthenticatedGossiper) PropagateChanPolicyUpdate(
	newSchema routing.ChannelPolicy, chanPoints ...wire.OutPoint) error

PropagateChanPolicyUpdate signals the AuthenticatedGossiper to update the channel forwarding policies for the specified channels. If no channels are specified, then the update will be applied to all outgoing channels from the source node. Policy updates are done in two stages: first, the AuthenticatedGossiper ensures the update has been committed by dependent sub-systems, then it signs and broadcasts new updates to the network.

func (*AuthenticatedGossiper) PruneSyncState

func (d *AuthenticatedGossiper) PruneSyncState(peer *btcec.PublicKey)

PruneSyncState is called by outside sub-systems once a peer that we were previously connected to has been disconnected. In this case we can stop the existing gossipSyncer assigned to the peer and free up resources.

func (*AuthenticatedGossiper) Start

func (d *AuthenticatedGossiper) Start() error

Start spawns network messages handler goroutine and registers on new block notifications in order to properly handle the premature announcements.

func (*AuthenticatedGossiper) Stop

func (d *AuthenticatedGossiper) Stop()

Stop signals any active goroutines for a graceful closure.

func (*AuthenticatedGossiper) SynchronizeNode

func (d *AuthenticatedGossiper) SynchronizeNode(syncPeer lnpeer.Peer) error

SynchronizeNode sends a message to the service indicating it should synchronize lightning topology state with the target node. This method is to be utilized when a node connections for the first time to provide it with the latest topology update state. In order to accomplish this, (currently) the entire network graph is read from disk, then serialized to the format defined within the current wire protocol. This cache of graph data is then sent directly to the target node.

type ChannelGraphBootstrapper

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

ChannelGraphBootstrapper is an implementation of the NetworkPeerBootstrapper which attempts to retrieve advertised peers directly from the active channel graph. This instance requires a backing autopilot.ChannelGraph instance in order to operate properly.

func (*ChannelGraphBootstrapper) Name

func (c *ChannelGraphBootstrapper) Name() string

Name returns a human readable string which names the concrete implementation of the NetworkPeerBootstrapper.

NOTE: Part of the NetworkPeerBootstrapper interface.

func (*ChannelGraphBootstrapper) SampleNodeAddrs

func (c *ChannelGraphBootstrapper) SampleNodeAddrs(numAddrs uint32,
	ignore map[autopilot.NodeID]struct{}) ([]*lnwire.NetAddress, error)

SampleNodeAddrs uniformly samples a set of specified address from the network peer bootstrapper source. The num addrs field passed in denotes how many valid peer addresses to return.

NOTE: Part of the NetworkPeerBootstrapper interface.

type ChannelGraphTimeSeries

type ChannelGraphTimeSeries interface {
	// HighestChanID should return the channel ID of the channel we know of
	// that's furthest in the target chain. This channel will have a block
	// height that's close to the current tip of the main chain as we
	// know it.  We'll use this to start our QueryChannelRange dance with
	// the remote node.
	HighestChanID(chain chainhash.Hash) (*lnwire.ShortChannelID, error)

	// UpdatesInHorizon returns all known channel and node updates with an
	// update timestamp between the start time and end time. We'll use this
	// to catch up a remote node to the set of channel updates that they
	// may have missed out on within the target chain.
	UpdatesInHorizon(chain chainhash.Hash,
		startTime time.Time, endTime time.Time) ([]lnwire.Message, error)

	// FilterKnownChanIDs takes a target chain, and a set of channel ID's,
	// and returns a filtered set of chan ID's. This filtered set of chan
	// ID's represents the ID's that we don't know of which were in the
	// passed superSet.
	FilterKnownChanIDs(chain chainhash.Hash,
		superSet []lnwire.ShortChannelID) ([]lnwire.ShortChannelID, error)

	// FilterChannelRange returns the set of channels that we created
	// between the start height and the end height. We'll use this to to a
	// remote peer's QueryChannelRange message.
	FilterChannelRange(chain chainhash.Hash,
		startHeight, endHeight uint32) ([]lnwire.ShortChannelID, error)

	// FetchChanAnns returns a full set of channel announcements as well as
	// their updates that match the set of specified short channel ID's.
	// We'll use this to reply to a QueryShortChanIDs message sent by a
	// remote peer. The response will contain a unique set of
	// ChannelAnnouncements, the latest ChannelUpdate for each of the
	// announcements, and a unique set of NodeAnnouncements.
	FetchChanAnns(chain chainhash.Hash,
		shortChanIDs []lnwire.ShortChannelID) ([]lnwire.Message, error)

	// FetchChanUpdates returns the latest channel update messages for the
	// specified short channel ID. If no channel updates are known for the
	// channel, then an empty slice will be returned.
	FetchChanUpdates(chain chainhash.Hash,
		shortChanID lnwire.ShortChannelID) ([]*lnwire.ChannelUpdate, error)
}

ChannelGraphTimeSeries is an interface that provides time and block based querying into our view of the channel graph. New channels will have monotonically increasing block heights, and new channel updates will have increasing timestamps. Once we connect to a peer, we'll use the methods in this interface to determine if we're already in sync, or need to request some new information from them.

type Config

type Config struct {
	// ChainHash is a hash that indicates which resident chain of the
	// AuthenticatedGossiper. Any announcements that don't match this
	// chain hash will be ignored.
	//
	// TODO(roasbeef): eventually make into map so can de-multiplex
	// incoming announcements
	//   * also need to do same for Notifier
	ChainHash chainhash.Hash

	// Router is the subsystem which is responsible for managing the
	// topology of lightning network. After incoming channel, node, channel
	// updates announcements are validated they are sent to the router in
	// order to be included in the LN graph.
	Router routing.ChannelGraphSource

	// ChanSeries is an interfaces that provides access to a time series
	// view of the current known channel graph. Each gossipSyncer enabled
	// peer will utilize this in order to create and respond to channel
	// graph time series queries.
	ChanSeries ChannelGraphTimeSeries

	// Notifier is used for receiving notifications of incoming blocks.
	// With each new incoming block found we process previously premature
	// announcements.
	//
	// TODO(roasbeef): could possibly just replace this with an epoch
	// channel.
	Notifier chainntnfs.ChainNotifier

	// Broadcast broadcasts a particular set of announcements to all peers
	// that the daemon is connected to. If supplied, the exclude parameter
	// indicates that the target peer should be excluded from the
	// broadcast.
	Broadcast func(skips map[routing.Vertex]struct{},
		msg ...lnwire.Message) error

	// SendToPeer is a function which allows the service to send a set of
	// messages to a particular peer identified by the target public key.
	SendToPeer func(target *btcec.PublicKey, msg ...lnwire.Message) error

	// FindPeer returns the actively registered peer for a given remote
	// public key. An error is returned if the peer was not found or a
	// shutdown has been requested.
	FindPeer func(identityKey *btcec.PublicKey) (lnpeer.Peer, error)

	// NotifyWhenOnline is a function that allows the gossiper to be
	// notified when a certain peer comes online, allowing it to
	// retry sending a peer message.
	//
	// NOTE: The peerChan channel must be buffered.
	NotifyWhenOnline func(peer *btcec.PublicKey, peerChan chan<- lnpeer.Peer)

	// ProofMatureDelta the number of confirmations which is needed before
	// exchange the channel announcement proofs.
	ProofMatureDelta uint32

	// TrickleDelay the period of trickle timer which flushes to the
	// network the pending batch of new announcements we've received since
	// the last trickle tick.
	TrickleDelay time.Duration

	// RetransmitDelay is the period of a timer which indicates that we
	// should check if we need re-broadcast any of our personal channels.
	RetransmitDelay time.Duration

	// DB is a global boltdb instance which is needed to pass it in waiting
	// proof storage to make waiting proofs persistent.
	DB *channeldb.DB

	// AnnSigner is an instance of the MessageSigner interface which will
	// be used to manually sign any outgoing channel updates. The signer
	// implementation should be backed by the public key of the backing
	// Lightning node.
	//
	// TODO(roasbeef): extract ann crafting + sign from fundingMgr into
	// here?
	AnnSigner lnwallet.MessageSigner
}

Config defines the configuration for the service. ALL elements within the configuration MUST be non-nil for the service to carry out its duties.

type DNSSeedBootstrapper

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

DNSSeedBootstrapper as an implementation of the NetworkPeerBootstrapper interface which implements peer bootstrapping via a special DNS seed as defined in BOLT-0010. For further details concerning Lightning's current DNS boot strapping protocol, see this link:

func (*DNSSeedBootstrapper) Name

func (d *DNSSeedBootstrapper) Name() string

Name returns a human readable string which names the concrete implementation of the NetworkPeerBootstrapper.

func (*DNSSeedBootstrapper) SampleNodeAddrs

func (d *DNSSeedBootstrapper) SampleNodeAddrs(numAddrs uint32,
	ignore map[autopilot.NodeID]struct{}) ([]*lnwire.NetAddress, error)

SampleNodeAddrs uniformly samples a set of specified address from the network peer bootstrapper source. The num addrs field passed in denotes how many valid peer addresses to return. The set of DNS seeds are used successively to retrieve eligible target nodes.

type NetworkPeerBootstrapper

type NetworkPeerBootstrapper interface {
	// SampleNodeAddrs uniformly samples a set of specified address from
	// the network peer bootstrapper source. The num addrs field passed in
	// denotes how many valid peer addresses to return. The passed set of
	// node nodes allows the caller to ignore a set of nodes perhaps
	// because they already have connections established.
	SampleNodeAddrs(numAddrs uint32,
		ignore map[autopilot.NodeID]struct{}) ([]*lnwire.NetAddress, error)

	// Name returns a human readable string which names the concrete
	// implementation of the NetworkPeerBootstrapper.
	Name() string
}

NetworkPeerBootstrapper is an interface that represents an initial peer bootstrap mechanism. This interface is to be used to bootstrap a new peer to the connection by providing it with the pubkey+address of a set of existing peers on the network. Several bootstrap mechanisms can be implemented such as DNS, in channel graph, DHT's, etc.

func NewDNSSeedBootstrapper

func NewDNSSeedBootstrapper(seeds [][2]string, net tor.Net) NetworkPeerBootstrapper

NewDNSSeedBootstrapper returns a new instance of the DNSSeedBootstrapper. The set of passed seeds should point to DNS servers that properly implement Lightning's DNS peer bootstrapping protocol as defined in BOLT-0010. The set of passed DNS seeds should come in pairs, with the second host name to be used as a fallback for manual TCP resolution in the case of an error receiving the UDP response. The second host should return a single A record with the IP address of the authoritative name server.

func NewGraphBootstrapper

func NewGraphBootstrapper(cg autopilot.ChannelGraph) (NetworkPeerBootstrapper, error)

NewGraphBootstrapper returns a new instance of a ChannelGraphBootstrapper backed by an active autopilot.ChannelGraph instance. This type of network peer bootstrapper will use the authenticated nodes within the known channel graph to bootstrap connections.

Jump to

Keyboard shortcuts

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