2020
2121use crate :: ConnectedPoint ;
2222use crate :: upgrade:: { InboundUpgrade , OutboundUpgrade , UpgradeError } ;
23- use crate :: upgrade:: { ProtocolName , NegotiatedComplete } ;
23+ use crate :: upgrade:: ProtocolName ;
2424use futures:: { future:: Either , prelude:: * } ;
2525use log:: debug;
2626use multistream_select:: { self , DialerSelectFuture , ListenerSelectFuture } ;
2727use std:: { iter, mem} ;
2828use tokio_io:: { AsyncRead , AsyncWrite } ;
2929
30+ pub use multistream_select:: Version ;
31+
3032/// Applies an upgrade to the inbound and outbound direction of a connection or substream.
31- pub fn apply < C , U > ( conn : C , up : U , cp : ConnectedPoint )
33+ pub fn apply < C , U > ( conn : C , up : U , cp : ConnectedPoint , v : Version )
3234 -> Either < InboundUpgradeApply < C , U > , OutboundUpgradeApply < C , U > >
3335where
3436 C : AsyncRead + AsyncWrite ,
3739 if cp. is_listener ( ) {
3840 Either :: A ( apply_inbound ( conn, up) )
3941 } else {
40- Either :: B ( apply_outbound ( conn, up) )
42+ Either :: B ( apply_outbound ( conn, up, v ) )
4143 }
4244}
4345
@@ -55,13 +57,13 @@ where
5557}
5658
5759/// Tries to perform an upgrade on an outbound connection or substream.
58- pub fn apply_outbound < C , U > ( conn : C , up : U ) -> OutboundUpgradeApply < C , U >
60+ pub fn apply_outbound < C , U > ( conn : C , up : U , v : Version ) -> OutboundUpgradeApply < C , U >
5961where
6062 C : AsyncRead + AsyncWrite ,
6163 U : OutboundUpgrade < C >
6264{
6365 let iter = up. protocol_info ( ) . into_iter ( ) . map ( NameWrap as fn ( _) -> NameWrap < _ > ) ;
64- let future = multistream_select:: dialer_select_proto ( conn, iter) ;
66+ let future = multistream_select:: dialer_select_proto ( conn, iter, v ) ;
6567 OutboundUpgradeApply {
6668 inner : OutboundUpgradeApplyState :: Init { future, upgrade : up }
6769 }
@@ -155,11 +157,6 @@ where
155157 future : DialerSelectFuture < C , NameWrapIter < <U :: InfoIter as IntoIterator >:: IntoIter > > ,
156158 upgrade : U
157159 } ,
158- AwaitNegotiated {
159- io : NegotiatedComplete < C > ,
160- upgrade : U ,
161- protocol : U :: Info
162- } ,
163160 Upgrade {
164161 future : U :: Future
165162 } ,
@@ -185,24 +182,8 @@ where
185182 return Ok ( Async :: NotReady )
186183 }
187184 } ;
188- self . inner = OutboundUpgradeApplyState :: AwaitNegotiated {
189- io : connection. complete ( ) ,
190- protocol : info. 0 ,
191- upgrade
192- } ;
193- }
194- OutboundUpgradeApplyState :: AwaitNegotiated { mut io, protocol, upgrade } => {
195- let io = match io. poll ( ) ? {
196- Async :: NotReady => {
197- self . inner = OutboundUpgradeApplyState :: AwaitNegotiated {
198- io, protocol, upgrade
199- } ;
200- return Ok ( Async :: NotReady )
201- }
202- Async :: Ready ( io) => io
203- } ;
204185 self . inner = OutboundUpgradeApplyState :: Upgrade {
205- future : upgrade. upgrade_outbound ( io , protocol )
186+ future : upgrade. upgrade_outbound ( connection , info . 0 )
206187 } ;
207188 }
208189 OutboundUpgradeApplyState :: Upgrade { mut future } => {
0 commit comments