diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-06-03 13:50:37 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-06-03 13:50:37 +0000 |
commit | a04d70028c0615e7910f68328db9c61bba67128b (patch) | |
tree | 8d27cc7e8ad6b25cf01ac2cbae6f2839deec00f8 /src/peerstore/gnunet-service-peerstore.c | |
parent | eb985bf2eae6054292e3cbffbfeb4aaea3e394d5 (diff) | |
download | gnunet-a04d70028c0615e7910f68328db9c61bba67128b.tar.gz gnunet-a04d70028c0615e7910f68328db9c61bba67128b.zip |
peerstore: fixes in watch functionality
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 706fcaaae..82961f685 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -144,7 +144,7 @@ int record_iterator(void *cls, | |||
144 | struct GNUNET_PEERSTORE_Record *record, | 144 | struct GNUNET_PEERSTORE_Record *record, |
145 | char *emsg) | 145 | char *emsg) |
146 | { | 146 | { |
147 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 147 | struct GNUNET_SERVER_Client *client = cls; |
148 | struct StoreRecordMessage *srm; | 148 | struct StoreRecordMessage *srm; |
149 | 149 | ||
150 | srm = PEERSTORE_create_record_message(record->sub_system, | 150 | srm = PEERSTORE_create_record_message(record->sub_system, |
@@ -154,7 +154,7 @@ int record_iterator(void *cls, | |||
154 | record->value_size, | 154 | record->value_size, |
155 | record->expiry, | 155 | record->expiry, |
156 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); | 156 | GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_RECORD); |
157 | GNUNET_SERVER_transmit_context_append_message(tc, (const struct GNUNET_MessageHeader *)srm); | 157 | GNUNET_SERVER_notification_context_unicast(nc, client, (struct GNUNET_MessageHeader *)srm, GNUNET_NO); |
158 | return GNUNET_YES; | 158 | return GNUNET_YES; |
159 | } | 159 | } |
160 | 160 | ||
@@ -189,19 +189,17 @@ int watch_notifier_it(void *cls, | |||
189 | record->expiry, | 189 | record->expiry, |
190 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); | 190 | GNUNET_MESSAGE_TYPE_PEERSTORE_WATCH_RECORD); |
191 | GNUNET_SERVER_notification_context_unicast(nc, client, | 191 | GNUNET_SERVER_notification_context_unicast(nc, client, |
192 | (const struct GNUNET_MessageHeader *)srm, GNUNET_YES); | 192 | (const struct GNUNET_MessageHeader *)srm, GNUNET_NO); |
193 | return GNUNET_YES; | 193 | return GNUNET_YES; |
194 | } | 194 | } |
195 | 195 | ||
196 | /** | 196 | /** |
197 | * Given a new record, notifies watchers | 197 | * Given a new record, notifies watchers |
198 | * | 198 | * |
199 | * @cls closure, a 'struct GNUNET_PEERSTORE_Record *' | 199 | * @param record changed record to update watchers with |
200 | * @tc unused | ||
201 | */ | 200 | */ |
202 | void watch_notifier (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 201 | void watch_notifier (struct GNUNET_PEERSTORE_Record *record) |
203 | { | 202 | { |
204 | struct GNUNET_PEERSTORE_Record *record = cls; | ||
205 | struct GNUNET_HashCode keyhash; | 203 | struct GNUNET_HashCode keyhash; |
206 | 204 | ||
207 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending update to any watchers.\n"); | 205 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending update to any watchers.\n"); |
@@ -265,7 +263,7 @@ void handle_iterate (void *cls, | |||
265 | const struct GNUNET_MessageHeader *message) | 263 | const struct GNUNET_MessageHeader *message) |
266 | { | 264 | { |
267 | struct GNUNET_PEERSTORE_Record *record; | 265 | struct GNUNET_PEERSTORE_Record *record; |
268 | struct GNUNET_SERVER_TransmitContext *tc; | 266 | struct GNUNET_MessageHeader *endmsg; |
269 | 267 | ||
270 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request from client.\n"); | 268 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received an iterate request from client.\n"); |
271 | record = PEERSTORE_parse_record_message(message); | 269 | record = PEERSTORE_parse_record_message(message); |
@@ -281,20 +279,21 @@ void handle_iterate (void *cls, | |||
281 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 279 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
282 | return; | 280 | return; |
283 | } | 281 | } |
284 | tc = GNUNET_SERVER_transmit_context_create (client); | 282 | GNUNET_SERVER_notification_context_add(nc, client); |
285 | if(GNUNET_OK == db->iterate_records(db->cls, | 283 | if(GNUNET_OK == db->iterate_records(db->cls, |
286 | record->sub_system, | 284 | record->sub_system, |
287 | record->peer, | 285 | record->peer, |
288 | record->key, | 286 | record->key, |
289 | &record_iterator, | 287 | &record_iterator, |
290 | tc)) | 288 | client)) |
291 | { | 289 | { |
292 | GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | 290 | endmsg = GNUNET_new(struct GNUNET_MessageHeader); |
293 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 291 | endmsg->size = htons(sizeof(struct GNUNET_MessageHeader)); |
292 | endmsg->type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_ITERATE_END); | ||
293 | GNUNET_SERVER_notification_context_unicast(nc, client, endmsg, GNUNET_NO); | ||
294 | } | 294 | } |
295 | else | 295 | else |
296 | { | 296 | { |
297 | GNUNET_free(tc); | ||
298 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 297 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
299 | } | 298 | } |
300 | GNUNET_free(record); /* FIXME: destroy record */ | 299 | GNUNET_free(record); /* FIXME: destroy record */ |
@@ -312,7 +311,6 @@ void handle_store (void *cls, | |||
312 | const struct GNUNET_MessageHeader *message) | 311 | const struct GNUNET_MessageHeader *message) |
313 | { | 312 | { |
314 | struct GNUNET_PEERSTORE_Record *record; | 313 | struct GNUNET_PEERSTORE_Record *record; |
315 | struct GNUNET_SERVER_TransmitContext *tc; | ||
316 | 314 | ||
317 | record = PEERSTORE_parse_record_message(message); | 315 | record = PEERSTORE_parse_record_message(message); |
318 | if(NULL == record) | 316 | if(NULL == record) |
@@ -348,10 +346,8 @@ void handle_store (void *cls, | |||
348 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 346 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
349 | return; | 347 | return; |
350 | } | 348 | } |
351 | tc = GNUNET_SERVER_transmit_context_create (client); | 349 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
352 | GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT_OK); | 350 | watch_notifier(record); |
353 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
354 | GNUNET_SCHEDULER_add_continuation(&watch_notifier, record, -1); | ||
355 | } | 351 | } |
356 | 352 | ||
357 | /** | 353 | /** |