diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index cbf36f96a..8ca1d634d 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -57,8 +57,17 @@ type ChannelLink interface { // short channel ID encodes the exact location in the main chain that // the original funding output can be found. ShortChanID() lnwire.ShortChannelID + + // UpdateForwardingPolicy updates the forwarding policy for the target + // ChannelLink. Once updated, the link will use the new forwarding + // policy to govern if it an incoming HTLC should be forwarded or not. + UpdateForwardingPolicy(ForwardingPolicy) + // Bandwidth returns the amount of satoshis which current link might - // pass through channel link. + // pass through channel link. The value returned from this method + // represents the up to date available flow through the channel. This + // takes into account any forwarded but un-cleared HTLC's, and any + // HTLC's which have been set to the over flow queue. Bandwidth() btcutil.Amount // Stats return the statistics of channel link. Number of updates, diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 99a435c5f..5b1c594f2 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -740,6 +740,36 @@ func (l *channelLink) getBandwidth() btcutil.Amount { return l.channel.LocalAvailableBalance() - l.overflowQueue.pendingAmount() } +// policyUpdate is a message sent to a channel link when an outside sub-system +// wishes to update the current forwarding policy. +type policyUpdate struct { + policy ForwardingPolicy + + done chan struct{} +} + +// UpdateForwardingPolicy updates the forwarding policy for the target +// ChannelLink. Once updated, the link will use the new forwarding policy to +// govern if it an incoming HTLC should be forwarded or not. +// +// NOTE: Part of the ChannelLink interface. +func (l *channelLink) UpdateForwardingPolicy(newPolicy ForwardingPolicy) { + cmd := &policyUpdate{ + policy: newPolicy, + done: make(chan struct{}), + } + + select { + case l.linkControl <- cmd: + case <-l.quit: + } + + select { + case <-cmd.done: + case <-l.quit: + } +} + // Stats returns the statistics of channel link. // // NOTE: Part of the ChannelLink interface.