1- use  std:: { future:: Future ,  net :: Ipv4Addr ,   sync:: Arc ,  time:: Duration } ; 
1+ use  std:: { future:: Future ,  sync:: Arc ,  time:: Duration } ; 
22
33use  rand:: Rng ; 
44use  reqwest:: Client ; 
5- use  serde:: Deserialize ; 
65use  tokio:: { 
76	sync:: { Mutex ,  RwLock } , 
87	task:: JoinHandle , 
98} ; 
109use  url:: Url ; 
10+ use  rivet_api:: models:: { ProvisionServer ,  ProvisionDatacentersGetServersResponse } ; 
1111
1212pub  struct  ServiceDiscovery  { 
1313	fetch_endpoint :  Url , 
14- 	last :  RwLock < Vec < ApiServer > > , 
14+ 	last :  RwLock < Vec < ProvisionServer > > , 
1515	handle :  Mutex < Option < JoinHandle < ( ) > > > , 
1616} 
1717
@@ -27,7 +27,7 @@ impl ServiceDiscovery {
2727	/// Starts a background tokio task that periodically fetches the endpoint and calls `cb`. 
2828pub  fn  start < F ,  Fut ,  E > ( self :  & Arc < Self > ,  cb :  F ) 
2929	where 
30- 		F :  Fn ( Vec < ApiServer > )  -> Fut  + Send  + Sync  + ' static , 
30+ 		F :  Fn ( Vec < ProvisionServer > )  -> Fut  + Send  + Sync  + ' static , 
3131		Fut :  Future < Output  = Result < ( ) ,  E > >  + Send  + ' static , 
3232		E :  std:: fmt:: Debug , 
3333	{ 
@@ -64,23 +64,23 @@ impl ServiceDiscovery {
6464	} 
6565
6666	/// Returns the last retrieved value without fetching. 
67- pub  async  fn  get ( & self )  -> Vec < ApiServer >  { 
67+ pub  async  fn  get ( & self )  -> Vec < ProvisionServer >  { 
6868		self . last . read ( ) . await . clone ( ) 
6969	} 
7070
7171	/// Manually fetches the endpoint. 
72- pub  async  fn  fetch ( & self )  -> Result < Vec < ApiServer > ,  reqwest:: Error >  { 
72+ pub  async  fn  fetch ( & self )  -> Result < Vec < ProvisionServer > ,  reqwest:: Error >  { 
7373		let  client = Client :: new ( ) ; 
7474		Ok ( self . fetch_inner ( & client) . await ?. servers ) 
7575	} 
7676
77- 	async  fn  fetch_inner ( & self ,  client :  & Client )  -> Result < ApiResponse ,  reqwest:: Error >  { 
77+ 	async  fn  fetch_inner ( & self ,  client :  & Client )  -> Result < ProvisionDatacentersGetServersResponse ,  reqwest:: Error >  { 
7878		Ok ( client
7979			. get ( self . fetch_endpoint . clone ( ) ) 
8080			. send ( ) 
8181			. await ?
8282			. error_for_status ( ) ?
83- 			. json :: < ApiResponse > ( ) 
83+ 			. json :: < ProvisionDatacentersGetServersResponse > ( ) 
8484			. await ?) 
8585	} 
8686} 
@@ -93,13 +93,3 @@ impl Drop for ServiceDiscovery {
9393		} 
9494	} 
9595} 
96- 
97- #[ derive( Deserialize ) ]  
98- pub  struct  ApiResponse  { 
99- 	pub  servers :  Vec < ApiServer > , 
100- } 
101- 
102- #[ derive( Deserialize ,  Clone ) ]  
103- pub  struct  ApiServer  { 
104- 	pub  lan_ip :  Option < Ipv4Addr > , 
105- } 
0 commit comments