firewalldb: rename DB to BoltDB

In preparation for a db-backend agnostic DB struct along with a SQL
implementation of the various stores in the package which will be housed
under a struct named `SQLDB`.
This commit is contained in:
Elle Mouton 2025-04-01 09:30:42 +02:00
parent 70143dc10e
commit 5026e66e7c
No known key found for this signature in database
GPG key ID: D7D916376026F177
9 changed files with 31 additions and 26 deletions

View file

@ -117,7 +117,9 @@ type Action struct {
}
// AddAction serialises and adds an Action to the DB under the given sessionID.
func (db *DB) AddAction(sessionID session.ID, action *Action) (uint64, error) {
func (db *BoltDB) AddAction(sessionID session.ID, action *Action) (uint64,
error) {
var buf bytes.Buffer
if err := SerializeAction(&buf, action); err != nil {
return 0, err
@ -231,7 +233,7 @@ func getAction(actionsBkt *bbolt.Bucket, al *ActionLocator) (*Action, error) {
// SetActionState finds the action specified by the ActionLocator and sets its
// state to the given state.
func (db *DB) SetActionState(al *ActionLocator, state ActionState,
func (db *BoltDB) SetActionState(al *ActionLocator, state ActionState,
errorReason string) error {
if errorReason != "" && state != ActionStateError {
@ -293,7 +295,7 @@ type ListActionsFilterFn func(a *Action, reversed bool) (bool, bool)
// The indexOffset and maxNum params can be used to control the number of
// actions returned. The return values are the list of actions, the last index
// and the total count (iff query.CountTotal is set).
func (db *DB) ListActions(filterFn ListActionsFilterFn,
func (db *BoltDB) ListActions(filterFn ListActionsFilterFn,
query *ListActionsQuery) ([]*Action, uint64, uint64, error) {
var (
@ -345,7 +347,7 @@ func (db *DB) ListActions(filterFn ListActionsFilterFn,
// ListSessionActions returns a list of the given session's Actions that pass
// the filterFn requirements.
func (db *DB) ListSessionActions(sessionID session.ID,
func (db *BoltDB) ListSessionActions(sessionID session.ID,
filterFn ListActionsFilterFn, query *ListActionsQuery) ([]*Action,
uint64, uint64, error) {
@ -391,7 +393,7 @@ func (db *DB) ListSessionActions(sessionID session.ID,
// pass the filterFn requirements.
//
// TODO: update to allow for pagination.
func (db *DB) ListGroupActions(ctx context.Context, groupID session.ID,
func (db *BoltDB) ListGroupActions(ctx context.Context, groupID session.ID,
filterFn ListActionsFilterFn) ([]*Action, error) {
if filterFn == nil {
@ -589,7 +591,7 @@ type ActionReadDBGetter interface {
}
// GetActionsReadDB is a method on DB that constructs an ActionsReadDB.
func (db *DB) GetActionsReadDB(groupID session.ID,
func (db *BoltDB) GetActionsReadDB(groupID session.ID,
featureName string) ActionsReadDB {
return &allActionsReadDB{
@ -601,7 +603,7 @@ func (db *DB) GetActionsReadDB(groupID session.ID,
// allActionsReadDb is an implementation of the ActionsReadDB.
type allActionsReadDB struct {
db *DB
db *BoltDB
groupID session.ID
featureName string
}

View file

@ -43,7 +43,7 @@ var (
func TestActionStorage(t *testing.T) {
tmpDir := t.TempDir()
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
@ -151,7 +151,7 @@ func TestActionStorage(t *testing.T) {
func TestListActions(t *testing.T) {
tmpDir := t.TempDir()
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
@ -353,7 +353,7 @@ func TestListGroupActions(t *testing.T) {
index.AddPair(sessionID1, group1)
index.AddPair(sessionID2, group1)
db, err := NewDB(t.TempDir(), "test.db", index)
db, err := NewBoltDB(t.TempDir(), "test.db", index)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()

View file

@ -37,15 +37,18 @@ var (
ErrNoSuchKeyFound = fmt.Errorf("no such key found")
)
// DB is a bolt-backed persistent store.
type DB struct {
// BoltDB is a bolt-backed persistent store.
type BoltDB struct {
*bbolt.DB
sessionIDIndex SessionDB
}
// NewDB creates a new bolt database that can be found at the given directory.
func NewDB(dir, fileName string, sessionIDIndex SessionDB) (*DB, error) {
// NewBoltDB creates a new bolt database that can be found at the given
// directory.
func NewBoltDB(dir, fileName string, sessionIDIndex SessionDB) (*BoltDB,
error) {
firstInit := false
path := filepath.Join(dir, fileName)
@ -68,7 +71,7 @@ func NewDB(dir, fileName string, sessionIDIndex SessionDB) (*DB, error) {
return nil, err
}
return &DB{
return &BoltDB{
DB: db,
sessionIDIndex: sessionIDIndex,
}, nil

View file

@ -104,7 +104,7 @@ type RulesDB interface {
}
// GetKVStores constructs a new rules.KVStores backed by a bbolt db.
func (db *DB) GetKVStores(rule string, groupID session.ID,
func (db *BoltDB) GetKVStores(rule string, groupID session.ID,
feature string) KVStores {
return &kvdbExecutor[KVStoreTx]{

View file

@ -18,7 +18,7 @@ func TestKVStoreTxs(t *testing.T) {
ctx := context.Background()
tmpDir := t.TempDir()
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
@ -86,7 +86,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
featureName = "auto-fees"
}
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
@ -134,7 +134,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
require.NoError(t, db.Close())
// Restart it.
db, err = NewDB(tmpDir, "test.db", nil)
db, err = NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
@ -168,7 +168,7 @@ func TestKVStoreNameSpaces(t *testing.T) {
ctx := context.Background()
tmpDir := t.TempDir()
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()

View file

@ -41,7 +41,7 @@ type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
// group ID key.
func (db *DB) PrivacyDB(groupID session.ID) PrivacyMapDB {
func (db *BoltDB) PrivacyDB(groupID session.ID) PrivacyMapDB {
return &kvdbExecutor[PrivacyMapTx]{
db: db.DB,
wrapTx: func(tx *bbolt.Tx) PrivacyMapTx {

View file

@ -14,7 +14,7 @@ func TestPrivacyMapStorage(t *testing.T) {
ctx := context.Background()
tmpDir := t.TempDir()
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
@ -188,7 +188,7 @@ func TestPrivacyMapTxs(t *testing.T) {
ctx := context.Background()
tmpDir := t.TempDir()
db, err := NewDB(tmpDir, "test.db", nil)
db, err := NewBoltDB(tmpDir, "test.db", nil)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()

View file

@ -63,7 +63,7 @@ type sessionRpcServerConfig struct {
superMacBaker litmac.Baker
firstConnectionDeadline time.Duration
permMgr *perms.Manager
actionsDB *firewalldb.DB
actionsDB *firewalldb.BoltDB
autopilot autopilotserver.Autopilot
ruleMgrs rules.ManagerSet
privMap firewalldb.NewPrivacyMapDB

View file

@ -223,7 +223,7 @@ type LightningTerminal struct {
stores *stores
firewallDB *firewalldb.DB
firewallDB *firewalldb.BoltDB
restHandler http.Handler
restCancel func()
@ -457,7 +457,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
g.ruleMgrs = rules.NewRuleManagerSet()
g.firewallDB, err = firewalldb.NewDB(
g.firewallDB, err = firewalldb.NewBoltDB(
networkDir, firewalldb.DBFilename, g.stores.sessions,
)
if err != nil {