Add apn-topic & token-type set by the client

This commit is contained in:
Andrea Maria Piana 2020-07-30 10:24:30 +02:00
parent 60e61caad8
commit 91074ac95e
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
7 changed files with 93 additions and 78 deletions

View File

@ -267,8 +267,6 @@ func NewMessenger(
// Overriding until we handle different identities
pushNotificationClientConfig.Identity = identity
// Hardcoding this for now, as it's the only one we support
pushNotificationClientConfig.TokenType = protobuf.PushNotificationRegistration_APN_TOKEN
pushNotificationClientConfig.Logger = logger
pushNotificationClientConfig.InstallationID = installationID
@ -3146,7 +3144,7 @@ func (m *Messenger) addedContactsAndMutedChatIDs() ([]*ecdsa.PublicKey, []string
}
// RegisterForPushNotification register deviceToken with any push notification server enabled
func (m *Messenger) RegisterForPushNotifications(ctx context.Context, deviceToken string) error {
func (m *Messenger) RegisterForPushNotifications(ctx context.Context, deviceToken, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType) error {
if m.pushNotificationClient == nil {
return errors.New("push notification client not enabled")
}
@ -3154,7 +3152,7 @@ func (m *Messenger) RegisterForPushNotifications(ctx context.Context, deviceToke
defer m.mutex.Unlock()
contactIDs, mutedChatIDs := m.addedContactsAndMutedChatIDs()
return m.pushNotificationClient.Register(deviceToken, contactIDs, mutedChatIDs)
return m.pushNotificationClient.Register(deviceToken, apnTopic, tokenType, contactIDs, mutedChatIDs)
}
// RegisteredForPushNotifications returns whether we successfully registered with all the servers

View File

@ -125,6 +125,7 @@ type PushNotificationRegistration struct {
Unregister bool `protobuf:"varint,9,opt,name=unregister,proto3" json:"unregister,omitempty"`
Grant []byte `protobuf:"bytes,10,opt,name=grant,proto3" json:"grant,omitempty"`
AllowFromContactsOnly bool `protobuf:"varint,11,opt,name=allow_from_contacts_only,json=allowFromContactsOnly,proto3" json:"allow_from_contacts_only,omitempty"`
ApnTopic string `protobuf:"bytes,12,opt,name=apn_topic,json=apnTopic,proto3" json:"apn_topic,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
@ -232,6 +233,13 @@ func (m *PushNotificationRegistration) GetAllowFromContactsOnly() bool {
return false
}
func (m *PushNotificationRegistration) GetApnTopic() string {
if m != nil {
return m.ApnTopic
}
return ""
}
type PushNotificationRegistrationResponse struct {
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
Error PushNotificationRegistrationResponse_ErrorType `protobuf:"varint,2,opt,name=error,proto3,enum=protobuf.PushNotificationRegistrationResponse_ErrorType" json:"error,omitempty"`
@ -754,60 +762,61 @@ func init() {
func init() { proto.RegisterFile("push_notifications.proto", fileDescriptor_200acd86044eaa5d) }
var fileDescriptor_200acd86044eaa5d = []byte{
// 878 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x41, 0x6f, 0xeb, 0x44,
0x17, 0xfd, 0x9c, 0xa4, 0x4d, 0x72, 0x93, 0x2f, 0x4d, 0x47, 0x6d, 0x9f, 0x79, 0xa2, 0x10, 0x0c,
0x12, 0x51, 0x17, 0x11, 0x2a, 0x12, 0xef, 0x89, 0x15, 0xa1, 0x75, 0x8b, 0xd5, 0xc6, 0x0e, 0x13,
0x97, 0xa7, 0x27, 0x21, 0x59, 0x8e, 0x3d, 0x69, 0xad, 0xba, 0x1e, 0x33, 0x33, 0x2e, 0xca, 0x8e,
0x1f, 0xc0, 0x86, 0x2d, 0x1b, 0xfe, 0x02, 0xe2, 0x17, 0x22, 0x8f, 0xed, 0xe0, 0x36, 0x6e, 0x5a,
0x24, 0x56, 0xf6, 0x9c, 0xb9, 0xf7, 0xce, 0xcc, 0x39, 0xf7, 0x5c, 0x50, 0xe3, 0x84, 0xdf, 0x38,
0x11, 0x15, 0xc1, 0x22, 0xf0, 0x5c, 0x11, 0xd0, 0x88, 0x8f, 0x62, 0x46, 0x05, 0x45, 0x2d, 0xf9,
0x99, 0x27, 0x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xed, 0x5c, 0xad, 0x49, 0xb5, 0x06, 0xcf, 0x91, 0x84, 0x8b, 0x84, 0xf9, 0xb6, 0x8c, 0xfc, 0xf2,
0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6f, 0xe8, 0xb9, 0x16, 0x90, 0x08, 0x00, 0x00,
// 896 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4f, 0x6f, 0xe3, 0x44,
0x14, 0xc7, 0x49, 0xba, 0x49, 0x5e, 0x42, 0x9a, 0x8e, 0xda, 0xae, 0x59, 0x28, 0x04, 0x83, 0x44,
0xd4, 0x43, 0x84, 0x8a, 0xc4, 0xae, 0x38, 0x11, 0x5a, 0xb7, 0x44, 0x6d, 0xec, 0x30, 0x71, 0x59,
0xad, 0x84, 0x34, 0x72, 0xec, 0x49, 0x6b, 0xd5, 0xf5, 0x98, 0x99, 0x49, 0x51, 0x6e, 0x7c, 0x00,
0x2e, 0x5c, 0xf9, 0x14, 0x88, 0x33, 0x1f, 0x0e, 0x79, 0x6c, 0x07, 0xb7, 0x71, 0xd3, 0x22, 0x71,
0xb2, 0xdf, 0x6f, 0xde, 0x9f, 0x99, 0xdf, 0x7b, 0xbf, 0x07, 0x7a, 0xbc, 0x10, 0xd7, 0x24, 0x62,
0x32, 0x98, 0x07, 0x9e, 0x2b, 0x03, 0x16, 0x89, 0x41, 0xcc, 0x99, 0x64, 0xa8, 0xa1, 0x3e, 0xb3,
0xc5, 0xdc, 0xf8, 0xbb, 0x06, 0x1f, 0x4d, 0x16, 0xe2, 0xda, 0x2a, 0x78, 0x61, 0x7a, 0x15, 0x08,
0xc9, 0xd5, 0x3f, 0xb2, 0x01, 0x24, 0xbb, 0xa1, 0x11, 0x91, 0xcb, 0x98, 0xea, 0x5a, 0x4f, 0xeb,
0x77, 0x8e, 0xbe, 0x1c, 0xe4, 0xf1, 0x83, 0x4d, 0xb1, 0x03,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xad, 0x08, 0x00, 0x00,
}

View File

@ -19,6 +19,7 @@ message PushNotificationRegistration {
bool unregister = 9;
bytes grant = 10;
bool allow_from_contacts_only = 11;
string apn_topic = 12;
}
message PushNotificationRegistrationResponse {

View File

@ -17,6 +17,7 @@ import (
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/common"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/protocol/pushnotificationclient"
"github.com/status-im/status-go/protocol/pushnotificationserver"
"github.com/status-im/status-go/protocol/tt"
@ -26,6 +27,7 @@ import (
const (
bob1DeviceToken = "token-1"
bob2DeviceToken = "token-2"
testAPNTopic = "topic"
)
func TestMessengerPushNotificationSuite(t *testing.T) {
@ -139,7 +141,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
err = bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
s.Require().NoError(err)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
// Pull servers and check we registered
err = tt.RetryWithBackOff(func() error {
@ -169,7 +171,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
s.Require().NoError(err)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
s.Require().NoError(err)
err = tt.RetryWithBackOff(func() error {
@ -319,7 +321,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
err = bob.EnablePushNotificationsFromContactsOnly()
s.Require().NoError(err)
err = bob.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
err = bob.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
s.Require().NoError(err)
// Pull servers and check we registered
@ -463,7 +465,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
err = bob.EnablePushNotificationsFromContactsOnly()
s.Require().NoError(err)
err = bob.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
err = bob.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
s.Require().NoError(err)
// Pull servers and check we registered
@ -650,7 +652,7 @@ func (s *MessengerPushNotificationSuite) TestActAsYourOwnPushNotificationServer(
err := bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
s.Require().NoError(err)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
// Pull servers and check we registered
err = tt.RetryWithBackOff(func() error {
@ -680,7 +682,7 @@ func (s *MessengerPushNotificationSuite) TestActAsYourOwnPushNotificationServer(
err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey)
s.Require().NoError(err)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
s.Require().NoError(err)
err = tt.RetryWithBackOff(func() error {

View File

@ -121,9 +121,6 @@ type Config struct {
InstallationID string
Logger *zap.Logger
// TokenType is the type of token
TokenType protobuf.PushNotificationRegistration_TokenType
}
type Client struct {
@ -141,6 +138,10 @@ type Client struct {
AccessToken string
// deviceToken is the device token for this device
deviceToken string
// TokenType is the type of token
tokenType protobuf.PushNotificationRegistration_TokenType
// APNTopic is the topic of the apn topic for push notification
apnTopic string
// randomReader only used for testing so we have deterministic encryption
reader io.Reader
@ -245,11 +246,11 @@ func (c *Client) Reregister(contactIDs []*ecdsa.PublicKey, mutedChatIDs []string
return nil
}
return c.Register(c.deviceToken, contactIDs, mutedChatIDs)
return c.Register(c.deviceToken, c.apnTopic, c.tokenType, contactIDs, mutedChatIDs)
}
// Register registers with all the servers
func (c *Client) Register(deviceToken string, contactIDs []*ecdsa.PublicKey, mutedChatIDs []string) error {
func (c *Client) Register(deviceToken, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType, contactIDs []*ecdsa.PublicKey, mutedChatIDs []string) error {
// stop registration loop
c.stopRegistrationLoop()
@ -260,6 +261,8 @@ func (c *Client) Register(deviceToken string, contactIDs []*ecdsa.PublicKey, mut
}
c.deviceToken = deviceToken
c.apnTopic = apnTopic
c.tokenType = tokenType
registration, err := c.buildPushNotificationRegistrationMessage(contactIDs, mutedChatIDs)
if err != nil {
@ -440,7 +443,7 @@ func (c *Client) EnablePushNotificationsFromContactsOnly(contactIDs []*ecdsa.Pub
c.config.AllowFromContactsOnly = true
if c.lastPushNotificationRegistration != nil {
c.config.Logger.Debug("re-registering after enabling push notifications from contacts only")
return c.Register(c.deviceToken, contactIDs, mutedChatIDs)
return c.Register(c.deviceToken, c.apnTopic, c.tokenType, contactIDs, mutedChatIDs)
}
return nil
}
@ -450,7 +453,7 @@ func (c *Client) DisablePushNotificationsFromContactsOnly(contactIDs []*ecdsa.Pu
c.config.AllowFromContactsOnly = false
if c.lastPushNotificationRegistration != nil {
c.config.Logger.Debug("re-registering after disabling push notifications from contacts only")
return c.Register(c.deviceToken, contactIDs, mutedChatIDs)
return c.Register(c.deviceToken, c.apnTopic, c.tokenType, contactIDs, mutedChatIDs)
}
return nil
}
@ -549,8 +552,9 @@ func (c *Client) loadLastPushNotificationRegistration() error {
c.lastContactIDs = lastContactIDs
c.lastPushNotificationRegistration = lastRegistration
c.deviceToken = lastRegistration.DeviceToken
c.apnTopic = lastRegistration.ApnTopic
c.tokenType = lastRegistration.TokenType
return nil
}
func (c *Client) stopRegistrationLoop() {
@ -834,7 +838,8 @@ func (c *Client) buildPushNotificationRegistrationMessage(contactIDs []*ecdsa.Pu
options := &protobuf.PushNotificationRegistration{
AccessToken: token,
TokenType: c.config.TokenType,
TokenType: c.tokenType,
ApnTopic: c.apnTopic,
Version: c.getVersion(),
InstallationId: c.config.InstallationID,
DeviceToken: c.deviceToken,

View File

@ -57,7 +57,7 @@ func PushNotificationRegistrationToGoRushRequest(requestAndRegistrations []*Requ
Tokens: []string{registration.DeviceToken},
Platform: tokenTypeToGoRushPlatform(registration.TokenType),
Message: defaultNotificationMessage,
Topic: "im.status.ethereum.pr",
Topic: registration.ApnTopic,
Data: &GoRushRequestData{
EncryptedMessage: hex.EncodeToString(request.Message),
ChatID: request.ChatId,

View File

@ -430,7 +430,7 @@ func (api *PublicAPI) StopPushNotificationsServer() error {
// PushNotification client endpoints
func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceToken string) error {
func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceToken string, apnTopic string, tokenType protobuf.PushNotificationRegistration_TokenType) error {
// We set both for now as they are equivalent
err := api.service.accountsDB.SaveSetting("remote-push-notifications-enabled?", true)
if err != nil {
@ -441,7 +441,7 @@ func (api *PublicAPI) RegisterForPushNotifications(ctx context.Context, deviceTo
return err
}
return api.service.messenger.RegisterForPushNotifications(ctx, deviceToken)
return api.service.messenger.RegisterForPushNotifications(ctx, deviceToken, apnTopic, tokenType)
}
func (api *PublicAPI) UnregisterForPushNotifications(ctx context.Context) error {