mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
multi+refactor: remove unnecessary type alias
Remove the `NewPrivacyMapDB` type alias. It is not needed.
This commit is contained in:
parent
c7e82b55c6
commit
b9ad66471d
6 changed files with 23 additions and 29 deletions
|
|
@ -60,19 +60,19 @@ var _ mid.RequestInterceptor = (*PrivacyMapper)(nil)
|
|||
// PrivacyMapper is a RequestInterceptor that maps any pseudo names in certain
|
||||
// requests to their real values and vice versa for responses.
|
||||
type PrivacyMapper struct {
|
||||
newDB firewalldb.NewPrivacyMapDB
|
||||
db firewalldb.PrivacyMapper
|
||||
randIntn func(int) (int, error)
|
||||
sessionDB firewalldb.SessionDB
|
||||
}
|
||||
|
||||
// NewPrivacyMapper returns a new instance of PrivacyMapper. The randIntn
|
||||
// function is used to draw randomness for request field obfuscation.
|
||||
func NewPrivacyMapper(newDB firewalldb.NewPrivacyMapDB,
|
||||
func NewPrivacyMapper(newDB firewalldb.PrivacyMapper,
|
||||
randIntn func(int) (int, error),
|
||||
sessionDB firewalldb.SessionDB) *PrivacyMapper {
|
||||
|
||||
return &PrivacyMapper{
|
||||
newDB: newDB,
|
||||
db: newDB,
|
||||
randIntn: randIntn,
|
||||
sessionDB: sessionDB,
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ func (p *PrivacyMapper) checkAndReplaceIncomingRequest(ctx context.Context,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
db := p.newDB(session.GroupID)
|
||||
db := p.db.PrivacyDB(session.GroupID)
|
||||
|
||||
// If we don't have a handler for the URI, we don't allow the request
|
||||
// to go through.
|
||||
|
|
@ -225,7 +225,7 @@ func (p *PrivacyMapper) replaceOutgoingResponse(ctx context.Context, uri string,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
db := p.newDB(session.GroupID)
|
||||
db := p.db.PrivacyDB(session.GroupID)
|
||||
|
||||
// If we don't have a handler for the URI, we don't allow the response
|
||||
// to go to avoid accidental leaks.
|
||||
|
|
|
|||
|
|
@ -902,7 +902,7 @@ func TestPrivacyMapper(t *testing.T) {
|
|||
|
||||
// randIntn is used for deterministic testing.
|
||||
randIntn := func(n int) (int, error) { return 100, nil }
|
||||
p := NewPrivacyMapper(db.NewSessionDB, randIntn, pd)
|
||||
p := NewPrivacyMapper(db, randIntn, pd)
|
||||
|
||||
rawMsg, err := proto.Marshal(test.msg)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -978,7 +978,7 @@ func TestPrivacyMapper(t *testing.T) {
|
|||
rawMsg, err := proto.Marshal(msg)
|
||||
require.NoError(t, err)
|
||||
|
||||
p := NewPrivacyMapper(db.NewSessionDB, CryptoRandIntn, pd)
|
||||
p := NewPrivacyMapper(db, CryptoRandIntn, pd)
|
||||
require.NoError(t, err)
|
||||
|
||||
// We test the independent outgoing amount (incoming amount
|
||||
|
|
@ -1071,7 +1071,7 @@ func newMockDB(t *testing.T, preloadRealToPseudo map[string]string,
|
|||
sessID session.ID) mockDB {
|
||||
|
||||
db := mockDB{privDB: make(map[string]*mockPrivacyMapDB)}
|
||||
sessDB := db.NewSessionDB(sessID)
|
||||
sessDB := db.PrivacyDB(sessID)
|
||||
|
||||
_ = sessDB.Update(context.Background(), func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
|
@ -1085,14 +1085,14 @@ func newMockDB(t *testing.T, preloadRealToPseudo map[string]string,
|
|||
return db
|
||||
}
|
||||
|
||||
func (m mockDB) NewSessionDB(sessionID session.ID) firewalldb.PrivacyMapDB {
|
||||
db, ok := m.privDB[string(sessionID[:])]
|
||||
func (m mockDB) PrivacyDB(groupID session.ID) firewalldb.PrivacyMapDB {
|
||||
db, ok := m.privDB[string(groupID[:])]
|
||||
if ok {
|
||||
return db
|
||||
}
|
||||
|
||||
newDB := newMockPrivacyMapDB()
|
||||
m.privDB[string(sessionID[:])] = newDB
|
||||
m.privDB[string(groupID[:])] = newDB
|
||||
|
||||
return newDB
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ type RuleEnforcer struct {
|
|||
actionsDB firewalldb.ActionReadDBGetter
|
||||
sessionDB firewalldb.SessionDB
|
||||
markActionErrored func(reqID uint64, reason string) error
|
||||
newPrivMap firewalldb.NewPrivacyMapDB
|
||||
privMapDB firewalldb.PrivacyMapper
|
||||
|
||||
permsMgr *perms.Manager
|
||||
getFeaturePerms featurePerms
|
||||
|
|
@ -64,7 +64,7 @@ func NewRuleEnforcer(ruleDB firewalldb.RulesDB,
|
|||
lndClient lndclient.LightningClient, lndConnID string,
|
||||
ruleMgrs rules.ManagerSet,
|
||||
markActionErrored func(reqID uint64, reason string) error,
|
||||
privMap firewalldb.NewPrivacyMapDB) *RuleEnforcer {
|
||||
privMap firewalldb.PrivacyMapper) *RuleEnforcer {
|
||||
|
||||
return &RuleEnforcer{
|
||||
ruleDB: ruleDB,
|
||||
|
|
@ -76,7 +76,7 @@ func NewRuleEnforcer(ruleDB firewalldb.RulesDB,
|
|||
lndClient: lndClient,
|
||||
ruleMgrs: ruleMgrs,
|
||||
markActionErrored: markActionErrored,
|
||||
newPrivMap: privMap,
|
||||
privMapDB: privMap,
|
||||
sessionDB: sessionIDIndex,
|
||||
lndConnID: lndConnID,
|
||||
}
|
||||
|
|
@ -392,7 +392,7 @@ func (r *RuleEnforcer) initRule(ctx context.Context, reqID uint64, name string,
|
|||
}
|
||||
|
||||
if privacy {
|
||||
privMap := r.newPrivMap(session.GroupID)
|
||||
privMap := r.privMapDB.PrivacyDB(session.GroupID)
|
||||
|
||||
ruleValues, err = ruleValues.PseudoToReal(
|
||||
ctx, privMap, session.PrivacyFlags,
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/lightninglabs/lightning-terminal/session"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -29,10 +27,6 @@ var (
|
|||
"value already exists")
|
||||
)
|
||||
|
||||
// NewPrivacyMapDB is a function type that takes a group ID and uses it to
|
||||
// construct a new PrivacyMapDB.
|
||||
type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
|
||||
|
||||
// PrivacyMapDB provides an Update and View method that will allow the caller
|
||||
// to perform atomic read and write transactions defined by PrivacyMapTx on the
|
||||
// underlying DB.
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ type sessionRpcServerConfig struct {
|
|||
actionsDB *firewalldb.BoltDB
|
||||
autopilot autopilotserver.Autopilot
|
||||
ruleMgrs rules.ManagerSet
|
||||
privMap firewalldb.NewPrivacyMapDB
|
||||
privMap firewalldb.PrivacyMapper
|
||||
}
|
||||
|
||||
// newSessionRPCServer creates a new sessionRpcServer using the passed config.
|
||||
|
|
@ -628,7 +628,7 @@ func (s *sessionRpcServer) PrivacyMapConversion(ctx context.Context,
|
|||
}
|
||||
|
||||
var res string
|
||||
privMap := s.cfg.privMap(groupID)
|
||||
privMap := s.cfg.privMap.PrivacyDB(groupID)
|
||||
err = privMap.View(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
|
|
@ -900,7 +900,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
|
|||
linkedGroupID = &groupID
|
||||
linkedGroupSession = groupSess
|
||||
|
||||
privDB := s.cfg.privMap(groupID)
|
||||
privDB := s.cfg.privMap.PrivacyDB(groupID)
|
||||
err = privDB.View(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
|
|
@ -1225,7 +1225,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
|
|||
}
|
||||
|
||||
// Register all the privacy map pairs for this session ID.
|
||||
privDB := s.cfg.privMap(sess.GroupID)
|
||||
privDB := s.cfg.privMap.PrivacyDB(sess.GroupID)
|
||||
err = privDB.Update(ctx, func(ctx context.Context,
|
||||
tx firewalldb.PrivacyMapTx) error {
|
||||
|
||||
|
|
@ -1487,7 +1487,7 @@ func (s *sessionRpcServer) marshalRPCSession(ctx context.Context,
|
|||
}
|
||||
|
||||
if sess.WithPrivacyMapper {
|
||||
db := s.cfg.privMap(
|
||||
db := s.cfg.privMap.PrivacyDB(
|
||||
sess.GroupID,
|
||||
)
|
||||
val, err = val.PseudoToReal(
|
||||
|
|
|
|||
|
|
@ -534,7 +534,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
|
|||
actionsDB: g.stores.firewallBolt,
|
||||
autopilot: g.autopilotClient,
|
||||
ruleMgrs: g.ruleMgrs,
|
||||
privMap: g.stores.firewall.PrivacyDB,
|
||||
privMap: g.stores.firewall,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create new session rpc "+
|
||||
|
|
@ -1100,7 +1100,7 @@ func (g *LightningTerminal) startInternalSubServers(ctx context.Context,
|
|||
}
|
||||
|
||||
privacyMapper := firewall.NewPrivacyMapper(
|
||||
g.stores.firewall.PrivacyDB, firewall.CryptoRandIntn,
|
||||
g.stores.firewall, firewall.CryptoRandIntn,
|
||||
g.stores.sessions,
|
||||
)
|
||||
|
||||
|
|
@ -1123,7 +1123,7 @@ func (g *LightningTerminal) startInternalSubServers(ctx context.Context,
|
|||
reqID, firewalldb.ActionStateError,
|
||||
reason,
|
||||
)
|
||||
}, g.stores.firewall.PrivacyDB,
|
||||
}, g.stores.firewall,
|
||||
)
|
||||
|
||||
mw = append(mw, ruleEnforcer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue