Skip to content

Commit 2234cc8

Browse files
committed
authmailbox: add MultiSubscriptionConfig for future extensibility
Introduce MultiSubscriptionConfig to prepare for future extensions with additional config fields.
1 parent c19e739 commit 2234cc8

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

authmailbox/client_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ func TestServerClientAuthAndRestart(t *testing.T) {
157157

158158
// We also add a multi-subscription to the same two keys, so we can make
159159
// sure we can receive messages from multiple clients at once.
160-
multiSub := NewMultiSubscription(*clientCfg)
160+
multiSub := NewMultiSubscription(MultiSubscriptionConfig{
161+
BaseClientConfig: *clientCfg,
162+
})
161163
err := multiSub.Subscribe(
162164
ctx, url.URL{Host: clientCfg.ServerAddress}, clientKey1, filter,
163165
)

authmailbox/multi_subscription.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ type clientSubscriptions struct {
3131
// mailbox servers. It manages subscriptions and message queues for each client
3232
// and provides a unified interface for receiving messages.
3333
type MultiSubscription struct {
34-
// baseClientConfig holds the basic configuration for the mailbox
35-
// clients. All fields except the ServerAddress are used to create
36-
// new mailbox clients when needed.
37-
baseClientConfig ClientConfig
34+
// cfg holds the configuration for the MultiSubscription instance.
35+
cfg MultiSubscriptionConfig
3836

3937
// clients holds the active mailbox clients, keyed by their server URL.
4038
clients map[url.URL]*clientSubscriptions
@@ -48,15 +46,24 @@ type MultiSubscription struct {
4846
sync.RWMutex
4947
}
5048

49+
// MultiSubscriptionConfig holds the configuration parameters for creating a
50+
// MultiSubscription instance.
51+
type MultiSubscriptionConfig struct {
52+
// baseClientConfig holds the basic configuration for the mailbox
53+
// clients. All fields except the ServerAddress are used to create
54+
// new mailbox clients when needed.
55+
BaseClientConfig ClientConfig
56+
}
57+
5158
// NewMultiSubscription creates a new MultiSubscription instance.
52-
func NewMultiSubscription(baseClientConfig ClientConfig) *MultiSubscription {
59+
func NewMultiSubscription(cfg MultiSubscriptionConfig) *MultiSubscription {
5360
queue := lfn.NewConcurrentQueue[*ReceivedMessages](lfn.DefaultQueueSize)
5461
queue.Start()
5562

5663
return &MultiSubscription{
57-
baseClientConfig: baseClientConfig,
58-
clients: make(map[url.URL]*clientSubscriptions),
59-
msgQueue: queue,
64+
cfg: cfg,
65+
clients: make(map[url.URL]*clientSubscriptions),
66+
msgQueue: queue,
6067
}
6168
}
6269

@@ -69,7 +76,7 @@ func (m *MultiSubscription) Subscribe(ctx context.Context, serverURL url.URL,
6976

7077
// We hold the mutex for access to common resources.
7178
m.Lock()
72-
cfgCopy := m.baseClientConfig
79+
cfgCopy := m.cfg.BaseClientConfig
7380
client, ok := m.clients[serverURL]
7481

7582
// If this is the first time we're seeing a server URL, we first create

tapgarden/custodian.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ func NewCustodian(cfg *CustodianConfig) *Custodian {
235235
statusEventsSubs: statusEventsSubs,
236236
events: make(map[wire.OutPoint]*address.Event),
237237
mboxSubscriptions: mbox.NewMultiSubscription(
238-
mbox.ClientConfig{
239-
Insecure: cfg.MboxInsecure,
240-
SkipTlsVerify: !cfg.MboxInsecure,
241-
Signer: cfg.Signer,
242-
MinBackoff: backoffCfg.InitialBackoff,
243-
MaxBackoff: backoffCfg.MaxBackoff,
238+
mbox.MultiSubscriptionConfig{
239+
BaseClientConfig: mbox.ClientConfig{
240+
Insecure: cfg.MboxInsecure,
241+
SkipTlsVerify: !cfg.MboxInsecure,
242+
243+
Signer: cfg.Signer,
244+
MinBackoff: backoffCfg.InitialBackoff,
245+
MaxBackoff: backoffCfg.MaxBackoff,
246+
},
244247
},
245248
),
246249
ContextGuard: &fn.ContextGuard{

0 commit comments

Comments
 (0)