remove unused events (libcwtch-rs audit); add anti dup on import
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dan Ballard 2022-07-29 17:24:22 -07:00
parent 5b1ac38473
commit 56cf2b7bf6
4 changed files with 19 additions and 29 deletions

View File

@ -124,23 +124,11 @@ const (
// Password, NewPassword
ChangePassword = Type("ChangePassword")
// Error(err), EventID
ChangePasswordError = Type("ChangePasswordError")
// EventID
ChangePasswordSuccess = Type("ChangePasswordSuccess")
// a group has been successfully added or newly created
// attributes:
// Data [serialized *model.Group]
GroupCreated = Type("GroupCreated")
// RemotePeer
DeleteContact = Type("DeleteContact")
// GroupID
DeleteGroup = Type("DeleteGroup")
// PeerStateChange servers as a new incoming connection message as well, and can/is consumed by frontends to alert of new p2p connections
// RemotePeer
// ConnectionState
@ -192,9 +180,6 @@ const (
Syn = Type("Syn")
Ack = Type("Ack")
// For situations where we want to update $Identity -> $RemotePeer/$GroupID's total message count to be $Data
MessageCounterResync = Type("MessageCounterResync")
// File Handling Events
StopFileShare = Type("StopFileShare")
StopAllFileShares = Type("StopAllFileShares")

View File

@ -483,8 +483,14 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (int, error) {
return -1, err
}
cp.mutex.Lock()
conversationInfo, err := cp.storage.GetConversationByHandle(gci.GroupID)
if conversationInfo != nil {
cp.mutex.Unlock()
return -1, err
}
groupConversationID, err := cp.storage.NewConversation(gci.GroupID, map[string]string{}, model.AccessControlList{}, true)
cp.mutex.Unlock()
if err == nil {
cp.SetConversationAttribute(groupConversationID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupID)), gci.GroupID)
cp.SetConversationAttribute(groupConversationID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)), gci.ServerHost)
@ -500,9 +506,13 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (int, error) {
func (cp *cwtchPeer) NewContactConversation(handle string, acl model.AccessControl, accepted bool) (int, error) {
cp.mutex.Lock()
defer cp.mutex.Unlock()
conversationID, err := cp.storage.NewConversation(handle, model.Attributes{event.SaveHistoryKey: event.DeleteHistoryDefault}, model.AccessControlList{handle: acl}, accepted)
cp.eventBus.Publish(event.NewEvent(event.ContactCreated, map[event.Field]string{event.ConversationID: strconv.Itoa(conversationID), event.RemotePeer: handle}))
return conversationID, err
conversationInfo, err := cp.storage.GetConversationByHandle(handle)
if conversationInfo == nil {
conversationID, err := cp.storage.NewConversation(handle, model.Attributes{event.SaveHistoryKey: event.DeleteHistoryDefault}, model.AccessControlList{handle: acl}, accepted)
cp.eventBus.Publish(event.NewEvent(event.ContactCreated, map[event.Field]string{event.ConversationID: strconv.Itoa(conversationID), event.RemotePeer: handle}))
return conversationID, err
}
return -1, err
}
// AcceptConversation looks up a conversation by `handle` and sets the Accepted status to `true`

View File

@ -101,8 +101,6 @@ func NewProtocolEngine(identity primitives.Identity, privateKey ed25519.PrivateK
engine.eventManager.Subscribe(event.SendMessageToPeer, engine.queue)
engine.eventManager.Subscribe(event.SendGetValMessageToPeer, engine.queue)
engine.eventManager.Subscribe(event.SendRetValMessageToPeer, engine.queue)
engine.eventManager.Subscribe(event.DeleteContact, engine.queue)
engine.eventManager.Subscribe(event.DeleteGroup, engine.queue)
engine.eventManager.Subscribe(event.UpdateConversationAuthorization, engine.queue)
engine.eventManager.Subscribe(event.BlockUnknownPeers, engine.queue)
@ -161,13 +159,6 @@ func (e *engine) eventHandler() {
go e.peerWithTokenServer(ev.Data[event.GroupServer], ev.Data[event.ServerTokenOnion], ev.Data[event.ServerTokenY], signature)
case event.LeaveServer:
e.leaveServer(ev.Data[event.GroupServer])
case event.DeleteContact:
onion := ev.Data[event.RemotePeer]
// We remove this peer from out blocklist which will prevent them from contacting us if we have "block unknown peers" turned on.
e.authorizations.Delete(ev.Data[event.RemotePeer])
e.deleteConnection(onion)
case event.DeleteGroup:
// TODO: There isn't a way here to determine if other Groups are using a server connection...
case event.SendMessageToGroup:
ciphertext, _ := base64.StdEncoding.DecodeString(ev.Data[event.Ciphertext])
signature, _ := base64.StdEncoding.DecodeString(ev.Data[event.Signature])

View File

@ -144,18 +144,20 @@ func TestCwtchPeerIntegration(t *testing.T) {
// ***** Peering, server joining, group creation / invite *****
log.Infoln("Alice peering with Bob...")
log.Infoln("Alice and Bob creating conversations...")
// Simulate Alice Adding Bob
log.Infof(" alice.NewConvo(bob)...")
alice2bobConversationID, err := alice.NewContactConversation(bob.GetOnion(), model.DefaultP2PAccessControl(), true)
if err != nil {
t.Fatalf("error adding conversaiton %v", alice2bobConversationID)
}
log.Infof(" bob.NewConvo(alice)...")
bob2aliceConversationID, err := bob.NewContactConversation(alice.GetOnion(), model.DefaultP2PAccessControl(), true)
if err != nil {
t.Fatalf("error adding conversaiton %v", bob2aliceConversationID)
}
log.Infof("Alice peering with Carol...")
log.Infof("Alice and Carol creating conversations...")
// Simulate Alice Adding Carol
alice2carolConversationID, err := alice.NewContactConversation(carol.GetOnion(), model.DefaultP2PAccessControl(), true)
if err != nil {
@ -166,7 +168,9 @@ func TestCwtchPeerIntegration(t *testing.T) {
t.Fatalf("error adding conversaiton %v", carol2aliceConversationID)
}
log.Infof("Alice peering with Bob...")
alice.PeerWithOnion(bob.GetOnion())
log.Infof("Alice Peering with Carol...")
alice.PeerWithOnion(carol.GetOnion())
// Test that we can rekey alice without issues...