peers separate
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2024-05-28 16:47:04 +02:00
parent c1883f1524
commit e674a0cb33
11 changed files with 164 additions and 79 deletions

View File

@ -12,6 +12,7 @@ import (
"forge.redroom.link/yves/meowlib"
"github.com/dgraph-io/badger"
"github.com/google/uuid"
)
type PeerStorage struct {
@ -22,7 +23,12 @@ type PeerStorage struct {
// Open the badger database from struct PeerStorage
func (ps *PeerStorage) open() error {
if ps.DbFile == "" {
ps.DbFile = uuid.New().String()
}
if ps.cache == nil {
ps.cache = make(map[string]*Peer)
}
opts := badger.DefaultOptions(filepath.Join(GetConfig().StoragePath, GetConfig().GetIdentity().Uuid, ps.DbFile))
opts.Logger = nil
var err error
@ -55,6 +61,8 @@ func (ps *PeerStorage) StorePeer(peer *Peer) error {
}
shakey := sha256.Sum256([]byte(peer.Uid))
key := shakey[:]
// add it to cache
ps.cache[peer.Uid] = peer
// then store it in the database
return ps.db.Update(func(txn *badger.Txn) error {
return txn.Set(key, data)