Coder Social home page Coder Social logo

notifiers's Introduction

Delta Chat Notification Proxy

The Delta Chat notification proxy is deployed as a central service on https://notifications.delta.chat

The notification proxy is a small Rust program that forwards "device tokens" to Apple and Google "Push Services" that in turn wake up the Delta Chat app on user's devices.

Usage

Certificates

The certificate file provided must be a .p12 file. Instructions for how to create can be found here.

Running

$ cargo build --release
$ ./target/release/notifiers --certificate-file <file.p12> --password <password>

Registering devices

$ curl -X POST -d '{ "token": "<device token>" }' http://localhost:9000/register

Enabling metrics

To enable OpenMetrics (Prometheus) metrics endpoint, run with --metrics argument, e.g. --metrics 127.0.0.1:9001. Metrics can then be retrieved with curl http://127.0.0.1:9001/metrics.

notifiers's People

Contributors

link2xt avatar dignifiedquire avatar r10s avatar hpk42 avatar

Stargazers

adz avatar  avatar Simon Laux avatar  avatar

Watchers

 avatar  avatar  avatar

notifiers's Issues

Add jitter to heardbeat notifications

Currently heartbeat notifications tend to all be fired at the same time, especially as the server gets stopped and restarted during backup. This causes problem with Grafana alerts that detect when increase(heartbeat_notifications_total[20m]) becomes zero. With 20m notification interval this metric is sometimes zero when backup job that runs every day stops notification service right before all notifications are supposed to be fired.

Implementing proper pacing is too much work as we don't need to perfectly distribute the notifications over time, but adding random delay should solve the problem.

Certificate loading error

https://github.com/dignifiedquire/notifiers/blob/master/src/notifier.rs#L20

SignerError("error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:
1149:, error:0D06C03A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1 error:crypto/asn1/tasn_dec.c:713:, error:0D08303A:asn1 encodi
ng routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:646:Field=version, Type=PKCS12")

also this error isn't reported to the logger I had to modify the code to get it out.

document dependencies

When we compiled this on debian, we had to install build-essential, libssl-dev, and pkg-config. Can this be documented in the README.md?

Starting fails

Error from the log:

Mar 27 20:20:44 page systemd[1]: Started notifications.service - Notification Service.
Mar 27 20:20:44 page notifiers[231468]: Error: Failed to create production client
Mar 27 20:20:44 page notifiers[231468]: Caused by:
Mar 27 20:20:44 page notifiers[231468]:     0: Error creating a signature: error:0308010C:digital envelope routines:func(128):unsupported:../crypto/evp/evp_fetch.c:373:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
Mar 27 20:20:44 page notifiers[231468]:     1: error:0308010C:digital envelope routines:func(128):unsupported:../crypto/evp/evp_fetch.c:373:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
Mar 27 20:20:44 page systemd[1]: notifications.service: Main process exited, code=exited, status=1/FAILURE
Mar 27 20:20:44 page systemd[1]: notifications.service: Failed with result 'exit-code'.

Notification failure does not result in token removal

Log contains a lot of error 400 codes like this:

Feb 18 23:12:01 page notifiers[155882]: {"level":50,"time":1708297921762,"msg":"failed to send notification: 8f...dd, ResponseError(Response { error: Some(ErrorBody { reason: DeviceTokenNotForTopic, timestamp: None }), apns_id: Some(\"...\"), code: 400 })"}

Also this:

Feb 18 23:11:17 page notifiers[155882]: {"level":50,"time":1708297877638,"msg":"failed to send notification: 8d...46, ResponseError(Response { error: Some(ErrorBody { reason: BadDeviceToken, timestamp: None }), apns_id: Some(\"...\"), code: 400 })"}

We should remove tokens from the database in these cases, but currently we just log the error:

Err(err) => {
error!("failed to send notification: {}, {:?}", device_token, err);
}

Implement Firebase Cloud Messaging support

/notify endpoint should support Firebase Cloud Messaging.
Currently unprefixed tokens go to APNS production server and tokens with sandbox: prefix go to APNS sandbox server. Tokens with fcm-*: prefix should go to FCM server.

We can take the code from https://github.com/threema-ch/push-relay/blob/a5ef862ec5cccdd5d738c49042d60595068adbc4/src/push/fcm.rs (Apache/MIT licensed like Rust).
It is however outdated, there is a guide for migrating to modern REST API at https://firebase.google.com/docs/cloud-messaging/migrate-v1

http-header `apns-push-type: alert` missing

https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_usernotifications_filtering says:

To silence a remote notification, you must set the apns-push-type header field to alert when you send the notification to the APNS server. Otherwise, the system always displays the notification banner to the user.

seems we need to set the http-header apns-push-type: alert - i assume, this is currently not the case, as as silencing is currently not working and as there is a PR for exactly that open at WalletConnect/a2#74 - more information at https://developer.apple.com/documentation/usernotifications/sending-notification-requests-to-apns

nb: the client-part was just merged with deltachat/deltachat-ios#2124 and compliance seems to be set, so this single header line might be the last bit to finally make silencing working :)

Add license

There is currently no license listed for this repository and in Cargo.toml.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.