nl::Weave::Profiles::Time::TimeSyncNode

Summary

Inheritance

Inherits from: nl::Weave::Profiles::Time::_TimeSyncNodeBase

Constructors and Destructors

TimeSyncNode(void)

mBootTimeForNextAutoDiscovery_usec
timesync_t
mIsAutoSyncEnabled
bool
states used for auto sync feature.
mIsUrgentDiscoveryPending
bool
mNominalDiscoveryPeriod_msec
int32_t
mShortestDiscoveryPeriod_msec
int32_t
mSyncPeriod_msec
int32_t

mActiveContact
communication context.
mExchangeContext
mUnadjTimestampLastSent_usec
timesync_t

EnterState_Discover(void)
void
these state transition functions are internal and cannot return error code as the previous state would have no way to handle them.
EnterState_ServiceSync_1(void)
void
EnterState_ServiceSync_2(void)
void
EnterState_Sync_1(void)
void
EnterState_Sync_2(void)
void

Public types

ClientState enum
current state of this Time Sync Client
CommState enum
status of communication to a certain contact.
ContributorFilter)(void *const aApp, Contact aContact[], const int aSize) typedef
void(*
callback happens right before we calculate the time correction from responses.
OnSyncRequestReceivedHandler)(void *const aApp, const WeaveMessageInfo *aMsgInfo, const uint8_t aLikelyhood, const bool aIsTimeCoordinator) typedef
bool(*
callback to indicate we just received a time sync request.
ResponseStatus enum
status of stored response to a certain contact.
ServerState{
  kServerState_UnreliableAfterBoot,
  kServerState_Idle
}
enum
current state of this Time Sync Server
SyncFailedHandler)(void *const aApp, const WEAVE_ERROR aErrorCode) typedef
void(*
callback happens when sync is considered failed, including auto sync.
SyncSucceededHandler)(void *const aApp, const timesync_t aOffsetUsec, const bool aIsReliable, const bool aIsServer, const uint8_t aNumContributor) typedef
bool(*
callback happens after sync is considered successful, including auto sync, but before the result is applied.
TimeChangeNotificationHandler)(void *const aApp, const uint64_t aNodeId, const IPAddress &aNodeAddr) typedef
void(*
callback to indicate we just received a Time Change Notification.

Public attributes

FilterTimeCorrectionContributor
OnSyncFailed
OnSyncRequestReceived
if not set, the default implementation always returns true
OnSyncSucceeded
if not set, the default behavior is taking all results, except for very small server corrections
OnTimeChangeNotificationReceived
mEncryptionType
uint8_t
encryption method for local communication
mKeyId
uint16_t
key id used for local communication

Protected attributes

mApp
void *
pointer to higher layer data
mClientState
mConnectionToService
TCP connection used to talk to the service.
mContacts[WEAVE_CONFIG_TIME_CLIENT_MAX_NUM_CONTACTS]
Contact information learned throughout discovery.
mIsAlwaysFresh
bool
mIsInCallback
bool
true if we're in a callback to higher layer
mLastLikelihoodSent
int8_t
mNumContributorInLastLocalSync
uint8_t
mRole
TimeSyncRole
Actual role of this node.
mServerState
mServiceContact
mTimestampLastCorrectionFromServerOrNtp_usec
timesync_t
note it has to be boot time as we need compensation for sleep time
mTimestampLastLocalSync_usec
timesync_t
note it has to be boot time as we need compensation for sleep time

Public functions

Abort(void)
force the engine to go back to idle state, aborting anything it is doing.
DisableAutoSync(void)
void
disable auto sync.
EnableAutoSync(const int32_t aSyncPeriod_msec, const int32_t aNominalDiscoveryPeriod_msec, const int32_t aShortestDiscoveryPeriod_msec)
enable auto sync.
GetCapacityOfContactList(void) const
int
simple getter for the maximum number of contacts this engine is configured to store
GetClientState(void) const
simple getter for client state
GetNextLikelihood(void) const
int8_t
extract the likelihood for persistent.
GetServerState(void) const
simple getter for the server state
InitClient(void *const aApp, WeaveExchangeManager *aExchangeMgr, const uint8_t aEncryptionType, const uint16_t aKeyId, const int8_t aInitialLikelyhood)
initialize this client.
InitCoordinator(nl::Weave::WeaveExchangeManager *aExchangeMgr, const uint8_t aEncryptionType, const uint16_t aKeyId, const int32_t aSyncPeriod_msec, const int32_t aNominalDiscoveryPeriod_msec, const int32_t aShortestDiscoveryPeriod_msec)
initialize this coordinator.
InitServer(void *const aApp, WeaveExchangeManager *const aExchangeMgr, const bool aIsAlwaysFresh)
initialize for the Server role must be called as the first function after object construction if the intention is to be a Time Sync Server.
MulticastTimeChangeNotification(const uint8_t aEncryptionType, const uint16_t aKeyId) const
void
Called by higher layer to multicast time change notification.
RegisterCorrectionFromServerOrNtp(void)
void
Called by higher layer to indicate that we just finished a round of time sync with either any Server or through some reliable means like NTP.
RegisterLocalSyncOperation(const uint8_t aNumContributor)
void
Called by higher layer to indicate that we just finished a round of time sync with other local Coordinators.
Shutdown(void)
stop the service, no matter which role it is playing.
Sync(const bool aForceDiscoverAgain)
sync using existing contacts.
SyncWithNodes(const int16_t aNumNode, const ServingNode aNodes[])
sync using the given list of contacts.
SyncWithService(WeaveConnection *const aConnection)
sync using the given TCP connection and associated encryption and key id.

Protected functions

AbortOnError(const WEAVE_ERROR aCode)
void
internal abort if aCode is not WEAVE_NO_ERROR
AutoSyncNow(void)
void
internal function to kick off an auto sync session
CallbackForSyncCompletion(const bool aIsSuccessful, bool aShouldUpdate, const bool aIsCorrectionReliable, const bool aIsFromServer, const uint8_t aNumContributor, const timesync_t aSystemTimestamp_usec, const timesync_t aDiffTime_usec)
induce callback to the application layer.
ClearState(void)
void
DestroyCommContext(void)
bool
close the Weave ExchangeContext
EndLocalSyncAndTryCalculateTimeFix(void)
void
EndServiceSyncAndTryCalculateTimeFix(void)
void
FindReplaceableContact(const uint64_t aNodeId, const IPAddress & aNodeAddr, bool aIsTimeChangeNotification)
return a slot to store contact information
GetClientStateName(void) const
const char *const
GetNextIdleContact(void)
get the next valid and idle contact to talk to
GetNumNotYetCompletedContacts(void)
int16_t
get the number of contacts that are valid, but we haven't talk to them yet.
GetNumReliableResponses(void)
int16_t
get the number of 'reliable' responses collected so far.
InitState(const TimeSyncRole aRole, void *const aApp, WeaveExchangeManager *const aExchangeMgr)
InvalidateAllContacts(void)
void
invalidate all local contacts
InvalidateServiceContact(void)
void
invalidate contact to the service
RegisterCommError(Contact *const aContact)
void
register communication error on a certain contact, and shorten auto discovery period if needed aContact can be NULL to indicate we have no one to talk to, and hence just shorten the auto discovery period
SendSyncRequest(bool *const rIsMessageSent, Contact *const aContact)
send unicast sync request to a contact.
SetAllCompletedContactsToIdle(void)
int16_t
reset all completed contacts to idle state again, but don't touch the response.
SetAllValidContactsToIdleAndInvalidateResponse(void)
int16_t
set all valid local contacts to idle state and clear the response.
SetClientState(const ClientState state)
void
SetupUnicastCommContext(Contact *const aContact)
create new Weave Exchange for unicast communication
StoreNotifyingContact(const uint64_t aNodeId, const IPAddress & aNodeAddr)
void
store the contact information of a node who just sent us a time change notification
UpdateMulticastSyncResponse(const uint64_t aNodeId, const IPAddress & aNodeAddr, const TimeSyncResponse & aResponse)
void
process a response coming back from a multicast request
UpdateUnicastSyncResponse(const TimeSyncResponse & aResponse)
void
process a response coming back from a unicast request
_InitClient(const uint8_t aEncryptionType, const uint16_t aKeyId, const int8_t aInitialLikelyhood)
initialize for the Client role.
_InitServer(const bool aIsAlwaysFresh)
initialize for the Server role.
_ShutdownClient(void)
stop the client not available in callbacks.
_ShutdownCoordinator(void)
stop the coordinator not available in callbacks.
_ShutdownServer(void)
stop the server not available in callbacks.

Protected static functions

HandleAutoDiscoveryTimeout(System::Layer *aSystemLayer, void *aAppState, System::Error aError)
void
HandleAutoSyncTimeout(System::Layer *aSystemLayer, void *aAppState, System::Error aError)
void
HandleMulticastResponseTimeout(System::Layer *aSystemLayer, void *aAppState, System::Error aError)
void
HandleMulticastSyncResponse(ExchangeContext *ec, const IPPacketInfo *pktInfo, const WeaveMessageInfo *msgInfo, uint32_t profileId, uint8_t msgType, PacketBuffer *payload)
void
HandleSyncRequest(ExchangeContext *ec, const IPPacketInfo *pktInfo, const WeaveMessageInfo *msgInfo, uint32_t profileId, uint8_t msgType, PacketBuffer *payload)
void
callback from Weave Exchange when a time sync request arrives
HandleTimeChangeNotification(ExchangeContext *ec, const IPPacketInfo *pktInfo, const WeaveMessageInfo *msgInfo, uint32_t profileId, uint8_t msgType, PacketBuffer *payload)
void
HandleUnicastResponseTimeout(ExchangeContext *const ec)
void
HandleUnicastSyncResponse(ExchangeContext *ec, const IPPacketInfo *pktInfo, const WeaveMessageInfo *msgInfo, uint32_t profileId, uint8_t msgType, PacketBuffer *payload)
void
HandleUnreliableAfterBootTimer(System::Layer *aSystemLayer, void *aAppState, System::Error aError)
void
callback from Weave Timer when we passed the unreliable after boot barrier
_OnSyncSucceeded(void *const aApp, const nl::Weave::Profiles::Time::timesync_t aOffsetUsec, const bool aIsReliable, const bool aIsServer, const uint8_t aNumContributor)
bool

mBootTimeForNextAutoDiscovery_usec

timesync_t mBootTimeForNextAutoDiscovery_usec

mIsAutoSyncEnabled

bool mIsAutoSyncEnabled

states used for auto sync feature.

mIsUrgentDiscoveryPending

bool mIsUrgentDiscoveryPending

mNominalDiscoveryPeriod_msec

int32_t mNominalDiscoveryPeriod_msec

mShortestDiscoveryPeriod_msec

int32_t mShortestDiscoveryPeriod_msec

mSyncPeriod_msec

int32_t mSyncPeriod_msec

mActiveContact

Contact * mActiveContact

communication context.

mExchangeContext

ExchangeContext * mExchangeContext

mUnadjTimestampLastSent_usec

timesync_t mUnadjTimestampLastSent_usec

EnterState_Discover

void EnterState_Discover(
  void
)

these state transition functions are internal and cannot return error code as the previous state would have no way to handle them.

any failure shall result to eventually another state transition (could be timeout) if even the timer fails, we are out of trick and could hang in some wrong state

EnterState_ServiceSync_1

void EnterState_ServiceSync_1(
  void
)

EnterState_ServiceSync_2

void EnterState_ServiceSync_2(
  void
)

EnterState_Sync_1

void EnterState_Sync_1(
  void
)

EnterState_Sync_2

void EnterState_Sync_2(
  void
)

Public types

ClientState

 ClientState

current state of this Time Sync Client

CommState

 CommState

status of communication to a certain contact.

This is in the public because Contact is in public

ContributorFilter

void(* ContributorFilter)(void *const aApp, Contact aContact[], const int aSize)

callback happens right before we calculate the time correction from responses.

application layer could overwrite aContact[i].mResponseStatus to kResponseStatus_Invalid so that response would be ignored in the calculation

Details
Parameters
[in] aApp
A pointer to app layer data, set in Init.
[in] aContact
array of contacts and response status
[in] aSize
number of records in the aContact array

OnSyncRequestReceivedHandler

bool(* OnSyncRequestReceivedHandler)(void *const aApp, const WeaveMessageInfo *aMsgInfo, const uint8_t aLikelyhood, const bool aIsTimeCoordinator)

callback to indicate we just received a time sync request.

Details
Parameters
[in] aApp
A pointer to app layer data, set in Init.
[in] aMsgInfo
A WeaveMessageInfo containing information about the received time sync request, including information about the sender.
[in] aLikelyhood
likelihood of response as requested by the originator
[in] aIsTimeCoordinator
true if the originating node is a Time Sync Coordinator
Returns
false and the engine shall ignore this request

ResponseStatus

 ResponseStatus

status of stored response to a certain contact.

This is in the public because Contact is in public

ServerState

 ServerState

current state of this Time Sync Server

Properties
kServerState_Idle

the server is ready to respond to requests with normal settings

kServerState_UnreliableAfterBoot

time reserved for the server to sync its system time through some other means only meaningful if aIsAlwaysFresh is true when Init is called

SyncFailedHandler

void(* SyncFailedHandler)(void *const aApp, const WEAVE_ERROR aErrorCode)

callback happens when sync is considered failed, including auto sync.

note that callback doesn't happen if Abort is called to stop syncing

Details
Parameters
[in] aApp
A pointer to app layer data, set in Init.
[in] aErrorCode
reason for the failure

SyncSucceededHandler

bool(* SyncSucceededHandler)(void *const aApp, const timesync_t aOffsetUsec, const bool aIsReliable, const bool aIsServer, const uint8_t aNumContributor)

callback happens after sync is considered successful, including auto sync, but before the result is applied.

Note that successful doesn't mean we have applicable results. In case no response was received, aNumContributor would be set to 0. application layer could overwrite aContact[i].mResponseStatus to kResponseStatus_Invalid so that response would be ignored in the calculation

Details
Parameters
[in] aApp
A pointer to app layer data, set in Init.
[in] aOffsetUsec
amount of correction in usec
[in] aIsReliable
is the correction considered reliable by the built-in logic
[in] aIsServer
does the correction come from Server(s)
[in] aNumContributor
number of nodes which contributed to this correction. 0 means there is no results from sync operation.
Returns
true if this offset shall be used to adjust system time. in case aNumContributor is 0, the return value would be ignored.

TimeChangeNotificationHandler

void(* TimeChangeNotificationHandler)(void *const aApp, const uint64_t aNodeId, const IPAddress &aNodeAddr)

callback to indicate we just received a Time Change Notification.

if auto sync mode is enabled, a time sync would be scheduled shortly after this callback automatically. otherwise the application layer can choose to call Sync family of functions to directly kick off sync operation not restricted by the normal not-available-in-call-back rule. however, it must be noted that this special callback is still on top of callback stack of Weave exchange layer.

Details
Parameters
[in] aApp
A pointer to app layer data, set in Init.
[in] aNodeId
requesting node ID
[in] aNodeAddr
requesting node address

Public attributes

FilterTimeCorrectionContributor

ContributorFilter FilterTimeCorrectionContributor

OnSyncFailed

SyncFailedHandler OnSyncFailed

OnSyncRequestReceived

OnSyncRequestReceivedHandler OnSyncRequestReceived

if not set, the default implementation always returns true

OnSyncSucceeded

SyncSucceededHandler OnSyncSucceeded

if not set, the default behavior is taking all results, except for very small server corrections

OnTimeChangeNotificationReceived

TimeChangeNotificationHandler OnTimeChangeNotificationReceived

mEncryptionType

uint8_t mEncryptionType

encryption method for local communication

mKeyId

uint16_t mKeyId

key id used for local communication

Protected attributes

mApp

void * mApp

pointer to higher layer data

mClientState

ClientState mClientState

mConnectionToService

WeaveConnection * mConnectionToService

TCP connection used to talk to the service.

mContacts

Contact mContacts[WEAVE_CONFIG_TIME_CLIENT_MAX_NUM_CONTACTS]

Contact information learned throughout discovery.

mIsAlwaysFresh

bool mIsAlwaysFresh

mIsInCallback

bool mIsInCallback

true if we're in a callback to higher layer

mLastLikelihoodSent

int8_t mLastLikelihoodSent

mNumContributorInLastLocalSync

uint8_t mNumContributorInLastLocalSync

mRole

TimeSyncRole mRole

Actual role of this node.

mServerState

ServerState mServerState

mServiceContact

Contact mServiceContact

mTimestampLastCorrectionFromServerOrNtp_usec

timesync_t mTimestampLastCorrectionFromServerOrNtp_usec

note it has to be boot time as we need compensation for sleep time

mTimestampLastLocalSync_usec

timesync_t mTimestampLastLocalSync_usec

note it has to be boot time as we need compensation for sleep time

Public functions

Abort

WEAVE_ERROR Abort(
  void
)

force the engine to go back to idle state, aborting anything it is doing.

note no sync success or failure would be called. all Weave Exchanges would be closed. TCP connections would not be touched further. no operation if we're already in idle state. not available in callbacks.

Details
Returns
WEAVE_NO_ERROR on success

DisableAutoSync

void DisableAutoSync(
  void
)

disable auto sync.

only available in idle state. not available in callbacks.

EnableAutoSync

WEAVE_ERROR EnableAutoSync(
  const int32_t aSyncPeriod_msec,
  const int32_t aNominalDiscoveryPeriod_msec,
  const int32_t aShortestDiscoveryPeriod_msec
)

enable auto sync.

only available in idle state. discovery happens right away. not available in callbacks.

Details
Parameters
[in] aSyncPeriod_msec
number of msec between syncing
[in] aNominalDiscoveryPeriod_msec
number of msec between discovery, if no communication error is observed
[in] aShortestDiscoveryPeriod_msec
shortest time between discovery, in msec, if communication error has been observed
Returns
WEAVE_NO_ERROR on success

GetCapacityOfContactList

int GetCapacityOfContactList(
  void
) const 

simple getter for the maximum number of contacts this engine is configured to store

GetClientState

ClientState GetClientState(
  void
) const 

simple getter for client state

GetNextLikelihood

int8_t GetNextLikelihood(
  void
) const 

extract the likelihood for persistent.

the result would only be valid after sync operation is completed, within callbacks of OnSyncSucceeded and OnSyncFailed. otherwise it's transient and might be the current Likelihood rather than the next one to be used.

Details
Returns
likelihood for response to be used in the next request

GetServerState

ServerState GetServerState(
  void
) const 

simple getter for the server state

InitClient

WEAVE_ERROR InitClient(
  void *const aApp,
  WeaveExchangeManager *aExchangeMgr,
  const uint8_t aEncryptionType,
  const uint16_t aKeyId,
  const int8_t aInitialLikelyhood
)

initialize this client.

not available in callbacks

Details
Parameters
[in] aApp
A pointer to higher layer data, used in callbacks to higher layer.
[in] aExchangeMgr
A pointer to system wide Weave Exchange Manager object
[in] aRole
can be either kTimeSyncRole_Client or kTimeSyncRole_Coordinator
[in] aEncryptionType
encryption type to be used for requests and responses
[in] aKeyId
key id to be used for requests and responses
[in] aInitialLikelyhood
initial likelihood to be used for discovery stage
Returns
WEAVE_NO_ERROR on success

InitCoordinator

WEAVE_ERROR InitCoordinator(
  nl::Weave::WeaveExchangeManager *aExchangeMgr,
  const uint8_t aEncryptionType,
  const uint16_t aKeyId,
  const int32_t aSyncPeriod_msec,
  const int32_t aNominalDiscoveryPeriod_msec,
  const int32_t aShortestDiscoveryPeriod_msec
)

initialize this coordinator.

Details
Parameters
[in] aExchangeMgr
A pointer to system wide Weave Exchange Manager object
[in] aEncryptionType
encryption type to be used for requests and responses
[in] aKeyId
key id to be used for requests and responses
[in] aSyncPeriod_msec
number of msec between syncing
[in] aNominalDiscoveryPeriod_msec
shortest time between discovery, in msec, if no communication error is observed
[in] aShortestDiscoveryPeriod_msec
smallest number of msec between discovery, if communication error has been observed
Returns
WEAVE_NO_ERROR on success

InitServer

WEAVE_ERROR InitServer(
  void *const aApp,
  WeaveExchangeManager *const aExchangeMgr,
  const bool aIsAlwaysFresh
)

initialize for the Server role must be called as the first function after object construction if the intention is to be a Time Sync Server.

not available in callbacks

Details
Parameters
[in] aApp
A pointer to higher layer data, used in callbacks to higher layer.
[in] aExchangeMgr
A pointer to system wide Weave Exchange Manager object
[in] aIsAlwaysFresh
could be set to true to indicate the server is always synced except for the initial unreliable time. shall be set to false for Coordinator.
Returns
WEAVE_NO_ERROR on success

MulticastTimeChangeNotification

void MulticastTimeChangeNotification(
  const uint8_t aEncryptionType,
  const uint16_t aKeyId
) const 

Called by higher layer to multicast time change notification.

not available in callbacks.

Details
Parameters
[in] aEncryptionType
type of encryption to be used for this notification
[in] aKeyId
key id to be used for this notification

RegisterCorrectionFromServerOrNtp

void RegisterCorrectionFromServerOrNtp(
  void
)

Called by higher layer to indicate that we just finished a round of time sync with either any Server or through some reliable means like NTP.

RegisterLocalSyncOperation

void RegisterLocalSyncOperation(
  const uint8_t aNumContributor
)

Called by higher layer to indicate that we just finished a round of time sync with other local Coordinators.

Details
Parameters
[in] aNumContributor
number of coordinators contributed to this time sync

Shutdown

WEAVE_ERROR Shutdown(
  void
)

stop the service, no matter which role it is playing.

This function must be called to properly reclaim resources allocated, before another call to any of the init functions can be made. not available in callbacks.

Details
Returns
WEAVE_NO_ERROR on success

Sync

WEAVE_ERROR Sync(
  const bool aForceDiscoverAgain
)

sync using existing contacts.

sync operation could fail if there is no valid contacts available. set aForceDiscoverAgain to true to force discovery immediately. only available in idle state. not available in callbacks.

Details
Parameters
[in] aForceDiscoverAgain
true if all existing contacts shall be flushed and discovery operation performed
Returns
WEAVE_NO_ERROR on success

SyncWithNodes

WEAVE_ERROR SyncWithNodes(
  const int16_t aNumNode,
  const ServingNode aNodes[]
)

sync using the given list of contacts.

existing contact list would be flushed. only available in idle state. not available in callbacks.

Details
Parameters
[in] aNumNode
number of contact in array aNodes
[in] aNodes
array of contact records
Returns
WEAVE_NO_ERROR on success

SyncWithService

WEAVE_ERROR SyncWithService(
  WeaveConnection *const aConnection
)

sync using the given TCP connection and associated encryption and key id.

caller must take ownership of the TCP connection after sync finishes. no callback would be overwritten for the TCP connection, as a new Weave Exchange would be created and callbacks set on top of that context only available in idle state. not available in callbacks.

Details
Parameters
[in] aConnection
A pointer to Weave connection
Returns
WEAVE_NO_ERROR on success

TimeSyncNode

 TimeSyncNode(
  void
)

Protected functions

AbortOnError

void AbortOnError(
  const WEAVE_ERROR aCode
)

internal abort if aCode is not WEAVE_NO_ERROR

AutoSyncNow

void AutoSyncNow(
  void
)

internal function to kick off an auto sync session

CallbackForSyncCompletion

WEAVE_ERROR CallbackForSyncCompletion(
  const bool aIsSuccessful,
  bool aShouldUpdate,
  const bool aIsCorrectionReliable,
  const bool aIsFromServer,
  const uint8_t aNumContributor,
  const timesync_t aSystemTimestamp_usec,
  const timesync_t aDiffTime_usec
)

induce callback to the application layer.

set aIsSuccessful to false to induce the error callback

ClearState

void ClearState(
  void
)

DestroyCommContext

bool DestroyCommContext(
  void
)

close the Weave ExchangeContext

EndLocalSyncAndTryCalculateTimeFix

void EndLocalSyncAndTryCalculateTimeFix(
  void
)

EndServiceSyncAndTryCalculateTimeFix

void EndServiceSyncAndTryCalculateTimeFix(
  void
)

FindReplaceableContact

Contact * FindReplaceableContact(
  const uint64_t aNodeId,
  const IPAddress & aNodeAddr,
  bool aIsTimeChangeNotification
)

return a slot to store contact information

GetClientStateName

const char *const GetClientStateName(
  void
) const 

GetNextIdleContact

Contact * GetNextIdleContact(
  void
)

get the next valid and idle contact to talk to

GetNumNotYetCompletedContacts

int16_t GetNumNotYetCompletedContacts(
  void
)

get the number of contacts that are valid, but we haven't talk to them yet.

GetNumReliableResponses

int16_t GetNumReliableResponses(
  void
)

get the number of 'reliable' responses collected so far.

called to determine if we have collected enough number of responses

InitState

WEAVE_ERROR InitState(
  const TimeSyncRole aRole,
  void *const aApp,
  WeaveExchangeManager *const aExchangeMgr
)

InvalidateAllContacts

void InvalidateAllContacts(
  void
)

invalidate all local contacts

InvalidateServiceContact

void InvalidateServiceContact(
  void
)

invalidate contact to the service

RegisterCommError

void RegisterCommError(
  Contact *const aContact
)

register communication error on a certain contact, and shorten auto discovery period if needed aContact can be NULL to indicate we have no one to talk to, and hence just shorten the auto discovery period

SendSyncRequest

WEAVE_ERROR SendSyncRequest(
  bool *const rIsMessageSent,
  Contact *const aContact
)

send unicast sync request to a contact.

*rIsMessageSent will be set to indicate if the message has been sent out. communication errors like address not reachable is not returned, so caller shall check both the return code and *rIsMessageSent.

SetAllCompletedContactsToIdle

int16_t SetAllCompletedContactsToIdle(
  void
)

reset all completed contacts to idle state again, but don't touch the response.

this is called between two rounds of communication to the same node

SetAllValidContactsToIdleAndInvalidateResponse

int16_t SetAllValidContactsToIdleAndInvalidateResponse(
  void
)

set all valid local contacts to idle state and clear the response.

this is called before we start contacting them one by one

SetClientState

void SetClientState(
  const ClientState state
)

SetupUnicastCommContext

WEAVE_ERROR SetupUnicastCommContext(
  Contact *const aContact
)

create new Weave Exchange for unicast communication

StoreNotifyingContact

void StoreNotifyingContact(
  const uint64_t aNodeId,
  const IPAddress & aNodeAddr
)

store the contact information of a node who just sent us a time change notification

UpdateMulticastSyncResponse

void UpdateMulticastSyncResponse(
  const uint64_t aNodeId,
  const IPAddress & aNodeAddr,
  const TimeSyncResponse & aResponse
)

process a response coming back from a multicast request

UpdateUnicastSyncResponse

void UpdateUnicastSyncResponse(
  const TimeSyncResponse & aResponse
)

process a response coming back from a unicast request

_InitClient

WEAVE_ERROR _InitClient(
  const uint8_t aEncryptionType,
  const uint16_t aKeyId,
  const int8_t aInitialLikelyhood
)

initialize for the Client role.

Intended to be used internally by Init family of public functions. Must set mClientState before return. not available in callbacks

Details
Parameters
[in] aEncryptionType
encryption type to be used for requests and responses
[in] aKeyId
key id to be used for requests and responses
[in] aInitialLikelyhood
initial likelihood to be used for discovery stage
Returns
WEAVE_NO_ERROR on success

_InitServer

WEAVE_ERROR _InitServer(
  const bool aIsAlwaysFresh
)

initialize for the Server role.

Intended to be used internally by Init family of public functions. Must set mClientState before return. not available in callbacks

Details
Parameters
[in] aIsAlwaysFresh
could be set to true to indicate the server is always synced except for the initial unreliable time. shall be set to false for Coordinator.
Returns
WEAVE_NO_ERROR on success

_ShutdownClient

WEAVE_ERROR _ShutdownClient(
  void
)

stop the client not available in callbacks.

Details
Returns
WEAVE_NO_ERROR on success

_ShutdownCoordinator

WEAVE_ERROR _ShutdownCoordinator(
  void
)

stop the coordinator not available in callbacks.

Details
Returns
WEAVE_NO_ERROR on success

_ShutdownServer

WEAVE_ERROR _ShutdownServer(
  void
)

stop the server not available in callbacks.

Details
Returns
WEAVE_NO_ERROR on success

Protected static functions

HandleAutoDiscoveryTimeout

void HandleAutoDiscoveryTimeout(
  System::Layer *aSystemLayer,
  void *aAppState,
  System::Error aError
)

HandleAutoSyncTimeout

void HandleAutoSyncTimeout(
  System::Layer *aSystemLayer,
  void *aAppState,
  System::Error aError
)

HandleMulticastResponseTimeout

void HandleMulticastResponseTimeout(
  System::Layer *aSystemLayer,
  void *aAppState,
  System::Error aError
)

HandleMulticastSyncResponse

void HandleMulticastSyncResponse(
  ExchangeContext *ec,
  const IPPacketInfo *pktInfo,
  const WeaveMessageInfo *msgInfo,
  uint32_t profileId,
  uint8_t msgType,
  PacketBuffer *payload
)

HandleSyncRequest

void HandleSyncRequest(
  ExchangeContext *ec,
  const IPPacketInfo *pktInfo,
  const WeaveMessageInfo *msgInfo,
  uint32_t profileId,
  uint8_t msgType,
  PacketBuffer *payload
)

callback from Weave Exchange when a time sync request arrives

HandleTimeChangeNotification

void HandleTimeChangeNotification(
  ExchangeContext *ec,
  const IPPacketInfo *pktInfo,
  const WeaveMessageInfo *msgInfo,
  uint32_t profileId,
  uint8_t msgType,
  PacketBuffer *payload
)

HandleUnicastResponseTimeout

void HandleUnicastResponseTimeout(
  ExchangeContext *const ec
)

HandleUnicastSyncResponse

void HandleUnicastSyncResponse(
  ExchangeContext *ec,
  const IPPacketInfo *pktInfo,
  const WeaveMessageInfo *msgInfo,
  uint32_t profileId,
  uint8_t msgType,
  PacketBuffer *payload
)

HandleUnreliableAfterBootTimer

void HandleUnreliableAfterBootTimer(
  System::Layer *aSystemLayer,
  void *aAppState,
  System::Error aError
)

callback from Weave Timer when we passed the unreliable after boot barrier

_OnSyncSucceeded

bool _OnSyncSucceeded(
  void *const aApp,
  const nl::Weave::Profiles::Time::timesync_t aOffsetUsec,
  const bool aIsReliable,
  const bool aIsServer,
  const uint8_t aNumContributor
)