Skip to content

Commit cfba672

Browse files
committed
firewalldb: thread context to PseudoToReal
1 parent 99a35b5 commit cfba672

File tree

6 files changed

+37
-27
lines changed

6 files changed

+37
-27
lines changed

firewall/privacy_mapper.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func handleListChannelsRequest(db firewalldb.PrivacyMapDB,
559559
err := db.View(ctx, func(ctx context.Context,
560560
tx firewalldb.PrivacyMapTx) error {
561561

562-
peer, err := firewalldb.RevealBytes(tx, r.Peer)
562+
peer, err := firewalldb.RevealBytes(ctx, tx, r.Peer)
563563
if err != nil {
564564
return err
565565
}
@@ -778,8 +778,8 @@ func handleUpdatePolicyRequest(db firewalldb.PrivacyMapDB,
778778
tx firewalldb.PrivacyMapTx) error {
779779

780780
var err error
781-
newTxid, newIndex, err = firewalldb.RevealChanPoint(
782-
tx, newTxid, newIndex,
781+
newTxid, newIndex, err = firewalldb.RevealChanPoint( //nolint:lll
782+
ctx, tx, newTxid, newIndex,
783783
)
784784
return err
785785
})
@@ -1380,7 +1380,7 @@ func handleBatchOpenChannelRequest(db firewalldb.PrivacyMapDB,
13801380
nodePubkey := c.NodePubkey
13811381
if !flags.Contains(session.ClearPubkeys) {
13821382
nodePubkey, err = firewalldb.RevealBytes(
1383-
tx, c.NodePubkey,
1383+
ctx, tx, c.NodePubkey,
13841384
)
13851385
if err != nil {
13861386
return err
@@ -1518,7 +1518,7 @@ func handleChannelOpenRequest(db firewalldb.PrivacyMapDB,
15181518

15191519
if !flags.Contains(session.ClearPubkeys) {
15201520
nodePubkey, err = firewalldb.RevealBytes(
1521-
tx, nodePubkey,
1521+
ctx, tx, nodePubkey,
15221522
)
15231523
if err != nil {
15241524
return err
@@ -1665,7 +1665,7 @@ func handleConnectPeerRequest(db firewalldb.PrivacyMapDB,
16651665
pubkey := r.Addr.Pubkey
16661666
if !flags.Contains(session.ClearPubkeys) {
16671667
pubkey, err = firewalldb.RevealString(
1668-
tx, r.Addr.Pubkey,
1668+
ctx, tx, r.Addr.Pubkey,
16691669
)
16701670
if err != nil {
16711671
return err
@@ -1675,7 +1675,7 @@ func handleConnectPeerRequest(db firewalldb.PrivacyMapDB,
16751675
host := r.Addr.Host
16761676
if !flags.Contains(session.ClearNetworkAddresses) {
16771677
host, err = firewalldb.RevealString(
1678-
tx, r.Addr.Host,
1678+
ctx, tx, r.Addr.Host,
16791679
)
16801680
if err != nil {
16811681
return err

firewalldb/privacy_mapper.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type PrivacyMapTx interface {
7575

7676
// PseudoToReal returns the real value associated with the given pseudo
7777
// value. If no such pair is found, then ErrNoSuchKeyFound is returned.
78-
PseudoToReal(pseudo string) (string, error)
78+
PseudoToReal(ctx context.Context, pseudo string) (string, error)
7979

8080
// RealToPseudo returns the pseudo value associated with the given real
8181
// value. If no such pair is found, then ErrNoSuchKeyFound is returned.
@@ -228,7 +228,9 @@ func (p *privacyMapTx) NewPair(_ context.Context, real, pseudo string) error {
228228
// it does then the real value is returned, else an error is returned.
229229
//
230230
// NOTE: this is part of the PrivacyMapTx interface.
231-
func (p *privacyMapTx) PseudoToReal(pseudo string) (string, error) {
231+
func (p *privacyMapTx) PseudoToReal(_ context.Context, pseudo string) (string,
232+
error) {
233+
232234
privacyBucket, err := getBucket(p.boltTx, privacyBucketKey)
233235
if err != nil {
234236
return "", err
@@ -354,12 +356,14 @@ func NewPseudoStr(n int) (string, error) {
354356
return string(b), nil
355357
}
356358

357-
func RevealString(tx PrivacyMapTx, pseudo string) (string, error) {
359+
func RevealString(ctx context.Context, tx PrivacyMapTx, pseudo string) (string,
360+
error) {
361+
358362
if pseudo == "" {
359363
return pseudo, nil
360364
}
361365

362-
return tx.PseudoToReal(pseudo)
366+
return tx.PseudoToReal(ctx, pseudo)
363367
}
364368

365369
func HideUint64(ctx context.Context, tx PrivacyMapTx, real uint64) (uint64,
@@ -382,12 +386,14 @@ func HideUint64(ctx context.Context, tx PrivacyMapTx, real uint64) (uint64,
382386
return pseudoUint64, nil
383387
}
384388

385-
func RevealUint64(tx PrivacyMapTx, pseudo uint64) (uint64, error) {
389+
func RevealUint64(ctx context.Context, tx PrivacyMapTx, pseudo uint64) (uint64,
390+
error) {
391+
386392
if pseudo == 0 {
387393
return 0, nil
388394
}
389395

390-
real, err := tx.PseudoToReal(Uint64ToStr(pseudo))
396+
real, err := tx.PseudoToReal(ctx, Uint64ToStr(pseudo))
391397
if err != nil {
392398
return 0, err
393399
}
@@ -429,11 +435,11 @@ func NewPseudoChanPoint() (string, error) {
429435
return fmt.Sprintf("%s:%d", pseudoTXID, pseudoIndex), nil
430436
}
431437

432-
func RevealChanPoint(tx PrivacyMapTx, txid string, index uint32) (string,
433-
uint32, error) {
438+
func RevealChanPoint(ctx context.Context, tx PrivacyMapTx, txid string,
439+
index uint32) (string, uint32, error) {
434440

435441
fakePoint := fmt.Sprintf("%s:%d", txid, index)
436-
real, err := tx.PseudoToReal(fakePoint)
442+
real, err := tx.PseudoToReal(ctx, fakePoint)
437443
if err != nil {
438444
return "", 0, err
439445
}
@@ -477,13 +483,15 @@ func HideBytes(ctx context.Context, tx PrivacyMapTx, realBytes []byte) ([]byte,
477483
return hex.DecodeString(pseudo)
478484
}
479485

480-
func RevealBytes(tx PrivacyMapTx, pseudoBytes []byte) ([]byte, error) {
486+
func RevealBytes(ctx context.Context, tx PrivacyMapTx,
487+
pseudoBytes []byte) ([]byte, error) {
488+
481489
if pseudoBytes == nil {
482490
return nil, nil
483491
}
484492

485493
pseudo := hex.EncodeToString(pseudoBytes)
486-
pseudo, err := RevealString(tx, pseudo)
494+
pseudo, err := RevealString(ctx, tx, pseudo)
487495
if err != nil {
488496
return nil, err
489497
}

firewalldb/privacy_mapper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestPrivacyMapStorage(t *testing.T) {
2626
_, err = tx.RealToPseudo("real")
2727
require.ErrorIs(t, err, ErrNoSuchKeyFound)
2828

29-
_, err = tx.PseudoToReal("pseudo")
29+
_, err = tx.PseudoToReal(ctx, "pseudo")
3030
require.ErrorIs(t, err, ErrNoSuchKeyFound)
3131

3232
err = tx.NewPair(ctx, "real", "pseudo")
@@ -36,7 +36,7 @@ func TestPrivacyMapStorage(t *testing.T) {
3636
require.NoError(t, err)
3737
require.Equal(t, "pseudo", pseudo)
3838

39-
real, err := tx.PseudoToReal("pseudo")
39+
real, err := tx.PseudoToReal(ctx, "pseudo")
4040
require.NoError(t, err)
4141
require.Equal(t, "real", real)
4242

@@ -56,7 +56,7 @@ func TestPrivacyMapStorage(t *testing.T) {
5656
_, err = tx.RealToPseudo("real")
5757
require.ErrorIs(t, err, ErrNoSuchKeyFound)
5858

59-
_, err = tx.PseudoToReal("pseudo")
59+
_, err = tx.PseudoToReal(ctx, "pseudo")
6060
require.ErrorIs(t, err, ErrNoSuchKeyFound)
6161

6262
err = tx.NewPair(ctx, "real 2", "pseudo 2")
@@ -66,7 +66,7 @@ func TestPrivacyMapStorage(t *testing.T) {
6666
require.NoError(t, err)
6767
require.Equal(t, "pseudo 2", pseudo)
6868

69-
real, err := tx.PseudoToReal("pseudo 2")
69+
real, err := tx.PseudoToReal(ctx, "pseudo 2")
7070
require.NoError(t, err)
7171
require.Equal(t, "real 2", real)
7272

rules/channel_restrictions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (c *ChannelRestrict) PseudoToReal(ctx context.Context,
353353
tx firewalldb.PrivacyMapTx) error {
354354

355355
for i, chanID := range c.DenyList {
356-
real, err := firewalldb.RevealUint64(tx, chanID)
356+
real, err := firewalldb.RevealUint64(ctx, tx, chanID)
357357
if err != nil {
358358
return err
359359
}

rules/peer_restrictions.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,13 @@ func (c *PeerRestrict) PseudoToReal(ctx context.Context,
394394
return &PeerRestrict{DenyList: restrictList}, nil
395395
}
396396

397-
err := db.View(ctx, func(_ context.Context,
397+
err := db.View(ctx, func(ctx context.Context,
398398
tx firewalldb.PrivacyMapTx) error {
399399

400400
for i, peerPubKey := range c.DenyList {
401-
real, err := firewalldb.RevealString(tx, peerPubKey)
401+
real, err := firewalldb.RevealString(
402+
ctx, tx, peerPubKey,
403+
)
402404
if err != nil {
403405
return err
404406
}

session_rpcserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
629629

630630
var res string
631631
privMap := s.cfg.privMap(groupID)
632-
err = privMap.View(ctx, func(_ context.Context,
632+
err = privMap.View(ctx, func(ctx context.Context,
633633
tx firewalldb.PrivacyMapTx) error {
634634

635635
var err error
@@ -638,7 +638,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
638638
return err
639639
}
640640

641-
res, err = tx.PseudoToReal(req.Input)
641+
res, err = tx.PseudoToReal(ctx, req.Input)
642642
return err
643643
})
644644
if err != nil {

0 commit comments

Comments
 (0)