/**
* A value that we are storing.
- */
+ */
struct Value
{
* only used if anonymity is zero.
*/
unsigned int zero_anon_offset;
-
+
/**
* Number of bytes in 'data'.
*/
- uint32_t size;
+ uint32_t size;
/**
* Priority of the value.
* Anonymity level for the value.
*/
uint32_t anonymity;
-
+
/**
* Replication level for the value.
*/
* @return GNUNET_OK on success
*/
static int
-heap_plugin_put (void *cls,
- const struct GNUNET_HashCode * key,
+heap_plugin_put (void *cls,
+ const struct GNUNET_HashCode * key,
uint32_t size,
- const void *data,
+ const void *data,
enum GNUNET_BLOCK_Type type,
uint32_t priority, uint32_t anonymity,
uint32_t replication,
value->data = &value[1];
value->expire_heap = GNUNET_CONTAINER_heap_insert (plugin->by_expiration,
value,
- expiration.abs_value);
+ expiration.abs_value_us);
value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication,
value,
replication);
break;
if (NULL == zabt)
{
- zabt = GNUNET_malloc (sizeof (struct ZeroAnonByType));
+ zabt = GNUNET_new (struct ZeroAnonByType);
zabt->type = type;
GNUNET_CONTAINER_DLL_insert (plugin->zero_head,
plugin->zero_tail,
* The plugin.
*/
struct Plugin *plugin;
-
+
/**
* Requested value hash.
*/
* Function to call with the result.
*/
PluginDatumProcessor proc;
-
+
/**
* Closure for 'proc'.
*/
* @param value the value to check against the query
* @return GNUNET_YES if the value matches
*/
-static int
+static int
match (const struct GetContext *gc,
struct Value *value)
{
if (0 != gc->offset--)
return GNUNET_OK;
if (GNUNET_NO ==
- gc->proc (gc->proc_cls,
+ gc->proc (gc->proc_cls,
key,
value->size,
&value[1],
&gc);
if (0 == gc.offset)
{
- proc (proc_cls,
+ proc (proc_cls,
NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
{
GNUNET_CONTAINER_multihashmap_get_multiple (plugin->keyvalue,
key,
- &count_iterator,
+ &count_iterator,
&gc);
if (0 == gc.offset)
{
- proc (proc_cls,
+ proc (proc_cls,
NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
* @param proc_cls closure for proc
*/
static void
-heap_plugin_get_replication (void *cls,
+heap_plugin_get_replication (void *cls,
PluginDatumProcessor proc,
void *proc_cls)
{
value = GNUNET_CONTAINER_heap_remove_root (plugin->by_replication);
if (NULL == value)
{
- proc (proc_cls,
+ proc (proc_cls,
NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
value->replication--;
value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication,
value,
- value->replication);
+ value->replication);
}
else
{
/* need a better way to pick a random item, replication level is always 0 */
value->replication_heap = GNUNET_CONTAINER_heap_insert (plugin->by_replication,
value,
- value->replication);
+ value->replication);
value = GNUNET_CONTAINER_heap_walk_get_next (plugin->by_replication);
}
if (GNUNET_NO ==
- proc (proc_cls,
+ proc (proc_cls,
&value->key,
value->size,
&value[1],
value = GNUNET_CONTAINER_heap_peek (plugin->by_expiration);
if (NULL == value)
{
- proc (proc_cls,
+ proc (proc_cls,
NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
}
if (GNUNET_NO ==
- proc (proc_cls,
+ proc (proc_cls,
&value->key,
value->size,
&value[1],
* @return GNUNET_OK on success
*/
static int
-heap_plugin_update (void *cls,
- uint64_t uid,
+heap_plugin_update (void *cls,
+ uint64_t uid,
int delta,
struct GNUNET_TIME_Absolute expire, char **msg)
{
value = (struct Value*) (long) uid;
GNUNET_assert (NULL != value);
- if (value->expiration.abs_value != expire.abs_value)
+ if (value->expiration.abs_value_us != expire.abs_value_us)
{
value->expiration = expire;
GNUNET_CONTAINER_heap_update_cost (plugin->by_expiration,
value->expire_heap,
- expire.abs_value);
+ expire.abs_value_us);
}
if ( (delta < 0) && (value->priority < - delta) )
value->priority = 0;
}
if (0 == count)
{
- proc (proc_cls,
+ proc (proc_cls,
NULL, 0, NULL, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0);
return;
- }
+ }
offset = offset % count;
for (zabt = plugin->zero_head; NULL != zabt; zabt = zabt->next)
{
GNUNET_assert (NULL != zabt);
value = zabt->array[offset];
if (GNUNET_NO ==
- proc (proc_cls,
+ proc (proc_cls,
&value->key,
value->size,
&value[1],
void *val)
{
struct GetAllContext *gac = cls;
-
- gac->proc (gac->proc_cls,
+
+ gac->proc (gac->proc_cls,
key,
1);
return GNUNET_OK;
"HASHMAPSIZE",
&esize))
esize = 128 * 1024;
- plugin = GNUNET_malloc (sizeof (struct Plugin));
+ plugin = GNUNET_new (struct Plugin);
plugin->env = env;
plugin->keyvalue = GNUNET_CONTAINER_multihashmap_create (esize, GNUNET_YES);
plugin->by_expiration = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
plugin->by_replication = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
- api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions));
+ api = GNUNET_new (struct GNUNET_DATASTORE_PluginFunctions);
api->cls = plugin;
api->estimate_size = &heap_plugin_estimate_size;
api->put = &heap_plugin_put;