Adding sync around timeline, adding hooks for latency checks

This commit is contained in:
Sarah Jamie Lewis 2018-05-05 21:18:00 -07:00
parent e01a4b2018
commit b4eb27ae1d
3 changed files with 13 additions and 8 deletions

View File

@ -299,7 +299,8 @@ func main() {
if group == nil {
fmt.Printf("Error: group does not exist\n")
} else {
for _, m := range group.Timeline.Messages {
timeline := group.GetTimeline()
for _, m := range timeline.Messages {
verified := "not-verified"
if m.Verified {
verified = "verified"

View File

@ -9,6 +9,7 @@ import (
"golang.org/x/crypto/nacl/secretbox"
"io"
"time"
"sync"
)
//Group defines and encapsulates Cwtch's conception of group chat. Which are sessions
@ -21,6 +22,7 @@ type Group struct {
Timeline Timeline
Accepted bool
Owner string
lock sync.Mutex
}
// NewGroup initializes a new group associated with a given CwtchServer
@ -64,26 +66,27 @@ func (g *Group) Invite() []byte {
}
func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, verified bool) *Message {
g.lock.Lock()
timelineMessage := &Message{
Message: message.GetText(),
Timestamp: time.Unix(int64(message.GetTimestamp()), 0),
Received: time.Now(),
Signature: message.GetSignature(),
Verified: verified,
PeerID: message.GetOnion(),
PreviousMessageSig: message.GetPreviousMessageSig(),
}
g.Timeline.Insert(timelineMessage)
g.lock.Unlock()
return timelineMessage
}
// AddMember ...
func (g *Group) AddMember() {
// TODO: Rotate Key
}
func (g *Group) GetTimeline() (t Timeline) {
g.lock.Lock()
t = g.Timeline
g.lock.Unlock()
return
// RemoveMember ...
func (g *Group) RemoveMember() {
// TODO: Rotate Key
}
//EncryptMessage takes a message and encrypts the message under the group key.

View File

@ -14,6 +14,7 @@ type Timeline struct {
// Message is a local representation of a given message sent over a group chat channel.
type Message struct {
Timestamp time.Time
Received time.Time
PeerID string
Message string
Signature []byte