diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-09 07:18:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-09 07:18:53 +0000 |
commit | a13d301ba2910e6df6c93eb4a15106a0323e46cc (patch) | |
tree | acf9f3c3189d65fff3a4a08f2bb33fe3be0b2153 /src/namestore/namestore_api_monitor.c | |
parent | cdb6307117f72f42da7889debc4b4e903e4ca953 (diff) | |
download | gnunet-a13d301ba2910e6df6c93eb4a15106a0323e46cc.tar.gz gnunet-a13d301ba2910e6df6c93eb4a15106a0323e46cc.zip |
add '-m' option to gnunet-namestore, extend namestore monitor API with notification about being in sync
Diffstat (limited to 'src/namestore/namestore_api_monitor.c')
-rw-r--r-- | src/namestore/namestore_api_monitor.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/namestore/namestore_api_monitor.c b/src/namestore/namestore_api_monitor.c index 5eb3e6803..8f6aacf19 100644 --- a/src/namestore/namestore_api_monitor.c +++ b/src/namestore/namestore_api_monitor.c | |||
@@ -56,9 +56,14 @@ struct GNUNET_NAMESTORE_ZoneMonitor | |||
56 | GNUNET_NAMESTORE_RecordMonitor monitor; | 56 | GNUNET_NAMESTORE_RecordMonitor monitor; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Closure for 'monitor'. | 59 | * Function called when we've synchronized. |
60 | */ | 60 | */ |
61 | void *monitor_cls; | 61 | GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb; |
62 | |||
63 | /** | ||
64 | * Closure for 'monitor' and 'sync_cb'. | ||
65 | */ | ||
66 | void *cls; | ||
62 | 67 | ||
63 | /** | 68 | /** |
64 | * Transmission handle to client. | 69 | * Transmission handle to client. |
@@ -101,7 +106,7 @@ reconnect (struct GNUNET_NAMESTORE_ZoneMonitor *zm) | |||
101 | { | 106 | { |
102 | if (NULL != zm->h) | 107 | if (NULL != zm->h) |
103 | GNUNET_CLIENT_disconnect (zm->h); | 108 | GNUNET_CLIENT_disconnect (zm->h); |
104 | zm->monitor (zm->monitor_cls, | 109 | zm->monitor (zm->cls, |
105 | NULL, | 110 | NULL, |
106 | GNUNET_TIME_UNIT_ZERO_ABS, | 111 | GNUNET_TIME_UNIT_ZERO_ABS, |
107 | NULL, 0, NULL, NULL); | 112 | NULL, 0, NULL, NULL); |
@@ -142,6 +147,17 @@ handle_updates (void *cls, | |||
142 | reconnect (zm); | 147 | reconnect (zm); |
143 | return; | 148 | return; |
144 | } | 149 | } |
150 | if ( (ntohs (msg->size) == sizeof (struct GNUNET_MessageHeader)) && | ||
151 | (GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC == ntohs (msg->type) ) ) | ||
152 | { | ||
153 | GNUNET_CLIENT_receive (zm->h, | ||
154 | &handle_updates, | ||
155 | zm, | ||
156 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
157 | if (NULL != zm->sync_cb) | ||
158 | zm->sync_cb (zm->cls); | ||
159 | return; | ||
160 | } | ||
145 | if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) || | 161 | if ( (ntohs (msg->size) < sizeof (struct LookupNameResponseMessage)) || |
146 | (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs (msg->type) ) ) | 162 | (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE != ntohs (msg->type) ) ) |
147 | { | 163 | { |
@@ -189,7 +205,7 @@ handle_updates (void *cls, | |||
189 | &handle_updates, | 205 | &handle_updates, |
190 | zm, | 206 | zm, |
191 | GNUNET_TIME_UNIT_FOREVER_REL); | 207 | GNUNET_TIME_UNIT_FOREVER_REL); |
192 | zm->monitor(zm->monitor_cls, | 208 | zm->monitor(zm->cls, |
193 | &lrm->public_key, expire, | 209 | &lrm->public_key, expire, |
194 | name_tmp, | 210 | name_tmp, |
195 | rd_count, rd, &lrm->signature); | 211 | rd_count, rd, &lrm->signature); |
@@ -238,14 +254,16 @@ transmit_monitor_message (void *cls, | |||
238 | * @param cfg configuration to use to connect to namestore | 254 | * @param cfg configuration to use to connect to namestore |
239 | * @param zone zone to monitor, NULL for all zones | 255 | * @param zone zone to monitor, NULL for all zones |
240 | * @param monitor function to call on zone changes | 256 | * @param monitor function to call on zone changes |
241 | * @param monitor_cls closure for 'monitor' | 257 | * @param sync_cb function called when we're in sync with the namestore |
258 | * @param cls closure for 'monitor' and 'sync_cb' | ||
242 | * @return handle to stop monitoring | 259 | * @return handle to stop monitoring |
243 | */ | 260 | */ |
244 | struct GNUNET_NAMESTORE_ZoneMonitor * | 261 | struct GNUNET_NAMESTORE_ZoneMonitor * |
245 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 262 | GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
246 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 263 | const struct GNUNET_CRYPTO_ShortHashCode *zone, |
247 | GNUNET_NAMESTORE_RecordMonitor monitor, | 264 | GNUNET_NAMESTORE_RecordMonitor monitor, |
248 | void *monitor_cls) | 265 | GNUNET_NAMESTORE_RecordsSynchronizedCallback sync_cb, |
266 | void *cls) | ||
249 | { | 267 | { |
250 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; | 268 | struct GNUNET_NAMESTORE_ZoneMonitor *zm; |
251 | struct GNUNET_CLIENT_Connection *client; | 269 | struct GNUNET_CLIENT_Connection *client; |
@@ -260,7 +278,8 @@ GNUNET_NAMESTORE_zone_monitor_start (const struct GNUNET_CONFIGURATION_Handle *c | |||
260 | else | 278 | else |
261 | zm->zone = *zone; | 279 | zm->zone = *zone; |
262 | zm->monitor = monitor; | 280 | zm->monitor = monitor; |
263 | zm->monitor_cls = monitor_cls; | 281 | zm->sync_cb = sync_cb; |
282 | zm->cls = cls; | ||
264 | zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h, | 283 | zm->th = GNUNET_CLIENT_notify_transmit_ready (zm->h, |
265 | sizeof (struct ZoneMonitorStartMessage), | 284 | sizeof (struct ZoneMonitorStartMessage), |
266 | GNUNET_TIME_UNIT_FOREVER_REL, | 285 | GNUNET_TIME_UNIT_FOREVER_REL, |