@@ -389,9 +389,9 @@ void ziti_set_fully_authenticated(ziti_context ztx, const char *session_token) {
389389 ziti_ctrl_set_token (ztx_get_controller (ztx ), session_token );
390390 ziti_ctrl_list_controllers (ctrl , ctrl_list_cb , ztx );
391391
392- const char * url ;
392+ const char * er_name ;
393393 ziti_channel_t * ch ;
394- MODEL_MAP_FOREACH (url , ch , & ztx -> channels ) {
394+ MODEL_MAP_FOREACH (er_name , ch , & ztx -> channels ) {
395395 ziti_channel_update_token (ch , session_token );
396396 }
397397 }
@@ -907,11 +907,11 @@ void ziti_dump(ziti_context ztx, int (*printer)(void *arg, const char *fmt, ...)
907907
908908 printer (ctx , "\n==================\nChannels:\n" );
909909 ziti_channel_t * ch ;
910- const char * url ;
911- MODEL_MAP_FOREACH (url , ch , & ztx -> channels ) {
910+ const char * er_id ;
911+ MODEL_MAP_FOREACH (er_id , ch , & ztx -> channels ) {
912912 printer (ctx , "ch[%d] %s\n" , ch -> id , ch -> name );
913913 printer (ctx , "\tconnected[%c] version[%s] address[%s]" ,
914- ziti_channel_is_connected (ch ) ? 'Y' : 'N' , ch -> version , url );
914+ ziti_channel_is_connected (ch ) ? 'Y' : 'N' , ch -> version , ch -> url );
915915 if (ziti_channel_is_connected (ch )) {
916916 printer (ctx , " latency[%" PRIu64 "]\n" , ziti_channel_latency (ch ));
917917 } else {
@@ -1450,26 +1450,28 @@ static void edge_routers_cb(ziti_edge_router_array ers, const ziti_error *err, v
14501450 }
14511451
14521452 model_map curr_routers = {0 };
1453- const char * er_url ;
1453+ const char * er_name ;
14541454 ziti_channel_t * ch ;
1455- MODEL_MAP_FOREACH (er_url , ch , & ztx -> channels ) {
1456- model_map_set (& curr_routers , er_url , (void * ) er_url );
1455+ MODEL_MAP_FOREACH (er_name , ch , & ztx -> channels ) {
1456+ model_map_set (& curr_routers , er_name , (void * ) er_name );
14571457 }
14581458
14591459 ziti_edge_router * * erp = ers ;
14601460 while (* erp ) {
14611461 ziti_edge_router * er = * erp ;
1462- const char * tls = er -> protocols .tls ;
14631462
1464- if (tls ) {
1465- // check if it is already in the list
1466- if (model_map_remove (& curr_routers , tls ) == NULL ) {
1467- ZTX_LOG (TRACE , "connecting to %s(%s)" , er -> name , tls );
1468- ziti_channel_connect (ztx , er -> name , tls );
1463+ // check if it is already in the list
1464+ if (model_map_remove (& curr_routers , er -> name ) == NULL ) {
1465+ if (ziti_channel_connect (ztx , er ) == ZITI_OK ) {
14691466 ers_changed = true;
1467+ ZTX_LOG (TRACE , "connecting to %s(%s)" , er -> name , er -> protocols .tls );
14701468 }
1471- } else {
1472- ZTX_LOG (DEBUG , "edge router %s does not have TLS edge listener" , er -> name );
1469+ } else if (er -> protocols .tls != NULL ) {
1470+ // N.B.: if protocols.tls is NULL,
1471+ // controller may not have refreshed the ER model leave the channel as is
1472+ // otherwise update the url
1473+ ch = model_map_get (& ztx -> channels , er -> name );
1474+ ziti_channel_set_url (ch , er -> protocols .tls );
14731475 }
14741476
14751477 free_ziti_edge_router (er );
@@ -1480,9 +1482,9 @@ static void edge_routers_cb(ziti_edge_router_array ers, const ziti_error *err, v
14801482
14811483 model_map_iter it = model_map_iterator (& curr_routers );
14821484 while (it != NULL ) {
1483- er_url = model_map_it_key (it );
1484- ch = model_map_remove (& ztx -> channels , er_url );
1485- ZTX_LOG (INFO , "removing channel[%s@%s]: no longer available" , ch -> name , er_url );
1485+ er_name = model_map_it_key (it );
1486+ ch = model_map_remove (& ztx -> channels , er_name );
1487+ ZTX_LOG (INFO , "removing channel[%s@%s]: no longer available" , ch -> name , ch -> url );
14861488 ziti_channel_close (ch , ZITI_GATEWAY_UNAVAILABLE );
14871489 it = model_map_it_remove (it );
14881490 ers_changed = true;
@@ -1734,7 +1736,7 @@ void ziti_on_channel_event(ziti_channel_t *ch, ziti_router_status status, ziti_c
17341736 ziti_send_event (ztx , & ev );
17351737
17361738 if (status == EdgeRouterRemoved ) {
1737- model_map_remove (& ztx -> channels , ch -> url );
1739+ model_map_remove (& ztx -> channels , ch -> name );
17381740 if (ztx -> closing ) {
17391741 shutdown_and_free (ztx );
17401742 }
@@ -2034,12 +2036,9 @@ ziti_channel_t * ztx_get_channel(ziti_context ztx, const ziti_edge_router *er) {
20342036 assert (ztx );
20352037 assert (er );
20362038
2037- model_string url = er -> protocols .tls ;
2038- if (url == NULL ) return NULL ;
2039-
2040- ziti_channel_t * ch = (ziti_channel_t * ) model_map_get (& ztx -> channels , url );
2039+ ziti_channel_t * ch = (ziti_channel_t * ) model_map_get (& ztx -> channels , er -> name );
20412040 if (ch == NULL ) {
2042- ziti_channel_connect (ztx , er -> name , url );
2041+ ziti_channel_connect (ztx , er );
20432042 }
20442043 return ch ;
20452044}
0 commit comments