Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

clock.c File Reference


Detailed Description

Maintain an accurate clock skew of our host's clock with respect to the absolute time.

Author:
Raphael Manfredi
Date:
2003

#include "common.h"
#include "clock.h"
#include "lib/cq.h"
#include "lib/misc.h"
#include "lib/walloc.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "lib/stats.h"
#include "lib/tm.h"
#include "lib/override.h"

Data Structures

struct  used_val

Defines

#define REUSE_DELAY   10800 /**< 3 hours */
 3 hours

#define ENOUGH_DATA   30 /**< Update skew when we have enough data */
 Update skew when we have enough data.

#define MIN_DATA   15 /**< Minimum amount of points for update */
 Minimum amount of points for update.

#define MAX_SDEV   60.0 /**< Maximum dispersion we tolerate */
 Maximum dispersion we tolerate.

#define CLEAN_STEPS   3 /**< Amount of steps to remove off-track data */
 Amount of steps to remove off-track data.


Functions

 RCSID ("$Id:clock.c, v 1.16 2005/08/31 21:37:28 rmanfredi Exp $")
void val_free (struct used_val *v)
 Dispose of the value from the `used' table.

void val_destroy (cqueue_t *unused_cq, gpointer obj)
 Called from callout queue when it's time to destroy the record.

used_valval_create (const host_addr_t addr, gint precision)
 Create a value for the `used' table.

void val_reused (struct used_val *v, gint precision)
 Accepted an update due to a lower precision entry, reschedule the expiration timeout.

void clock_init (void)
 Called at startup time to initialize local structures.

void used_free_kv (gpointer unused_key, gpointer val, gpointer unused_x)
void clock_close (void)
 Called at shutdown time to cleanup local structures.

void clock_adjust (void)
 Adjust clock skew when we have enough datapoints.

void clock_update (time_t update, gint precision, const host_addr_t addr)
 Update clock information, with given precision in seconds.

time_t clock_loc2gmt (time_t stamp)
 Given a local timestamp, use our skew to correct it to GMT.

time_t clock_gmt2loc (time_t stamp)
 Given a GMT timestamp, convert it to a local stamp using our skew.


Variables

GHashTable * used
 Records the IP address used.

gpointer datapoints = NULL
 This container holds the data points (clock offset between the real UTC time and our local clock time) collected.


Define Documentation

#define CLEAN_STEPS   3 /**< Amount of steps to remove off-track data */
 

Amount of steps to remove off-track data.

#define ENOUGH_DATA   30 /**< Update skew when we have enough data */
 

Update skew when we have enough data.

#define MAX_SDEV   60.0 /**< Maximum dispersion we tolerate */
 

Maximum dispersion we tolerate.

#define MIN_DATA   15 /**< Minimum amount of points for update */
 

Minimum amount of points for update.

#define REUSE_DELAY   10800 /**< 3 hours */
 

3 hours


Function Documentation

void clock_adjust void   )  [static]
 

Adjust clock skew when we have enough datapoints.

void clock_close void   ) 
 

Called at shutdown time to cleanup local structures.

time_t clock_gmt2loc time_t  stamp  ) 
 

Given a GMT timestamp, convert it to a local stamp using our skew.

void clock_init void   ) 
 

Called at startup time to initialize local structures.

time_t clock_loc2gmt time_t  stamp  ) 
 

Given a local timestamp, use our skew to correct it to GMT.

void clock_update time_t  update,
gint  precision,
const host_addr_t  addr
 

Update clock information, with given precision in seconds.

The `ip' is used to avoid using the same source more than once per REUSE_DELAY seconds.

RCSID "$Id:clock.  c,
v 1.16 2005/08/31 21:37:28 rmanfredi Exp $" 
 

void used_free_kv gpointer  unused_key,
gpointer  val,
gpointer  unused_x
[static]
 

struct used_val* val_create const host_addr_t  addr,
gint  precision
 

Create a value for the `used' table.

void val_destroy cqueue_t unused_cq,
gpointer  obj
[static]
 

Called from callout queue when it's time to destroy the record.

void val_free struct used_val v  )  [static]
 

Dispose of the value from the `used' table.

void val_reused struct used_val v,
gint  precision
[static]
 

Accepted an update due to a lower precision entry, reschedule the expiration timeout.


Variable Documentation

gpointer datapoints = NULL
 

This container holds the data points (clock offset between the real UTC time and our local clock time) collected.

For each update, there are two data points entered: u+d and u-d, where u is the update point and d is the precision of the value.

When we have "enough" data points, we compute the average and the standard deviation, then we remove all the points lying outside the range [average - sigma, average + sigma]. We then recompute the average and use that to update our clock skew.

Since we can't update the system clock, we define a skew and the relation between the real, the local time and the skew is:

real_time = local_time + clock_skew

The routine clock_loc2gmt() is used to compute the real time based on the local time, given the currently determined skew. The skewing of the local time is only used when the host is not running NTP. Otherwise, we compute the skew just for the fun of it.

GHashTable* used [static]
 

Records the IP address used.


Generated on Sun Feb 12 10:49:59 2006 for Gtk-Gnutella by doxygen 1.3.6