|
1 | 1 | use crate::message::logout::Logout; |
2 | 2 | use crate::message::reject::Reject; |
3 | 3 | use crate::message::verification::verify_message; |
4 | | -use crate::message::verification_error::MessageVerificationError; |
| 4 | +use crate::message::verification_error::{CompIdType, MessageVerificationError}; |
5 | 5 | use crate::session::ctx::{SessionCtx, TransitionResult}; |
6 | 6 | use crate::session::outbound; |
7 | 7 | use crate::session::state::SessionState; |
8 | 8 | use crate::transport::writer::WriterRef; |
9 | | -use tracing::warn; |
10 | 9 | use hotfix_message::Part; |
11 | 10 | use hotfix_message::message::Message; |
12 | 11 | use hotfix_message::session_fields::{MSG_SEQ_NUM, SessionRejectReason}; |
13 | 12 | use hotfix_store::MessageStore; |
14 | 13 | use tracing::error; |
| 14 | +use tracing::warn; |
15 | 15 |
|
16 | 16 | pub(crate) fn verify_message_with_ctx<A, S: MessageStore>( |
17 | 17 | ctx: &SessionCtx<A, S>, |
@@ -63,7 +63,33 @@ pub(crate) async fn handle_incorrect_begin_string<A, S: MessageStore>( |
63 | 63 | Err(err) => warn!("failed to send logout for incorrect begin string: {err}"), |
64 | 64 | } |
65 | 65 | writer.disconnect().await; |
66 | | - TransitionResult::TransitionTo(SessionState::new_disconnected(true, "incorrect begin string")) |
| 66 | + TransitionResult::TransitionTo(SessionState::new_disconnected( |
| 67 | + true, |
| 68 | + "incorrect begin string", |
| 69 | + )) |
| 70 | +} |
| 71 | + |
| 72 | +pub(crate) async fn handle_incorrect_comp_id<A, S: MessageStore>( |
| 73 | + ctx: &mut SessionCtx<A, S>, |
| 74 | + writer: &WriterRef, |
| 75 | + received_comp_id: String, |
| 76 | + comp_id_type: CompIdType, |
| 77 | + msg_seq_num: u64, |
| 78 | +) -> TransitionResult { |
| 79 | + error!("rejecting message with incorrect comp ID: {received_comp_id} (type: {comp_id_type:?})"); |
| 80 | + let reject = Reject::new(msg_seq_num) |
| 81 | + .session_reject_reason(SessionRejectReason::ValueIsIncorrect) |
| 82 | + .text(&format!("invalid comp ID {received_comp_id}")); |
| 83 | + if let Err(err) = outbound::send_message(ctx, writer, reject).await { |
| 84 | + error!("failed to send reject message with invalid comp ID: {err}"); |
| 85 | + } |
| 86 | + let logout = Logout::with_reason("incorrect comp ID received".to_string()); |
| 87 | + match ctx.prepare_message(logout).await { |
| 88 | + Ok(prepared) => writer.send_raw_message(prepared.raw).await, |
| 89 | + Err(err) => warn!("failed to send logout for incorrect comp ID: {err}"), |
| 90 | + } |
| 91 | + writer.disconnect().await; |
| 92 | + TransitionResult::TransitionTo(SessionState::new_disconnected(true, "incorrect comp ID")) |
67 | 93 | } |
68 | 94 |
|
69 | 95 | pub(crate) async fn handle_invalid_msg_type<A, S: MessageStore>( |
|
0 commit comments