#include "gnunet_peerstore_plugin.h"
#include "peerstore_common.h"
-/**
- * Context of a PEERSTORE watch
- */
-struct WatchContext
-{
-
- /**
- * Hash of key of watched record
- */
- struct GNUNET_HashCode keyhash;
-
- /**
- * Client requested the watch
- */
- struct GNUNET_SERVER_Client *client;
-
-};
-
/**
* Interval for expired records cleanup (in seconds)
*/
-#define CLEANUP_INTERVAL 300 /* 5mins */
+#define EXPIRED_RECORDS_CLEANUP_INTERVAL 300 /* 5mins */
/**
* Our configuration.
}
GNUNET_SERVER_notification_context_destroy(nc);
GNUNET_CONTAINER_multihashmap_destroy(watchers);
+ watchers = NULL;
GNUNET_SCHEDULER_shutdown();
}
deleted = db->expire_records(db->cls, GNUNET_TIME_absolute_get());
GNUNET_log(GNUNET_ERROR_TYPE_INFO, "%d records expired.\n", deleted);
GNUNET_SCHEDULER_add_delayed(
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, CLEANUP_INTERVAL),
+ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, EXPIRED_RECORDS_CLEANUP_INTERVAL),
&cleanup_expired_records, NULL);
}
* @param cls closuer, a 'struct GNUNET_PEERSTORE_Record *'
* @param key hash of record key
* @param value the watcher client, a 'struct GNUNET_SERVER_Client *'
- * @return #GNUNET_YES to continue iterating
+ * @return #GNUNET_OK to continue iterating
*/
int client_disconnect_it(void *cls,
const struct GNUNET_HashCode *key,
{
if(cls == value)
GNUNET_CONTAINER_multihashmap_remove(watchers, key, value);
- return GNUNET_YES;
+ return GNUNET_OK;
}
/**
* client)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A client was disconnected, cleaning up.\n");
- GNUNET_CONTAINER_multihashmap_iterate(watchers,
- &client_disconnect_it, client);
+ if(NULL != watchers)
+ GNUNET_CONTAINER_multihashmap_iterate(watchers,
+ &client_disconnect_it, client);
}
/**
struct StoreRecordMessage *srm;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found a watcher to update.\n");
- if(NULL == client)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Removing a dead client.\n");
- GNUNET_CONTAINER_multihashmap_remove(watchers, key, client);
- return GNUNET_YES;
- }
srm = PEERSTORE_create_record_message(record->sub_system,
record->peer,
record->key,
{
struct GNUNET_HashCode keyhash;
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending update to any watchers.\n");
PEERSTORE_hash_key(record->sub_system,
record->peer,
record->key,
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterate request: ss `%s', peer `%s', key `%s'\n",
+ record->sub_system,
+ (NULL == record->peer) ? "NULL" : GNUNET_i2s(record->peer),
+ (NULL == record->key) ? "NULL" : record->key);
GNUNET_SERVER_notification_context_add(nc, client);
if(GNUNET_OK == db->iterate_records(db->cls,
record->sub_system,
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_PEERSTORE_Record *record;
+ struct StoreRecordMessage *srm;
record = PEERSTORE_parse_record_message(message);
if(NULL == record)
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
+ srm = (struct StoreRecordMessage *)message;
if(NULL == record->sub_system
|| NULL == record->peer
|| NULL == record->key)
record->key,
record->value,
record->value_size,
- *record->expiry))
+ *record->expiry,
+ srm->options))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to store requested value, sqlite database error.");
PEERSTORE_destroy_record(record);