@@ -24,7 +24,7 @@ impl Service for NoopService {
2424}
2525
2626pub struct ServiceRunner < F > {
27- services : Vec < Box < dyn Service > > ,
27+ service : Option < Box < dyn Service > > ,
2828 outgoing_receiver : tokio:: sync:: mpsc:: UnboundedReceiver < Box < dyn Encode > > ,
2929 outgoing_sender : tokio:: sync:: mpsc:: UnboundedSender < Box < dyn Encode > > ,
3030 connection : SshTransportConnection ,
@@ -119,7 +119,7 @@ impl<
119119 pub fn new ( connection : SshTransportConnection , service_provider : F ) -> Self {
120120 let ( outgoing_sender, outgoing_receiver) = tokio:: sync:: mpsc:: unbounded_channel ( ) ;
121121 Self {
122- services : vec ! [ ] ,
122+ service : None ,
123123 outgoing_receiver,
124124 outgoing_sender,
125125 connection,
@@ -155,11 +155,11 @@ impl<
155155 } ) => {
156156 let sequence_no = packet. number ;
157157 let mut handled = false ;
158- for service in self . services . iter_mut ( ) {
158+ if let Some ( ref mut service) = self . service {
159+ // FIXME: make this a let chain once we move to Rust2024
159160 if service. packet_types ( ) . contains ( & v) {
160161 service. handle_packet ( packet) ;
161162 handled = true ;
162- break ;
163163 }
164164 }
165165 if !handled {
@@ -199,7 +199,20 @@ impl<
199199 service_name,
200200 self . outgoing_sender . clone ( ) ,
201201 ) {
202- self . services . push ( service) ;
202+ if self . service . is_none ( ) {
203+ self . service = Some ( service) ;
204+ } else {
205+ if let Err ( e) = self
206+ . connection
207+ . send_packet ( & DisconnectMsg (
208+ DisconnectReason :: ProtocolError ,
209+ ) )
210+ . await
211+ {
212+ debug ! ( "Error sending packet: {e}" ) ;
213+ }
214+ return ;
215+ }
203216 let packet = ServiceAcceptMsg {
204217 name : service_name. to_vec ( ) . into ( ) ,
205218 } ;
0 commit comments