@@ -16,7 +16,7 @@ use crate::{
1616 handshake:: { v0_handshake_incoming, v0_handshake_outgoing} ,
1717 ProtocolError , ResultForService ,
1818 } ,
19- Data , PublicKey , SecretKey , Splittable , LOG_TARGET ,
19+ Data , PublicKey , SecretKey , Splittable , LOG_TARGET , SEND_DATA_BUFFER ,
2020} ;
2121
2222const HEARTBEAT_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
@@ -43,7 +43,7 @@ async fn check_authorization<SK: SecretKey>(
4343
4444async fn sending < PK : PublicKey , D : Data , S : AsyncWrite + Unpin + Send > (
4545 mut sender : S ,
46- mut data_from_user : mpsc:: UnboundedReceiver < D > ,
46+ mut data_from_user : mpsc:: Receiver < D > ,
4747) -> Result < ( ) , ProtocolError < PK > > {
4848 use Message :: * ;
4949 loop {
@@ -94,7 +94,7 @@ async fn manage_connection<
9494> (
9595 sender : S ,
9696 receiver : R ,
97- data_from_user : mpsc:: UnboundedReceiver < D > ,
97+ data_from_user : mpsc:: Receiver < D > ,
9898 data_for_user : mpsc:: UnboundedSender < D > ,
9999) -> Result < ( ) , ProtocolError < PK > > {
100100 let sending = sending ( sender, data_from_user) ;
@@ -122,7 +122,7 @@ pub async fn outgoing<SK: SecretKey, D: Data, S: Splittable>(
122122 target: LOG_TARGET ,
123123 "Outgoing handshake with {} finished successfully." , public_key
124124 ) ;
125- let ( data_for_network, data_from_user) = mpsc:: unbounded ( ) ;
125+ let ( data_for_network, data_from_user) = mpsc:: channel ( SEND_DATA_BUFFER ) ;
126126 result_for_parent
127127 . unbounded_send ( ( public_key. clone ( ) , Some ( data_for_network) ) )
128128 . map_err ( |_| ProtocolError :: NoParentConnection ) ?;
@@ -160,7 +160,7 @@ pub async fn incoming<SK: SecretKey, D: Data, S: Splittable>(
160160 return Err ( ProtocolError :: NotAuthorized ) ;
161161 }
162162
163- let ( data_for_network, data_from_user) = mpsc:: unbounded ( ) ;
163+ let ( data_for_network, data_from_user) = mpsc:: channel ( SEND_DATA_BUFFER ) ;
164164 result_for_parent
165165 . unbounded_send ( ( public_key. clone ( ) , Some ( data_for_network) ) )
166166 . map_err ( |_| ProtocolError :: NoParentConnection ) ?;
@@ -288,12 +288,12 @@ mod tests {
288288 _ = & mut outgoing_handle => panic!( "outgoing process unexpectedly finished" ) ,
289289 result = result_from_outgoing. next( ) => {
290290 let ( _, maybe_data_for_outgoing) = result. expect( "the channel shouldn't be dropped" ) ;
291- let data_for_outgoing = maybe_data_for_outgoing. expect( "successfully connected" ) ;
291+ let mut data_for_outgoing = maybe_data_for_outgoing. expect( "successfully connected" ) ;
292292 data_for_outgoing
293- . unbounded_send ( vec![ 4 , 3 , 43 ] )
293+ . try_send ( vec![ 4 , 3 , 43 ] )
294294 . expect( "should send" ) ;
295295 data_for_outgoing
296- . unbounded_send ( vec![ 2 , 1 , 3 , 7 ] )
296+ . try_send ( vec![ 2 , 1 , 3 , 7 ] )
297297 . expect( "should send" ) ;
298298 data_for_outgoing
299299 } ,
@@ -303,12 +303,12 @@ mod tests {
303303 _ = & mut outgoing_handle => panic!( "outgoing process unexpectedly finished" ) ,
304304 result = result_from_incoming. next( ) => {
305305 let ( _, maybe_data_for_incoming) = result. expect( "the channel shouldn't be dropped" ) ;
306- let data_for_incoming = maybe_data_for_incoming. expect( "successfully connected" ) ;
306+ let mut data_for_incoming = maybe_data_for_incoming. expect( "successfully connected" ) ;
307307 data_for_incoming
308- . unbounded_send ( vec![ 5 , 4 , 44 ] )
308+ . try_send ( vec![ 5 , 4 , 44 ] )
309309 . expect( "should send" ) ;
310310 data_for_incoming
311- . unbounded_send ( vec![ 3 , 2 , 4 , 8 ] )
311+ . try_send ( vec![ 3 , 2 , 4 , 8 ] )
312312 . expect( "should send" ) ;
313313 data_for_incoming
314314 } ,
@@ -426,9 +426,9 @@ mod tests {
426426 _ = & mut outgoing_handle => panic!( "outgoing process unexpectedly finished" ) ,
427427 result = result_from_outgoing. next( ) => {
428428 let ( _, maybe_data_for_outgoing) = result. expect( "the channel shouldn't be dropped" ) ;
429- let data_for_outgoing = maybe_data_for_outgoing. expect( "successfully connected" ) ;
429+ let mut data_for_outgoing = maybe_data_for_outgoing. expect( "successfully connected" ) ;
430430 data_for_outgoing
431- . unbounded_send ( vec![ 2 , 1 , 3 , 7 ] )
431+ . try_send ( vec![ 2 , 1 , 3 , 7 ] )
432432 . expect( "should send" ) ;
433433 data_for_outgoing
434434 } ,
0 commit comments