33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55use crate :: auth;
6- use crate :: constants:: { CONTROL_PORT , TUNNEL_SERVICE_USER_AGENT } ;
6+ use crate :: constants:: {
7+ CONTROL_PORT , PROTOCOL_VERSION_TAG , PROTOCOL_VERSION_TAG_PREFIX , TUNNEL_SERVICE_USER_AGENT ,
8+ } ;
79use crate :: state:: { LauncherPaths , PersistedState } ;
810use crate :: util:: errors:: {
911 wrap, AnyError , DevTunnelError , InvalidTunnelName , TunnelCreationFailed , WrappedError ,
@@ -138,6 +140,8 @@ pub struct DevTunnels {
138140pub struct ActiveTunnel {
139141 /// Name of the tunnel
140142 pub name : String ,
143+ /// Underlying dev tunnels ID
144+ pub id : String ,
141145 manager : ActiveTunnelManager ,
142146}
143147
@@ -378,7 +382,7 @@ impl DevTunnels {
378382 preferred_name : Option < String > ,
379383 use_random_name : bool ,
380384 ) -> Result < ActiveTunnel , AnyError > {
381- let ( tunnel, persisted) = match self . launcher_tunnel . load ( ) {
385+ let ( mut tunnel, persisted) = match self . launcher_tunnel . load ( ) {
382386 Some ( mut persisted) => {
383387 if let Some ( name) = preferred_name {
384388 if persisted. name . ne ( & name) {
@@ -404,6 +408,12 @@ impl DevTunnels {
404408 }
405409 } ;
406410
411+ if !tunnel. tags . iter ( ) . any ( |t| t == PROTOCOL_VERSION_TAG ) {
412+ tunnel = self
413+ . update_protocol_version_tag ( tunnel, & HOST_TUNNEL_REQUEST_OPTIONS )
414+ . await ?;
415+ }
416+
407417 let locator = TunnelLocator :: try_from ( & tunnel) . unwrap ( ) ;
408418 let host_token = get_host_token_from_tunnel ( & tunnel) ;
409419
@@ -462,7 +472,11 @@ impl DevTunnels {
462472 let mut tried_recycle = false ;
463473
464474 let new_tunnel = Tunnel {
465- tags : vec ! [ name. to_string( ) , VSCODE_CLI_TUNNEL_TAG . to_string( ) ] ,
475+ tags : vec ! [
476+ name. to_string( ) ,
477+ PROTOCOL_VERSION_TAG . to_string( ) ,
478+ VSCODE_CLI_TUNNEL_TAG . to_string( ) ,
479+ ] ,
466480 ..Default :: default ( )
467481 } ;
468482
@@ -507,6 +521,40 @@ impl DevTunnels {
507521 }
508522 }
509523
524+ /// Ensures the tunnel contains a tag for the current PROTCOL_VERSION, and no
525+ /// other version tags.
526+ async fn update_protocol_version_tag (
527+ & self ,
528+ tunnel : Tunnel ,
529+ options : & TunnelRequestOptions ,
530+ ) -> Result < Tunnel , AnyError > {
531+ debug ! (
532+ self . log,
533+ "Updating tunnel protocol version tag to {}" , PROTOCOL_VERSION_TAG
534+ ) ;
535+ let mut new_tags: Vec < String > = tunnel
536+ . tags
537+ . into_iter ( )
538+ . filter ( |t| !t. starts_with ( PROTOCOL_VERSION_TAG_PREFIX ) )
539+ . collect ( ) ;
540+ new_tags. push ( PROTOCOL_VERSION_TAG . to_string ( ) ) ;
541+
542+ let tunnel_update = Tunnel {
543+ tags : new_tags,
544+ tunnel_id : tunnel. tunnel_id . clone ( ) ,
545+ cluster_id : tunnel. cluster_id . clone ( ) ,
546+ ..Default :: default ( )
547+ } ;
548+
549+ let result = spanf ! (
550+ self . log,
551+ self . log. span( "dev-tunnel.protocol-tag-update" ) ,
552+ self . client. update_tunnel( & tunnel_update, options)
553+ ) ;
554+
555+ result. map_err ( |e| wrap ( e, "tunnel tag update failed" ) . into ( ) )
556+ }
557+
510558 /// Tries to delete an unused tunnel, and then creates a tunnel with the
511559 /// given `new_name`.
512560 async fn try_recycle_tunnel ( & mut self ) -> Result < bool , AnyError > {
@@ -690,6 +738,7 @@ impl DevTunnels {
690738
691739 Ok ( ActiveTunnel {
692740 name : tunnel_details. name . clone ( ) ,
741+ id : tunnel_details. id . clone ( ) ,
693742 manager,
694743 } )
695744 }
0 commit comments