mirror of
https://github.com/vacp2p/mvds.git
synced 2026-01-08 19:48:03 -05:00
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.
46 lines
777 B
Go
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
|
|
}
|