Files
mvds/store/messagestore_dummy.go
Andrea Maria Piana 9e1addbac0 Don't rely on the presence of GroupID for non-Messages types
This commits changes the behavior so that we don't rely on the presence
of GroupID in the payload.

Adds some tests to verify the basic functionalities of BATCH and
INTERACTIVE mode, but more are required to ensure the correct
functioning.

Error handling and state management is probably also to be inspected
more carefully.
2019-07-25 12:42:46 +02:00

46 lines
777 B
Go

package store
import (
"errors"
"sync"
"github.com/vacp2p/mvds/protobuf"
"github.com/vacp2p/mvds/state"
)
type DummyStore struct {
sync.Mutex
ms map[state.MessageID]*protobuf.Message
}
func NewDummyStore() DummyStore {
return DummyStore{ms: make(map[state.MessageID]*protobuf.Message)}
}
func (ds *DummyStore) Has(id state.MessageID) (bool, error) {
ds.Lock()
defer ds.Unlock()
_, ok := ds.ms[id]
return ok, nil
}
func (ds *DummyStore) 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 *DummyStore) Add(message *protobuf.Message) error {
ds.Lock()
defer ds.Unlock()
ds.ms[message.ID()] = message
return nil
}