class TimeSyncNode

Defined at line 434 of file x64-shared/gen/third_party/openweave-core/src/include/Weave/Profiles/time/WeaveTime.h

Public Members

OnSyncRequestReceivedHandler OnSyncRequestReceived
TimeChangeNotificationHandler OnTimeChangeNotificationReceived
ContributorFilter FilterTimeCorrectionContributor
SyncSucceededHandler OnSyncSucceeded
SyncFailedHandler OnSyncFailed
uint8_t mEncryptionType
uint16_t mKeyId

Protected Members

void * mApp
TimeSyncRole mRole
bool mIsInCallback
ServerState mServerState
bool mIsAlwaysFresh
uint8_t mNumContributorInLastLocalSync
timesync_t mTimestampLastCorrectionFromServerOrNtp_usec
timesync_t mTimestampLastLocalSync_usec
ClientState mClientState
bool mIsAutoSyncEnabled
int32_t mSyncPeriod_msec
bool mIsUrgentDiscoveryPending
int32_t mNominalDiscoveryPeriod_msec
int32_t mShortestDiscoveryPeriod_msec
timesync_t mBootTimeForNextAutoDiscovery_usec
Contact[4] mContacts
Contact mServiceContact
WeaveConnection * mConnectionToService
Contact * mActiveContact
ExchangeContext * mExchangeContext
timesync_t mUnadjTimestampLastSent_usec
int8_t mLastLikelihoodSent

Public Methods

void TimeSyncNode ()
WEAVE_ERROR Shutdown ()

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.

Returns

WEAVE_NO_ERROR on success

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.

Parameters

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

Returns

WEAVE_NO_ERROR on success

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

Parameters

aApp [in] A pointer to higher layer data, used in callbacks to higher layer.
aExchangeMgr [in] A pointer to system wide Weave Exchange Manager object
aIsAlwaysFresh [in] 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

ServerState GetServerState ()

simple getter for the server state

void RegisterCorrectionFromServerOrNtp ()

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.

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.

Parameters

aNumContributor [in] number of coordinators contributed to this time sync
void MulticastTimeChangeNotification (const uint8_t aEncryptionType, const uint16_t aKeyId)

Called by higher layer to multicast time change notification.

not available in callbacks.

Parameters

aEncryptionType [in] type of encryption to be used for this notification
aKeyId [in] key id to be used for this notification
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

Parameters

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

Returns

WEAVE_NO_ERROR on success

ClientState GetClientState ()

simple getter for client state

int GetCapacityOfContactList ()

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

int8_t GetNextLikelihood ()

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.

Returns

likelihood for response to be used in the next request

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.

Parameters

aSyncPeriod_msec [in] number of msec between syncing
aNominalDiscoveryPeriod_msec [in] number of msec between discovery, if no communication error is observed
aShortestDiscoveryPeriod_msec [in] shortest time between discovery, in msec, if communication error has been observed

Returns

WEAVE_NO_ERROR on success

void DisableAutoSync ()

disable auto sync.

only available in idle state.

not available in callbacks.

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.

Parameters

aForceDiscoverAgain [in] true if all existing contacts shall be flushed and discovery operation performed

Returns

WEAVE_NO_ERROR on success

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.

Parameters

aConnection [in] A pointer to Weave connection

Returns

WEAVE_NO_ERROR on success

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.

Parameters

aNumNode [in] number of contact in array aNodes
aNodes [in] array of contact records

Returns

WEAVE_NO_ERROR on success

WEAVE_ERROR Abort ()

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.

Returns

WEAVE_NO_ERROR on success

Protected Methods

bool IsOperationalState (ClientState aState)

Determine whether given state is operational

Convenience method to determine whether the ClientState denotes

operational state, i.e. the client has completed initialization and is

not in the process of shutting down.

Parameters

aState [in] state to be evaluated

Returns

true if the state falls after the initialization has completed

and before the shutdown has started, false otherwise.

Defined at line 1124 of file x64-shared/gen/third_party/openweave-core/src/include/Weave/Profiles/time/WeaveTime.h

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

stop the coordinator

not available in callbacks.

Returns

WEAVE_NO_ERROR on success

bool _OnSyncSucceeded (void *const aApp, const nl::Weave::Profiles::Time::timesync_t aOffsetUsec, const bool aIsReliable, const bool aIsServer, const uint8_t aNumContributor)
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

Parameters

aIsAlwaysFresh [in] 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

WEAVE_ERROR _ShutdownServer ()

stop the server

not available in callbacks.

Returns

WEAVE_NO_ERROR on success

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

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

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

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

Parameters

