Skip to content

Commit 262416f

Browse files
committed
multi+refactor: remove unnecessary type alias
Remove the `NewPrivacyMapDB` type alias. It is not needed.
1 parent 7715ec1 commit 262416f

File tree

6 files changed

+23
-29
lines changed

6 files changed

+23
-29
lines changed

firewall/privacy_mapper.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ var _ mid.RequestInterceptor = (*PrivacyMapper)(nil)
6060
// PrivacyMapper is a RequestInterceptor that maps any pseudo names in certain
6161
// requests to their real values and vice versa for responses.
6262
type PrivacyMapper struct {
63-
newDB firewalldb.NewPrivacyMapDB
63+
db firewalldb.PrivacyMapper
6464
randIntn func(int) (int, error)
6565
sessionDB firewalldb.SessionDB
6666
}
6767

6868
// NewPrivacyMapper returns a new instance of PrivacyMapper. The randIntn
6969
// function is used to draw randomness for request field obfuscation.
70-
func NewPrivacyMapper(newDB firewalldb.NewPrivacyMapDB,
70+
func NewPrivacyMapper(newDB firewalldb.PrivacyMapper,
7171
randIntn func(int) (int, error),
7272
sessionDB firewalldb.SessionDB) *PrivacyMapper {
7373

7474
return &PrivacyMapper{
75-
newDB: newDB,
75+
db: newDB,
7676
randIntn: randIntn,
7777
sessionDB: sessionDB,
7878
}
@@ -195,7 +195,7 @@ func (p *PrivacyMapper) checkAndReplaceIncomingRequest(ctx context.Context,
195195
return nil, err
196196
}
197197

198-
db := p.newDB(session.GroupID)
198+
db := p.db.PrivacyDB(session.GroupID)
199199

200200
// If we don't have a handler for the URI, we don't allow the request
201201
// to go through.
@@ -225,7 +225,7 @@ func (p *PrivacyMapper) replaceOutgoingResponse(ctx context.Context, uri string,
225225
return nil, err
226226
}
227227

228-
db := p.newDB(session.GroupID)
228+
db := p.db.PrivacyDB(session.GroupID)
229229

230230
// If we don't have a handler for the URI, we don't allow the response
231231
// to go to avoid accidental leaks.

firewall/privacy_mapper_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ func TestPrivacyMapper(t *testing.T) {
902902

903903
// randIntn is used for deterministic testing.
904904
randIntn := func(n int) (int, error) { return 100, nil }
905-
p := NewPrivacyMapper(db.NewSessionDB, randIntn, pd)
905+
p := NewPrivacyMapper(db, randIntn, pd)
906906

907907
rawMsg, err := proto.Marshal(test.msg)
908908
require.NoError(t, err)
@@ -978,7 +978,7 @@ func TestPrivacyMapper(t *testing.T) {
978978
rawMsg, err := proto.Marshal(msg)
979979
require.NoError(t, err)
980980

981-
p := NewPrivacyMapper(db.NewSessionDB, CryptoRandIntn, pd)
981+
p := NewPrivacyMapper(db, CryptoRandIntn, pd)
982982
require.NoError(t, err)
983983

984984
// We test the independent outgoing amount (incoming amount
@@ -1071,7 +1071,7 @@ func newMockDB(t *testing.T, preloadRealToPseudo map[string]string,
10711071
sessID session.ID) mockDB {
10721072

10731073
db := mockDB{privDB: make(map[string]*mockPrivacyMapDB)}
1074-
sessDB := db.NewSessionDB(sessID)
1074+
sessDB := db.PrivacyDB(sessID)
10751075

10761076
_ = sessDB.Update(context.Background(), func(ctx context.Context,
10771077
tx firewalldb.PrivacyMapTx) error {
@@ -1085,14 +1085,14 @@ func newMockDB(t *testing.T, preloadRealToPseudo map[string]string,
10851085
return db
10861086
}
10871087

1088-
func (m mockDB) NewSessionDB(sessionID session.ID) firewalldb.PrivacyMapDB {
1089-
db, ok := m.privDB[string(sessionID[:])]
1088+
func (m mockDB) PrivacyDB(groupID session.ID) firewalldb.PrivacyMapDB {
1089+
db, ok := m.privDB[string(groupID[:])]
10901090
if ok {
10911091
return db
10921092
}
10931093

10941094
newDB := newMockPrivacyMapDB()
1095-
m.privDB[string(sessionID[:])] = newDB
1095+
m.privDB[string(groupID[:])] = newDB
10961096

10971097
return newDB
10981098
}

firewall/rule_enforcer.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type RuleEnforcer struct {
3333
actionsDB firewalldb.ActionReadDBGetter
3434
sessionDB firewalldb.SessionDB
3535
markActionErrored func(reqID uint64, reason string) error
36-
newPrivMap firewalldb.NewPrivacyMapDB
36+
privMapDB firewalldb.PrivacyMapper
3737

3838
permsMgr *perms.Manager
3939
getFeaturePerms featurePerms
@@ -64,7 +64,7 @@ func NewRuleEnforcer(ruleDB firewalldb.RulesDB,
6464
lndClient lndclient.LightningClient, lndConnID string,
6565
ruleMgrs rules.ManagerSet,
6666
markActionErrored func(reqID uint64, reason string) error,
67-
privMap firewalldb.NewPrivacyMapDB) *RuleEnforcer {
67+
privMap firewalldb.PrivacyMapper) *RuleEnforcer {
6868

6969
return &RuleEnforcer{
7070
ruleDB: ruleDB,
@@ -76,7 +76,7 @@ func NewRuleEnforcer(ruleDB firewalldb.RulesDB,
7676
lndClient: lndClient,
7777
ruleMgrs: ruleMgrs,
7878
markActionErrored: markActionErrored,
79-
newPrivMap: privMap,
79+
privMapDB: privMap,
8080
sessionDB: sessionIDIndex,
8181
lndConnID: lndConnID,
8282
}
@@ -392,7 +392,7 @@ func (r *RuleEnforcer) initRule(ctx context.Context, reqID uint64, name string,
392392
}
393393

394394
if privacy {
395-
privMap := r.newPrivMap(session.GroupID)
395+
privMap := r.privMapDB.PrivacyDB(session.GroupID)
396396

397397
ruleValues, err = ruleValues.PseudoToReal(
398398
ctx, privMap, session.PrivacyFlags,

firewalldb/privacy_mapper.go

-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"strconv"
1212
"strings"
1313
"sync"
14-
15-
"github.com/lightninglabs/lightning-terminal/session"
1614
)
1715

1816
var (
@@ -29,10 +27,6 @@ var (
2927
"value already exists")
3028
)
3129

32-
// NewPrivacyMapDB is a function type that takes a group ID and uses it to
33-
// construct a new PrivacyMapDB.
34-
type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
35-
3630
// PrivacyMapDB provides an Update and View method that will allow the caller
3731
// to perform atomic read and write transactions defined by PrivacyMapTx on the
3832
// underlying DB.

session_rpcserver.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type sessionRpcServerConfig struct {
6666
actionsDB *firewalldb.BoltDB
6767
autopilot autopilotserver.Autopilot
6868
ruleMgrs rules.ManagerSet
69-
privMap firewalldb.NewPrivacyMapDB
69+
privMap firewalldb.PrivacyMapper
7070
}
7171

7272
// newSessionRPCServer creates a new sessionRpcServer using the passed config.
@@ -628,7 +628,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
628628
}
629629

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

@@ -900,7 +900,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
900900
linkedGroupID = &groupID
901901
linkedGroupSession = groupSess
902902

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

@@ -1225,7 +1225,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12251225
}
12261226

12271227
// Register all the privacy map pairs for this session ID.
1228-
privDB := s.cfg.privMap(sess.GroupID)
1228+
privDB := s.cfg.privMap.PrivacyDB(sess.GroupID)
12291229
err = privDB.Update(ctx, func(ctx context.Context,
12301230
tx firewalldb.PrivacyMapTx) error {
12311231

@@ -1487,7 +1487,7 @@ func (s *sessionRpcServer) marshalRPCSession(ctx context.Context,
14871487
}
14881488

14891489
if sess.WithPrivacyMapper {
1490-
db := s.cfg.privMap(
1490+
db := s.cfg.privMap.PrivacyDB(
14911491
sess.GroupID,
14921492
)
14931493
val, err = val.PseudoToReal(

terminal.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
534534
actionsDB: g.stores.firewallBolt,
535535
autopilot: g.autopilotClient,
536536
ruleMgrs: g.ruleMgrs,
537-
privMap: g.stores.firewall.PrivacyDB,
537+
privMap: g.stores.firewall,
538538
})
539539
if err != nil {
540540
return fmt.Errorf("could not create new session rpc "+
@@ -1100,7 +1100,7 @@ func (g *LightningTerminal) startInternalSubServers(ctx context.Context,
11001100
}
11011101

11021102
privacyMapper := firewall.NewPrivacyMapper(
1103-
g.stores.firewall.PrivacyDB, firewall.CryptoRandIntn,
1103+
g.stores.firewall, firewall.CryptoRandIntn,
11041104
g.stores.sessions,
11051105
)
11061106

@@ -1123,7 +1123,7 @@ func (g *LightningTerminal) startInternalSubServers(ctx context.Context,
11231123
reqID, firewalldb.ActionStateError,
11241124
reason,
11251125
)
1126-
}, g.stores.firewall.PrivacyDB,
1126+
}, g.stores.firewall,
11271127
)
11281128

11291129
mw = append(mw, ruleEnforcer)

0 commit comments

Comments
 (0)