lightning-terminal/firewalldb/db.go
Viktor Tigerström 770c1beecf
firewalldb: export FirewallDBs interface
In the upcoming migration of the firewall database to SQL, the helper
functions that creates the test databases of different types, need to
return a unified interface in order to not have to control the
migration tests file by build tags. Therefore, we export the unified
interface FirewallDBs, so that it can be returned public test DB
creation functions
2025-07-21 14:45:45 +02:00

50 lines
946 B
Go

package firewalldb
import (
"context"
"fmt"
"sync"
"github.com/lightningnetwork/lnd/fn"
)
var (
// ErrNoSuchKeyFound is returned when there is no key-value pair found
// for the given key.
ErrNoSuchKeyFound = fmt.Errorf("no such key found")
)
// DB manages the firewall rules database.
type DB struct {
started sync.Once
stopped sync.Once
FirewallDBs
cancel fn.Option[context.CancelFunc]
}
// NewDB creates a new firewall database. For now, it only contains the
// underlying rules' and privacy mapper databases.
func NewDB(dbs FirewallDBs) *DB {
return &DB{
FirewallDBs: dbs,
}
}
// Start starts the firewall database.
func (db *DB) Start(ctx context.Context) error {
db.started.Do(func() {
_, cancel := context.WithCancel(ctx)
db.cancel = fn.Some(cancel)
})
return db.DeleteTempKVStores(ctx)
}
// Stop stops the firewall database operations.
func (db *DB) Stop() error {
db.stopped.Do(func() {})
return nil
}