mirror of
https://github.com/vacp2p/dasy.git
synced 2026-01-09 14:58:06 -05:00
using mvds id
This commit is contained in:
@@ -18,7 +18,7 @@ type Peer state.PeerID
|
||||
type Client struct {
|
||||
node mvds.Node
|
||||
|
||||
lastMessage protobuf.MessageID
|
||||
lastMessage state.MessageID // @todo maybe make type
|
||||
}
|
||||
|
||||
// Invite invites a peer to a chat.
|
||||
@@ -43,7 +43,7 @@ func (c *Client) Kick(chat Chat, peer Peer) {
|
||||
|
||||
// We may not need this as we can rely on the acks of data sync
|
||||
// Ack acknowledges `Join`, `Leave` and `Kick` messages.
|
||||
func (c *Client) Ack(chat Chat, messageID protobuf.MessageID) {
|
||||
func (c *Client) Ack(chat Chat, messageID state.MessageID) {
|
||||
|
||||
}
|
||||
|
||||
@@ -66,12 +66,12 @@ func (c *Client) send(chat Chat, t protobuf.Message_MessageType, body []byte) er
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = c.node.AppendMessage(state.GroupID(chat), buf)
|
||||
id, err := c.node.AppendMessage(state.GroupID(chat), buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.lastMessage = msg.ID()
|
||||
c.lastMessage = id
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
// Package protobuf contains protocol buffers as well as helper functions for those buffers.
|
||||
package protobuf
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
// MessageID is a hash of `message_type`, `body` & `previous_message`.
|
||||
type MessageID [32]byte
|
||||
|
||||
// ID returns the message ID.
|
||||
func (m *Message) ID() MessageID {
|
||||
t := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint32(t, uint32(m.MessageType))
|
||||
|
||||
b := append([]byte("MESSAGE_ID"), t...)
|
||||
b = append(b, m.Body...)
|
||||
b = append(b, m.PreviousMessage...)
|
||||
|
||||
return sha256.Sum256(b)
|
||||
}
|
||||
Reference in New Issue
Block a user