Skip to content
Snippets Groups Projects
Commit 9e405098 authored by Jonah Husson's avatar Jonah Husson
Browse files

MR comment fixes

parent d7b425c5
No related branches found
No related tags found
No related merge requests found
......@@ -96,25 +96,31 @@ var rootCmd = &cobra.Command{
},
}
// setupConnection handles connecting to permissioning and polling for the NDF once connected
func setupConnection(impl *notifications.Impl, permissioningCertPath, permissioningAddr string) error {
// Read in permissioning certificate
cert, err := utils.ReadFile(permissioningCertPath)
if err != nil {
jww.FATAL.Panicf("Could not read permissioning cert: %+v", err)
return errors.Wrap(err, "Could not read permissioning cert")
}
// Add host for permissioning server
_, err = impl.Comms.AddHost(id.PERMISSIONING, permissioningAddr, cert, true, true)
if err != nil {
jww.FATAL.Panicf("Failed to Create permissioning host: %+v", err)
return errors.Wrap(err, "Failed to Create permissioning host")
}
// Loop until an NDF is received
var def *ndf.NetworkDefinition
for def == nil {
def, err = notifications.PollNdf(nil, impl.Comms)
// Don't stop if error is expected
if err != nil && !strings.Contains(err.Error(), ndf.NO_NDF) {
return errors.Wrap(err, "Failed to get NDF")
}
}
// Update NDF & gateway host
err = impl.UpdateNdf(def)
if err != nil {
return errors.Wrap(err, "Failed to update impl's NDF")
......
......@@ -72,6 +72,7 @@ func (nb *Impl) RunNotificationLoop(loopDuration int, killChan chan struct{}, er
case <-time.After(time.Millisecond * time.Duration(loopDuration)):
}
// Poll for UIDs to notify
UIDs, err := nb.pollFunc(nb)
if err != nil {
errChan <- errors.Wrap(err, "Failed to poll gateway for users to notify")
......@@ -79,6 +80,7 @@ func (nb *Impl) RunNotificationLoop(loopDuration int, killChan chan struct{}, er
}
for _, id := range UIDs {
// Attempt to notify a given user (will not error if UID not registered)
_, err := nb.notifyFunc(nb.fcm, id, fc, nb.Storage)
if err != nil {
errChan <- errors.Wrapf(err, "Failed to notify user with ID %+v", id)
......@@ -120,13 +122,15 @@ func StartNotifications(params Params, noTLS, noFirebase bool) (*Impl, error) {
}
}
// set up stored functions
impl.pollFunc = pollForNotifications
impl.notifyFunc = notifyUser
// Start notification comms server
handler := NewImplementation(impl)
impl.Comms = notificationBot.StartNotificationBot(id.NOTIFICATION_BOT, params.PublicAddress, handler, cert, key)
// Set up firebase messaging client
if !noFirebase {
app, err := firebase.SetupMessagingApp(params.FBCreds)
if err != nil {
......@@ -159,6 +163,7 @@ func notifyUser(fcm *messaging.Client, uid string, fc *firebase.FirebaseComm, db
u, err := db.GetUser(uid)
if err != nil {
jww.DEBUG.Printf("No registration found for user with ID %+v", uid)
// This path is not an error. if no results are returned, the user hasn't registered for notifications
return "", nil
}
......@@ -210,7 +215,7 @@ func (nb *Impl) UnregisterForNotifications(auth *connect.Auth) error {
func (nb *Impl) UpdateNdf(ndf *ndf.NetworkDefinition) error {
gw := ndf.Gateways[len(ndf.Gateways)-1]
_, err := nb.Comms.AddHost("gw", gw.Address, []byte(gw.TlsCertificate), false, true)
_, err := nb.Comms.AddHost("gw", gw.Address, []byte(gw.TlsCertificate), true, true)
if err != nil {
return errors.Wrap(err, "Failed to add gateway host from NDF")
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment