Skip to content

Commit

Permalink
fix(FTL-17152): remove hash did from ws request interface (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoussefAWasfy authored Oct 1, 2024
1 parent 740af0d commit de4845b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 1 addition & 3 deletions affinidi-did-resolver-cache-sdk/src/networking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ mod request_queue;

/// WSRequest is the request format to the websocket connection
/// did: DID to resolve
/// hash: SHA256 Hash of the DID
#[derive(Debug, Deserialize, Serialize)]
pub struct WSRequest {
pub did: String,
pub hash: String,
}

/// WSResponse is the response format from the websocket connection
Expand Down Expand Up @@ -85,7 +83,7 @@ impl DIDCacheClient {

// 1. Send the request to the network task, which will then send via websocket to the remote server
network_task_tx
.send(WSCommands::Send(tx, unique_id.clone(), WSRequest { did: did.into(), hash: did_hash.into() }))
.send(WSCommands::Send(tx, unique_id.clone(), WSRequest { did: did.into() }))
.await
.map_err(|e| {
DIDCacheError::TransportError(format!(
Expand Down
6 changes: 5 additions & 1 deletion affinidi-did-resolver-cache-sdk/src/networking/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use std::time::Duration;

use crate::{config::ClientConfig, errors::DIDCacheError, WSRequest};
use blake2::{Blake2s256, Digest};
use futures_util::{SinkExt, StreamExt};
use ssi::dids::Document;
use tokio::{
Expand Down Expand Up @@ -101,7 +102,10 @@ impl NetworkTask {
if let Some(cmd) = value {
match cmd {
WSCommands::Send(channel, uid, request) => {
if network_task.cache.insert(request.hash.clone(), &uid, channel) {
let mut hasher = Blake2s256::new();
hasher.update(request.did.clone());
let did_hash = format!("{:x}", hasher.finalize());
if network_task.cache.insert(did_hash, &uid, channel) {
let _ = network_task.ws_send(&mut websocket, &request).await;
}
}
Expand Down
6 changes: 5 additions & 1 deletion affinidi-did-resolver-cache-server/src/handlers/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use axum::{
},
response::IntoResponse,
};
use blake2::{Blake2s256, Digest};
use tokio::select;
use tracing::{debug, info, span, warn, Instrument};

Expand Down Expand Up @@ -82,9 +83,12 @@ async fn handle_socket(mut socket: WebSocket, state: SharedData) {
}
Err(e) => {
// Couldn't resolve the DID, send an error back
let mut hasher = Blake2s256::new();
hasher.update(request.did.clone());
let did_hash = format!("{:x}", hasher.finalize());
warn!("Couldn't resolve DID: ({}) Reason: {}", &request.did, e);
state.stats().await.increment_resolver_error();
if let Err(e) = socket.send(Message::Text(serde_json::to_string(&WSResponseType::Error(WSResponseError {did: request.did, hash: request.hash, error: e.to_string()})).unwrap())).await {
if let Err(e) = socket.send(Message::Text(serde_json::to_string(&WSResponseType::Error(WSResponseError {did: request.did, hash: did_hash, error: e.to_string()})).unwrap())).await {
warn!("ws: Error sending error response: {:?}", e);
break;
}
Expand Down

0 comments on commit de4845b

Please sign in to comment.