peer: add SendMessageLazy
This commit is contained in:
parent
660bbaf646
commit
f39edd8000
@ -35,6 +35,11 @@ func (p *mockPeer) SendMessage(_ bool, msgs ...lnwire.Message) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *mockPeer) SendMessageLazy(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
return p.SendMessage(sync, msgs...)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *mockPeer) AddNewChannel(_ *channeldb.OpenChannel, _ <-chan struct{}) error {
|
func (p *mockPeer) AddNewChannel(_ *channeldb.OpenChannel, _ <-chan struct{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,10 @@ func (n *testNode) SendMessage(_ bool, msg ...lnwire.Message) error {
|
|||||||
return n.sendMessage(msg[0])
|
return n.sendMessage(msg[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *testNode) SendMessageLazy(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
return n.SendMessage(sync, msgs...)
|
||||||
|
}
|
||||||
|
|
||||||
func (n *testNode) WipeChannel(_ *wire.OutPoint) error {
|
func (n *testNode) WipeChannel(_ *wire.OutPoint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1549,6 +1549,9 @@ func (m *mockPeer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (m *mockPeer) SendMessageLazy(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
return m.SendMessage(sync, msgs...)
|
||||||
|
}
|
||||||
func (m *mockPeer) AddNewChannel(_ *channeldb.OpenChannel,
|
func (m *mockPeer) AddNewChannel(_ *channeldb.OpenChannel,
|
||||||
_ <-chan struct{}) error {
|
_ <-chan struct{}) error {
|
||||||
return nil
|
return nil
|
||||||
|
@ -502,6 +502,10 @@ func (s *mockServer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *mockServer) SendMessageLazy(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
panic("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *mockServer) readHandler(message lnwire.Message) error {
|
func (s *mockServer) readHandler(message lnwire.Message) error {
|
||||||
var targetChan lnwire.ChannelID
|
var targetChan lnwire.ChannelID
|
||||||
|
|
||||||
|
@ -12,10 +12,17 @@ import (
|
|||||||
// Peer is an interface which represents the remote lightning node inside our
|
// Peer is an interface which represents the remote lightning node inside our
|
||||||
// system.
|
// system.
|
||||||
type Peer interface {
|
type Peer interface {
|
||||||
// SendMessage sends a variadic number of message to remote peer. The
|
// SendMessage sends a variadic number of high-priority message to
|
||||||
// first argument denotes if the method should block until the message
|
// remote peer. The first argument denotes if the method should block
|
||||||
// has been sent to the remote peer.
|
// until the messages have been sent to the remote peer or an error is
|
||||||
SendMessage(sync bool, msg ...lnwire.Message) error
|
// returned, otherwise it returns immediately after queuing.
|
||||||
|
SendMessage(sync bool, msgs ...lnwire.Message) error
|
||||||
|
|
||||||
|
// SendMessageLazy sends a variadic number of low-priority message to
|
||||||
|
// remote peer. The first argument denotes if the method should block
|
||||||
|
// until the messages have been sent to the remote peer or an error is
|
||||||
|
// returned, otherwise it returns immediately after queueing.
|
||||||
|
SendMessageLazy(sync bool, msgs ...lnwire.Message) error
|
||||||
|
|
||||||
// AddNewChannel adds a new channel to the peer. The channel should fail
|
// AddNewChannel adds a new channel to the peer. The channel should fail
|
||||||
// to be added if the cancel channel is closed.
|
// to be added if the cancel channel is closed.
|
||||||
|
31
peer.go
31
peer.go
@ -2351,12 +2351,31 @@ func (p *peer) resendChanSyncMsg(cid lnwire.ChannelID) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMessage sends a variadic number of message to remote peer. The first
|
// SendMessage sends a variadic number of high-priority message to remote peer.
|
||||||
// argument denotes if the method should block until the message has been sent
|
// The first argument denotes if the method should block until the messages have
|
||||||
// to the remote peer.
|
// been sent to the remote peer or an error is returned, otherwise it returns
|
||||||
|
// immediately after queuing.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the lnpeer.Peer interface.
|
// NOTE: Part of the lnpeer.Peer interface.
|
||||||
func (p *peer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
func (p *peer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
return p.sendMessage(sync, true, msgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendMessageLazy sends a variadic number of low-priority message to remote
|
||||||
|
// peer. The first argument denotes if the method should block until the
|
||||||
|
// messages have been sent to the remote peer or an error is returned, otherwise
|
||||||
|
// it returns immediately after queueing.
|
||||||
|
//
|
||||||
|
// NOTE: Part of the lnpeer.Peer interface.
|
||||||
|
func (p *peer) SendMessageLazy(sync bool, msgs ...lnwire.Message) error {
|
||||||
|
return p.sendMessage(sync, false, msgs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sendMessage queues a variadic number of messages using the passed priority
|
||||||
|
// to the remote peer. If sync is true, this method will block until the
|
||||||
|
// messages have been sent to the remote peer or an error is returned, otherwise
|
||||||
|
// it returns immediately after queueing.
|
||||||
|
func (p *peer) sendMessage(sync, priority bool, msgs ...lnwire.Message) error {
|
||||||
// Add all incoming messages to the outgoing queue. A list of error
|
// Add all incoming messages to the outgoing queue. A list of error
|
||||||
// chans is populated for each message if the caller requested a sync
|
// chans is populated for each message if the caller requested a sync
|
||||||
// send.
|
// send.
|
||||||
@ -2370,7 +2389,11 @@ func (p *peer) SendMessage(sync bool, msgs ...lnwire.Message) error {
|
|||||||
errChans = append(errChans, errChan)
|
errChans = append(errChans, errChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.queueMsg(msg, errChan)
|
if priority {
|
||||||
|
p.queueMsg(msg, errChan)
|
||||||
|
} else {
|
||||||
|
p.queueMsgLazy(msg, errChan)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for all replies from the writeHandler. For async sends, this
|
// Wait for all replies from the writeHandler. For async sends, this
|
||||||
|
Loading…
Reference in New Issue
Block a user