Skip to content

Commit 5b31f16

Browse files
committed
firewalldb: thread context to RealToPseudo
Update the RealToPseudo method of the PrivacyMapTx interface to take a context.
1 parent 7e8e4a9 commit 5b31f16

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

firewall/privacy_mapper_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,9 @@ func (m *mockPrivacyMapDB) PseudoToReal(_ context.Context, pseudo string) (
11401140
return r, nil
11411141
}
11421142

1143-
func (m *mockPrivacyMapDB) RealToPseudo(real string) (string, error) {
1143+
func (m *mockPrivacyMapDB) RealToPseudo(_ context.Context, real string) (string,
1144+
error) {
1145+
11441146
p, ok := m.r2p[real]
11451147
if !ok {
11461148
return "", firewalldb.ErrNoSuchKeyFound

firewalldb/privacy_mapper.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type PrivacyMapTx interface {
7979

8080
// RealToPseudo returns the pseudo value associated with the given real
8181
// value. If no such pair is found, then ErrNoSuchKeyFound is returned.
82-
RealToPseudo(real string) (string, error)
82+
RealToPseudo(ctx context.Context, real string) (string, error)
8383

8484
// FetchAllPairs loads and returns the real-to-pseudo pairs in the form
8585
// of a PrivacyMapPairs struct.
@@ -258,7 +258,9 @@ func (p *privacyMapTx) PseudoToReal(_ context.Context, pseudo string) (string,
258258
// it does then the pseudo value is returned, else an error is returned.
259259
//
260260
// NOTE: this is part of the PrivacyMapTx interface.
261-
func (p *privacyMapTx) RealToPseudo(real string) (string, error) {
261+
func (p *privacyMapTx) RealToPseudo(_ context.Context, real string) (string,
262+
error) {
263+
262264
privacyBucket, err := getBucket(p.boltTx, privacyBucketKey)
263265
if err != nil {
264266
return "", err
@@ -319,7 +321,7 @@ func (p *privacyMapTx) FetchAllPairs() (*PrivacyMapPairs, error) {
319321
func HideString(ctx context.Context, tx PrivacyMapTx, real string) (string,
320322
error) {
321323

322-
pseudo, err := tx.RealToPseudo(real)
324+
pseudo, err := tx.RealToPseudo(ctx, real)
323325
if err != nil && err != ErrNoSuchKeyFound {
324326
return "", err
325327
}
@@ -370,7 +372,7 @@ func HideUint64(ctx context.Context, tx PrivacyMapTx, real uint64) (uint64,
370372
error) {
371373

372374
str := Uint64ToStr(real)
373-
pseudo, err := tx.RealToPseudo(str)
375+
pseudo, err := tx.RealToPseudo(ctx, str)
374376
if err != nil && err != ErrNoSuchKeyFound {
375377
return 0, err
376378
}
@@ -405,7 +407,7 @@ func HideChanPoint(ctx context.Context, tx PrivacyMapTx, txid string,
405407
index uint32) (string, uint32, error) {
406408

407409
cp := fmt.Sprintf("%s:%d", txid, index)
408-
pseudo, err := tx.RealToPseudo(cp)
410+
pseudo, err := tx.RealToPseudo(ctx, cp)
409411
if err != nil && err != ErrNoSuchKeyFound {
410412
return "", 0, err
411413
}

firewalldb/privacy_mapper_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestPrivacyMapStorage(t *testing.T) {
2323
pdb1 := db.PrivacyDB([4]byte{1, 1, 1, 1})
2424

2525
_ = pdb1.Update(ctx, func(ctx context.Context, tx PrivacyMapTx) error {
26-
_, err = tx.RealToPseudo("real")
26+
_, err = tx.RealToPseudo(ctx, "real")
2727
require.ErrorIs(t, err, ErrNoSuchKeyFound)
2828

2929
_, err = tx.PseudoToReal(ctx, "pseudo")
@@ -32,7 +32,7 @@ func TestPrivacyMapStorage(t *testing.T) {
3232
err = tx.NewPair(ctx, "real", "pseudo")
3333
require.NoError(t, err)
3434

35-
pseudo, err := tx.RealToPseudo("real")
35+
pseudo, err := tx.RealToPseudo(ctx, "real")
3636
require.NoError(t, err)
3737
require.Equal(t, "pseudo", pseudo)
3838

@@ -53,7 +53,7 @@ func TestPrivacyMapStorage(t *testing.T) {
5353
pdb2 := db.PrivacyDB([4]byte{2, 2, 2, 2})
5454

5555
_ = pdb2.Update(ctx, func(ctx context.Context, tx PrivacyMapTx) error {
56-
_, err = tx.RealToPseudo("real")
56+
_, err = tx.RealToPseudo(ctx, "real")
5757
require.ErrorIs(t, err, ErrNoSuchKeyFound)
5858

5959
_, err = tx.PseudoToReal(ctx, "pseudo")
@@ -62,7 +62,7 @@ func TestPrivacyMapStorage(t *testing.T) {
6262
err = tx.NewPair(ctx, "real 2", "pseudo 2")
6363
require.NoError(t, err)
6464

65-
pseudo, err := tx.RealToPseudo("real 2")
65+
pseudo, err := tx.RealToPseudo(ctx, "real 2")
6666
require.NoError(t, err)
6767
require.Equal(t, "pseudo 2", pseudo)
6868

@@ -206,7 +206,7 @@ func TestPrivacyMapTxs(t *testing.T) {
206206
return err
207207
}
208208

209-
p, err := tx.RealToPseudo("real")
209+
p, err := tx.RealToPseudo(ctx, "real")
210210
if err != nil {
211211
return err
212212
}
@@ -218,7 +218,7 @@ func TestPrivacyMapTxs(t *testing.T) {
218218
require.Error(t, err)
219219

220220
err = pdb1.View(ctx, func(ctx context.Context, tx PrivacyMapTx) error {
221-
_, err := tx.RealToPseudo("real")
221+
_, err := tx.RealToPseudo(ctx, "real")
222222
return err
223223
})
224224
require.ErrorIs(t, err, ErrNoSuchKeyFound)

session_rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
634634

635635
var err error
636636
if req.RealToPseudo {
637-
res, err = tx.RealToPseudo(req.Input)
637+
res, err = tx.RealToPseudo(ctx, req.Input)
638638
return err
639639
}
640640

0 commit comments

Comments
 (0)