Skip to content

Commit 7c7e467

Browse files
committed
firewalldb: update comments and var names
Change all comments and variable names mentioning "session ID" to "group ID" instead. As of this commit, session linking is not yet possible and so what ever session IDs are passed in are also group IDs.
1 parent cc95a01 commit 7c7e467

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

firewalldb/kvstores.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ the `perm` and `temp` buckets are identical in structure. The only difference is
1313
that the `temp` bucket is cleared on restart of the db.
1414
1515
rules -> perm -> rule-name -> global -> {k:v}
16-
-> sessions -> sessionID -> session-kv-store -> {k:v}
16+
-> sessions -> group ID -> session-kv-store -> {k:v}
1717
-> feature-kv-stores -> feature-name -> {k:v}
1818
1919
-> temp -> rule-name -> global -> {k:v}
20-
-> sessions -> sessionID -> session-kv-store -> {k:v}
20+
-> sessions -> group ID -> session-kv-store -> {k:v}
2121
-> feature-kv-stores -> feature-name -> {k:v}
2222
*/
2323

@@ -44,7 +44,7 @@ var (
4444
sessKVStoreBucketKey = []byte("session-kv-store")
4545

4646
// featureKVStoreBucketKey is the kye under which a kv store specific
47-
// the session id and feature name is stored.
47+
// the group id and feature name is stored.
4848
featureKVStoreBucketKey = []byte("feature-kv-store")
4949
)
5050

