diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-01-14 13:32:21 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-01-14 13:32:21 +0000 |
commit | 4def9d37a92933d763f5882f1e25be1f5aad2ba9 (patch) | |
tree | dc26667e8b21cf9ecb2670fd11185bcd7ba24364 /src | |
parent | d77de7b84a9d2a705cc77ae87f2fd72c5b75e5b0 (diff) | |
download | gnunet-4def9d37a92933d763f5882f1e25be1f5aad2ba9.tar.gz gnunet-4def9d37a92933d763f5882f1e25be1f5aad2ba9.zip |
- only log changed values
Diffstat (limited to 'src')
-rw-r--r-- | src/testbed/gnunet-daemon-latency-logger.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c index e4faa8c98..bac89deee 100644 --- a/src/testbed/gnunet-daemon-latency-logger.c +++ b/src/testbed/gnunet-daemon-latency-logger.c | |||
@@ -58,6 +58,29 @@ | |||
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Entry type to be used in the map to store old latency values | ||
62 | */ | ||
63 | struct Entry | ||
64 | { | ||
65 | /** | ||
66 | * The peer's identity | ||
67 | */ | ||
68 | struct GNUNET_PeerIdentity id; | ||
69 | |||
70 | /** | ||
71 | * The last known value for latency | ||
72 | */ | ||
73 | unsigned int latency; | ||
74 | |||
75 | }; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Handle to the map used to store old latency values for peers | ||
80 | */ | ||
81 | static struct GNUNET_CONTAINER_MultiPeerMap *map; | ||
82 | |||
83 | /** | ||
61 | * The SQLite database handle | 84 | * The SQLite database handle |
62 | */ | 85 | */ |
63 | static struct sqlite3 *db; | 86 | static struct sqlite3 *db; |
@@ -79,6 +102,31 @@ GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | |||
79 | 102 | ||
80 | 103 | ||
81 | /** | 104 | /** |
105 | * @ingroup hashmap | ||
106 | * Iterator over hash map entries. | ||
107 | * | ||
108 | * @param cls closure | ||
109 | * @param key current public key | ||
110 | * @param value value in the hash map | ||
111 | * @return #GNUNET_YES if we should continue to | ||
112 | * iterate, | ||
113 | * #GNUNET_NO if not. | ||
114 | */ | ||
115 | static int | ||
116 | free_iterator (void *cls, | ||
117 | const struct GNUNET_PeerIdentity *key, | ||
118 | void *value) | ||
119 | { | ||
120 | struct Entry *e = cls; | ||
121 | |||
122 | GNUNET_assert (GNUNET_YES == | ||
123 | GNUNET_CONTAINER_multipeermap_remove (map, key, e)); | ||
124 | GNUNET_free (e); | ||
125 | return GNUNET_YES; | ||
126 | } | ||
127 | |||
128 | |||
129 | /** | ||
82 | * Shutdown | 130 | * Shutdown |
83 | * | 131 | * |
84 | * @param cls NULL | 132 | * @param cls NULL |
@@ -98,6 +146,13 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
98 | } | 146 | } |
99 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); | 147 | GNUNET_break (SQLITE_OK == sqlite3_close (db)); |
100 | db = NULL; | 148 | db = NULL; |
149 | if (NULL != map) | ||
150 | { | ||
151 | GNUNET_assert (GNUNET_SYSERR != | ||
152 | GNUNET_CONTAINER_multipeermap_iterate (map, free_iterator, NULL)); | ||
153 | GNUNET_CONTAINER_multipeermap_destroy (map); | ||
154 | map = NULL; | ||
155 | } | ||
101 | } | 156 | } |
102 | 157 | ||
103 | /** | 158 | /** |
@@ -131,6 +186,7 @@ addr_info_cb (void *cls, | |||
131 | " ?2," | 186 | " ?2," |
132 | " datetime('now')" | 187 | " datetime('now')" |
133 | ");"; | 188 | ");"; |
189 | struct Entry *entry; | ||
134 | int latency; | 190 | int latency; |
135 | unsigned int cnt; | 191 | unsigned int cnt; |
136 | 192 | ||
@@ -146,6 +202,15 @@ addr_info_cb (void *cls, | |||
146 | 202 | ||
147 | insert: | 203 | insert: |
148 | latency = (int) ntohl (ats[cnt].value); | 204 | latency = (int) ntohl (ats[cnt].value); |
205 | entry = NULL; | ||
206 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (map, | ||
207 | &address->peer)) | ||
208 | { | ||
209 | entry = GNUNET_CONTAINER_multipeermap_get (map, &address->peer); | ||
210 | GNUNET_assert (NULL != entry); | ||
211 | if (latency == entry->latency) | ||
212 | return; | ||
213 | } | ||
149 | if (NULL == stmt_insert) | 214 | if (NULL == stmt_insert) |
150 | { | 215 | { |
151 | if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, | 216 | if (SQLITE_OK != sqlite3_prepare_v2 (db, query_insert, -1, &stmt_insert, |
@@ -173,6 +238,15 @@ addr_info_cb (void *cls, | |||
173 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); | 238 | LOG_SQLITE (db, NULL, GNUNET_ERROR_TYPE_ERROR, "sqlite3_insert"); |
174 | goto err_shutdown; | 239 | goto err_shutdown; |
175 | } | 240 | } |
241 | if (NULL == entry) | ||
242 | { | ||
243 | entry = GNUNET_new (struct Entry); | ||
244 | entry->id = address->peer; | ||
245 | GNUNET_CONTAINER_multipeermap_put (map, | ||
246 | &entry->id, entry, | ||
247 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
248 | } | ||
249 | entry->latency = latency; | ||
176 | return; | 250 | return; |
177 | 251 | ||
178 | err_shutdown: | 252 | err_shutdown: |
@@ -226,6 +300,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
226 | GNUNET_free (dbfile); | 300 | GNUNET_free (dbfile); |
227 | dbfile = NULL; | 301 | dbfile = NULL; |
228 | ats = GNUNET_ATS_performance_init (c, addr_info_cb, NULL); | 302 | ats = GNUNET_ATS_performance_init (c, addr_info_cb, NULL); |
303 | map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES); | ||
229 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 304 | shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
230 | &do_shutdown, NULL); | 305 | &do_shutdown, NULL); |
231 | } | 306 | } |