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 { if group == nil {
fmt.Printf("Error: group does not exist\n") fmt.Printf("Error: group does not exist\n")
} else { } else {
for _, m := range group.Timeline.Messages { timeline := group.GetTimeline()
for _, m := range timeline.Messages {
verified := "not-verified" verified := "not-verified"
if m.Verified { if m.Verified {
verified = "verified" verified = "verified"

View File

@ -9,6 +9,7 @@ import (
"golang.org/x/crypto/nacl/secretbox" "golang.org/x/crypto/nacl/secretbox"
"io" "io"
"time" "time"
"sync"
) )
//Group defines and encapsulates Cwtch's conception of group chat. Which are sessions //Group defines and encapsulates Cwtch's conception of group chat. Which are sessions
@ -21,6 +22,7 @@ type Group struct {
Timeline Timeline Timeline Timeline
Accepted bool Accepted bool
Owner string Owner string
lock sync.Mutex
} }
// NewGroup initializes a new group associated with a given CwtchServer // 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 { func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, verified bool) *Message {
g.lock.Lock()
timelineMessage := &Message{ timelineMessage := &Message{
Message: message.GetText(), Message: message.GetText(),
Timestamp: time.Unix(int64(message.GetTimestamp()), 0), Timestamp: time.Unix(int64(message.GetTimestamp()), 0),
Received: time.Now(),
Signature: message.GetSignature(), Signature: message.GetSignature(),
Verified: verified, Verified: verified,
PeerID: message.GetOnion(), PeerID: message.GetOnion(),
PreviousMessageSig: message.GetPreviousMessageSig(), PreviousMessageSig: message.GetPreviousMessageSig(),
} }
g.Timeline.Insert(timelineMessage) g.Timeline.Insert(timelineMessage)
g.lock.Unlock()
return timelineMessage return timelineMessage
} }
// AddMember ... func (g *Group) GetTimeline() (t Timeline) {
func (g *Group) AddMember() { g.lock.Lock()
// TODO: Rotate Key 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. //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. // Message is a local representation of a given message sent over a group chat channel.
type Message struct { type Message struct {
Timestamp time.Time Timestamp time.Time
Received time.Time
PeerID string PeerID string
Message string Message string
Signature []byte Signature []byte