Refactor: move peer name identifier to DB package
This commit is contained in:
1 parent
92cfd3b4f9
commit
30d6639a98
2 files changed
+6
-3
No files matched your search
@@ -23,6 +23,10 @@ var (
|
|||||||
topBucket = []byte("top")
|
topBucket = []byte("top")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NameIdent = "peername"
|
||||||
|
)
|
||||||
|
|
||||||
func NewBoltDB(dbPathname string) (*BoltDB, error) {
|
func NewBoltDB(dbPathname string) (*BoltDB, error) {
|
||||||
db, err := bolt.Open(dbPathname, 0660, nil)
|
db, err := bolt.Open(dbPathname, 0660, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+2
-3
@@ -920,13 +920,12 @@ func (alloc *Allocator) reportFreeSpace() {
|
|||||||
// Persistent data
|
// Persistent data
|
||||||
const (
|
const (
|
||||||
ringIdent = "ring"
|
ringIdent = "ring"
|
||||||
nameIdent = "peername"
|
|
||||||
ownedIdent = "ownedAddresses"
|
ownedIdent = "ownedAddresses"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (alloc *Allocator) persistRing() {
|
func (alloc *Allocator) persistRing() {
|
||||||
// It would be better if these two Save operations happened in the same transaction
|
// It would be better if these two Save operations happened in the same transaction
|
||||||
if err := alloc.db.Save(nameIdent, alloc.ourName); err != nil {
|
if err := alloc.db.Save(db.NameIdent, alloc.ourName); err != nil {
|
||||||
alloc.fatalf("Error persisting ring data: %s", err)
|
alloc.fatalf("Error persisting ring data: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -938,7 +937,7 @@ func (alloc *Allocator) persistRing() {
|
|||||||
// Returns true if persisted data is to be used, otherwise false
|
// Returns true if persisted data is to be used, otherwise false
|
||||||
func (alloc *Allocator) loadPersistedData() bool {
|
func (alloc *Allocator) loadPersistedData() bool {
|
||||||
var checkPeerName mesh.PeerName
|
var checkPeerName mesh.PeerName
|
||||||
nameFound, err := alloc.db.Load(nameIdent, &checkPeerName)
|
nameFound, err := alloc.db.Load(db.NameIdent, &checkPeerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
alloc.fatalf("Error loading persisted peer name: %s", err)
|
alloc.fatalf("Error loading persisted peer name: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user