Page MenuHomePhabricator

D12635.id.diff
No OneTemporary

D12635.id.diff

diff --git a/services/tunnelbroker/src/main.rs b/services/tunnelbroker/src/main.rs
--- a/services/tunnelbroker/src/main.rs
+++ b/services/tunnelbroker/src/main.rs
@@ -8,10 +8,14 @@
pub mod notifs;
pub mod websockets;
+use crate::constants::ENV_APNS_CONFIG;
+use crate::notifs::apns::config::APNsConfig;
+use crate::notifs::apns::APNsClient;
+use crate::notifs::NotifClient;
use anyhow::{anyhow, Result};
use config::CONFIG;
use std::str::FromStr;
-use tracing::{self, Level};
+use tracing::{self, error, info, Level};
use tracing_subscriber::EnvFilter;
#[tokio::main]
@@ -32,6 +36,25 @@
let apns_config = CONFIG.apns_config.clone();
+ let apns = match apns_config {
+ Some(config) => match APNsClient::new(&config) {
+ Ok(apns_client) => {
+ info!("APNs client created successfully");
+ Some(apns_client)
+ }
+ Err(err) => {
+ error!("Error creating APNs client: {}", err);
+ None
+ }
+ },
+ None => {
+ error!("APNs config is missing");
+ None
+ }
+ };
+
+ let notif_client = NotifClient { apns };
+
let grpc_server = grpc::run_server(db_client.clone(), &amqp_connection);
let websocket_server =
websockets::run_server(db_client.clone(), &amqp_connection);
diff --git a/services/tunnelbroker/src/notifs/apns/error.rs b/services/tunnelbroker/src/notifs/apns/error.rs
--- a/services/tunnelbroker/src/notifs/apns/error.rs
+++ b/services/tunnelbroker/src/notifs/apns/error.rs
@@ -3,6 +3,7 @@
#[derive(Debug, From, Display, Error)]
pub enum Error {
JWTError,
+ ReqwestError(reqwest::Error),
}
impl From<jsonwebtoken::errors::Error> for Error {
diff --git a/services/tunnelbroker/src/notifs/apns/mod.rs b/services/tunnelbroker/src/notifs/apns/mod.rs
--- a/services/tunnelbroker/src/notifs/apns/mod.rs
+++ b/services/tunnelbroker/src/notifs/apns/mod.rs
@@ -1,7 +1,8 @@
+use crate::notifs::apns::config::APNsConfig;
use crate::notifs::apns::token::APNsToken;
-
+use std::time::Duration;
pub mod config;
-mod error;
+pub mod error;
pub mod token;
#[derive(Clone)]
@@ -10,3 +11,22 @@
token: APNsToken,
is_prod: bool,
}
+
+impl APNsClient {
+ pub fn new(config: &APNsConfig) -> Result<Self, error::Error> {
+ let token_ttl = Duration::from_secs(60 * 55);
+ let token = APNsToken::new(config, token_ttl)?;
+
+ let http2_client = reqwest::Client::builder()
+ .http2_prior_knowledge()
+ .http2_keep_alive_interval(Some(Duration::from_secs(5)))
+ .http2_keep_alive_while_idle(true)
+ .build()?;
+
+ Ok(APNsClient {
+ http2_client,
+ token,
+ is_prod: config.production,
+ })
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 12:45 PM (13 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2600978
Default Alt Text
D12635.id.diff (2 KB)

Event Timeline