aEncryptionType [in] encryption type to be used for requests and responses
aKeyId [in] key id to be used for requests and responses
aInitialLikelyhood [in] initial likelihood to be used for discovery stage

Returns

WEAVE_NO_ERROR on success

WEAVE_ERROR _ShutdownClient ()

stop the client

not available in callbacks.

Returns

WEAVE_NO_ERROR on success

void InvalidateServiceContact ()

invalidate contact to the service

void InvalidateAllContacts ()

invalidate all local contacts

int16_t SetAllValidContactsToIdleAndInvalidateResponse ()

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

this is called before we start contacting them one by one

int16_t SetAllCompletedContactsToIdle ()

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

int16_t GetNumNotYetCompletedContacts ()

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

int16_t GetNumReliableResponses ()

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

called to determine if we have collected enough number of responses

Contact * GetNextIdleContact ()

get the next valid and idle contact to talk to

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

return a slot to store contact information

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

process a response coming back from a multicast request

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

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

void UpdateUnicastSyncResponse (const TimeSyncResponse & aResponse)

process a response coming back from a unicast request

void EndLocalSyncAndTryCalculateTimeFix ()

wrap up a local sync and calculate the correction

void EndServiceSyncAndTryCalculateTimeFix ()

wrap up a sync with the service and calculate the correction

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

void AbortOnError (const WEAVE_ERROR aCode)

internal abort if aCode is not WEAVE_NO_ERROR

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

bool DestroyCommContext ()

close the Weave ExchangeContext

WEAVE_ERROR SetupUnicastCommContext (Contact *const aContact)

create new Weave Exchange for unicast communication

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.

void SetClientState (const ClientState state)
const char * GetClientStateName ()
void AutoSyncNow ()

internal function to kick off an auto sync session

void EnterState_Discover ()
void EnterState_Sync_1 ()
void EnterState_Sync_2 ()
void EnterState_ServiceSync_1 ()
void EnterState_ServiceSync_2 ()
void HandleTimeChangeNotification (ExchangeContext * ec, const IPPacketInfo * pktInfo, const WeaveMessageInfo * msgInfo, uint32_t profileId, uint8_t msgType, PacketBuffer * payload)

@

}

void HandleUnicastSyncResponse (ExchangeContext * ec, const IPPacketInfo * pktInfo, const WeaveMessageInfo * msgInfo, uint32_t profileId, uint8_t msgType, PacketBuffer * payload)
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 HandleAutoDiscoveryTimeout (System::Layer * aSystemLayer, void * aAppState, System::Error aError)
void HandleUnicastResponseTimeout (ExchangeContext *const ec)
void HandleAutoSyncTimeout (System::Layer * aSystemLayer, void * aAppState, System::Error aError)

Enumerations

enum ServerState
Name Value
kServerState_Uninitialized 0
kServerState_ContructionFailed 1
kServerState_Constructed 2
kServerState_InitializationFailed 3
kServerState_UnreliableAfterBoot 4
kServerState_Idle 5
kServerState_ShutdownCompleted 6
kServerState_ShutdownFailed 7

current state of this Time Sync Server

Defined at line 440 of file x64-shared/gen/third_party/openweave-core/src/include/Weave/Profiles/time/WeaveTime.h

enum ClientState
Name Value
kClientState_Uninitialized 0
kClientState_ContructionFailed 1
kClientState_Constructed 2
kClientState_InitializationFailed 3
kClientState_BeginNormal 4
kClientState_Idle 5
kClientState_Sync_Discovery 6
kClientState_Sync_1 7
kClientState_Sync_2 8
kClientState_ServiceSync_1 9
kClientState_ServiceSync_2 10
kClientState_EndNormal 11
kClientState_ShutdownNeeded 12
kClientState_ShutdownCompleted 13
kClientState_ShutdownFailed 14

current state of this Time Sync Client

Defined at line 459 of file x64-shared/gen/third_party/openweave-core/src/include/Weave/Profiles/time/WeaveTime.h

enum CommState
Name Value
kCommState_Invalid 0
kCommState_Idle 1
kCommState_Active 2
kCommState_Completed 3

status of communication to a certain contact.

This is in the public because Contact is in public

Defined at line 490 of file x64-shared/gen/third_party/openweave-core/src/include/Weave/Profiles/time/WeaveTime.h

enum ResponseStatus
Name Value
kResponseStatus_Invalid 0
kResponseStatus_ReliableResponse 1
kResponseStatus_LessReliableResponse 2
kResponseStatus_UnusableResponse 3

status of stored response to a certain contact.

This is in the public because Contact is in public

Defined at line 500 of file x64-shared/gen/third_party/openweave-core/src/include/Weave/Profiles/time/WeaveTime.h