diff --git a/app/app.go b/app/app.go index d79653d..8d916a3 100644 --- a/app/app.go +++ b/app/app.go @@ -24,7 +24,7 @@ type application struct { mutex sync.Mutex primaryonion string storage map[string]storage.ProfileStore - EventBus *event.Manager + eventBus *event.Manager } // Application is a full cwtch peer application. It allows management, usage and storage of multiple peers @@ -38,7 +38,7 @@ type Application interface { ListPeers() map[string]string LaunchPeers() - //GetTorStatus() (map[string]string, error) + EventBus() *event.Manager Shutdown() } @@ -48,8 +48,8 @@ func NewApp(acn connectivity.ACN, appDirectory string) Application { log.Debugf("NewApp(%v)\n", appDirectory) app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, acn: acn} os.Mkdir(path.Join(app.directory, "profiles"), 0700) - app.EventBus = new(event.Manager) - app.EventBus.Initialize() + app.eventBus = new(event.Manager) + app.eventBus.Initialize() return app } @@ -77,7 +77,7 @@ func (app *application) CreatePeer(name string, password string) (peer.CwtchPeer if err != nil { return nil, err } - p.Init(app.acn, app.EventBus) + p.Init(app.acn, app.eventBus) _, exists := app.peers[p.GetProfile().Onion] if exists { p.Shutdown() @@ -113,7 +113,7 @@ func (app *application) LoadProfiles(password string) error { continue } - p.Init(app.acn, app.EventBus) + p.Init(app.acn, app.eventBus) app.mutex.Lock() app.peers[p.GetProfile().Onion] = p @@ -162,6 +162,11 @@ func (app *application) GetTorStatus() (map[string]string, error) { return app.torManager.GetStatus() }*/ +// Fetch the app's event manager +func (app *application) EventBus() *event.Manager { + return app.eventBus +} + // Shutdown shutsdown all peers of an app and then the tormanager func (app *application) Shutdown() { for _, peer := range app.peers { diff --git a/model/group.go b/model/group.go index d15dd6a..6c98fa1 100644 --- a/model/group.go +++ b/model/group.go @@ -103,7 +103,6 @@ func (g *Group) Invite(initialMessage []byte) ([]byte, error) { // AddMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte) *Message { - g.lock.Lock() timelineMessage := &Message{ Message: message.GetText(), Timestamp: time.Unix(int64(message.GetTimestamp()), 0), @@ -112,13 +111,7 @@ func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte) PeerID: message.GetOnion(), PreviousMessageSig: message.GetPreviousMessageSig(), } - seen := g.Timeline.Insert(timelineMessage) - g.lock.Unlock() - - // Send a new Message notification if we have an app that is listening. - if g.NewMessage != nil && !seen { - g.NewMessage <- *timelineMessage - } + g.Timeline.Insert(timelineMessage) return timelineMessage } diff --git a/model/profile.go b/model/profile.go index ee54f07..ee67785 100644 --- a/model/profile.go +++ b/model/profile.go @@ -294,23 +294,12 @@ func (p *Profile) ProcessInvite(gci *protocol.GroupChatInvite, peerHostname stri // AddGroup is a convenience method for adding a group to a profile. func (p *Profile) AddGroup(group *Group) { - existingGroup, exists := p.Groups[group.GroupID] + _, exists := p.Groups[group.GroupID] if !exists { - decodedPub, _ := base32.StdEncoding.DecodeString(strings.ToUpper(group.Owner[:56])) - valid := ed25519.Verify(ed25519.PublicKey(decodedPub[:32]), []byte(group.GroupID+group.GroupServer), group.SignedGroupID) - if valid { - p.lock.Lock() - defer p.lock.Unlock() - p.Groups[group.GroupID] = group - } - } else if exists && existingGroup.Owner == group.Owner { p.lock.Lock() defer p.lock.Unlock() p.Groups[group.GroupID] = group } - - // If we are sent an invite or group update by someone who is not an owner - // then we reject the group. } // AttemptDecryption takes a ciphertext and signature and attempts to decrypt it under known groups. @@ -327,7 +316,6 @@ func (p *Profile) AttemptDecryption(ciphertext []byte, signature []byte) (bool, group.Compromised() return false, group.GroupID, nil } - return true, group.GroupID, group.AddMessage(dgm, signature) } } diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index f29d0e0..39d003b 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -109,7 +109,7 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (groupID string, err err data, err := base64.StdEncoding.DecodeString(exportedInvite[5+44:]) if err == nil { cpp := &protocol.CwtchPeerPacket{} - err := proto.Unmarshal(data, cpp) + err = proto.Unmarshal(data, cpp) if err == nil { pk, err := base64.StdEncoding.DecodeString(exportedInvite[5 : 5+44]) if err == nil { @@ -280,9 +280,10 @@ func (cp *cwtchPeer) eventHandler() { ev := cp.queue.Next() switch ev.EventType { case event.EncryptedGroupMessage: - ok, groupID, _ := cp.Profile.AttemptDecryption([]byte(ev.Data["Ciphertext"]), []byte(ev.Data["Signature"])) + ok, groupID, message := cp.Profile.AttemptDecryption([]byte(ev.Data["Ciphertext"]), []byte(ev.Data["Signature"])) + log.Debugf("ok,gid,msg = %v,%v,%v", ok, groupID, message) if ok { - cp.eventBus.Publish(event.NewEvent(event.NewMessageFromGroup, map[string]string{"GroupID": groupID})) + cp.eventBus.Publish(event.NewEvent(event.NewMessageFromGroup, map[string]string{"Data": message.Message, "GroupID": groupID, "Onion": message.PeerID})) } case event.NewGroupInvite: var groupInvite protocol.GroupChatInvite @@ -292,7 +293,6 @@ func (cp *cwtchPeer) eventHandler() { if ev.EventType != "" { log.Errorf("peer event handler received an event it was not subscribed for: %v", ev.EventType) } - return } } }