From f53a99e18efca3f859a41a850d50b7bfd7278a14 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 4 Apr 2018 17:36:38 -0700 Subject: [PATCH] htlcswitch: modify the SendMessage method on the Peer interface to optionally block In this commit, add a new argument to the SendMessage method to allow callers to request that the method block until the message has been sent on the socket to the remote peer. --- htlcswitch/interfaces.go | 7 +++++-- htlcswitch/link_test.go | 2 +- htlcswitch/mock.go | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/htlcswitch/interfaces.go b/htlcswitch/interfaces.go index 51a5146e..8086624a 100644 --- a/htlcswitch/interfaces.go +++ b/htlcswitch/interfaces.go @@ -111,8 +111,11 @@ type ChannelLink interface { // Peer is an interface which represents the remote lightning node inside our // system. type Peer interface { - // SendMessage sends message to remote peer. - SendMessage(lnwire.Message) error + // SendMessage sends message to remote peer. The second arguments + // denote if the method should block until the message has been sent to + // the remote peer. If set, this allows the caller to more strongly + // synchronize. + SendMessage(msg lnwire.Message, sync bool) error // WipeChannel removes the channel uniquely identified by its channel // point from all indexes associated with the peer. diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index 84f20953..95f11d0f 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -1392,7 +1392,7 @@ type mockPeer struct { quit chan struct{} } -func (m *mockPeer) SendMessage(msg lnwire.Message) error { +func (m *mockPeer) SendMessage(msg lnwire.Message, sync bool) error { select { case m.sentMsgs <- msg: case <-m.quit: diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 658b636e..42c1843c 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -447,7 +447,7 @@ func (s *mockServer) intersect(f messageInterceptor) { s.interceptorFuncs = append(s.interceptorFuncs, f) } -func (s *mockServer) SendMessage(message lnwire.Message) error { +func (s *mockServer) SendMessage(message lnwire.Message, sync bool) error { select { case s.messages <- message: