@@ -11,6 +11,7 @@ import (
1111 "time"
1212
1313 "github.com/btcsuite/btcd/btcec/v2"
14+ "github.com/davecgh/go-spew/spew"
1415 "github.com/lightninglabs/lightning-node-connect/hashmailrpc"
1516 "github.com/lightninglabs/taproot-assets/asset"
1617 "github.com/lightninglabs/taproot-assets/fn"
@@ -66,6 +67,9 @@ type Courier interface {
6667 // SetSubscribers sets the set of subscribers that will be notified
6768 // of proof courier related events.
6869 SetSubscribers (map [uint64 ]* fn.EventReceiver [fn.Event ])
70+
71+ // Close stops the courier instance.
72+ Close () error
6973}
7074
7175// CourierAddr is a fully validated courier address (including protocol specific
@@ -223,6 +227,7 @@ func (h *UniverseRpcCourierAddr) NewCourier(_ context.Context,
223227 backoffHandle : backoffHandle ,
224228 transfer : cfg .TransferLog ,
225229 subscribers : subscribers ,
230+ rawConn : conn ,
226231 }, nil
227232}
228233
@@ -291,11 +296,16 @@ type ProofMailbox interface {
291296 // CleanUp attempts to tear down the mailbox as specified by the passed
292297 // sid.
293298 CleanUp (ctx context.Context , sid streamID ) error
299+
300+ // Close closes the underlying connection to the hashmail server.
301+ Close () error
294302}
295303
296304// HashMailBox is an implementation of the ProofMailbox interface backed by the
297305// hashmailrpc.HashMailClient.
298306type HashMailBox struct {
307+ rawConn * grpc.ClientConn
308+
299309 client hashmailrpc.HashMailClient
300310}
301311
@@ -341,7 +351,8 @@ func NewHashMailBox(courierAddr *url.URL) (*HashMailBox,
341351 client := hashmailrpc .NewHashMailClient (conn )
342352
343353 return & HashMailBox {
344- client : client ,
354+ client : client ,
355+ rawConn : conn ,
345356 }, nil
346357}
347358
@@ -480,6 +491,11 @@ func (h *HashMailBox) CleanUp(ctx context.Context, sid streamID) error {
480491 return err
481492}
482493
494+ // Close closes the underlying connection to the hashmail server.
495+ func (h * HashMailBox ) Close () error {
496+ return h .rawConn .Close ()
497+ }
498+
483499// A compile-time assertion to ensure that the HashMailBox meets the
484500// ProofMailbox interface.
485501var _ ProofMailbox = (* HashMailBox )(nil )
@@ -853,6 +869,8 @@ func (h *HashMailCourier) DeliverProof(ctx context.Context,
853869
854870 log .Infof ("Received ACK from receiver! Cleaning up mailboxes..." )
855871
872+ defer h .Close ()
873+
856874 // Once we receive this ACK, we can clean up our mailbox and also the
857875 // receiver's mailbox.
858876 if err := h .mailbox .CleanUp (ctx , senderStreamID ); err != nil {
@@ -928,6 +946,17 @@ func (h *HashMailCourier) publishSubscriberEvent(event fn.Event) {
928946 }
929947}
930948
949+ // Close closes the underlying connection to the hashmail server.
950+ func (h * HashMailCourier ) Close () error {
951+ if err := h .mailbox .Close (); err != nil {
952+ log .Warnf ("unable to close mailbox session, " +
953+ "recipient=%v: %v" , err , spew .Sdump (h .recipient ))
954+ return err
955+ }
956+
957+ return nil
958+ }
959+
931960// BackoffWaitEvent is an event that is sent to a subscriber each time we
932961// wait via the Backoff procedure before retrying to deliver a proof to the
933962// receiver.
@@ -1030,6 +1059,10 @@ type UniverseRpcCourier struct {
10301059 // the universe RPC server.
10311060 client unirpc.UniverseClient
10321061
1062+ // rawConn is the raw connection that the courier will use to interact
1063+ // with the remote gRPC service.
1064+ rawConn * grpc.ClientConn
1065+
10331066 // backoffHandle is a handle to the backoff procedure used in proof
10341067 // delivery.
10351068 backoffHandle * BackoffHandler
@@ -1297,6 +1330,11 @@ func (c *UniverseRpcCourier) publishSubscriberEvent(event fn.Event) {
12971330 }
12981331}
12991332
1333+ // Close closes the courier's connection to the remote gRPC service.
1334+ func (c * UniverseRpcCourier ) Close () error {
1335+ return c .rawConn .Close ()
1336+ }
1337+
13001338// A compile-time assertion to ensure the UniverseRpcCourier meets the
13011339// proof.Courier interface.
13021340var _ Courier = (* UniverseRpcCourier )(nil )
0 commit comments