Skip to content

Commit

Permalink
Add personal filter
Browse files Browse the repository at this point in the history
Add a filter for 1-to-1, currently not used but useful in potential
migrations
  • Loading branch information
cammellos committed Jul 4, 2019
1 parent b3efbb5 commit f213910
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
26 changes: 25 additions & 1 deletion messaging/filter/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 9 additions & 4 deletions messaging/filter/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion services/shhext/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f213910

Please sign in to comment.