Skip to content

Commit

Permalink
let event streaming be off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Oct 12, 2024
1 parent 868ee2c commit d2e3734
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions mm2src/mm2_core/src/mm_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ impl MmCtx {
pub fn use_trading_proto_v2(&self) -> bool { self.conf["use_trading_proto_v2"].as_bool().unwrap_or_default() }

/// Returns the event streaming configuration in use.
pub fn event_streaming_configuration(&self) -> EventStreamingConfiguration {
serde_json::from_value(self.conf["event_streaming_configuration"].clone()).unwrap_or_default()
pub fn event_streaming_configuration(&self) -> Option<EventStreamingConfiguration> {
serde_json::from_value(self.conf["event_streaming_configuration"].clone()).ok()
}

/// Returns the cloneable `WeakSpawner`.
Expand Down
2 changes: 0 additions & 2 deletions mm2src/mm2_event_stream/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ use serde::Deserialize;
/// The network-related configuration of the event streaming interface.
// TODO: This better fits in mm2_net but then we would have circular dependency error trying to import it in mm2_core.
pub struct EventStreamingConfiguration {
pub disabled: bool,
pub worker_path: String,
pub access_control_allow_origin: String,
}

impl Default for EventStreamingConfiguration {
fn default() -> Self {
Self {
disabled: false,
worker_path: "event_streaming_worker.js".to_string(),
access_control_allow_origin: "*".to_string(),
}
Expand Down
3 changes: 1 addition & 2 deletions mm2src/mm2_main/src/lp_native_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ fn migration_1(_ctx: &MmArc) {}

#[cfg(target_arch = "wasm32")]
fn init_wasm_event_streaming(ctx: &MmArc) {
let event_streaming_config = ctx.event_streaming_configuration();
if !event_streaming_config.disabled {
if let Some(event_streaming_config) = ctx.event_streaming_configuration() {
ctx.spawner()
.spawn(handle_worker_stream(ctx.clone(), event_streaming_config.worker_path));
}
Expand Down
7 changes: 3 additions & 4 deletions mm2src/mm2_net/src/event_streaming/sse_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ pub async fn handle_sse(request: Request<Body>, ctx_h: u32) -> Result<Response<B
Err(err) => return handle_internal_error(err).await,
};

let event_streaming_config = ctx.event_streaming_configuration();
if event_streaming_config.disabled {
return handle_internal_error("Event streaming is explicitly disabled".to_string()).await;
}
let Some(event_streaming_config) = ctx.event_streaming_configuration() else {
return handle_internal_error("Event streaming is disabled".to_string()).await;
};

let client_id = match request.uri().query().and_then(|query| {
query
Expand Down

0 comments on commit d2e3734

Please sign in to comment.