diff --git a/service/p2p.go b/service/p2p.go index 1731471..e04c4d2 100644 --- a/service/p2p.go +++ b/service/p2p.go @@ -11,6 +11,7 @@ import ( "git.lumeweb.com/LumeWeb/libs5-go/protocol/base" "git.lumeweb.com/LumeWeb/libs5-go/protocol/signed" "git.lumeweb.com/LumeWeb/libs5-go/structs" + "git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/libs5-go/utils" "github.com/vmihailenco/msgpack/v5" bolt "go.etcd.io/bbolt" @@ -300,6 +301,25 @@ func (p *P2PImpl) readNodeVotes(nodeId *encoding.NodeId) (interfaces.NodeVotes, return score, nil } +func (p *P2PImpl) saveNodeVotes(nodeId *encoding.NodeId) (interfaces.NodeVotes, error) { + votes, err := p.readNodeVotes(nodeId) + if err != nil { + return nil, err + } + + data, err := msgpack.Marshal(votes) + if err != nil { + return nil, err + } + + err = p.nodesBucket.Put(nodeId.Raw(), data) + if err != nil { + return nil, err + } + + return votes, nil +} + func (p *P2PImpl) GetNodeScore(nodeId *encoding.NodeId) (float64, error) { if nodeId.Equals(p.localNodeID) { return 1, nil