@ -86,18 +86,19 @@ static struct NTP_NODE_PEER* add_peer(struct NTP_NODE_TIME* np, uint64_t node_id
struct NTP_NODE_PEER * p = & np - > peers [ np - > peer_count ] ;
p - > node_id = node_id ;
p - > offset_us = 0 ;
p - > has_offset = 0 ;
np - > peer_count + + ;
return p ;
}
static void check_drift ( uint64_t node_id , int64_t offset_us ) {
int64_t abs_us = offset_us < 0 ? - offset_us : offset_us ;
static void check_drift ( uint64_t node_id , int64_t offset_delta_ us ) {
int64_t abs_us = offset_delta_ us < 0 ? - offset_delta_ us : offset_delta _us ;
if ( abs_us > NTP_NODE_DRIFT_ERROR_US ) {
DEBUG_WARN ( DEBUG_CATEGORY_GENERAL , " NTP_node: clock drift >10s with node %012llx: %lldus " ,
( unsigned long long ) node_id , ( long long ) offset_us ) ;
DEBUG_WARN ( DEBUG_CATEGORY_GENERAL , " NTP_node: clock offset changed by >10s with node %012llx: %lldus " ,
( unsigned long long ) node_id , ( long long ) offset_delta_ us ) ;
} else if ( abs_us > NTP_NODE_DRIFT_WARN_US ) {
DEBUG_WARN ( DEBUG_CATEGORY_GENERAL , " NTP_node: clock drift >2s with node %012llx: %lldus " ,
( unsigned long long ) node_id , ( long long ) offset_us ) ;
DEBUG_WARN ( DEBUG_CATEGORY_GENERAL , " NTP_node: clock offset changed by >2s with node %012llx: %lldus " ,
( unsigned long long ) node_id , ( long long ) offset_delta_ us ) ;
}
}
@ -135,9 +136,14 @@ static void ntp_node_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) {
struct NTP_NODE_TIME * np = & inst - > ntp_node ;
struct NTP_NODE_PEER * peer = find_peer ( np , conn - > peer_node_id ) ;
if ( ! peer ) peer = add_peer ( np , conn - > peer_node_id ) ;
if ( peer ) peer - > offset_us = peer_offset ;
if ( ! peer ) return ;
check_drift ( conn - > peer_node_id , peer_offset ) ;
if ( peer - > has_offset ) {
int64_t offset_delta = peer_offset - peer - > offset_us ;
check_drift ( conn - > peer_node_id , offset_delta ) ;
}
peer - > offset_us = peer_offset ;
peer - > has_offset = 1 ;
int was_unsynced = ! ntp_time_is_synced ( inst ) ;