@@ -30,9 +30,8 @@ use futures::{
30
30
} ;
31
31
use futures:: { Future , FutureExt } ;
32
32
use pin_project:: pin_project;
33
- use swimos_agent_protocol:: encoding:: ad_hoc:: CommandMessageEncoder ;
34
33
use swimos_agent_protocol:: encoding:: store:: { RawMapStoreInitDecoder , RawValueStoreInitDecoder } ;
35
- use swimos_agent_protocol:: { CommandMessage , LaneRequest , MapMessage } ;
34
+ use swimos_agent_protocol:: { LaneRequest , MapMessage } ;
36
35
use swimos_api:: agent:: DownlinkKind ;
37
36
use swimos_api:: agent:: { HttpLaneRequest , LaneConfig , RawHttpLaneResponse } ;
38
37
use swimos_api:: error:: {
@@ -52,7 +51,6 @@ use swimos_utilities::future::RetryStrategy;
52
51
use swimos_utilities:: routing:: RouteUri ;
53
52
use tokio:: io:: AsyncWriteExt ;
54
53
use tokio:: sync:: mpsc;
55
- use tokio_util:: codec:: Encoder ;
56
54
use tracing:: { debug, error, info, trace} ;
57
55
use uuid:: Uuid ;
58
56
@@ -1064,9 +1062,8 @@ where
1064
1062
mut suspended,
1065
1063
link_requests :
1066
1064
LinkRequestCollector {
1067
- next_commander_id,
1068
1065
downlinks : downlink_requests,
1069
- commanders : commander_requests ,
1066
+ commander_ids ,
1070
1067
} ,
1071
1068
mut join_lane_init,
1072
1069
mut ad_hoc_buffer,
@@ -1078,7 +1075,7 @@ where
1078
1075
let mut pending_writes = FuturesUnordered :: new ( ) ;
1079
1076
let mut link_futures = FuturesUnordered :: new ( ) ;
1080
1077
let mut external_item_ids_rev = HashMap :: new ( ) ;
1081
- let cmd_ids = RefCell :: new ( CommanderIds :: new ( next_commander_id ) ) ;
1078
+ let cmd_ids = RefCell :: new ( commander_ids ) ;
1082
1079
1083
1080
for ( name, id) in external_item_ids. iter ( ) {
1084
1081
external_item_ids_rev. insert ( * id, name) ;
@@ -1106,17 +1103,6 @@ where
1106
1103
link_futures. push ( LinkFuture :: Opening ( Some ( request) , fut) ) ;
1107
1104
}
1108
1105
1109
- // Request commanders from the init phase.
1110
- let mut cmd_encoder = CommandMessageEncoder :: default ( ) ;
1111
- for request in commander_requests {
1112
- let CommanderRequest { path, id } = request;
1113
-
1114
- let msg = CommandMessage :: < _ , ( ) > :: register ( path, id) ;
1115
- cmd_encoder
1116
- . encode ( msg, & mut ad_hoc_buffer)
1117
- . expect ( "Encoding should be infallible." ) ;
1118
- }
1119
-
1120
1106
for ( ( name, kind) , ( tx, rx) ) in lane_io {
1121
1107
if kind. map_like ( ) {
1122
1108
let id = external_item_ids[ & name] ;
@@ -1934,24 +1920,16 @@ async fn open_with_retry(
1934
1920
}
1935
1921
}
1936
1922
1937
- #[ derive( Debug ) ]
1938
- struct CommanderRequest {
1939
- path : Address < Text > ,
1940
- id : u16 ,
1941
- }
1942
-
1943
1923
struct LinkRequestCollector < Context > {
1944
- next_commander_id : u16 ,
1945
1924
downlinks : Vec < DownlinkSpawnRequest < Context > > ,
1946
- commanders : Vec < CommanderRequest > ,
1925
+ commander_ids : CommanderIds ,
1947
1926
}
1948
1927
1949
1928
impl < Context > Default for LinkRequestCollector < Context > {
1950
1929
fn default ( ) -> Self {
1951
1930
Self {
1952
- next_commander_id : 0 ,
1953
1931
downlinks : Default :: default ( ) ,
1954
- commanders : Default :: default ( ) ,
1932
+ commander_ids : CommanderIds :: default ( ) ,
1955
1933
}
1956
1934
}
1957
1935
}
@@ -1960,7 +1938,7 @@ impl<Context> std::fmt::Debug for LinkRequestCollector<Context> {
1960
1938
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1961
1939
f. debug_struct ( "LinkRequestCollector" )
1962
1940
. field ( "downlinks" , & self . downlinks )
1963
- . field ( "commanders " , & self . commanders )
1941
+ . field ( "commander_ids " , & self . commander_ids )
1964
1942
. finish ( )
1965
1943
}
1966
1944
}
@@ -1982,14 +1960,7 @@ impl<Context> LinkSpawner<Context> for RefCell<LinkRequestCollector<Context>> {
1982
1960
1983
1961
fn register_commander ( & self , path : Address < Text > ) -> Result < u16 , CommanderRegistrationError > {
1984
1962
let mut guard = self . borrow_mut ( ) ;
1985
- let id = guard. next_commander_id ;
1986
- if let Some ( next) = guard. next_commander_id . checked_add ( 1 ) {
1987
- guard. next_commander_id = next;
1988
- } else {
1989
- return Err ( CommanderRegistrationError :: CommanderIdOverflow ) ;
1990
- }
1991
- guard. commanders . push ( CommanderRequest { path, id } ) ;
1992
- Ok ( id)
1963
+ guard. commander_ids . get_request ( & path)
1993
1964
}
1994
1965
}
1995
1966
@@ -2017,19 +1988,13 @@ where
2017
1988
}
2018
1989
}
2019
1990
1991
+ #[ derive( Default , Debug ) ]
2020
1992
struct CommanderIds {
2021
1993
next_id : u16 ,
2022
1994
assigned : HashMap < Address < Text > , u16 > ,
2023
1995
}
2024
1996
2025
1997
impl CommanderIds {
2026
- fn new ( next_id : u16 ) -> Self {
2027
- CommanderIds {
2028
- next_id,
2029
- assigned : HashMap :: new ( ) ,
2030
- }
2031
- }
2032
-
2033
1998
fn get_request ( & mut self , address : & Address < Text > ) -> Result < u16 , CommanderRegistrationError > {
2034
1999
let id = if let Some ( id) = self . assigned . get ( address) {
2035
2000
* id
0 commit comments