1
- use std:: { future:: Future , net :: Ipv4Addr , sync:: Arc , time:: Duration } ;
1
+ use std:: { future:: Future , sync:: Arc , time:: Duration } ;
2
2
3
3
use rand:: Rng ;
4
4
use reqwest:: Client ;
5
- use serde:: Deserialize ;
6
5
use tokio:: {
7
6
sync:: { Mutex , RwLock } ,
8
7
task:: JoinHandle ,
9
8
} ;
10
9
use url:: Url ;
10
+ use rivet_api:: models:: { ProvisionServer , ProvisionDatacentersGetServersResponse } ;
11
11
12
12
pub struct ServiceDiscovery {
13
13
fetch_endpoint : Url ,
14
- last : RwLock < Vec < ApiServer > > ,
14
+ last : RwLock < Vec < ProvisionServer > > ,
15
15
handle : Mutex < Option < JoinHandle < ( ) > > > ,
16
16
}
17
17
@@ -27,7 +27,7 @@ impl ServiceDiscovery {
27
27
/// Starts a background tokio task that periodically fetches the endpoint and calls `cb`.
28
28
pub fn start < F , Fut , E > ( self : & Arc < Self > , cb : F )
29
29
where
30
- F : Fn ( Vec < ApiServer > ) -> Fut + Send + Sync + ' static ,
30
+ F : Fn ( Vec < ProvisionServer > ) -> Fut + Send + Sync + ' static ,
31
31
Fut : Future < Output = Result < ( ) , E > > + Send + ' static ,
32
32
E : std:: fmt:: Debug ,
33
33
{
@@ -64,23 +64,23 @@ impl ServiceDiscovery {
64
64
}
65
65
66
66
/// Returns the last retrieved value without fetching.
67
- pub async fn get ( & self ) -> Vec < ApiServer > {
67
+ pub async fn get ( & self ) -> Vec < ProvisionServer > {
68
68
self . last . read ( ) . await . clone ( )
69
69
}
70
70
71
71
/// 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 > {
73
73
let client = Client :: new ( ) ;
74
74
Ok ( self . fetch_inner ( & client) . await ?. servers )
75
75
}
76
76
77
- async fn fetch_inner ( & self , client : & Client ) -> Result < ApiResponse , reqwest:: Error > {
77
+ async fn fetch_inner ( & self , client : & Client ) -> Result < ProvisionDatacentersGetServersResponse , reqwest:: Error > {
78
78
Ok ( client
79
79
. get ( self . fetch_endpoint . clone ( ) )
80
80
. send ( )
81
81
. await ?
82
82
. error_for_status ( ) ?
83
- . json :: < ApiResponse > ( )
83
+ . json :: < ProvisionDatacentersGetServersResponse > ( )
84
84
. await ?)
85
85
}
86
86
}
@@ -93,13 +93,3 @@ impl Drop for ServiceDiscovery {
93
93
}
94
94
}
95
95
}
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