|
1 | 1 | use {
|
2 | 2 | crate::utils::{
|
3 |
| - create_client, encode_auth, generate_account, verify_jwt, UnregisterIdentityRequestAuth, |
4 |
| - JWT_LEEWAY, RELAY_MESSAGE_DELIVERY_TIMEOUT, |
| 3 | + encode_auth, generate_account, verify_jwt, UnregisterIdentityRequestAuth, JWT_LEEWAY, |
| 4 | + RELAY_MESSAGE_DELIVERY_TIMEOUT, |
5 | 5 | },
|
6 | 6 | base64::Engine,
|
7 | 7 | chacha20poly1305::{
|
@@ -53,13 +53,13 @@ use {
|
53 | 53 | cacao::{self, signature::Eip191},
|
54 | 54 | ed25519_dalek::Keypair,
|
55 | 55 | },
|
56 |
| - domain::DecodedClientId, |
| 56 | + domain::{DecodedClientId, ProjectId}, |
57 | 57 | rpc::msg_id::get_message_id,
|
58 | 58 | },
|
59 | 59 | serde_json::json,
|
60 | 60 | sha2::Digest,
|
61 | 61 | sha3::Keccak256,
|
62 |
| - std::{collections::HashSet, env}, |
| 62 | + std::{collections::HashSet, env, sync::Arc}, |
63 | 63 | tokio::sync::broadcast::Receiver,
|
64 | 64 | url::Url,
|
65 | 65 | uuid::Uuid,
|
@@ -151,6 +151,44 @@ struct Vars {
|
151 | 151 | keys_server_url: Url,
|
152 | 152 | }
|
153 | 153 |
|
| 154 | +pub async fn create_client( |
| 155 | + relay_url: Url, |
| 156 | + relay_project_id: ProjectId, |
| 157 | + notify_url: Url, |
| 158 | +) -> ( |
| 159 | + Arc<relay_client::websocket::Client>, |
| 160 | + Receiver<notify_server::services::websocket_server::relay_ws_client::RelayClientEvent>, |
| 161 | +) { |
| 162 | + let (tx, mut rx) = tokio::sync::broadcast::channel(8); |
| 163 | + let (mpsc_tx, mut mpsc_rx) = tokio::sync::mpsc::unbounded_channel(); |
| 164 | + tokio::task::spawn(async move { |
| 165 | + while let Some(event) = mpsc_rx.recv().await { |
| 166 | + let _ = tx.send(event); |
| 167 | + } |
| 168 | + }); |
| 169 | + let connection_handler = |
| 170 | + notify_server::services::websocket_server::relay_ws_client::RelayConnectionHandler::new( |
| 171 | + "notify-client", |
| 172 | + mpsc_tx, |
| 173 | + ); |
| 174 | + let relay_ws_client = Arc::new(relay_client::websocket::Client::new(connection_handler)); |
| 175 | + |
| 176 | + let keypair = Keypair::generate(&mut StdRng::from_entropy()); |
| 177 | + let opts = notify_server::relay_client_helpers::create_ws_connect_options( |
| 178 | + &keypair, |
| 179 | + relay_url, |
| 180 | + notify_url, |
| 181 | + relay_project_id, |
| 182 | + ) |
| 183 | + .unwrap(); |
| 184 | + relay_ws_client.connect(&opts).await.unwrap(); |
| 185 | + |
| 186 | + // Eat up the "connected" message |
| 187 | + _ = rx.recv().await.unwrap(); |
| 188 | + |
| 189 | + (relay_ws_client, rx) |
| 190 | +} |
| 191 | + |
154 | 192 | #[allow(clippy::too_many_arguments)]
|
155 | 193 | async fn watch_subscriptions(
|
156 | 194 | vars: &Vars,
|
|
0 commit comments