mirror of https://github.com/vacp2p/dasy.git
remove/protobuf-parent (#10)
* started removing * updates * fix * please pass * remove import
This commit is contained in:
parent
9a23767042
commit
c2e58f0124
|
@ -17,7 +17,6 @@ import (
|
||||||
"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"
|
"github.com/vacp2p/mvds/state"
|
||||||
"github.com/vacp2p/mvds/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Chat is the ID for a specific chat.
|
// 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
|
id Peer // @todo think of turning dataSyncNode ID into a func
|
||||||
|
|
||||||
node internal.DataSyncNode
|
node internal.DataSyncNode
|
||||||
store store.MessageStore
|
//store store.MessageStore
|
||||||
|
|
||||||
identity *ecdsa.PrivateKey
|
identity *ecdsa.PrivateKey
|
||||||
|
|
||||||
feeds map[protobuf.Message_MessageType]*event.Feed
|
feeds map[protobuf.Message_MessageType]*event.Feed
|
||||||
lastMessages map[Chat]state.MessageID // @todo maybe make type
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invite invites a peer to a chat.
|
// 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{
|
msg := &protobuf.Message{
|
||||||
MessageType: protobuf.Message_MessageType(t),
|
MessageType: protobuf.Message_MessageType(t),
|
||||||
Body: body,
|
Body: body,
|
||||||
PreviousMessage: c.lastMessage(chat),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := crypto.Sign(c.identity, msg)
|
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")
|
return state.MessageID{}, errors.Wrap(err, "failed to append message")
|
||||||
}
|
}
|
||||||
|
|
||||||
c.lastMessages[chat] = id
|
|
||||||
|
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,38 +143,4 @@ func (c *Client) onReceive(message mvdsproto.Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
go c.Feed(msg.MessageType).Send(payload)
|
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[:]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ func TestClient_Post(t *testing.T) {
|
||||||
|
|
||||||
client := Client{
|
client := Client{
|
||||||
node: node,
|
node: node,
|
||||||
lastMessages: make(map[Chat]state.MessageID),
|
|
||||||
identity: identity,
|
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 {
|
func createMessage() *protobuf.Message {
|
||||||
msg := &protobuf.Message{
|
msg := &protobuf.Message{
|
||||||
MessageType: protobuf.Message_POST,
|
MessageType: protobuf.Message_POST,
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import "github.com/vacp2p/mvds/state"
|
//import "github.com/vacp2p/mvds/state"
|
||||||
|
//
|
||||||
func bytesToMessageID(b []byte) state.MessageID {
|
//func bytesToMessageID(b []byte) state.MessageID {
|
||||||
var id state.MessageID
|
// var id state.MessageID
|
||||||
copy(id[:], b)
|
// copy(id[:], b)
|
||||||
return id
|
// return id
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
func bytesToGroupID(b []byte) state.GroupID {
|
//func bytesToGroupID(b []byte) state.GroupID {
|
||||||
var id state.GroupID
|
// var id state.GroupID
|
||||||
copy(id[:], b)
|
// copy(id[:], b)
|
||||||
return id
|
// return id
|
||||||
}
|
//}
|
||||||
|
|
|
@ -3,11 +3,9 @@
|
||||||
|
|
||||||
package protobuf
|
package protobuf
|
||||||
|
|
||||||
import (
|
import proto "github.com/golang/protobuf/proto"
|
||||||
fmt "fmt"
|
import fmt "fmt"
|
||||||
proto "github.com/golang/protobuf/proto"
|
import math "math"
|
||||||
math "math"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
var _ = proto.Marshal
|
var _ = proto.Marshal
|
||||||
|
@ -18,7 +16,7 @@ var _ = math.Inf
|
||||||
// is compatible with the proto package it is being compiled against.
|
// is compatible with the proto package it is being compiled against.
|
||||||
// A compilation error at this line likely means your copy of the
|
// A compilation error at this line likely means your copy of the
|
||||||
// proto package needs to be updated.
|
// proto package needs to be updated.
|
||||||
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
type Message_MessageType int32
|
type Message_MessageType int32
|
||||||
|
|
||||||
|
@ -39,7 +37,6 @@ var Message_MessageType_name = map[int32]string{
|
||||||
4: "ACK",
|
4: "ACK",
|
||||||
5: "POST",
|
5: "POST",
|
||||||
}
|
}
|
||||||
|
|
||||||
var Message_MessageType_value = map[string]int32{
|
var Message_MessageType_value = map[string]int32{
|
||||||
"INVITE": 0,
|
"INVITE": 0,
|
||||||
"JOIN": 1,
|
"JOIN": 1,
|
||||||
|
@ -52,16 +49,14 @@ var Message_MessageType_value = map[string]int32{
|
||||||
func (x Message_MessageType) String() string {
|
func (x Message_MessageType) String() string {
|
||||||
return proto.EnumName(Message_MessageType_name, int32(x))
|
return proto.EnumName(Message_MessageType_name, int32(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Message_MessageType) EnumDescriptor() ([]byte, []int) {
|
func (Message_MessageType) EnumDescriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_8368f5d77b0b9b7b, []int{0, 0}
|
return fileDescriptor_message_fd151bea13cda030, []int{0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
MessageType Message_MessageType `protobuf:"varint,1,opt,name=message_type,json=messageType,proto3,enum=mvds.Message_MessageType" json:"message_type,omitempty"`
|
MessageType Message_MessageType `protobuf:"varint,1,opt,name=message_type,json=messageType,proto3,enum=mvds.Message_MessageType" json:"message_type,omitempty"`
|
||||||
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
Body []byte `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
||||||
PreviousMessage []byte `protobuf:"bytes,3,opt,name=previous_message,json=previousMessage,proto3" json:"previous_message,omitempty"`
|
Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"`
|
||||||
Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"`
|
|
||||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||||
XXX_unrecognized []byte `json:"-"`
|
XXX_unrecognized []byte `json:"-"`
|
||||||
XXX_sizecache int32 `json:"-"`
|
XXX_sizecache int32 `json:"-"`
|
||||||
|
@ -71,17 +66,16 @@ func (m *Message) Reset() { *m = Message{} }
|
||||||
func (m *Message) String() string { return proto.CompactTextString(m) }
|
func (m *Message) String() string { return proto.CompactTextString(m) }
|
||||||
func (*Message) ProtoMessage() {}
|
func (*Message) ProtoMessage() {}
|
||||||
func (*Message) Descriptor() ([]byte, []int) {
|
func (*Message) Descriptor() ([]byte, []int) {
|
||||||
return fileDescriptor_8368f5d77b0b9b7b, []int{0}
|
return fileDescriptor_message_fd151bea13cda030, []int{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) XXX_Unmarshal(b []byte) error {
|
func (m *Message) XXX_Unmarshal(b []byte) error {
|
||||||
return xxx_messageInfo_Message.Unmarshal(m, b)
|
return xxx_messageInfo_Message.Unmarshal(m, b)
|
||||||
}
|
}
|
||||||
func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
func (m *Message) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
return xxx_messageInfo_Message.Marshal(b, m, deterministic)
|
return xxx_messageInfo_Message.Marshal(b, m, deterministic)
|
||||||
}
|
}
|
||||||
func (m *Message) XXX_Merge(src proto.Message) {
|
func (dst *Message) XXX_Merge(src proto.Message) {
|
||||||
xxx_messageInfo_Message.Merge(m, src)
|
xxx_messageInfo_Message.Merge(dst, src)
|
||||||
}
|
}
|
||||||
func (m *Message) XXX_Size() int {
|
func (m *Message) XXX_Size() int {
|
||||||
return xxx_messageInfo_Message.Size(m)
|
return xxx_messageInfo_Message.Size(m)
|
||||||
|
@ -106,13 +100,6 @@ func (m *Message) GetBody() []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Message) GetPreviousMessage() []byte {
|
|
||||||
if m != nil {
|
|
||||||
return m.PreviousMessage
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Message) GetSignature() []byte {
|
func (m *Message) GetSignature() []byte {
|
||||||
if m != nil {
|
if m != nil {
|
||||||
return m.Signature
|
return m.Signature
|
||||||
|
@ -121,27 +108,25 @@ func (m *Message) GetSignature() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterEnum("mvds.Message_MessageType", Message_MessageType_name, Message_MessageType_value)
|
|
||||||
proto.RegisterType((*Message)(nil), "mvds.Message")
|
proto.RegisterType((*Message)(nil), "mvds.Message")
|
||||||
|
proto.RegisterEnum("mvds.Message_MessageType", Message_MessageType_name, Message_MessageType_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { proto.RegisterFile("protobuf/message.proto", fileDescriptor_8368f5d77b0b9b7b) }
|
func init() { proto.RegisterFile("protobuf/message.proto", fileDescriptor_message_fd151bea13cda030) }
|
||||||
|
|
||||||
var fileDescriptor_8368f5d77b0b9b7b = []byte{
|
var fileDescriptor_message_fd151bea13cda030 = []byte{
|
||||||
// 228 bytes of a gzipped FileDescriptorProto
|
// 205 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x28, 0xca, 0x2f,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2b, 0x28, 0xca, 0x2f,
|
||||||
0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0x4f, 0xd5, 0x03, 0x0b, 0x08,
|
0xc9, 0x4f, 0x2a, 0x4d, 0xd3, 0xcf, 0x4d, 0x2d, 0x2e, 0x4e, 0x4c, 0x4f, 0xd5, 0x03, 0x0b, 0x08,
|
||||||
0xb1, 0xe4, 0x96, 0xa5, 0x14, 0x2b, 0x7d, 0x64, 0xe4, 0x62, 0xf7, 0x85, 0x88, 0x0b, 0xd9, 0x70,
|
0xb1, 0xe4, 0x96, 0xa5, 0x14, 0x2b, 0x1d, 0x63, 0xe4, 0x62, 0xf7, 0x85, 0x88, 0x0b, 0xd9, 0x70,
|
||||||
0xf1, 0x40, 0x95, 0xc4, 0x97, 0x54, 0x16, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x19, 0x49,
|
0xf1, 0x40, 0x95, 0xc4, 0x97, 0x54, 0x16, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x19, 0x49,
|
||||||
0xea, 0x81, 0x14, 0xea, 0x41, 0x15, 0xc1, 0xe8, 0x90, 0xca, 0x82, 0xd4, 0x20, 0xee, 0x5c, 0x04,
|
0xea, 0x81, 0x14, 0xea, 0x41, 0x15, 0xc1, 0xe8, 0x90, 0xca, 0x82, 0xd4, 0x20, 0xee, 0x5c, 0x04,
|
||||||
0x47, 0x48, 0x88, 0x8b, 0x25, 0x29, 0x3f, 0xa5, 0x52, 0x82, 0x49, 0x81, 0x51, 0x83, 0x27, 0x08,
|
0x47, 0x48, 0x88, 0x8b, 0x25, 0x29, 0x3f, 0xa5, 0x52, 0x82, 0x49, 0x81, 0x51, 0x83, 0x27, 0x08,
|
||||||
0xcc, 0x16, 0xd2, 0xe4, 0x12, 0x28, 0x28, 0x4a, 0x2d, 0xcb, 0xcc, 0x2f, 0x2d, 0x8e, 0x87, 0xaa,
|
0xcc, 0x16, 0x92, 0xe1, 0xe2, 0x2c, 0xce, 0x4c, 0xcf, 0x4b, 0x2c, 0x29, 0x2d, 0x4a, 0x95, 0x60,
|
||||||
0x95, 0x60, 0x06, 0xcb, 0xf3, 0xc3, 0xc4, 0x61, 0x96, 0xcb, 0x70, 0x71, 0x16, 0x67, 0xa6, 0xe7,
|
0x06, 0x4b, 0x20, 0x04, 0x94, 0xbc, 0xb9, 0xb8, 0x91, 0x4c, 0x13, 0xe2, 0xe2, 0x62, 0xf3, 0xf4,
|
||||||
0x25, 0x96, 0x94, 0x16, 0xa5, 0x4a, 0xb0, 0x80, 0xd5, 0x20, 0x04, 0x94, 0xbc, 0xb9, 0xb8, 0x91,
|
0x0b, 0xf3, 0x0c, 0x71, 0x15, 0x60, 0x10, 0xe2, 0xe0, 0x62, 0xf1, 0xf2, 0xf7, 0xf4, 0x13, 0x60,
|
||||||
0x2c, 0x16, 0xe2, 0xe2, 0x62, 0xf3, 0xf4, 0x0b, 0xf3, 0x0c, 0x71, 0x15, 0x60, 0x10, 0xe2, 0xe0,
|
0x14, 0xe2, 0xe4, 0x62, 0xf5, 0x71, 0x75, 0x0c, 0x73, 0x15, 0x60, 0x02, 0x09, 0x7a, 0x7b, 0x3a,
|
||||||
0x62, 0xf1, 0xf2, 0xf7, 0xf4, 0x13, 0x60, 0x14, 0xe2, 0xe4, 0x62, 0xf5, 0x71, 0x75, 0x0c, 0x73,
|
0x7b, 0x0b, 0x30, 0x0b, 0xb1, 0x73, 0x31, 0x3b, 0x3a, 0x7b, 0x0b, 0xb0, 0x80, 0x84, 0x02, 0xfc,
|
||||||
0x15, 0x60, 0x02, 0x09, 0x7a, 0x7b, 0x3a, 0x7b, 0x0b, 0x30, 0x0b, 0xb1, 0x73, 0x31, 0x3b, 0x3a,
|
0x83, 0x43, 0x04, 0x58, 0x9d, 0xb8, 0xa2, 0x38, 0x60, 0x1e, 0x4d, 0x62, 0x03, 0xb3, 0x8c, 0x01,
|
||||||
0x7b, 0x0b, 0xb0, 0x80, 0x84, 0x02, 0xfc, 0x83, 0x43, 0x04, 0x58, 0x9d, 0xb8, 0xa2, 0x38, 0x60,
|
0x01, 0x00, 0x00, 0xff, 0xff, 0x89, 0xfa, 0x23, 0xe1, 0xfb, 0x00, 0x00, 0x00,
|
||||||
0x61, 0x92, 0xc4, 0x06, 0x66, 0x19, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x41, 0x70, 0xaf, 0x4e,
|
|
||||||
0x26, 0x01, 0x00, 0x00,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,25 +16,6 @@ message Message {
|
||||||
|
|
||||||
MessageType message_type = 1;
|
MessageType message_type = 1;
|
||||||
bytes body = 2;
|
bytes body = 2;
|
||||||
bytes previous_message = 3;
|
bytes signature = 3;
|
||||||
bytes signature = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// extend mvds through header
|
|
||||||
//header for behaviors
|
|
||||||
//
|
|
||||||
//{
|
|
||||||
//{
|
|
||||||
//parents [ids]
|
|
||||||
//seqnr
|
|
||||||
//prio flag
|
|
||||||
//unsync
|
|
||||||
//deleted messages~
|
|
||||||
//}
|
|
||||||
//{
|
|
||||||
//invite etc...
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//}
|
|
|
@ -9,7 +9,6 @@ func (m *Message) ID() []byte {
|
||||||
b := make([]byte, 4)
|
b := make([]byte, 4)
|
||||||
binary.LittleEndian.PutUint32(b, uint32(m.MessageType))
|
binary.LittleEndian.PutUint32(b, uint32(m.MessageType))
|
||||||
b = append(b, m.Body...)
|
b = append(b, m.Body...)
|
||||||
b = append(b, m.PreviousMessage...)
|
|
||||||
|
|
||||||
hash := sha256.Sum256(b)
|
hash := sha256.Sum256(b)
|
||||||
return hash[:]
|
return hash[:]
|
||||||
|
|
Loading…
Reference in New Issue