HomePhabricator
Diffusion Comm 56f5dd41227a

[services] Tunnelbroker - Update FCM library wrapper with return of token…

Description

[services] Tunnelbroker - Update FCM library wrapper with return of token-related errors

Summary:
This diff introduces changes to the FCM library wrapper and fcm_status shared enum.

To distinguish common errors and wrong/expired device token errors the function should return different results.
Following a current keyserver's approach we should check for the following errors:

To pass the different errors to the C++ level the best and most elegant way is to return enum as Ok Rust result which formats like:

enum fcm_status {
        Ok,
        InvalidRegistration,
        NotRegistered,
}

and use CXX shared types.

Because when can't distinguish error types from Rust on the C++ side, they are always rust::error type and have only what() method.
Also, we will catch the common errors which are not needed to be distinguished using the catch approach.

Related Linear task: ENG-1764

Test Plan:
App building:

  1. Rust:

Run cargo build from services/tunnelbroker/rust-notifications directory.
Rust library will be successfully built.

  1. C++ (Docker):

Running run run-tunnelbroker-service successfully built the Rust library and link it.

  1. C++ (Nix):

Call cd services/tunnelbroker.
Running rm -dfr build && cmake -B build . && make -C build -j4 successfully built the Rust library and link it.

Notifications testings:
Library notifications push method can be called from the C++ as:

#include "rust_notifications/src/lib.rs.h"
#include "rust/cxx.h"
...

const fcmReturnStatus result = sendNotifToFCM = sendNotifToFCM(
    char const *fcmAPIKey,
    char const *deviceRegistrationID,
    char const *messageTitle,
    char const *messageBody
);

Behavior testings:

  • Test where errors are not related to the tokens appears and must be thrown and caught by the C++ catch:
    • Wrong server key throws a Rust exception error.
  • Test token-related errors:
    • Wrong token format returns an fcmReturnStatus enum with the value of InvalidRegistration.
    • The client requested a new token and we are sending notifs to the old one: return a fcmReturnStatus enum with the value of NotRegistered.
  • Test with good device token:
    • Returns an fcmReturnStatus enum with the value of Ok.

Reviewers: jon, varun, tomek, karol

Reviewed By: jon, tomek

Subscribers: ashoat, tomek, atul, karol, abosh

Differential Revision: https://phab.comm.dev/D5145