Skip to content

Commit ef93611

Browse files
committed
firewalldb: thread contexts to FetchAllPairs
Update the FetchAllPairs method of the PrivacyMapTx interface to take a context.
1 parent 5b31f16 commit ef93611

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

firewall/privacy_mapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,8 +1151,8 @@ func (m *mockPrivacyMapDB) RealToPseudo(_ context.Context, real string) (string,
11511151
return p, nil
11521152
}
11531153

1154-
func (m *mockPrivacyMapDB) FetchAllPairs() (*firewalldb.PrivacyMapPairs,
1155-
error) {
1154+
func (m *mockPrivacyMapDB) FetchAllPairs(_ context.Context) (
1155+
*firewalldb.PrivacyMapPairs, error) {
11561156

11571157
return firewalldb.NewPrivacyMapPairs(m.r2p), nil
11581158
}

firewalldb/privacy_mapper.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type PrivacyMapTx interface {
8383

8484
// FetchAllPairs loads and returns the real-to-pseudo pairs in the form
8585
// of a PrivacyMapPairs struct.
86-
FetchAllPairs() (*PrivacyMapPairs, error)
86+
FetchAllPairs(ctx context.Context) (*PrivacyMapPairs, error)
8787
}
8888

8989
// privacyMapDB is an implementation of PrivacyMapDB.
@@ -287,7 +287,9 @@ func (p *privacyMapTx) RealToPseudo(_ context.Context, real string) (string,
287287
// FetchAllPairs loads and returns the real-to-pseudo pairs.
288288
//
289289
// NOTE: this is part of the PrivacyMapTx interface.
290-
func (p *privacyMapTx) FetchAllPairs() (*PrivacyMapPairs, error) {
290+
func (p *privacyMapTx) FetchAllPairs(_ context.Context) (*PrivacyMapPairs,
291+
error) {
292+
291293
privacyBucket, err := getBucket(p.boltTx, privacyBucketKey)
292294
if err != nil {
293295
return nil, err

firewalldb/privacy_mapper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestPrivacyMapStorage(t *testing.T) {
4040
require.NoError(t, err)
4141
require.Equal(t, "real", real)
4242

43-
pairs, err := tx.FetchAllPairs()
43+
pairs, err := tx.FetchAllPairs(ctx)
4444
require.NoError(t, err)
4545

4646
require.EqualValues(t, pairs.pairs, map[string]string{
@@ -70,7 +70,7 @@ func TestPrivacyMapStorage(t *testing.T) {
7070
require.NoError(t, err)
7171
require.Equal(t, "real 2", real)
7272

73-
pairs, err := tx.FetchAllPairs()
73+
pairs, err := tx.FetchAllPairs(ctx)
7474
require.NoError(t, err)
7575

7676
require.EqualValues(t, pairs.pairs, map[string]string{
@@ -85,7 +85,7 @@ func TestPrivacyMapStorage(t *testing.T) {
8585
_ = pdb3.Update(ctx, func(ctx context.Context, tx PrivacyMapTx) error {
8686
// Check that calling FetchAllPairs returns an empty map if
8787
// nothing exists in the DB yet.
88-
m, err := tx.FetchAllPairs()
88+
m, err := tx.FetchAllPairs(ctx)
8989
require.NoError(t, err)
9090
require.Empty(t, m.pairs)
9191

@@ -116,7 +116,7 @@ func TestPrivacyMapStorage(t *testing.T) {
116116
require.NoError(t, err)
117117

118118
// Check that FetchAllPairs correctly returns all the pairs.
119-
pairs, err := tx.FetchAllPairs()
119+
pairs, err := tx.FetchAllPairs(ctx)
120120
require.NoError(t, err)
121121

122122
require.EqualValues(t, pairs.pairs, map[string]string{

session_rpcserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,10 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
901901
linkedGroupSession = groupSess
902902

903903
privDB := s.cfg.privMap(groupID)
904-
err = privDB.View(ctx, func(_ context.Context,
904+
err = privDB.View(ctx, func(ctx context.Context,
905905
tx firewalldb.PrivacyMapTx) error {
906906

907-
knownPrivMapPairs, err = tx.FetchAllPairs()
907+
knownPrivMapPairs, err = tx.FetchAllPairs(ctx)
908908

909909
return err
910910
})

0 commit comments

Comments
 (0)