## Time-Provider Algorithm

The time-provider algorithm assumes that the two remote procedure calls will come in the following order: ContactProvider followed by ServerRequestProviderTime. The algorithm to create a generic time-provider follows:

1. Initialize the TP process, as described previously. Listen for RPC calls.

2. If the ContactProvider procedure is invoked, perform the following steps:

a. Initialize the control message to the appropriate values (status value to K_TPI_SUCCESS; nextPoll, timeout, and noClockSet to valid integer values).

b. Set the communication status output parameter to rpc_s_ok.

c. Return from the procedure call. (The DCE RPC runtime returns the values to DTS.)

3. If the ServerRequestProviderTime procedure is run, perform the following steps:

a. Initialize the timestamp count to the appropriate number.

b. Use the utc_gettime( ) DTS API routine to read the system time.

c. Poll the external time source and read a UTC value. Use the utc_gmtime( ) routine to convert the UTC time value to a binary timestamp.

d. Use the utc_gettime( ) routine to read the system time.

e. Repeat steps b, c, and d the number of times specified by the values of K_MIN_TIMESTAMPS and K_MAX_TIMESTAMPS.

f. If steps b, c, or d return erroneous data, initialize the TP process status field (TPstatus) of the data message to K_TPI_FAILURE; otherwise, initialize the data message timestamps.

g. Set the communication status output parameter to rpc_s_ok.

h. Return from the procedure call. (The DCE RPC runtime sends the values back to DTS.)

4. The TP process continues listening for RPC calls.

##