From d9ce7737cc40363a2d3de4ce7e7fd148d94e62d2 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 2 Jan 2024 12:24:33 -0800 Subject: [PATCH] Fix Contact Retry Failure to Restart When toggling between connected and disconnected, the Contact Retry plugin could find itself in a state where the new event would never get requeued. Also: Make the unsigned nature of limit in GetMessage* Apis explicit. --- app/plugins/contactRetry.go | 11 +++++------ peer/cwtch_peer.go | 4 ++-- peer/cwtchprofilestorage.go | 2 +- peer/profile_interface.go | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/plugins/contactRetry.go b/app/plugins/contactRetry.go index 1cb0cab..8853c1c 100644 --- a/app/plugins/contactRetry.go +++ b/app/plugins/contactRetry.go @@ -302,8 +302,7 @@ func (cr *contactRetry) run() { cr.authorizedPeers.Store(id, true) if c, ok := cr.connections.Load(id); ok { contact := c.(*contact) - if contact.state == connections.DISCONNECTED && !contact.queued { - + if contact.state == connections.DISCONNECTED { // prioritize connections made in the last week if time.Since(contact.lastSeen).Hours() < PriorityQueueTimeSinceQualifierHours { cr.priorityQueue.insert(contact) @@ -461,10 +460,10 @@ func (cr *contactRetry) addConnection(id string, state connections.ConnectionSta cr.connections.Store(id, p) return } else { - // we have rerequested this connnection. Force set the queued parameter to true. - p, _ := cr.connections.Load(id) - if !p.(*contact).queued { - p.(*contact).queued = true + // we have rerequested this connnection, probably via an explicit ask, update it's state + if c, ok := cr.connections.Load(id); ok { + contact := c.(*contact) + contact.state = state } } } diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 3ecc838..7b9aa1d 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -94,7 +94,7 @@ func (cp *cwtchPeer) EnhancedImportBundle(importString string) string { return cp.ImportBundle(importString).Error() } -func (cp *cwtchPeer) EnhancedGetMessages(conversation int, index int, count int) string { +func (cp *cwtchPeer) EnhancedGetMessages(conversation int, index int, count uint) string { var emessages = make([]EnhancedMessage, count) messages, err := cp.GetMostRecentMessages(conversation, 0, index, count) @@ -888,7 +888,7 @@ func (cp *cwtchPeer) GetChannelMessageCount(conversation int, channel int) (int, } // GetMostRecentMessages returns a selection of messages, ordered by most recently inserted -func (cp *cwtchPeer) GetMostRecentMessages(conversation int, channel int, offset int, limit int) ([]model.ConversationMessage, error) { +func (cp *cwtchPeer) GetMostRecentMessages(conversation int, channel int, offset int, limit uint) ([]model.ConversationMessage, error) { return cp.storage.GetMostRecentMessages(conversation, channel, offset, limit) } diff --git a/peer/cwtchprofilestorage.go b/peer/cwtchprofilestorage.go index 74496c8..37330e9 100644 --- a/peer/cwtchprofilestorage.go +++ b/peer/cwtchprofilestorage.go @@ -781,7 +781,7 @@ func (cps *CwtchProfileStorage) SearchMessages(conversation int, channel int, pa } // GetMostRecentMessages returns the most recent messages in a channel up to a given limit at a given offset -func (cps *CwtchProfileStorage) GetMostRecentMessages(conversation int, channel int, offset int, limit int) ([]model.ConversationMessage, error) { +func (cps *CwtchProfileStorage) GetMostRecentMessages(conversation int, channel int, offset int, limit uint) ([]model.ConversationMessage, error) { channelID := ChannelID{Conversation: conversation, Channel: channel} cps.mutex.Lock() diff --git a/peer/profile_interface.go b/peer/profile_interface.go index 9d70504..08591b7 100644 --- a/peer/profile_interface.go +++ b/peer/profile_interface.go @@ -131,7 +131,7 @@ type CwtchPeer interface { GetChannelMessage(conversation int, channel int, id int) (string, model.Attributes, error) GetChannelMessageCount(conversation int, channel int) (int, error) GetChannelMessageByContentHash(conversation int, channel int, contenthash string) (int, error) - GetMostRecentMessages(conversation int, channel int, offset int, limit int) ([]model.ConversationMessage, error) + GetMostRecentMessages(conversation int, channel int, offset int, limit uint) ([]model.ConversationMessage, error) UpdateMessageAttribute(conversation int, channel int, id int, key string, value string) error SearchConversations(pattern string) string @@ -142,7 +142,7 @@ type CwtchPeer interface { EnhancedGetMessageByContentHash(conversation int, hash string) string // EnhancedGetMessages returns a set of json-encoded enhanced messages, suitable for rendering in a UI - EnhancedGetMessages(conversation int, index int, count int) string + EnhancedGetMessages(conversation int, index int, count uint) string // Server Token APIS // TODO move these to feature protected interfaces