mirror of https://github.com/vacp2p/dasy.git
parent
e7b5548812
commit
01e7ad18db
|
@ -95,11 +95,10 @@ func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) (s
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
lastMessage := c.lastMessages[chat]
|
|
||||||
msg := &protobuf.Message{
|
msg := &protobuf.Message{
|
||||||
MessageType: protobuf.Message_MessageType(t),
|
MessageType: protobuf.Message_MessageType(t),
|
||||||
Body: body,
|
Body: body,
|
||||||
PreviousMessage: lastMessage[:],
|
PreviousMessage: c.lastMessage(chat),
|
||||||
}
|
}
|
||||||
|
|
||||||
err := crypto.Sign(c.identity, msg)
|
err := crypto.Sign(c.identity, msg)
|
||||||
|
@ -173,3 +172,12 @@ func (c *Client) handlePreviousMessage(group state.GroupID, previousMessage stat
|
||||||
log.Printf("error while requesting message: %s", err.Error())
|
log.Printf("error while requesting message: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) lastMessage(chat Chat) []byte {
|
||||||
|
last, ok := c.lastMessages[chat]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return last[:]
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/vacp2p/dasy/event"
|
"github.com/vacp2p/dasy/event"
|
||||||
"github.com/vacp2p/dasy/protobuf"
|
"github.com/vacp2p/dasy/protobuf"
|
||||||
mvdsproto "github.com/vacp2p/mvds/protobuf"
|
mvdsproto "github.com/vacp2p/mvds/protobuf"
|
||||||
|
"github.com/vacp2p/mvds/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -27,6 +28,30 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
// @todo think about turning feed into an interface so we can mock it and ensure its never called when sigs fail
|
// @todo think about turning feed into an interface so we can mock it and ensure its never called when sigs fail
|
||||||
|
|
||||||
|
func TestClient_Post(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
|
||||||
|
node := internal.NewMockDataSyncNode(ctrl)
|
||||||
|
identity, _ := ecdsa.GenerateKey(secp256k1.S256(), rand.Reader)
|
||||||
|
|
||||||
|
client := Client{
|
||||||
|
node: node,
|
||||||
|
lastMessages: make(map[Chat]state.MessageID),
|
||||||
|
identity: identity,
|
||||||
|
}
|
||||||
|
|
||||||
|
chat := Chat([32]byte{0x01, 0x2, 0x3, 0x4})
|
||||||
|
msgid := state.MessageID([32]byte{0x01, 0x2, 0x3})
|
||||||
|
|
||||||
|
node.EXPECT().AppendMessage(state.GroupID(chat), gomock.Any()).Return(msgid, nil)
|
||||||
|
|
||||||
|
ret, _ := client.Post(chat, []byte("string"))
|
||||||
|
if msgid != ret {
|
||||||
|
t.Error("returned message ID does not match expected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestClient_Listen_MessageSentToFeed(t *testing.T) {
|
func TestClient_Listen_MessageSentToFeed(t *testing.T) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
Loading…
Reference in New Issue