Skip to content

Commit 7715ec1

Browse files
committed
firewalldb+lit: plug in SQL privacy mapper
1 parent ed31a0a commit 7715ec1

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

firewalldb/db.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,28 @@ var (
1414
ErrNoSuchKeyFound = fmt.Errorf("no such key found")
1515
)
1616

17+
// firewallDBs is an interface that groups the RulesDB and PrivacyMapper
18+
// interfaces.
19+
type firewallDBs interface {
20+
RulesDB
21+
PrivacyMapper
22+
}
23+
1724
// DB manages the firewall rules database.
1825
type DB struct {
1926
started sync.Once
2027
stopped sync.Once
2128

22-
RulesDB
29+
firewallDBs
2330

2431
cancel fn.Option[context.CancelFunc]
2532
}
2633

2734
// NewDB creates a new firewall database. For now, it only contains the
2835
// underlying rules' database.
29-
func NewDB(kvdb RulesDB) *DB {
36+
func NewDB(dbs firewallDBs) *DB {
3037
return &DB{
31-
RulesDB: kvdb,
38+
firewallDBs: dbs,
3239
}
3340
}
3441

firewalldb/interface.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,11 @@ type RulesDB interface {
9292
// DeleteTempKVStores deletes all temporary kv stores.
9393
DeleteTempKVStores(ctx context.Context) error
9494
}
95+
96+
// PrivacyMapper is an interface that abstracts access to the privacy mapper
97+
// database.
98+
type PrivacyMapper interface {
99+
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the
100+
// given group ID key.
101+
PrivacyDB(groupID session.ID) PrivacyMapDB
102+
}

firewalldb/privacy_mapper_kvdb.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var (
3030

3131
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
3232
// group ID key.
33+
//
34+
// NOTE: this is part of the PrivacyMapper interface.
3335
func (db *BoltDB) PrivacyDB(groupID session.ID) PrivacyMapDB {
3436
return &kvdbExecutor[PrivacyMapTx]{
3537
db: db.DB,

firewalldb/privacy_mapper_sql.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type SQLPrivacyPairQueries interface {
2424

2525
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
2626
// group ID key.
27+
//
28+
// NOTE: this is part of the PrivacyMapper interface.
2729
func (s *SQLDB) PrivacyDB(groupID session.ID) PrivacyMapDB {
2830
return &sqlExecutor[PrivacyMapTx]{
2931
db: s.db,

terminal.go

Lines changed: 3 additions & 3 deletions
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.firewallBolt.PrivacyDB,
537+
privMap: g.stores.firewall.PrivacyDB,
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.firewallBolt.PrivacyDB, firewall.CryptoRandIntn,
1103+
g.stores.firewall.PrivacyDB, 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.firewallBolt.PrivacyDB,
1126+
}, g.stores.firewall.PrivacyDB,
11271127
)
11281128

11291129
mw = append(mw, ruleEnforcer)

0 commit comments

Comments
 (0)