Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos committed Jun 4, 2019
1 parent cab2ec6 commit 2c75439
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
4 changes: 3 additions & 1 deletion services/shhext/chat/multidevice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 6 additions & 5 deletions services/shhext/chat/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions services/shhext/chat/sharedsecret/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions services/shhext/filter/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ 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()

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()
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions services/shhext/publisher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions services/shhext/publisher/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 2c75439

Please sign in to comment.