aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/gnunet-service-peerstore.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-06-04 16:03:17 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-06-04 16:03:17 +0000
commitf286cd0b87731774b9448a0cdc82f7c8682c4efe (patch)
treed84ace0bf67dd4f8a99888548f6ab635206eab4f /src/peerstore/gnunet-service-peerstore.c
parent7d18e9d89d2c920f9139bec7f55f01b00b5fd81a (diff)
downloadgnunet-f286cd0b87731774b9448a0cdc82f7c8682c4efe.tar.gz
gnunet-f286cd0b87731774b9448a0cdc82f7c8682c4efe.zip
peerstore: added 'replace' option and other fixes
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r--src/peerstore/gnunet-service-peerstore.c39
1 files changed, 10 insertions, 29 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c
index 5d3ea6bb1..418204850 100644
--- a/src/peerstore/gnunet-service-peerstore.c
+++ b/src/peerstore/gnunet-service-peerstore.c
@@ -30,24 +30,6 @@
30#include "peerstore_common.h" 30#include "peerstore_common.h"
31 31
32/** 32/**
33 * Context of a PEERSTORE watch
34 */
35struct WatchContext
36{
37
38 /**
39 * Hash of key of watched record
40 */
41 struct GNUNET_HashCode keyhash;
42
43 /**
44 * Client requested the watch
45 */
46 struct GNUNET_SERVER_Client *client;
47
48};
49
50/**
51 * Interval for expired records cleanup (in seconds) 33 * Interval for expired records cleanup (in seconds)
52 */ 34 */
53#define CLEANUP_INTERVAL 300 /* 5mins */ 35#define CLEANUP_INTERVAL 300 /* 5mins */
@@ -95,6 +77,7 @@ shutdown_task (void *cls,
95 } 77 }
96 GNUNET_SERVER_notification_context_destroy(nc); 78 GNUNET_SERVER_notification_context_destroy(nc);
97 GNUNET_CONTAINER_multihashmap_destroy(watchers); 79 GNUNET_CONTAINER_multihashmap_destroy(watchers);
80 watchers = NULL;
98 GNUNET_SCHEDULER_shutdown(); 81 GNUNET_SCHEDULER_shutdown();
99} 82}
100 83
@@ -123,7 +106,7 @@ cleanup_expired_records(void *cls,
123 * @param cls closuer, a 'struct GNUNET_PEERSTORE_Record *' 106 * @param cls closuer, a 'struct GNUNET_PEERSTORE_Record *'
124 * @param key hash of record key 107 * @param key hash of record key
125 * @param value the watcher client, a 'struct GNUNET_SERVER_Client *' 108 * @param value the watcher client, a 'struct GNUNET_SERVER_Client *'
126 * @return #GNUNET_YES to continue iterating 109 * @return #GNUNET_OK to continue iterating
127 */ 110 */
128int client_disconnect_it(void *cls, 111int client_disconnect_it(void *cls,
129 const struct GNUNET_HashCode *key, 112 const struct GNUNET_HashCode *key,
@@ -131,7 +114,7 @@ int client_disconnect_it(void *cls,
131{ 114{
132 if(cls == value) 115 if(cls == value)
133 GNUNET_CONTAINER_multihashmap_remove(watchers, key, value); 116 GNUNET_CONTAINER_multihashmap_remove(watchers, key, value);
134 return GNUNET_YES; 117 return GNUNET_OK;
135} 118}
136 119
137/** 120/**
@@ -146,8 +129,9 @@ handle_client_disconnect (void *cls,
146 * client) 129 * client)
147{ 130{
148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client was disconnected, cleaning up.\n"); 131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client was disconnected, cleaning up.\n");
149 GNUNET_CONTAINER_multihashmap_iterate(watchers, 132 if(NULL != watchers)
150 &client_disconnect_it, client); 133 GNUNET_CONTAINER_multihashmap_iterate(watchers,
134 &client_disconnect_it, client);
151} 135}
152 136
153/** 137/**
@@ -196,12 +180,6 @@ int watch_notifier_it(void *cls,
196 struct StoreRecordMessage *srm; 180 struct StoreRecordMessage *srm;
197 181
198 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n"); 182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n");
199 if(NULL == client)
200 {
201 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing a dead client.\n");
202 GNUNET_CONTAINER_multihashmap_remove(watchers, key, client);
203 return GNUNET_YES;
204 }
205 srm = PEERSTORE_create_record_message(record->sub_system, 183 srm = PEERSTORE_create_record_message(record->sub_system,
206 record->peer, 184 record->peer,
207 record->key, 185 record->key,
@@ -335,6 +313,7 @@ void handle_store (void *cls,
335 const struct GNUNET_MessageHeader *message) 313 const struct GNUNET_MessageHeader *message)
336{ 314{
337 struct GNUNET_PEERSTORE_Record *record; 315 struct GNUNET_PEERSTORE_Record *record;
316 struct StoreRecordMessage *srm;
338 317
339 record = PEERSTORE_parse_record_message(message); 318 record = PEERSTORE_parse_record_message(message);
340 if(NULL == record) 319 if(NULL == record)
@@ -343,6 +322,7 @@ void handle_store (void *cls,
343 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 322 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
344 return; 323 return;
345 } 324 }
325 srm = (struct StoreRecordMessage *)message;
346 if(NULL == record->sub_system 326 if(NULL == record->sub_system
347 || NULL == record->peer 327 || NULL == record->peer
348 || NULL == record->key) 328 || NULL == record->key)
@@ -363,7 +343,8 @@ void handle_store (void *cls,
363 record->key, 343 record->key,
364 record->value, 344 record->value,
365 record->value_size, 345 record->value_size,
366 *record->expiry)) 346 *record->expiry,
347 srm->options))
367 { 348 {
368 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to store requested value, sqlite database error."); 349 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to store requested value, sqlite database error.");
369 PEERSTORE_destroy_record(record); 350 PEERSTORE_destroy_record(record);