-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: implement relay websocket connection state #128
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "notify-server" | ||
version = "0.14.1" | ||
version = "0.15.1" | ||
edition = "2021" | ||
authors = ["Maciej Rak <[email protected]>"] | ||
build = "build.rs" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
WatchSubscriptionsEntry, | ||
}, | ||
websocket_service::{ | ||
decode_key, derive_key, handlers::decrypt_message, NotifyRequest, NotifyResponse, | ||
NotifyWatchSubscriptions, | ||
decode_key, derive_key, handlers::decrypt_message, publish_message, NotifyRequest, | ||
NotifyResponse, NotifyWatchSubscriptions, WebSocketClientState, | ||
}, | ||
Result, | ||
}, | ||
|
@@ -29,7 +29,7 @@ | |
mongodb::{bson::doc, Database}, | ||
relay_rpc::domain::{DecodedClientId, Topic}, | ||
serde_json::{json, Value}, | ||
std::sync::Arc, | ||
std::sync::{Arc, Mutex}, | ||
tracing::{info, instrument}, | ||
}; | ||
|
||
|
@@ -38,6 +38,7 @@ | |
msg: relay_client::websocket::PublishedMessage, | ||
state: &Arc<AppState>, | ||
client: &Arc<relay_client::websocket::Client>, | ||
client_state: &Arc<Mutex<WebSocketClientState>>, | ||
) -> Result<()> { | ||
if msg.topic != state.notify_keys.key_agreement_topic { | ||
return Err(Error::WrongNotifyWatchSubscriptionsTopic(msg.topic)); | ||
|
@@ -153,15 +154,17 @@ | |
base64::engine::general_purpose::STANDARD.encode(envelope.to_bytes()); | ||
|
||
info!("Publishing response on topic {response_topic}"); | ||
client | ||
.publish( | ||
response_topic.into(), | ||
base64_notification, | ||
NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_TAG, | ||
NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_TTL, | ||
false, | ||
) | ||
.await?; | ||
publish_message( | ||
client.clone(), | ||
client_state.clone(), | ||
state.clone(), | ||
response_topic.into(), | ||
&base64_notification, | ||
NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_TAG, | ||
NOTIFY_WATCH_SUBSCRIPTIONS_RESPONSE_TTL, | ||
false, | ||
) | ||
.await?; | ||
} | ||
|
||
Ok(()) | ||
|
@@ -226,12 +229,14 @@ | |
} | ||
|
||
// TODO do async outside of websocket request handler | ||
#[instrument(skip_all, fields(account = %account, app_domain = %app_domain))] | ||
pub async fn update_subscription_watchers( | ||
account: &str, | ||
app_domain: &str, | ||
database: &Database, | ||
client: &relay_client::websocket::Client, | ||
client: &Arc<relay_client::websocket::Client>, | ||
client_state: &Arc<Mutex<WebSocketClientState>>, | ||
app_state: &Arc<AppState>, | ||
authentication_secret: &ed25519_dalek::SigningKey, | ||
authentication_public: &ed25519_dalek::VerifyingKey, | ||
) -> Result<()> { | ||
|
@@ -242,14 +247,16 @@ | |
|
||
let did_pkh = format!("did:pkh:{account}"); | ||
|
||
#[instrument(skip_all, fields(did_pkh = %did_pkh, aud = %aud, subscriptions_count = %subscriptions.len()))] | ||
async fn send( | ||
subscriptions: Vec<NotifyServerSubscription>, | ||
aud: String, | ||
sym_key: &str, | ||
notify_did_key: String, | ||
did_pkh: String, | ||
client: &relay_client::websocket::Client, | ||
client: &Arc<relay_client::websocket::Client>, | ||
client_state: &Arc<Mutex<WebSocketClientState>>, | ||
app_state: &Arc<AppState>, | ||
authentication_secret: &ed25519_dalek::SigningKey, | ||
) -> Result<()> { | ||
let now = Utc::now(); | ||
|
@@ -277,15 +284,17 @@ | |
|
||
let topic = Topic::from(sha256::digest(&sym_key)); | ||
info!("topic: {topic}"); | ||
client | ||
.publish( | ||
topic, | ||
base64_notification, | ||
NOTIFY_SUBSCRIPTIONS_CHANGED_TAG, | ||
NOTIFY_SUBSCRIPTIONS_CHANGED_TTL, | ||
false, | ||
) | ||
.await?; | ||
publish_message( | ||
client.clone(), | ||
client_state.clone(), | ||
app_state.clone(), | ||
topic, | ||
&base64_notification, | ||
NOTIFY_SUBSCRIPTIONS_CHANGED_TAG, | ||
NOTIFY_SUBSCRIPTIONS_CHANGED_TTL, | ||
false, | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
@@ -308,6 +317,8 @@ | |
notify_did_key.clone(), | ||
did_pkh.clone(), | ||
client, | ||
client_state, | ||
app_state, | ||
authentication_secret, | ||
) | ||
.await?; | ||
|
@@ -331,6 +342,8 @@ | |
notify_did_key.clone(), | ||
did_pkh.clone(), | ||
client, | ||
client_state, | ||
app_state, | ||
Comment on lines
344
to
+346
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lot to have to pass around. Can we wrap all 3 of these in a struct (maybe called |
||
authentication_secret, | ||
) | ||
.await?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once my PR is merged can you reset this CHANGELOG, revert the version in Cargo.toml, and delete any created GitHub releases before merging?