remove/protobuf-parent (#10)

* started removing

* updates

* fix

* please pass

* remove import
This commit is contained in:
Dean Eigenmann
2019-10-22 11:08:57 +02:00
committed by GitHub
parent 9a23767042
commit c2e58f0124
6 changed files with 36 additions and 147 deletions

View File

@@ -17,7 +17,6 @@ import (
"github.com/vacp2p/dasy/protobuf"
mvdsproto "github.com/vacp2p/mvds/protobuf"
"github.com/vacp2p/mvds/state"
"github.com/vacp2p/mvds/store"
)
// Chat is the ID for a specific chat.
@@ -33,12 +32,11 @@ type Client struct {
id Peer // @todo think of turning dataSyncNode ID into a func
node internal.DataSyncNode
store store.MessageStore
//store store.MessageStore
identity *ecdsa.PrivateKey
feeds map[protobuf.Message_MessageType]*event.Feed
lastMessages map[Chat]state.MessageID // @todo maybe make type
}
// Invite invites a peer to a chat.
@@ -100,7 +98,6 @@ func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) (s
msg := &protobuf.Message{
MessageType: protobuf.Message_MessageType(t),
Body: body,
PreviousMessage: c.lastMessage(chat),
}
err := crypto.Sign(c.identity, msg)
@@ -118,8 +115,6 @@ func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) (s
return state.MessageID{}, errors.Wrap(err, "failed to append message")
}
c.lastMessages[chat] = id
return id, nil
}
@@ -148,38 +143,4 @@ func (c *Client) onReceive(message mvdsproto.Message) {
}
go c.Feed(msg.MessageType).Send(payload)
if len(msg.PreviousMessage) == 0 {
return
}
c.handlePreviousMessage(
bytesToGroupID(message.GroupId),
bytesToMessageID(msg.PreviousMessage),
)
}
func (c *Client) handlePreviousMessage(group state.GroupID, previousMessage state.MessageID) {
ok, err := c.store.Has(previousMessage)
if ok {
return
}
if err != nil {
log.Printf("error while checking if message exists: %s", err.Error())
}
err = c.node.RequestMessage(group, previousMessage)
if err != nil {
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[:]
}

View File

@@ -37,7 +37,6 @@ func TestClient_Post(t *testing.T) {
client := Client{
node: node,
lastMessages: make(map[Chat]state.MessageID),
identity: identity,
}
@@ -85,42 +84,6 @@ func TestClient_Listen_MessageSentToFeed(t *testing.T) {
}
}
func TestClient_Listen_RequestsMissingParent(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
node := internal.NewMockDataSyncNode(ctrl)
store := internal.NewMockMessageStore(ctrl)
client := Client{
node: node,
store: store,
feeds: make(map[protobuf.Message_MessageType]*event.Feed),
}
sub := make(chan mvdsproto.Message)
node.EXPECT().Subscribe().Return(sub)
store.EXPECT().Has(gomock.Any()).Return(false, nil)
node.EXPECT().RequestMessage(gomock.Any(), gomock.Any()).Return(nil)
go client.Listen()
msg := createMessage()
msg.PreviousMessage = []byte("parent")
ok := make(chan event.Payload)
client.Feed(msg.MessageType).Subscribe(ok)
val, _ := proto.Marshal(msg)
sub<-mvdsproto.Message{
Body: val,
}
<-ok
}
func createMessage() *protobuf.Message {
msg := &protobuf.Message{
MessageType: protobuf.Message_POST,

View File

@@ -1,15 +1,15 @@
package client
import "github.com/vacp2p/mvds/state"
func bytesToMessageID(b []byte) state.MessageID {
var id state.MessageID
copy(id[:], b)
return id
}
func bytesToGroupID(b []byte) state.GroupID {
var id state.GroupID
copy(id[:], b)
return id
}
//import "github.com/vacp2p/mvds/state"
//
//func bytesToMessageID(b []byte) state.MessageID {
// var id state.MessageID
// copy(id[:], b)
// return id
//}
//
//func bytesToGroupID(b []byte) state.GroupID {
// var id state.GroupID
// copy(id[:], b)
// return id
//}