Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
1b0e0604
Commit
1b0e0604
authored
Apr 16, 2021
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
revive register/unregister for notifications
parent
68809d20
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/notifications.go
+72
-30
72 additions, 30 deletions
api/notifications.go
with
72 additions
and
30 deletions
api/notifications.go
+
72
−
30
View file @
1b0e0604
...
...
@@ -7,7 +7,15 @@
package
api
import
jww
"github.com/spf13/jwalterweatherman"
import
(
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/hash"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
)
// RegisterForNotifications allows a client to register for push
// notifications.
...
...
@@ -17,22 +25,29 @@ import jww "github.com/spf13/jwalterweatherman"
// risk to the user.
func
(
c
*
Client
)
RegisterForNotifications
(
token
[]
byte
)
error
{
jww
.
INFO
.
Printf
(
"RegisterForNotifications(%s)"
,
token
)
// // Pull the host from the manage
// notificationBotHost, ok := cl.receptionManager.Comms.GetHost(&id.NotificationBot)
// if !ok {
// return errors.New("Failed to retrieve host for notification bot")
// }
// // Send the register message
// _, err := cl.receptionManager.Comms.RegisterForNotifications(notificationBotHost,
// &mixmessages.NotificationToken{
// Token: notificationToken,
// })
// if err != nil {
// err := errors.Errorf(
// "RegisterForNotifications: Unable to register for notifications! %s", err)
// return err
// }
// Pull the host from the manage
notificationBotHost
,
ok
:=
c
.
comms
.
GetHost
(
&
id
.
NotificationBot
)
if
!
ok
{
return
errors
.
New
(
"RegisterForNotifications: Failed to retrieve host for notification bot"
)
}
intermediaryReceptionID
,
sig
,
err
:=
c
.
getIidAndSig
()
if
err
!=
nil
{
return
err
}
// Send the register message
_
,
err
=
c
.
comms
.
RegisterForNotifications
(
notificationBotHost
,
&
mixmessages
.
NotificationRegisterRequest
{
Token
:
token
,
IntermediaryId
:
intermediaryReceptionID
,
TransmissionRsa
:
rsa
.
CreatePublicKeyPem
(
c
.
GetUser
()
.
TransmissionRSA
.
GetPublic
()),
TransmissionRsaSig
:
sig
,
TransmissionSalt
:
c
.
GetUser
()
.
TransmissionSalt
,
})
if
err
!=
nil
{
err
:=
errors
.
Errorf
(
"RegisterForNotifications: Unable to register for notifications! %s"
,
err
)
return
err
}
return
nil
}
...
...
@@ -40,19 +55,46 @@ func (c *Client) RegisterForNotifications(token []byte) error {
// UnregisterForNotifications turns of notifications for this client
func
(
c
*
Client
)
UnregisterForNotifications
()
error
{
jww
.
INFO
.
Printf
(
"UnregisterForNotifications()"
)
// // Pull the host from the manage
// notificationBotHost, ok := cl.receptionManager.Comms.GetHost(&id.NotificationBot)
// if !ok {
// return errors.New("Failed to retrieve host for notification bot")
// }
// // Send the unregister message
// _, err := cl.receptionManager.Comms.UnregisterForNotifications(notificationBotHost)
// if err != nil {
// err := errors.Errorf(
// "RegisterForNotifications: Unable to register for notifications! %s", err)
// return err
// }
// Pull the host from the manage
notificationBotHost
,
ok
:=
c
.
comms
.
GetHost
(
&
id
.
NotificationBot
)
if
!
ok
{
return
errors
.
New
(
"Failed to retrieve host for notification bot"
)
}
intermediaryReceptionID
,
sig
,
err
:=
c
.
getIidAndSig
()
if
err
!=
nil
{
return
err
}
// Send the unregister message
_
,
err
=
c
.
comms
.
UnregisterForNotifications
(
notificationBotHost
,
&
mixmessages
.
NotificationUnregisterRequest
{
IntermediaryId
:
intermediaryReceptionID
,
IIDTransmissionRsaSig
:
sig
,
})
if
err
!=
nil
{
err
:=
errors
.
Errorf
(
"RegisterForNotifications: Unable to register for notifications! %s"
,
err
)
return
err
}
return
nil
}
func
(
c
*
Client
)
getIidAndSig
()
([]
byte
,
[]
byte
,
error
)
{
intermediaryReceptionID
,
err
:=
ephemeral
.
GetIntermediaryId
(
c
.
GetUser
()
.
ReceptionID
)
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
WithMessage
(
err
,
"RegisterForNotifications: Failed to form intermediary ID"
)
}
h
,
err
:=
hash
.
NewCMixHash
()
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
WithMessage
(
err
,
"RegisterForNotifications: Failed to create cmix hash"
)
}
_
,
err
=
h
.
Write
(
intermediaryReceptionID
)
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
WithMessage
(
err
,
"RegisterForNotifications: Failed to write intermediary ID to hash"
)
}
sig
,
err
:=
rsa
.
Sign
(
c
.
rng
.
GetStream
(),
c
.
GetUser
()
.
TransmissionRSA
,
hash
.
CMixHash
,
h
.
Sum
(
nil
),
nil
)
if
err
!=
nil
{
return
nil
,
nil
,
errors
.
WithMessage
(
err
,
"RegisterForNotifications: Failed to sign intermediary ID"
)
}
return
intermediaryReceptionID
,
sig
,
nil
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment