@@ -20,7 +20,7 @@ use tracing::{debug, error, trace};
2020use super :: { Command , ReqError , ReqOptions } ;
2121use crate :: { ConnectionState , ExponentialBackoff , req:: SocketState } ;
2222
23- use msg_transport:: { Address , Transport } ;
23+ use msg_transport:: { Address , MeteredIo , PeerAddress , Transport } ;
2424use msg_wire:: {
2525 auth,
2626 compression:: { Compressor , try_decompress_payload} ,
@@ -31,15 +31,16 @@ use msg_wire::{
3131type ConnectionTask < Io , Err > = Pin < Box < dyn Future < Output = Result < Io , Err > > + Send > > ;
3232
3333/// A connection controller that manages the connection to a server with an exponential backoff.
34- type ConnectionCtl < Io , Addr > = ConnectionState < Framed < Io , reqrep:: Codec > , ExponentialBackoff , Addr > ;
34+ type ConnectionCtl < Io , S , A > =
35+ ConnectionState < Framed < MeteredIo < Io , S , A > , reqrep:: Codec > , ExponentialBackoff , A > ;
3536
3637/// The request socket driver. Endless future that drives
37- /// the the socket forward.
38+ /// the socket forward.
3839pub ( crate ) struct ReqDriver < T : Transport < A > , A : Address > {
3940 /// Options shared with the socket.
4041 pub ( crate ) options : Arc < ReqOptions > ,
4142 /// State shared with the socket.
42- pub ( crate ) socket_state : Arc < SocketState > ,
43+ pub ( crate ) socket_state : SocketState < T :: Stats > ,
4344 /// ID counter for outgoing requests.
4445 pub ( crate ) id_counter : u32 ,
4546 /// Commands from the socket.
@@ -52,7 +53,7 @@ pub(crate) struct ReqDriver<T: Transport<A>, A: Address> {
5253 pub ( crate ) conn_task : Option < ConnectionTask < T :: Io , T :: Error > > ,
5354 /// The transport controller, wrapped in a [`ConnectionState`] for backoff.
5455 /// The [`Framed`] object can send and receive messages from the socket.
55- pub ( crate ) conn_state : ConnectionCtl < T :: Io , A > ,
56+ pub ( crate ) conn_state : ConnectionCtl < T :: Io , T :: Stats , A > ,
5657 /// The outgoing message queue.
5758 pub ( crate ) egress_queue : VecDeque < reqrep:: Message > ,
5859 /// The currently pending requests, if any. Uses [`FxHashMap`] for performance.
@@ -276,7 +277,12 @@ where
276277 this. conn_task = None ;
277278
278279 if let Ok ( io) = result {
279- let mut framed = Framed :: new ( io, reqrep:: Codec :: new ( ) ) ;
280+ tracing:: debug!( target = ?io. peer_addr( ) , "new connection" ) ;
281+
282+ let metered =
283+ MeteredIo :: new ( io, Arc :: clone ( & this. socket_state . transport_stats ) ) ;
284+
285+ let mut framed = Framed :: new ( metered, reqrep:: Codec :: new ( ) ) ;
280286 framed. set_backpressure_boundary ( this. options . backpressure_boundary ) ;
281287 this. conn_state = ConnectionState :: Active { channel : framed } ;
282288 }
0 commit comments