@@ -9,7 +9,10 @@ use hickory_server::{
99 authority:: { Catalog , DnssecAuthority } ,
1010 proto:: {
1111 dnssec:: { Algorithm , SigSigner , SigningKey , crypto:: signing_key_from_der, rdata:: DNSKEY } ,
12- rr:: { Name , RData , Record , rdata:: SOA } ,
12+ rr:: {
13+ Name , RData , Record , RecordSet , RecordType , RrKey ,
14+ rdata:: { SOA , SRV } ,
15+ } ,
1316 } ,
1417 server:: { Request , RequestHandler , ResponseHandler , ResponseInfo } ,
1518 store:: in_memory:: InMemoryAuthority ,
@@ -130,15 +133,43 @@ impl GeoHandler {
130133 Ok ( Arc :: new ( authority) )
131134 }
132135
136+ /// Loads the servers list from the configured path and updates the SRV records accordingly.
133137 pub async fn load_servers_list ( & self ) -> eyre:: Result < ( ) > {
134138 let data = tokio:: fs:: read ( self . config . servers_list_path . as_path ( ) )
135139 . await
136140 . wrap_err ( "Could not read servers list file" ) ?;
137- let _servers : Vec < KeyExchangeServer > =
141+ let servers : Vec < KeyExchangeServer > =
138142 serde_json:: from_slice ( & data) . wrap_err ( "Could not parse servers list file" ) ?;
139143
144+ let current_ts_unix = std:: time:: SystemTime :: now ( )
145+ . duration_since ( std:: time:: UNIX_EPOCH )
146+ . wrap_err ( "Failed to get current unix timestamp" ) ?
147+ . as_secs ( ) ;
148+ let serial = current_ts_unix as u32 ; // intentional truncating behavior for serial number
149+
150+ // Create SRV record set
151+ let mut rrset = RecordSet :: new ( self . config . zone_name . clone ( ) , RecordType :: SRV , serial) ;
152+ for server in servers {
153+ let record = SRV :: new (
154+ 0 ,
155+ 0 ,
156+ server. port ,
157+ server. domain . parse ( ) . wrap_err ( "Invalid domain name" ) ?,
158+ ) ;
159+ rrset. add_rdata ( RData :: SRV ( record) ) ;
160+ }
161+
162+ // Key under which the SRV record set is stored
163+ let rrkey = RrKey :: new ( self . config . zone_name . clone ( ) . into ( ) , RecordType :: SRV ) ;
164+
165+ // Update SRV record set
166+ self . authority
167+ . records_mut ( )
168+ . await
169+ . insert ( rrkey, Arc :: new ( rrset) ) ;
170+
140171 // Re-sign zone
141- self . sign_zone ( ) . await ?;
172+ self . sign_zone ( ) . await . wrap_err ( "Failed to sign zone" ) ?;
142173 Ok ( ( ) )
143174 }
144175
@@ -151,6 +182,7 @@ impl GeoHandler {
151182 }
152183}
153184
185+ /// Helper wrapper to allow us to implement RequestHandler for `Arc<GeoHandler>`
154186pub struct GeoHandlerArc ( pub Arc < GeoHandler > ) ;
155187
156188#[ async_trait:: async_trait]
0 commit comments