Skip to content

Commit 8f9d6a0

Browse files
committed
firewalldb: rename DB to BoltDB
In preparation for a db-backend agnostic DB struct.
1 parent 4cc7bf2 commit 8f9d6a0

File tree

9 files changed

+31
-26
lines changed

9 files changed

+31
-26
lines changed

firewalldb/actions.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ type Action struct {
117117
}
118118

119119
// AddAction serialises and adds an Action to the DB under the given sessionID.
120-
func (db *DB) AddAction(sessionID session.ID, action *Action) (uint64, error) {
120+
func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
121+
error) {
122+
121123
var buf bytes.Buffer
122124
if err := SerializeAction(&buf, action); err != nil {
123125
return 0, err
@@ -231,7 +233,7 @@ func getAction(actionsBkt *bbolt.Bucket, al *ActionLocator) (*Action, error) {
231233

232234
// SetActionState finds the action specified by the ActionLocator and sets its
233235
// state to the given state.
234-
func (db *DB) SetActionState(al *ActionLocator, state ActionState,
236+
func (db *BoltDB) SetActionState(al *ActionLocator, state ActionState,
235237
errorReason string) error {
236238

237239
if errorReason != "" && state != ActionStateError {
@@ -293,7 +295,7 @@ type ListActionsFilterFn func(a *Action, reversed bool) (bool, bool)
293295
// The indexOffset and maxNum params can be used to control the number of
294296
// actions returned. The return values are the list of actions, the last index
295297
// and the total count (iff query.CountTotal is set).
296-
func (db *DB) ListActions(filterFn ListActionsFilterFn,
298+
func (db *BoltDB) ListActions(filterFn ListActionsFilterFn,
297299
query *ListActionsQuery) ([]*Action, uint64, uint64, error) {
298300

299301
var (
@@ -345,7 +347,7 @@ func (db *DB) ListActions(filterFn ListActionsFilterFn,
345347

346348
// ListSessionActions returns a list of the given session's Actions that pass
347349
// the filterFn requirements.
348-
func (db *DB) ListSessionActions(sessionID session.ID,
350+
func (db *BoltDB) ListSessionActions(sessionID session.ID,
349351
filterFn ListActionsFilterFn, query *ListActionsQuery) ([]*Action,
350352
uint64, uint64, error) {
351353

@@ -391,7 +393,7 @@ func (db *DB) ListSessionActions(sessionID session.ID,
391393
// pass the filterFn requirements.
392394
//
393395
// TODO: update to allow for pagination.
394-
func (db *DB) ListGroupActions(ctx context.Context, groupID session.ID,
396+
func (db *BoltDB) ListGroupActions(ctx context.Context, groupID session.ID,
395397
filterFn ListActionsFilterFn) ([]*Action, error) {
396398

397399
if filterFn == nil {
@@ -589,7 +591,7 @@ type ActionReadDBGetter interface {
589591
}
590592

591593
// GetActionsReadDB is a method on DB that constructs an ActionsReadDB.
592-
func (db *DB) GetActionsReadDB(groupID session.ID,
594+
func (db *BoltDB) GetActionsReadDB(groupID session.ID,
593595
featureName string) ActionsReadDB {
594596

595597
return &allActionsReadDB{
@@ -601,7 +603,7 @@ func (db *DB) GetActionsReadDB(groupID session.ID,
601603

602604
// allActionsReadDb is an implementation of the ActionsReadDB.
603605
type allActionsReadDB struct {
604-
db *DB
606+
db *BoltDB
605607
groupID session.ID
606608
featureName string
607609
}

firewalldb/actions_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
func TestActionStorage(t *testing.T) {
4444
tmpDir := t.TempDir()
4545

46-
db, err := NewDB(tmpDir, "test.db", nil)
46+
db, err := NewBoltDB(tmpDir, "test.db", nil)
4747
require.NoError(t, err)
4848
t.Cleanup(func() {
4949
_ = db.Close()
@@ -151,7 +151,7 @@ func TestActionStorage(t *testing.T) {
151151
func TestListActions(t *testing.T) {
152152
tmpDir := t.TempDir()
153153

154-
db, err := NewDB(tmpDir, "test.db", nil)
154+
db, err := NewBoltDB(tmpDir, "test.db", nil)
155155
require.NoError(t, err)
156156
t.Cleanup(func() {
157157
_ = db.Close()
@@ -353,7 +353,7 @@ func TestListGroupActions(t *testing.T) {
353353
index.AddPair(sessionID1, group1)
354354
index.AddPair(sessionID2, group1)
355355

356-
db, err := NewDB(t.TempDir(), "test.db", index)
356+
db, err := NewBoltDB(t.TempDir(), "test.db", index)
357357
require.NoError(t, err)
358358
t.Cleanup(func() {
359359
_ = db.Close()

firewalldb/db.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ var (
3737
ErrNoSuchKeyFound = fmt.Errorf("no such key found")
3838
)
3939

40-
// DB is a bolt-backed persistent store.
41-
type DB struct {
40+
// BoltDB is a bolt-backed persistent store.
41+
type BoltDB struct {
4242
*bbolt.DB
4343

4444
sessionIDIndex SessionDB
4545
}
4646

47-
// NewDB creates a new bolt database that can be found at the given directory.
48-
func NewDB(dir, fileName string, sessionIDIndex SessionDB) (*DB, error) {
47+
// NewBoltDB creates a new bolt database that can be found at the given
48+
// directory.
49+
func NewBoltDB(dir, fileName string, sessionIDIndex SessionDB) (*BoltDB,
50+
error) {
51+
4952
firstInit := false
5053
path := filepath.Join(dir, fileName)
5154

@@ -68,7 +71,7 @@ func NewDB(dir, fileName string, sessionIDIndex SessionDB) (*DB, error) {
6871
return nil, err
6972
}
7073

71-
return &DB{
74+
return &BoltDB{
7275
DB: db,
7376
sessionIDIndex: sessionIDIndex,
7477
}, nil

firewalldb/kvstores.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ type RulesDB interface {
104104
}
105105

106106
// GetKVStores constructs a new rules.KVStores backed by a bbolt db.
107-
func (db *DB) GetKVStores(rule string, groupID session.ID,
107+
func (db *BoltDB) GetKVStores(rule string, groupID session.ID,
108108
feature string) KVStores {
109109

110110
return &kvdbExecutor[KVStoreTx]{

firewalldb/kvstores_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestKVStoreTxs(t *testing.T) {
1818
ctx := context.Background()
1919
tmpDir := t.TempDir()
2020

21-
db, err := NewDB(tmpDir, "test.db", nil)
21+
db, err := NewBoltDB(tmpDir, "test.db", nil)
2222
require.NoError(t, err)
2323
t.Cleanup(func() {
2424
_ = db.Close()
@@ -86,7 +86,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
8686
featureName = "auto-fees"
8787
}
8888

89-
db, err := NewDB(tmpDir, "test.db", nil)
89+
db, err := NewBoltDB(tmpDir, "test.db", nil)
9090
require.NoError(t, err)
9191
t.Cleanup(func() {
9292
_ = db.Close()
@@ -134,7 +134,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
134134
require.NoError(t, db.Close())
135135

136136
// Restart it.
137-
db, err = NewDB(tmpDir, "test.db", nil)
137+
db, err = NewBoltDB(tmpDir, "test.db", nil)
138138
require.NoError(t, err)
139139
t.Cleanup(func() {
140140
_ = db.Close()
@@ -168,7 +168,7 @@ func TestKVStoreNameSpaces(t *testing.T) {
168168
ctx := context.Background()
169169
tmpDir := t.TempDir()
170170

171-
db, err := NewDB(tmpDir, "test.db", nil)
171+
db, err := NewBoltDB(tmpDir, "test.db", nil)
172172
require.NoError(t, err)
173173
t.Cleanup(func() {
174174
_ = db.Close()

firewalldb/privacy_mapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
4141

4242
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
4343
// group ID key.
44-
func (db *DB) PrivacyDB(groupID session.ID) PrivacyMapDB {
44+
func (db *BoltDB) PrivacyDB(groupID session.ID) PrivacyMapDB {
4545
return &kvdbExecutor[PrivacyMapTx]{
4646
db: db.DB,
4747
wrapTx: func(tx *bbolt.Tx) PrivacyMapTx {

firewalldb/privacy_mapper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func TestPrivacyMapStorage(t *testing.T) {
1414
ctx := context.Background()
1515

1616
tmpDir := t.TempDir()
17-
db, err := NewDB(tmpDir, "test.db", nil)
17+
db, err := NewBoltDB(tmpDir, "test.db", nil)
1818
require.NoError(t, err)
1919
t.Cleanup(func() {
2020
_ = db.Close()
@@ -188,7 +188,7 @@ func TestPrivacyMapTxs(t *testing.T) {
188188
ctx := context.Background()
189189

190190
tmpDir := t.TempDir()
191-
db, err := NewDB(tmpDir, "test.db", nil)
191+
db, err := NewBoltDB(tmpDir, "test.db", nil)
192192
require.NoError(t, err)
193193
t.Cleanup(func() {
194194
_ = db.Close()

session_rpcserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type sessionRpcServerConfig struct {
6363
superMacBaker litmac.Baker
6464
firstConnectionDeadline time.Duration
6565
permMgr *perms.Manager
66-
actionsDB *firewalldb.DB
66+
actionsDB *firewalldb.BoltDB
6767
autopilot autopilotserver.Autopilot
6868
ruleMgrs rules.ManagerSet
6969
privMap firewalldb.NewPrivacyMapDB

terminal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ type LightningTerminal struct {
223223

224224
stores *stores
225225

226-
firewallDB *firewalldb.DB
226+
firewallDB *firewalldb.BoltDB
227227

228228
restHandler http.Handler
229229
restCancel func()
@@ -457,7 +457,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
457457

458458
g.ruleMgrs = rules.NewRuleManagerSet()
459459

460-
g.firewallDB, err = firewalldb.NewDB(
460+
g.firewallDB, err = firewalldb.NewBoltDB(
461461
networkDir, firewalldb.DBFilename, g.stores.sessions,
462462
)
463463
if err != nil {

0 commit comments

Comments
 (0)