mirror of
https://github.com/vacp2p/mvds.git
synced 2026-01-08 19:48:03 -05:00
* protobuf * do not send ack when not required * remove from state if no ack required * different send modes * fix * updated * retransmit fix * updated * fixed * renamed to ephemeral * repeated * gen * resolution * cleanup * rough dependency code * todo * removed * only stores if ephemeral * started implementing the algo * simplified * updated * we never store ephemeral messages so we did not need * adds parents * new schema * tx to insert * err * removed old * fixed * changed log * test persistence of parents * removed * rename * ignoring * Update store/messagestore_sqlite.go Co-Authored-By: Adam Babik <adam@status.im> * Update node/node.go Co-Authored-By: Adam Babik <adam@status.im> * Update node/node.go Co-Authored-By: Adam Babik <adam@status.im> * Update node/node.go Co-Authored-By: Adam Babik <adam@status.im> * more fixes * Update store/messagestore_sqlite.go Co-Authored-By: Adam Babik <adam@status.im> * more fixes * using refs * Update node/node.go Co-Authored-By: Adam Babik <adam@status.im> * finished * Update store/messagestore_sqlite.go Co-Authored-By: Adam Babik <adam@status.im> * Update 1572372377_initial_schema.down.sql * desc + refactor * started refactoring resolution * Update README.md * rewrote resolve * mutex * todo * fixes * sql impl * added test * log * updates * updated * little bug * fix * added test * first changes from @adambabik * moved * fixed test, started eventual ones * fixed eventually test * mock install * consistent test * mock * fix lint * Update dependency/tracker_sqlite.go Co-Authored-By: Adam Babik <adam@status.im> * fix
82 lines
1.5 KiB
Go
82 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
|
|
"github.com/vacp2p/mvds/protobuf"
|
|
"github.com/vacp2p/mvds/state"
|
|
)
|
|
|
|
type memoryMessageStore struct {
|
|
sync.Mutex
|
|
ms map[state.MessageID]*protobuf.Message
|
|
}
|
|
|
|
func NewMemoryMessageStore() *memoryMessageStore {
|
|
return &memoryMessageStore{ms: make(map[state.MessageID]*protobuf.Message)}
|
|
}
|
|
|
|
func (ds *memoryMessageStore) Has(id state.MessageID) (bool, error) {
|
|
ds.Lock()
|
|
defer ds.Unlock()
|
|
|
|
_, ok := ds.ms[id]
|
|
return ok, nil
|
|
}
|
|
|
|
func (ds *memoryMessageStore) Get(id state.MessageID) (*protobuf.Message, error) {
|
|
ds.Lock()
|
|
defer ds.Unlock()
|
|
|
|
m, ok := ds.ms[id]
|
|
if !ok {
|
|
return nil, errors.New("message does not exist")
|
|
}
|
|
|
|
return m, nil
|
|
}
|
|
|
|
func (ds *memoryMessageStore) Add(message *protobuf.Message) error {
|
|
ds.Lock()
|
|
defer ds.Unlock()
|
|
ds.ms[message.ID()] = message
|
|
return nil
|
|
}
|
|
|
|
func (ds *memoryMessageStore) GetMessagesWithoutChildren(group state.GroupID) ([]state.MessageID, error) {
|
|
ds.Lock()
|
|
defer ds.Unlock()
|
|
|
|
hasChildren := make(map[state.MessageID]bool)
|
|
|
|
for id, msg := range ds.ms {
|
|
if state.ToGroupID(msg.GroupId) != group {
|
|
continue
|
|
}
|
|
|
|
if msg.Metadata != nil {
|
|
for _, parent := range msg.Metadata.Parents {
|
|
hasChildren[state.ToMessageID(parent)] = true
|
|
}
|
|
}
|
|
|
|
if hasChildren[id] {
|
|
continue
|
|
}
|
|
|
|
hasChildren[id] = false
|
|
}
|
|
|
|
msgs := make([]state.MessageID, 0)
|
|
for id, hasChildren := range hasChildren {
|
|
if hasChildren {
|
|
continue
|
|
}
|
|
|
|
msgs = append(msgs, id)
|
|
}
|
|
|
|
return msgs, nil
|
|
}
|