diff --git a/event/common.go b/event/common.go index 0271b6b..1b9843c 100644 --- a/event/common.go +++ b/event/common.go @@ -220,6 +220,7 @@ const ( // Conversation Search SearchResult = Type("SearchResult") + SearchCancelled = Type("SearchCancelled") ) // Field defines common event attributes diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index b0da6e1..b31a374 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -805,6 +805,11 @@ func (cp *cwtchPeer) GetChannelMessage(conversation int, channel int, id int) (s } func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern string) { + + // do not allow trivial searches that would match a wide variety of messages... + if len(pattern) <=5 { + return + } conversations, _ := cp.FetchConversations() maxCount := 0 @@ -824,8 +829,9 @@ func (cp *cwtchPeer) doSearch(ctx context.Context, searchID string, pattern stri for offset := 0; offset < (maxCount + 10); offset += 10 { select { case <-ctx.Done(): + cp.PublishEvent(event.NewEvent(event.SearchCancelled, map[event.Field]string{event.SearchID: searchID})) return - case <-time.After(time.Millisecond): + case <-time.After(time.Millisecond*100): for _, conversation := range conversations { ccount := conversationCount[conversation.ID] if offset > ccount { diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index cb2030b..6b29561 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -344,10 +344,11 @@ func (e *engine) Shutdown() { log.Infof("shutting down ephemeral service") // work around: service.shutdown() can block for a long time if it is Open()ing a new connection, putting it in a // goroutine means we can perform this operation and let the per service shutdown in their own time or until the app exits + conn := connection; // don't capture loop variable go func() { - connection.connectingLock.Lock() - connection.service.Shutdown() - connection.connectingLock.Unlock() + conn.connectingLock.Lock() + conn.service.Shutdown() + conn.connectingLock.Unlock() }() } @@ -380,6 +381,7 @@ func (e *engine) peerWithOnion(onion string) { } } } + e.ignoreOnShutdown(e.peerDisconnected)(onion) } func (e *engine) makeAntispamPayment(onion string) {