diff --git a/messaging/filter/service.go b/messaging/filter/service.go index 751b3c8a4..0860d8c37 100644 --- a/messaging/filter/service.go +++ b/messaging/filter/service.go @@ -168,12 +168,16 @@ func (s *Service) Start(checkPeriod time.Duration) { // Stop removes all the filters func (s *Service) Stop() error { + close(s.quit) + var chats []*Chat - close(s.quit) + s.mutex.Lock() for _, chat := range s.chats { chats = append(chats, chat) } + s.mutex.Unlock() + return s.Remove(chats) } @@ -345,6 +349,26 @@ func (s *Service) loadDiscovery(myKey *ecdsa.PrivateKey) error { discoveryChat.FilterID = discoveryResponse.FilterID s.chats[discoveryChat.ChatID] = discoveryChat + + // Load personal discovery + personalDiscoveryTopic := fmt.Sprintf("contact-discovery-%s", identityStr) + personalDiscoveryChat := &Chat{ + ChatID: personalDiscoveryTopic, + Listen: true, + Identity: identityStr, + Discovery: true, + } + + discoveryResponse, err = s.addAsymmetricFilter(myKey, personalDiscoveryChat.ChatID, true) + if err != nil { + return err + } + + personalDiscoveryChat.Topic = discoveryResponse.Topic + personalDiscoveryChat.FilterID = discoveryResponse.FilterID + + s.chats[personalDiscoveryChat.ChatID] = personalDiscoveryChat + return nil } diff --git a/messaging/filter/service_test.go b/messaging/filter/service_test.go index e98a338db..177c1b2a6 100644 --- a/messaging/filter/service_test.go +++ b/messaging/filter/service_test.go @@ -85,17 +85,22 @@ func (s *ServiceTestSuite) TearDownTest() { func (s *ServiceTestSuite) TestDiscoveryAndPartitionedTopic() { chats := []*Chat{} partitionedTopic := fmt.Sprintf("contact-discovery-%d", s.keys[0].partitionedTopic) + personalDiscoveryTopic := fmt.Sprintf("contact-discovery-%s", s.keys[0].PublicKeyString()) contactCodeTopic := "0x" + s.keys[0].PublicKeyString() + "-contact-code" _, err := s.service.Init(chats) s.Require().NoError(err) - s.Require().Equal(3, len(s.service.chats), "It creates two filters") + s.Require().Equal(4, len(s.service.chats), "It creates four filters") discoveryFilter := s.service.chats[discoveryTopic] s.Require().NotNil(discoveryFilter, "It adds the discovery filter") s.Require().True(discoveryFilter.Listen) + personalDiscoveryFilter := s.service.chats[personalDiscoveryTopic] + s.Require().NotNil(personalDiscoveryFilter, "It adds the discovery filter") + s.Require().True(personalDiscoveryFilter.Listen) + contactCodeFilter := s.service.chats[contactCodeTopic] s.Require().NotNil(contactCodeFilter, "It adds the contact code filter") s.Require().True(contactCodeFilter.Listen) @@ -127,7 +132,7 @@ func (s *ServiceTestSuite) TestPublicAndOneToOneChats() { actualChats[chat.ChatID] = chat } - s.Require().Equal(5, len(actualChats), "It creates two additional filters for the one to one and one for the public chat") + s.Require().Equal(6, len(actualChats), "It creates two additional filters for the one to one and one for the public chat") statusFilter := actualChats["status"] s.Require().NotNil(statusFilter, "It creates a filter for the public chat") @@ -180,7 +185,7 @@ func (s *ServiceTestSuite) TestNegotiatedTopic() { actualChats[chat.ChatID] = chat } - s.Require().Equal(5, len(actualChats), "It creates two additional filters for the negotiated topics") + s.Require().Equal(6, len(actualChats), "It creates two additional filters for the negotiated topics") negotiatedFilter1 := actualChats[negotiatedTopic1] s.Require().NotNil(negotiatedFilter1, "It adds the negotiated filter") @@ -221,7 +226,7 @@ func (s *ServiceTestSuite) TestNoInstallationIDs() { actualChats[chat.ChatID] = chat } - s.Require().Equal(4, len(actualChats), "It creates two additional filters for the negotiated topics") + s.Require().Equal(5, len(actualChats), "It creates two additional filters for the negotiated topics") negotiatedFilter1 := actualChats[negotiatedTopic1] s.Require().NotNil(negotiatedFilter1, "It adds the negotiated filter") diff --git a/services/shhext/api.go b/services/shhext/api.go index 4cc68296c..3d7a6b022 100644 --- a/services/shhext/api.go +++ b/services/shhext/api.go @@ -11,13 +11,13 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/rlp" "github.com/status-im/status-go/db" "github.com/status-im/status-go/mailserver" - "github.com/status-im/status-go/messaging/chat" "github.com/status-im/status-go/messaging/filter" "github.com/status-im/status-go/messaging/multidevice" "github.com/status-im/status-go/services/shhext/dedup"