HomePhabricator
Diffusion Comm 3d80ae630850

[services] Tunnelbroker - Update A2 (APNs) library wrapper with return of token…

Description

[services] Tunnelbroker - Update A2 (APNs) library wrapper with return of token-related errors

Summary:
This diff introduces changes to the A2 (APNs) library wrapper and apns_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 apns_status {
    Ok,
    Unregistered,
    BadDeviceToken,
}

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 apnsReturnStatus result = sendNotifToAPNS(
 char const * cert_path,
 char const * cert_pass,
 char const * device_token,
 char const * message_body,
 bool true);

Behavior testings:

  • Test when the error is not ResponseError type:
    • Wrong certificate path or password will throw a Rust Result exception which is caught by the catch. (Produces read error message).
  • Test when wrong device token is provided:
    • Function returns an apnsReturnStatus enum with the value of BadDeviceToken.
  • Test with good device token:
    • Function returns an apnsReturnStatus 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/D5149