@@ -34,6 +34,7 @@ use crate::message::reject::Reject;
3434use crate :: message:: resend_request:: ResendRequest ;
3535use crate :: message:: sequence_reset:: SequenceReset ;
3636use crate :: message:: test_request:: TestRequest ;
37+ use crate :: message:: verification:: VerificationFlags ;
3738use crate :: session:: admin_request:: AdminRequest ;
3839use crate :: session:: ctx:: { SessionCtx , TransitionResult , VerificationResult } ;
3940use crate :: session:: error:: SessionCreationError ;
@@ -53,9 +54,7 @@ use crate::store::MessageStore;
5354use crate :: transport:: writer:: WriterRef ;
5455use event:: SessionEvent ;
5556use hotfix_message:: parsed_message:: { InvalidReason , ParsedMessage } ;
56- use hotfix_message:: session_fields:: {
57- GAP_FILL_FLAG , MSG_SEQ_NUM , MSG_TYPE , SessionRejectReason , TEST_REQ_ID ,
58- } ;
57+ use hotfix_message:: session_fields:: { MSG_SEQ_NUM , MSG_TYPE , SessionRejectReason , TEST_REQ_ID } ;
5958
6059const SCHEDULE_CHECK_INTERVAL : u64 = 1 ;
6160
@@ -208,38 +207,24 @@ where
208207 }
209208 }
210209
211- if let SessionState :: AwaitingLogon ( _) = & mut self . state {
212- if message_type != Logon :: MSG_TYPE {
213- self . state . disconnect_writer ( ) . await ;
214- return Ok ( ( ) ) ;
215- }
210+ // TODO: add state-level pre-process check that validates whether the message type
211+ // is acceptable in the current state (e.g. AwaitingLogon rejects non-Logon,
212+ // unexpected Logon in Active should be rejected per FIX spec).
213+ if let SessionState :: AwaitingLogon ( _) = & mut self . state
214+ && message_type != Logon :: MSG_TYPE
215+ {
216+ self . state . disconnect_writer ( ) . await ;
217+ return Ok ( ( ) ) ;
216218 }
217219
218- // Logon has its own verification inside the AwaitingLogon guard
219- if message_type != Logon :: MSG_TYPE {
220- let ( check_too_high, check_too_low) = match message_type {
221- // check_too_high=false: QFJ-673 deadlock fix. When both sides send
222- // ResendRequest simultaneously, each side's ResendRequest will have a seq
223- // number higher than expected. By not treating that as an error, we allow
224- // the ResendRequest to be processed.
225- ResendRequest :: MSG_TYPE => ( false , true ) ,
226- Reject :: MSG_TYPE => ( false , true ) ,
227- Logout :: MSG_TYPE => ( false , false ) ,
228- SequenceReset :: MSG_TYPE => {
229- let is_gap_fill: bool = message. get ( GAP_FILL_FLAG ) . unwrap_or ( false ) ;
230- ( is_gap_fill, is_gap_fill)
231- }
232- _ => ( true , true ) ,
233- } ;
234-
235- if let VerificationResult :: Issue ( result) = self
236- . state
237- . handle_verification_issue ( & mut self . ctx , & message, check_too_high, check_too_low)
238- . await ?
239- {
240- self . apply_transition ( result) ;
241- return Ok ( ( ) ) ;
242- }
220+ let flags = VerificationFlags :: for_message ( & message) ?;
221+ if let VerificationResult :: Issue ( result) = self
222+ . state
223+ . handle_verification_issue ( & mut self . ctx , & message, flags)
224+ . await ?
225+ {
226+ self . apply_transition ( result) ;
227+ return Ok ( ( ) ) ;
243228 }
244229
245230 match message_type {
@@ -262,7 +247,7 @@ where
262247 self . on_logout ( ) . await ?;
263248 }
264249 Logon :: MSG_TYPE => {
265- self . on_logon ( & message ) . await ?;
250+ self . on_logon ( ) . await ?;
266251 }
267252 _ => self . process_app_message ( & message) . await ?,
268253 }
@@ -371,25 +356,13 @@ where
371356 }
372357 }
373358
374- async fn on_logon ( & mut self , message : & Message ) -> Result < ( ) , SessionOperationError > {
359+ async fn on_logon ( & mut self ) -> Result < ( ) , SessionOperationError > {
375360 if let SessionState :: AwaitingLogon ( AwaitingLogonState { writer, .. } ) = & self . state {
376361 let writer = writer. clone ( ) ;
377- match self
378- . state
379- . handle_verification_issue ( & mut self . ctx , message, true , true )
380- . await ?
381- {
382- VerificationResult :: Issue ( result) => {
383- self . apply_transition ( result) ;
384- }
385- VerificationResult :: Passed => {
386- // happy logon flow, the session is now active
387- self . state =
388- SessionState :: new_active ( writer, self . ctx . config . heartbeat_interval ) ;
389- self . ctx . application . on_logon ( ) . await ;
390- self . ctx . store . increment_target_seq_number ( ) . await ?;
391- }
392- }
362+ // happy logon flow, the session is now active
363+ self . state = SessionState :: new_active ( writer, self . ctx . config . heartbeat_interval ) ;
364+ self . ctx . application . on_logon ( ) . await ;
365+ self . ctx . store . increment_target_seq_number ( ) . await ?;
393366 } else {
394367 error ! ( "received unexpected logon message" ) ;
395368 }
0 commit comments