@@ -206,15 +206,22 @@ impl MatchingService {
206206 // Add the request to the queue
207207 log:: info!( "Adding send request {} to queue" , request_id) ;
208208 match self . queue . add_request ( queued_request) . await {
209- Ok ( Some ( match_result ) ) => {
209+ Ok ( Some ( ( send_result , recv_result ) ) ) => {
210210 // Immediate match found
211211 log:: info!( "Immediate match found for send request {}" , request_id) ;
212212
213+ // For send requests, we want the send side result
214+ let our_match_result = if request_id == send_result. matched_with {
215+ recv_result // We're the receive side
216+ } else {
217+ send_result // We're the send side
218+ } ;
219+
213220 return Ok ( MatchResponse {
214221 status : MatchStatus :: Matched ,
215222 sender_id : Some ( request_id) ,
216- receiver_id : Some ( match_result . matched_with ) ,
217- timestamp : match_result . timestamp ,
223+ receiver_id : Some ( our_match_result . matched_with ) ,
224+ timestamp : our_match_result . timestamp ,
218225 payload : Some ( request. payload ) ,
219226 message : None ,
220227 } ) ;
@@ -226,15 +233,22 @@ impl MatchingService {
226233 // Wait for a match with timeout
227234 let ttl = std:: time:: Duration :: from_millis ( request. ttl as u64 ) ;
228235 match tokio:: time:: timeout ( ttl, rx) . await {
229- Ok ( Ok ( match_result ) ) => {
236+ Ok ( Ok ( ( send_result , recv_result ) ) ) => {
230237 // We got a match result from the oneshot channel
231238 log:: info!( "Match found for send request {}" , request_id) ;
232239
240+ // For send requests, we want the send side result
241+ let our_match_result = if request_id == send_result. matched_with {
242+ recv_result // We're the receive side
243+ } else {
244+ send_result // We're the send side
245+ } ;
246+
233247 return Ok ( MatchResponse {
234248 status : MatchStatus :: Matched ,
235249 sender_id : Some ( request_id) ,
236- receiver_id : Some ( match_result . matched_with ) ,
237- timestamp : match_result . timestamp ,
250+ receiver_id : Some ( our_match_result . matched_with ) ,
251+ timestamp : our_match_result . timestamp ,
238252 payload : Some ( request. payload ) ,
239253 message : None ,
240254 } ) ;
@@ -292,16 +306,23 @@ impl MatchingService {
292306 // Add the request to the unified queue
293307 log:: info!( "Adding receive request {} to queue" , request_id) ;
294308 match self . queue . add_request ( queued_request) . await {
295- Ok ( Some ( match_result ) ) => {
309+ Ok ( Some ( ( send_result , recv_result ) ) ) => {
296310 // Immediate match found
297311 log:: info!( "Immediate match found for receive request {}" , request_id) ;
298312
313+ // For receive requests, we want the receive side result
314+ let our_match_result = if request_id == send_result. matched_with {
315+ recv_result // We're the receive side
316+ } else {
317+ send_result // We're the send side
318+ } ;
319+
299320 return Ok ( MatchResponse {
300321 status : MatchStatus :: Matched ,
301- sender_id : Some ( match_result . matched_with ) ,
322+ sender_id : Some ( our_match_result . matched_with ) ,
302323 receiver_id : Some ( request_id) ,
303- timestamp : match_result . timestamp ,
304- payload : match_result . payload ,
324+ timestamp : our_match_result . timestamp ,
325+ payload : our_match_result . payload ,
305326 message : None ,
306327 } ) ;
307328 } ,
@@ -400,12 +421,21 @@ impl MatchingService {
400421 // Immediate match found
401422 log:: info!( "Immediate match found for bump request {}" , request_id) ;
402423
424+ // Choose the correct match result based on which side we are
425+ let our_match_result = if request_id == send_match_result. matched_with {
426+ // We are the receive side
427+ recv_match_result
428+ } else {
429+ // We are the send side
430+ send_match_result
431+ } ;
432+
403433 return Ok ( MatchResponse {
404434 status : MatchStatus :: Matched ,
405435 sender_id : Some ( request_id) ,
406- receiver_id : Some ( match_result . matched_with ) ,
407- timestamp : match_result . timestamp ,
408- payload : match_result . payload ,
436+ receiver_id : Some ( our_match_result . matched_with ) ,
437+ timestamp : our_match_result . timestamp ,
438+ payload : our_match_result . payload ,
409439 message : None ,
410440 } ) ;
411441 } ,
@@ -420,12 +450,21 @@ impl MatchingService {
420450 // We got a match result from the oneshot channel
421451 log:: info!( "Match found for bump request {}" , request_id) ;
422452
453+ // Choose the correct match result based on which side we are
454+ let our_match_result = if request_id == send_match_result. matched_with {
455+ // We are the receive side
456+ recv_match_result
457+ } else {
458+ // We are the send side
459+ send_match_result
460+ } ;
461+
423462 return Ok ( MatchResponse {
424463 status : MatchStatus :: Matched ,
425464 sender_id : Some ( request_id) ,
426- receiver_id : Some ( match_result . matched_with ) ,
427- timestamp : match_result . timestamp ,
428- payload : match_result . payload ,
465+ receiver_id : Some ( our_match_result . matched_with ) ,
466+ timestamp : our_match_result . timestamp ,
467+ payload : our_match_result . payload ,
429468 message : None ,
430469 } ) ;
431470 } ,
0 commit comments