multi: satisfy new lnpeer interface
This commit is contained in:
parent
77d2853d76
commit
3ab17063ff
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/lnpeer"
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing"
|
"github.com/lightningnetwork/lnd/routing"
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
@ -2159,6 +2160,9 @@ func (p *mockPeer) SendMessage(_ bool, msgs ...lnwire.Message) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (p *mockPeer) AddNewChannel(_ *lnwallet.LightningChannel, _ <-chan struct{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (p *mockPeer) WipeChannel(_ *wire.OutPoint) error { return nil }
|
func (p *mockPeer) WipeChannel(_ *wire.OutPoint) error { return nil }
|
||||||
func (p *mockPeer) IdentityKey() *btcec.PublicKey { return p.pk }
|
func (p *mockPeer) IdentityKey() *btcec.PublicKey { return p.pk }
|
||||||
func (p *mockPeer) PubKey() [33]byte {
|
func (p *mockPeer) PubKey() [33]byte {
|
||||||
@ -2166,3 +2170,4 @@ func (p *mockPeer) PubKey() [33]byte {
|
|||||||
copy(pubkey[:], p.pk.SerializeCompressed())
|
copy(pubkey[:], p.pk.SerializeCompressed())
|
||||||
return pubkey
|
return pubkey
|
||||||
}
|
}
|
||||||
|
func (p *mockPeer) Address() net.Addr { return nil }
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -1411,6 +1412,9 @@ func (m *mockPeer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (m *mockPeer) AddNewChannel(_ *lnwallet.LightningChannel, _ <-chan struct{}) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (m *mockPeer) WipeChannel(*wire.OutPoint) error {
|
func (m *mockPeer) WipeChannel(*wire.OutPoint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1420,8 +1424,9 @@ func (m *mockPeer) PubKey() [33]byte {
|
|||||||
func (m *mockPeer) IdentityKey() *btcec.PublicKey {
|
func (m *mockPeer) IdentityKey() *btcec.PublicKey {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (m *mockPeer) Address() net.Addr {
|
||||||
var _ lnpeer.Peer = (*mockPeer)(nil)
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||||
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
@ -517,6 +518,16 @@ func (s *mockServer) IdentityKey() *btcec.PublicKey {
|
|||||||
return pubkey
|
return pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *mockServer) Address() net.Addr {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *mockServer) AddNewChannel(channel *lnwallet.LightningChannel,
|
||||||
|
cancel <-chan struct{}) error {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *mockServer) WipeChannel(*wire.OutPoint) error {
|
func (s *mockServer) WipeChannel(*wire.OutPoint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
39
peer.go
39
peer.go
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -185,6 +186,9 @@ type peer struct {
|
|||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A compile-time check to ensure that peer satisfies the lnpeer.Peer interface.
|
||||||
|
var _ lnpeer.Peer = (*peer)(nil)
|
||||||
|
|
||||||
// newPeer creates a new peer from an establish connection object, and a
|
// newPeer creates a new peer from an establish connection object, and a
|
||||||
// pointer to the main server.
|
// pointer to the main server.
|
||||||
func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
func newPeer(conn net.Conn, connReq *connmgr.ConnReq, server *server,
|
||||||
@ -1999,6 +2003,41 @@ func (p *peer) IdentityKey() *btcec.PublicKey {
|
|||||||
return p.addr.IdentityKey
|
return p.addr.IdentityKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Address returns the network address of the remote peer.
|
||||||
|
func (p *peer) Address() net.Addr {
|
||||||
|
return p.addr.Address
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddNewChannel adds a new channel to the peer. The channel should fail to be
|
||||||
|
// added if the cancel channel is closed.
|
||||||
|
func (p *peer) AddNewChannel(channel *lnwallet.LightningChannel,
|
||||||
|
cancel <-chan struct{}) error {
|
||||||
|
|
||||||
|
newChanDone := make(chan struct{})
|
||||||
|
newChanMsg := &newChannelMsg{
|
||||||
|
channel: channel,
|
||||||
|
done: newChanDone,
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case p.newChannels <- newChanMsg:
|
||||||
|
case <-cancel:
|
||||||
|
return errors.New("canceled adding new channel")
|
||||||
|
case <-p.quit:
|
||||||
|
return ErrPeerExiting
|
||||||
|
}
|
||||||
|
|
||||||
|
// We pause here to wait for the peer to recognize the new channel
|
||||||
|
// before we close the channel barrier corresponding to the channel.
|
||||||
|
select {
|
||||||
|
case <-newChanDone:
|
||||||
|
case <-p.quit:
|
||||||
|
return ErrPeerExiting
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): make all start/stop mutexes a CAS
|
// TODO(roasbeef): make all start/stop mutexes a CAS
|
||||||
|
|
||||||
// fetchLastChanUpdate returns a function which is able to retrieve the last
|
// fetchLastChanUpdate returns a function which is able to retrieve the last
|
||||||
|
Loading…
Reference in New Issue
Block a user