Add personal filter

Add a filter for 1-to-1, currently not used but useful in potential
migrations
This commit is contained in:
Andrea Maria Piana 2019-07-01 10:16:51 +02:00
parent b3efbb54f8
commit f2139105bf
3 changed files with 35 additions and 6 deletions

View File

@ -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
}

View File

@ -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")

View File

@ -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"