From 6d29ca322eaf303485c23a5f25230482105ce9af Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 29 Aug 2023 12:16:49 -0700 Subject: [PATCH] Redirect JoinServer Flow. Have Servers listen to QueueJoinServer Update. Handle delete contact flow for contact retry plugin --- app/plugins/contactRetry.go | 6 ++++++ functionality/servers/servers_functionality.go | 4 +++- peer/cwtch_peer.go | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/plugins/contactRetry.go b/app/plugins/contactRetry.go index 1ed749d..c6f4a70 100644 --- a/app/plugins/contactRetry.go +++ b/app/plugins/contactRetry.go @@ -179,6 +179,7 @@ func (cr *contactRetry) run() { cr.bus.Subscribe(event.QueueJoinServer, cr.queue) cr.bus.Subscribe(event.ProtocolEngineShutdown, cr.queue) cr.bus.Subscribe(event.ProtocolEngineCreated, cr.queue) + cr.bus.Subscribe(event.DeleteContact, cr.queue) for { // Only attempt connection if both the ACN and the Protocol Engines are Online... @@ -228,6 +229,11 @@ func (cr *contactRetry) run() { select { case e := <-cr.queue.OutChan(): switch e.EventType { + case event.DeleteContact: + // this case covers both servers and peers (servers are peers, and go through the + // same delete conversation flow) + peer := e.Data[event.RemotePeer] + cr.authorizedPeers.Delete(peer) case event.PeerStateChange: state := connections.ConnectionStateToType()[e.Data[event.ConnectionState]] peer := e.Data[event.RemotePeer] diff --git a/functionality/servers/servers_functionality.go b/functionality/servers/servers_functionality.go index 4a039be..7cd5f37 100644 --- a/functionality/servers/servers_functionality.go +++ b/functionality/servers/servers_functionality.go @@ -30,7 +30,7 @@ func (f *Functionality) NotifySettingsUpdate(settings settings.GlobalSettings) { } func (f *Functionality) EventsToRegister() []event.Type { - return []event.Type{event.Heartbeat} + return []event.Type{event.Heartbeat, event.QueueJoinServer} } func (f *Functionality) ExperimentsToRegister() []string { @@ -45,6 +45,8 @@ func (f *Functionality) OnEvent(ev event.Event, profile peer.CwtchPeer) { // TODO: do we need a secondary heartbeat for less common updates? case event.Heartbeat: f.PublishServerUpdate(profile) + case event.QueueJoinServer: + f.PublishServerUpdate(profile) } } } diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 3edbacb..50f8c33 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -670,7 +670,7 @@ func (cp *cwtchPeer) ImportGroup(exportedInvite string) (int, error) { cp.SetConversationAttribute(groupConversationID, attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupKey)), base64.StdEncoding.EncodeToString(gci.SharedKey)) cp.SetConversationAttribute(groupConversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.Name)), gci.GroupName) cp.eventBus.Publish(event.NewEvent(event.NewGroup, map[event.Field]string{event.ConversationID: strconv.Itoa(groupConversationID), event.GroupServer: gci.ServerHost, event.GroupInvite: exportedInvite, event.GroupName: gci.GroupName})) - cp.JoinServer(gci.ServerHost) + cp.QueueJoinServer(gci.ServerHost) } return groupConversationID, err } @@ -993,7 +993,7 @@ func (cp *cwtchPeer) AddServer(serverSpecification string) (string, error) { cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(k)), v) } cp.SetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ServerKeyZone.ConstructZonedPath(string(model.BundleType))), serverSpecification) - cp.JoinServer(onion) + cp.QueueJoinServer(onion) return onion, err } return "", err