removing old timeline notification code and dropping support for updating existing groups
This commit is contained in:
parent
157d4d740b
commit
f28cf6b781
17
app/app.go
17
app/app.go
|
@ -24,7 +24,7 @@ type application struct {
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
primaryonion string
|
primaryonion string
|
||||||
storage map[string]storage.ProfileStore
|
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
|
// 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
|
ListPeers() map[string]string
|
||||||
LaunchPeers()
|
LaunchPeers()
|
||||||
|
|
||||||
//GetTorStatus() (map[string]string, error)
|
EventBus() *event.Manager
|
||||||
|
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ func NewApp(acn connectivity.ACN, appDirectory string) Application {
|
||||||
log.Debugf("NewApp(%v)\n", appDirectory)
|
log.Debugf("NewApp(%v)\n", appDirectory)
|
||||||
app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, acn: acn}
|
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)
|
os.Mkdir(path.Join(app.directory, "profiles"), 0700)
|
||||||
app.EventBus = new(event.Manager)
|
app.eventBus = new(event.Manager)
|
||||||
app.EventBus.Initialize()
|
app.eventBus.Initialize()
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func (app *application) CreatePeer(name string, password string) (peer.CwtchPeer
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.Init(app.acn, app.EventBus)
|
p.Init(app.acn, app.eventBus)
|
||||||
_, exists := app.peers[p.GetProfile().Onion]
|
_, exists := app.peers[p.GetProfile().Onion]
|
||||||
if exists {
|
if exists {
|
||||||
p.Shutdown()
|
p.Shutdown()
|
||||||
|
@ -113,7 +113,7 @@ func (app *application) LoadProfiles(password string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
p.Init(app.acn, app.EventBus)
|
p.Init(app.acn, app.eventBus)
|
||||||
|
|
||||||
app.mutex.Lock()
|
app.mutex.Lock()
|
||||||
app.peers[p.GetProfile().Onion] = p
|
app.peers[p.GetProfile().Onion] = p
|
||||||
|
@ -162,6 +162,11 @@ func (app *application) GetTorStatus() (map[string]string, error) {
|
||||||
return app.torManager.GetStatus()
|
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
|
// Shutdown shutsdown all peers of an app and then the tormanager
|
||||||
func (app *application) Shutdown() {
|
func (app *application) Shutdown() {
|
||||||
for _, peer := range app.peers {
|
for _, peer := range app.peers {
|
||||||
|
|
|
@ -103,7 +103,6 @@ func (g *Group) Invite(initialMessage []byte) ([]byte, error) {
|
||||||
|
|
||||||
// AddMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline
|
// AddMessage takes a DecryptedGroupMessage and adds it to the Groups Timeline
|
||||||
func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte) *Message {
|
func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte) *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),
|
||||||
|
@ -112,13 +111,7 @@ func (g *Group) AddMessage(message *protocol.DecryptedGroupMessage, sig []byte)
|
||||||
PeerID: message.GetOnion(),
|
PeerID: message.GetOnion(),
|
||||||
PreviousMessageSig: message.GetPreviousMessageSig(),
|
PreviousMessageSig: message.GetPreviousMessageSig(),
|
||||||
}
|
}
|
||||||
seen := g.Timeline.Insert(timelineMessage)
|
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
|
|
||||||
}
|
|
||||||
return timelineMessage
|
return timelineMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
// AddGroup is a convenience method for adding a group to a profile.
|
||||||
func (p *Profile) AddGroup(group *Group) {
|
func (p *Profile) AddGroup(group *Group) {
|
||||||
existingGroup, exists := p.Groups[group.GroupID]
|
_, exists := p.Groups[group.GroupID]
|
||||||
if !exists {
|
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()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
p.Groups[group.GroupID] = group
|
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.
|
// 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()
|
group.Compromised()
|
||||||
return false, group.GroupID, nil
|
return false, group.GroupID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, group.GroupID, group.AddMessage(dgm, signature)
|
return true, group.GroupID, group.AddMessage(dgm, signature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (groupID string, err err
|
||||||
data, err := base64.StdEncoding.DecodeString(exportedInvite[5+44:])
|
data, err := base64.StdEncoding.DecodeString(exportedInvite[5+44:])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cpp := &protocol.CwtchPeerPacket{}
|
cpp := &protocol.CwtchPeerPacket{}
|
||||||
err := proto.Unmarshal(data, cpp)
|
err = proto.Unmarshal(data, cpp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
pk, err := base64.StdEncoding.DecodeString(exportedInvite[5 : 5+44])
|
pk, err := base64.StdEncoding.DecodeString(exportedInvite[5 : 5+44])
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -280,9 +280,10 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
ev := cp.queue.Next()
|
ev := cp.queue.Next()
|
||||||
switch ev.EventType {
|
switch ev.EventType {
|
||||||
case event.EncryptedGroupMessage:
|
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 {
|
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:
|
case event.NewGroupInvite:
|
||||||
var groupInvite protocol.GroupChatInvite
|
var groupInvite protocol.GroupChatInvite
|
||||||
|
@ -292,7 +293,6 @@ func (cp *cwtchPeer) eventHandler() {
|
||||||
if ev.EventType != "" {
|
if ev.EventType != "" {
|
||||||
log.Errorf("peer event handler received an event it was not subscribed for: %v", ev.EventType)
|
log.Errorf("peer event handler received an event it was not subscribed for: %v", ev.EventType)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue