@@ -400,6 +400,12 @@ impl<'de> Deserialize<'de> for PpsSourceConfig {
400400 }
401401}
402402
403+ #[ derive( Deserialize , Debug , PartialEq , Clone ) ]
404+ #[ serde( rename_all = "kebab-case" , deny_unknown_fields) ]
405+ pub struct CsptpSourceConfig {
406+ pub address : CsptpAddress ,
407+ }
408+
403409#[ derive( Debug , Deserialize , PartialEq , Clone ) ]
404410#[ serde( tag = "mode" ) ]
405411pub enum NtpSourceConfig {
@@ -417,6 +423,8 @@ pub enum NtpSourceConfig {
417423 #[ cfg( feature = "pps" ) ]
418424 #[ serde( rename = "pps" ) ]
419425 Pps ( PpsSourceConfig ) ,
426+ #[ serde( rename = "csptp" ) ]
427+ Csptp ( CsptpSourceConfig ) ,
420428}
421429
422430/// A normalized address has a host and a port part. However, the host may be
@@ -463,6 +471,9 @@ pub struct NtpAddress(pub NormalizedAddress);
463471#[ derive( Debug , Clone , PartialEq , Eq ) ]
464472pub struct NtsKeAddress ( pub NormalizedAddress ) ;
465473
474+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
475+ pub struct CsptpAddress ( pub NormalizedAddress ) ;
476+
466477impl < ' de > Deserialize < ' de > for NtpAddress {
467478 fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
468479 where
@@ -487,6 +498,18 @@ impl<'de> Deserialize<'de> for NtsKeAddress {
487498 }
488499}
489500
501+ impl < ' de > Deserialize < ' de > for CsptpAddress {
502+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
503+ where
504+ D : Deserializer < ' de > ,
505+ {
506+ let s = String :: deserialize ( deserializer) ?;
507+ Ok ( NormalizedAddress :: from_string_csptp ( s)
508+ . map_err ( serde:: de:: Error :: custom) ?
509+ . into ( ) )
510+ }
511+ }
512+
490513impl From < NormalizedAddress > for NtpAddress {
491514 fn from ( addr : NormalizedAddress ) -> Self {
492515 Self ( addr)
@@ -499,6 +522,12 @@ impl From<NormalizedAddress> for NtsKeAddress {
499522 }
500523}
501524
525+ impl From < NormalizedAddress > for CsptpAddress {
526+ fn from ( addr : NormalizedAddress ) -> Self {
527+ Self ( addr)
528+ }
529+ }
530+
502531impl Deref for NtsKeAddress {
503532 type Target = NormalizedAddress ;
504533
@@ -515,9 +544,18 @@ impl Deref for NtpAddress {
515544 }
516545}
517546
547+ impl Deref for CsptpAddress {
548+ type Target = NormalizedAddress ;
549+
550+ fn deref ( & self ) -> & Self :: Target {
551+ & self . 0
552+ }
553+ }
554+
518555impl NormalizedAddress {
519556 const NTP_DEFAULT_PORT : u16 = 123 ;
520557 const NTS_KE_DEFAULT_PORT : u16 = 4460 ;
558+ const CSPTP_DEFAULT_PORT : u16 = 319 ;
521559
522560 /// Specifically, this adds the `:123` port if no port is specified
523561 pub ( crate ) fn from_string_ntp ( address : String ) -> std:: io:: Result < Self > {
@@ -545,6 +583,19 @@ impl NormalizedAddress {
545583 } )
546584 }
547585
586+ /// Specifically, this adds the `:319` port if no port is specified
587+ pub ( crate ) fn from_string_csptp ( address : String ) -> std:: io:: Result < Self > {
588+ let ( server_name, port) = Self :: from_string_help ( address, Self :: CSPTP_DEFAULT_PORT ) ?;
589+
590+ Ok ( Self {
591+ server_name,
592+ port,
593+
594+ #[ cfg( test) ]
595+ hardcoded_dns_resolve : HardcodedDnsResolve :: default ( ) ,
596+ } )
597+ }
598+
548599 fn from_string_help ( address : String , default_port : u16 ) -> std:: io:: Result < ( String , u16 ) > {
549600 if address. split ( ':' ) . count ( ) > 2 {
550601 // IPv6, try to parse it as such
@@ -673,6 +724,7 @@ mod tests {
673724 NtpSourceConfig :: Sock ( _c) => "" . to_string ( ) ,
674725 #[ cfg( feature = "pps" ) ]
675726 NtpSourceConfig :: Pps ( _c) => "" . to_string ( ) ,
727+ NtpSourceConfig :: Csptp ( c) => c. address . to_string ( ) ,
676728 }
677729 }
678730
0 commit comments