@@ -113,7 +113,7 @@ impl MatchingService {
113113 payload : Option < String > ,
114114 expires_at : OffsetDateTime ,
115115 request_type : RequestType
116- ) -> ( QueuedRequest , std:: pin:: Pin < Box < dyn std:: future:: Future < Output = Result < MatchResult , Box < dyn std:: error:: Error > > > + Send > > ) {
116+ ) -> ( QueuedRequest , std:: pin:: Pin < Box < dyn std:: future:: Future < Output = Result < ( MatchResult , MatchResult ) , Box < dyn std:: error:: Error > > > + Send > > ) {
117117 match request_type {
118118 RequestType :: Bump => {
119119 // For Bump requests, use broadcast channel so both sides can receive
@@ -222,7 +222,7 @@ impl MatchingService {
222222 sender_id : Some ( request_id) ,
223223 receiver_id : Some ( our_match_result. matched_with ) ,
224224 timestamp : our_match_result. timestamp ,
225- payload : Some ( request . payload ) ,
225+ payload : None , // Send requests don't receive payload
226226 message : None ,
227227 } ) ;
228228 } ,
@@ -249,7 +249,7 @@ impl MatchingService {
249249 sender_id : Some ( request_id) ,
250250 receiver_id : Some ( our_match_result. matched_with ) ,
251251 timestamp : our_match_result. timestamp ,
252- payload : Some ( request . payload ) ,
252+ payload : None , // Send requests don't receive payload
253253 message : None ,
254254 } ) ;
255255 } ,
@@ -337,12 +337,22 @@ impl MatchingService {
337337 // We got a match result from the oneshot channel
338338 log:: info!( "Match found for receive request {}" , request_id) ;
339339
340+ // Destructure the match result tuple
341+ let ( send_result, recv_result) = match_result;
342+
343+ // For receive requests, we want the receive side result
344+ let our_match_result = if request_id == send_result. matched_with {
345+ recv_result // We're the receive side
346+ } else {
347+ send_result // We're the send side
348+ } ;
349+
340350 return Ok ( MatchResponse {
341351 status : MatchStatus :: Matched ,
342- sender_id : Some ( match_result . matched_with ) ,
352+ sender_id : Some ( our_match_result . matched_with ) ,
343353 receiver_id : Some ( request_id) ,
344- timestamp : match_result . timestamp ,
345- payload : match_result . payload ,
354+ timestamp : our_match_result . timestamp ,
355+ payload : our_match_result . payload ,
346356 message : None ,
347357 } ) ;
348358 } ,
@@ -417,17 +427,17 @@ impl MatchingService {
417427 // Add the request to the queue
418428 log:: info!( "Adding bump request {} to queue" , request_id) ;
419429 match self . queue . add_request ( queued_request) . await {
420- Ok ( Some ( match_result ) ) => {
430+ Ok ( Some ( ( send_result , recv_result ) ) ) => {
421431 // Immediate match found
422432 log:: info!( "Immediate match found for bump request {}" , request_id) ;
423433
424434 // Choose the correct match result based on which side we are
425- let our_match_result = if request_id == send_match_result . matched_with {
435+ let our_match_result = if request_id == send_result . matched_with {
426436 // We are the receive side
427- recv_match_result
437+ recv_result
428438 } else {
429439 // We are the send side
430- send_match_result
440+ send_result
431441 } ;
432442
433443 return Ok ( MatchResponse {
@@ -446,17 +456,17 @@ impl MatchingService {
446456 // Wait for a match with timeout
447457 let ttl = std:: time:: Duration :: from_millis ( request. ttl as u64 ) ;
448458 match tokio:: time:: timeout ( ttl, rx) . await {
449- Ok ( Ok ( match_result ) ) => {
459+ Ok ( Ok ( ( send_result , recv_result ) ) ) => {
450460 // We got a match result from the oneshot channel
451461 log:: info!( "Match found for bump request {}" , request_id) ;
452462
453463 // Choose the correct match result based on which side we are
454- let our_match_result = if request_id == send_match_result . matched_with {
464+ let our_match_result = if request_id == send_result . matched_with {
455465 // We are the receive side
456- recv_match_result
466+ recv_result
457467 } else {
458468 // We are the send side
459- send_match_result
469+ send_result
460470 } ;
461471
462472 return Ok ( MatchResponse {
0 commit comments