@@ -72,12 +72,12 @@ type KVStores interface {
7272
type KVStoreTx interface {
7373
// Global returns a persisted global, rule-name indexed, kv store. A
7474
// rule with a given name will have access to this store independent of
75-
// session ID or feature.
75+
// group ID or feature.
7676
Global() KVStore
7777

7878
// Local returns a persisted local kv store for the rule. Depending on
7979
// how the implementation is initialised, this will either be under the
80-
// session ID namespace or the session ID _and_ feature name namespace.
80+
// group ID namespace or the group ID _and_ feature name namespace.
8181
Local() KVStore
8282

8383
// GlobalTemp is similar to the Global store except that its contents
@@ -105,17 +105,17 @@ type KVStore interface {
105105

106106
// RulesDB can be used to initialise a new rules.KVStores.
107107
type RulesDB interface {
108-
GetKVStores(rule string, sessionID session.ID, feature string) KVStores
108+
GetKVStores(rule string, groupID session.ID, feature string) KVStores
109109
}
110110

111111
// GetKVStores constructs a new rules.KVStores backed by a bbolt db.
112-
func (db *DB) GetKVStores(rule string, sessionID session.ID,
112+
func (db *DB) GetKVStores(rule string, groupID session.ID,
113113
feature string) KVStores {
114114

115115
return &kvStores{
116116
DB: db,
117117
ruleName: rule,
118-
sessionID: sessionID,
118+
groupID: groupID,
119119
featureName: feature,
120120
}
121121
}
@@ -124,7 +124,7 @@ func (db *DB) GetKVStores(rule string, sessionID session.ID,
124124
type kvStores struct {
125125
*DB
126126
ruleName string
127-
sessionID session.ID
127+
groupID session.ID
128128
featureName string
129129
}
130130

@@ -237,10 +237,10 @@ func (tx *kvStoreTx) Global() KVStore {
237237
//
238238
// NOTE: this is part of the KVStoreTx interface.
239239
func (tx *kvStoreTx) Local() KVStore {
240-
fn := getSessionRuleBucket(true, tx.ruleName, tx.sessionID)
240+
fn := getSessionRuleBucket(true, tx.ruleName, tx.groupID)
241241
if tx.featureName != "" {
242242
fn = getSessionFeatureRuleBucket(
243-
true, tx.ruleName, tx.sessionID, tx.featureName,
243+
true, tx.ruleName, tx.groupID, tx.featureName,
244244
)
245245
}
246246

@@ -268,10 +268,10 @@ func (tx *kvStoreTx) GlobalTemp() KVStore {
268268
//
269269
// NOTE: this is part of the KVStoreTx interface.
270270
func (tx *kvStoreTx) LocalTemp() KVStore {
271-
fn := getSessionRuleBucket(true, tx.ruleName, tx.sessionID)
271+
fn := getSessionRuleBucket(true, tx.ruleName, tx.groupID)
272272
if tx.featureName != "" {
273273
fn = getSessionFeatureRuleBucket(
274-
false, tx.ruleName, tx.sessionID, tx.featureName,
274+
false, tx.ruleName, tx.groupID, tx.featureName,
275275
)
276276
}
277277

@@ -390,11 +390,11 @@ func getGlobalRuleBucket(perm bool, ruleName string) getBucketFunc {
390390
}
391391

392392
// getSessionRuleBucket returns a function that can be used to fetch the
393-
// bucket under which a kv store for a specific rule-name and session ID is
393+
// bucket under which a kv store for a specific rule-name and group ID is
394394
// stored. The `perm` param determines if the temporary or permanent store is
395395
// used.
396396
func getSessionRuleBucket(perm bool, ruleName string,
397-
sessionID session.ID) getBucketFunc {
397+
groupID session.ID) getBucketFunc {
398398

399399
return func(tx *bbolt.Tx, create bool) (*bbolt.Bucket, error) {
400400
ruleBucket, err := getRuleBucket(perm, ruleName)(tx, create)
@@ -414,27 +414,28 @@ func getSessionRuleBucket(perm bool, ruleName string,
414414
return nil, err
415415
}
416416

417-
return sessBucket.CreateBucketIfNotExists(sessionID[:])
417+
return sessBucket.CreateBucketIfNotExists(groupID[:])
418418
}
419419

420420
sessBucket := ruleBucket.Bucket(sessKVStoreBucketKey)
421421
if sessBucket == nil {
422422
return nil, nil
423423
}
424-
return sessBucket.Bucket(sessionID[:]), nil
424+
return sessBucket.Bucket(groupID[:]), nil
425425
}
426426
}
427427

428428
// getSessionFeatureRuleBucket returns a function that can be used to fetch the
429-
// bucket under which a kv store for a specific rule-name, session ID and
429+
// bucket under which a kv store for a specific rule-name, group ID and
430430
// feature name is stored. The `perm` param determines if the temporary or
431431
// permanent store is used.
432432
func getSessionFeatureRuleBucket(perm bool, ruleName string,
433-
sessionID session.ID, featureName string) getBucketFunc {
433+
groupID session.ID, featureName string) getBucketFunc {
434434

435435
return func(tx *bbolt.Tx, create bool) (*bbolt.Bucket, error) {
436436
sessBucket, err := getSessionRuleBucket(
437-
perm, ruleName, sessionID)(tx, create)
437+
perm, ruleName, groupID,
438+
)(tx, create)
438439
if err != nil {
439440
return nil, err
440441
}

firewalldb/kvstores_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"testing"
99

10+
"github.com/lightninglabs/lightning-terminal/session"
1011
"github.com/stretchr/testify/require"
1112
)
1213

@@ -153,17 +154,17 @@ func TestKVStoreNameSpaces(t *testing.T) {
153154
})
154155

155156
var (
156-
sessionID1 = [4]byte{1, 1, 1, 1}
157-
sessionID2 = [4]byte{2, 2, 2, 2}
157+
groupID1 = intToSessionID(1)
158+
groupID2 = intToSessionID(2)
158159
)
159160

160-
// Two DBs for same session but different features.
161-
rulesDB1 := db.GetKVStores("test-rule", sessionID1, "auto-fees")
162-
rulesDB2 := db.GetKVStores("test-rule", sessionID1, "re-balance")
161+
// Two DBs for same group but different features.
162+
rulesDB1 := db.GetKVStores("test-rule", groupID1, "auto-fees")
163+
rulesDB2 := db.GetKVStores("test-rule", groupID1, "re-balance")
163164

164-
// The third DB is for the same rule but a different session. It is
165+
// The third DB is for the same rule but a different group. It is
165166
// for the same feature as db 2.
166-
rulesDB3 := db.GetKVStores("test-rule", sessionID2, "re-balance")
167+
rulesDB3 := db.GetKVStores("test-rule", groupID2, "re-balance")
167168

168169
// Test that the three ruleDBs share the same global space.
169170
err = rulesDB1.Update(func(tx KVStoreTx) error {
@@ -270,12 +271,12 @@ func TestKVStoreNameSpaces(t *testing.T) {
270271
require.NoError(t, err)
271272
require.True(t, bytes.Equal(v, []byte("3")))
272273

273-
// Test that the session space is shared by the first two dbs but not
274+
// Test that the group space is shared by the first two dbs but not
274275
// the third. To do this, we re-init the DB's but leave the feature
275-
// names out. This way, we will access the session storage.
276-
rulesDB1 = db.GetKVStores("test-rule", sessionID1, "")
277-
rulesDB2 = db.GetKVStores("test-rule", sessionID1, "")
278-
rulesDB3 = db.GetKVStores("test-rule", sessionID2, "")
276+
// names out. This way, we will access the group storage.
277+
rulesDB1 = db.GetKVStores("test-rule", groupID1, "")
278+
rulesDB2 = db.GetKVStores("test-rule", groupID1, "")
279+
rulesDB3 = db.GetKVStores("test-rule", groupID2, "")
279280

280281
err = rulesDB1.Update(func(tx KVStoreTx) error {
281282
return tx.Local().Set(ctx, "test", []byte("thing 1"))
@@ -325,3 +326,10 @@ func TestKVStoreNameSpaces(t *testing.T) {
325326
require.NoError(t, err)
326327
require.True(t, bytes.Equal(v, []byte("thing 3")))
327328
}
329+
330+
func intToSessionID(i uint32) session.ID {
331+
var id session.ID
332+
byteOrder.PutUint32(id[:], i)
333+
334+
return id
335+
}

firewalldb/privacy_mapper.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
/*
1717
The PrivacyMapper data is stored in the following structure in the db:
1818
19-
privacy -> session id -> real-to-pseudo -> {k:v}
20-
-> pseudo-to-real -> {k:v}
19+
privacy -> group id -> real-to-pseudo -> {k:v}
20+
-> pseudo-to-real -> {k:v}
2121
*/
2222

2323
const (
@@ -33,16 +33,16 @@ var (
3333
pseudoStrAlphabetLen = len(pseudoStrAlphabet)
3434
)
3535

36-
// NewPrivacyMapDB is a function type that takes a session ID and uses it to
36+
// NewPrivacyMapDB is a function type that takes a group ID and uses it to
3737
// construct a new PrivacyMapDB.
38-
type NewPrivacyMapDB func(sessionID session.ID) PrivacyMapDB
38+
type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
3939

4040
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
41-
// sessionID key.
42-
func (db *DB) PrivacyDB(sessionID session.ID) PrivacyMapDB {
41+
// group ID key.
42+
func (db *DB) PrivacyDB(groupID session.ID) PrivacyMapDB {
4343
return &privacyMapDB{
44-
DB: db,
45-
sessionID: sessionID,
44+
DB: db,
45+
groupID: groupID,
4646
}
4747
}
4848

@@ -83,7 +83,7 @@ type PrivacyMapTx interface {
8383
// privacyMapDB is an implementation of PrivacyMapDB.
8484
type privacyMapDB struct {
8585
*DB
86-
sessionID session.ID
86+
groupID session.ID
8787
}
8888

8989
// beginTx starts db transaction. The transaction will be a read or read-write
@@ -175,7 +175,7 @@ func (p *privacyMapTx) NewPair(real, pseudo string) error {
175175
return err
176176
}
177177

178-
sessBucket, err := privacyBucket.CreateBucketIfNotExists(p.sessionID[:])
178+
sessBucket, err := privacyBucket.CreateBucketIfNotExists(p.groupID[:])
179179
if err != nil {
180180
return err
181181
}
@@ -210,7 +210,7 @@ func (p *privacyMapTx) PseudoToReal(pseudo string) (string, error) {
210210
return "", err
211211
}
212212

213-
sessBucket := privacyBucket.Bucket(p.sessionID[:])
213+
sessBucket := privacyBucket.Bucket(p.groupID[:])
214214
if sessBucket == nil {
215215
return "", ErrNoSuchKeyFound
216216
}
@@ -236,7 +236,7 @@ func (p *privacyMapTx) RealToPseudo(real string) (string, error) {
236236
return "", err
237237
}
238238

239-
sessBucket := privacyBucket.Bucket(p.sessionID[:])
239+
sessBucket := privacyBucket.Bucket(p.groupID[:])
240240
if sessBucket == nil {
241241
return "", ErrNoSuchKeyFound
242242
}

0 commit comments

Comments
 (0)