diff --git a/services/shhext/chat/multidevice/service.go b/services/shhext/chat/multidevice/service.go index 7a1da5fd6ba..5f6a0d36283 100644 --- a/services/shhext/chat/multidevice/service.go +++ b/services/shhext/chat/multidevice/service.go @@ -8,7 +8,9 @@ import ( ) type Installation struct { - ID string + // The installation-id of the device + ID string + // The last known protocol version of the device Version uint32 } diff --git a/services/shhext/chat/protocol.go b/services/shhext/chat/protocol.go index 25d8baf4287..6a804477e51 100644 --- a/services/shhext/chat/protocol.go +++ b/services/shhext/chat/protocol.go @@ -13,12 +13,13 @@ import ( const ProtocolVersion = 1 const sharedSecretNegotiationVersion = 1 const partitionedTopicMinVersion = 1 +const defaultMinVersion = 0 type PartitionTopic int const ( PartitionTopicNoSupport PartitionTopic = iota - PartitionTopicV1 PartitionTopic = iota + PartitionTopicV1 ) type ProtocolService struct { @@ -92,7 +93,7 @@ type ProtocolMessageSpec struct { func (p *ProtocolMessageSpec) MinVersion() uint32 { if len(p.Installations) == 0 { - return 0 + return defaultMinVersion } version := p.Installations[0].Version @@ -305,7 +306,7 @@ func (p *ProtocolService) HandleMessage(myIdentityKey *ecdsa.PrivateKey, theirPu func getProtocolVersion(bundles []*protobuf.Bundle, installationID string) uint32 { if installationID == "" { - return 0 + return defaultMinVersion } for _, bundle := range bundles { @@ -317,12 +318,12 @@ func getProtocolVersion(bundles []*protobuf.Bundle, installationID string) uint3 signedPreKey := signedPreKeys[installationID] if signedPreKey == nil { - return 0 + return defaultMinVersion } return signedPreKey.GetProtocolVersion() } } - return 0 + return defaultMinVersion } diff --git a/services/shhext/chat/sharedsecret/persistence.go b/services/shhext/chat/sharedsecret/persistence.go index 9a7769f0eda..958f47b5345 100644 --- a/services/shhext/chat/sharedsecret/persistence.go +++ b/services/shhext/chat/sharedsecret/persistence.go @@ -6,8 +6,12 @@ import ( ) type PersistenceService interface { + // Add adds a shared secret, associated with an identity and an installationID Add(identity []byte, secret []byte, installationID string) error + // Get returns a shared secret associated with multiple installationIDs Get(identity []byte, installationIDs []string) (*Response, error) + // All returns an array of shared secrets, each one of them represented + // as a byte array All() ([][][]byte, error) } diff --git a/services/shhext/filter/service.go b/services/shhext/filter/service.go index b9af11fe149..6c330869e98 100644 --- a/services/shhext/filter/service.go +++ b/services/shhext/filter/service.go @@ -195,7 +195,7 @@ func ContactCodeTopic(identity string) string { return "0x" + identity + "-contact-code" } -// Get returns a negotiated filter given an identity +// Get returns a negotiated chat given an identity func (s *Service) GetNegotiated(identity *ecdsa.PublicKey) *Chat { s.mutex.Lock() defer s.mutex.Unlock() @@ -203,7 +203,7 @@ func (s *Service) GetNegotiated(identity *ecdsa.PublicKey) *Chat { return s.chats[negotiatedID(identity)] } -// GetByID returns a filter by chatID +// GetByID returns a chat by chatID func (s *Service) GetByID(chatID string) *Chat { s.mutex.Lock() defer s.mutex.Unlock() @@ -217,7 +217,7 @@ func (s *Service) ProcessNegotiatedSecret(secret *sharedsecret.Secret) (*Chat, e defer s.mutex.Unlock() chatID := negotiatedID(secret.Identity) - // If we already have a filter do nothing + // If we already have a chat do nothing if _, ok := s.chats[chatID]; ok { return s.chats[chatID], nil } diff --git a/services/shhext/publisher/service.go b/services/shhext/publisher/service.go index 8fc3baec88d..c62912f3b00 100644 --- a/services/shhext/publisher/service.go +++ b/services/shhext/publisher/service.go @@ -326,8 +326,8 @@ func (s *Service) ProcessMessage(dedupMessage dedup.DeduplicateMessage) error { return nil } -// InitializeDirectMessage sends a 1:1 chat message to the underlying transport -func (s *Service) InitializeDirectMessage(signature string, destination hexutil.Bytes, DH bool, payload []byte) (*whisper.NewMessage, error) { +// CreateDirectMessage creates a 1:1 chat message +func (s *Service) CreateDirectMessage(signature string, destination hexutil.Bytes, DH bool, payload []byte) (*whisper.NewMessage, error) { if !s.config.PfsEnabled { return nil, ErrPFSNotEnabled } @@ -404,8 +404,8 @@ func (s *Service) directMessageToWhisper(myPrivateKey *ecdsa.PrivateKey, theirPu return &whisperMessage, nil } -// InitializePublicMessage sends a public chat message to the underlying transport -func (s *Service) InitializePublicMessage(signature string, chatID string, payload []byte, wrap bool) (*whisper.NewMessage, error) { +// CreatePublicMessage sends a public chat message to the underlying transport +func (s *Service) CreatePublicMessage(signature string, chatID string, payload []byte, wrap bool) (*whisper.NewMessage, error) { if !s.config.PfsEnabled { return nil, ErrPFSNotEnabled } @@ -511,7 +511,7 @@ func (s *Service) sendContactCode() (*whisper.NewMessage, error) { identity := fmt.Sprintf("%x", crypto.FromECDSAPub(&privateKey.PublicKey)) - message, err := s.InitializePublicMessage("0x"+identity, filter.ContactCodeTopic(identity), nil, true) + message, err := s.CreatePublicMessage("0x"+identity, filter.ContactCodeTopic(identity), nil, true) if err != nil { s.log.Error("could not build contact code", "identity", identity, "err", err) return nil, err diff --git a/services/shhext/publisher/service_test.go b/services/shhext/publisher/service_test.go index af2e78cb66f..07d9fdb6635 100644 --- a/services/shhext/publisher/service_test.go +++ b/services/shhext/publisher/service_test.go @@ -115,8 +115,8 @@ func (s *ServiceTestSuite) SetupTest() { s.bobKey = key2 } -func (s *ServiceTestSuite) TestInitializeDirectMessage() { - newMessage, err := s.alice.InitializeDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) +func (s *ServiceTestSuite) TestCreateDirectMessage() { + newMessage, err := s.alice.CreateDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) s.Require().NoError(err) message := &whisper.Message{ @@ -138,7 +138,7 @@ func (s *ServiceTestSuite) TestInitializeDirectMessage() { func (s *ServiceTestSuite) TestTopic() { // We build an initial message - newMessage1, err := s.alice.InitializeDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) + newMessage1, err := s.alice.CreateDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) s.Require().NoError(err) message1 := &whisper.Message{ @@ -173,7 +173,7 @@ func (s *ServiceTestSuite) TestTopic() { s.Require().NoError(err) // We build another message, this time it should use the partitioned topic - newMessage3, err := s.alice.InitializeDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) + newMessage3, err := s.alice.CreateDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) s.Require().NoError(err) message3 := &whisper.Message{ @@ -196,7 +196,7 @@ func (s *ServiceTestSuite) TestTopic() { s.Require().NoError(err) // We build another message, this time it should use the negotiated topic - newMessage4, err := s.bob.InitializeDirectMessage(s.bobKey.keyID, s.aliceKey.publicKeyBytes, false, []byte("hello")) + newMessage4, err := s.bob.CreateDirectMessage(s.bobKey.keyID, s.aliceKey.publicKeyBytes, false, []byte("hello")) s.Require().NoError(err) message4 := &whisper.Message{ @@ -226,7 +226,7 @@ func (s *ServiceTestSuite) TestTopic() { s.Require().NoError(err) // Alice sends another message to Bob, this time it should use the negotiated topic - newMessage5, err := s.alice.InitializeDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) + newMessage5, err := s.alice.CreateDirectMessage(s.aliceKey.keyID, s.bobKey.publicKeyBytes, false, []byte("hello")) s.Require().NoError(err) message5 := &whisper.Message{