aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/plugin_datacache_heap.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-11-13 20:05:40 +0000
committerChristian Grothoff <christian@grothoff.org>2012-11-13 20:05:40 +0000
commit4e1d85bac66209e6655f3fb4d3ddef7929f0f3fc (patch)
treedf5c5a0d972f35d741b51c3a3fc8d2298ac8b4fd /src/datacache/plugin_datacache_heap.c
parent855362e698928b0a5a8f72fc6427c2ea42af4e79 (diff)
downloadgnunet-4e1d85bac66209e6655f3fb4d3ddef7929f0f3fc.tar.gz
gnunet-4e1d85bac66209e6655f3fb4d3ddef7929f0f3fc.zip
changing datacache API to separate put-paths from data (so that plugins can test for duplicates), removing support for MySQL
Diffstat (limited to 'src/datacache/plugin_datacache_heap.c')
-rw-r--r--src/datacache/plugin_datacache_heap.c73
1 files changed, 60 insertions, 13 deletions
diff --git a/src/datacache/plugin_datacache_heap.c b/src/datacache/plugin_datacache_heap.c
index 2f55bcf53..8bc9b29f6 100644
--- a/src/datacache/plugin_datacache_heap.c
+++ b/src/datacache/plugin_datacache_heap.c
@@ -32,6 +32,7 @@
32#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache-heap", op, fn) 32#define LOG_STRERROR_FILE(kind,op,fn) GNUNET_log_from_strerror_file (kind, "datacache-heap", op, fn)
33 33
34 34
35
35/** 36/**
36 * Context for all functions in this plugin. 37 * Context for all functions in this plugin.
37 */ 38 */
@@ -76,11 +77,21 @@ struct Value
76 struct GNUNET_CONTAINER_HeapNode *hn; 77 struct GNUNET_CONTAINER_HeapNode *hn;
77 78
78 /** 79 /**
80 * Path information.
81 */
82 struct GNUNET_PeerIdentity *path_info;
83
84 /**
79 * Payload (actual payload follows this struct) 85 * Payload (actual payload follows this struct)
80 */ 86 */
81 size_t size; 87 size_t size;
82 88
83 /** 89 /**
90 * Number of entries in 'path_info'.
91 */
92 unsigned int path_info_len;
93
94 /**
84 * Type of the block. 95 * Type of the block.
85 */ 96 */
86 enum GNUNET_BLOCK_Type type; 97 enum GNUNET_BLOCK_Type type;
@@ -88,6 +99,9 @@ struct Value
88}; 99};
89 100
90 101
102#define OVERHEAD (sizeof (struct Value) + 64)
103
104
91/** 105/**
92 * Closure for 'put_cb'. 106 * Closure for 'put_cb'.
93 */ 107 */
@@ -109,6 +123,11 @@ struct PutContext
109 struct GNUNET_CONTAINER_Heap *heap; 123 struct GNUNET_CONTAINER_Heap *heap;
110 124
111 /** 125 /**
126 * Path information.
127 */
128 const struct GNUNET_PeerIdentity *path_info;
129
130 /**
112 * Number of bytes in 'data'. 131 * Number of bytes in 'data'.
113 */ 132 */
114 size_t size; 133 size_t size;
@@ -119,6 +138,11 @@ struct PutContext
119 enum GNUNET_BLOCK_Type type; 138 enum GNUNET_BLOCK_Type type;
120 139
121 /** 140 /**
141 * Number of entries in 'path_info'.
142 */
143 unsigned int path_info_len;
144
145 /**
122 * Value to set to GNUNET_YES if an equivalent block was found. 146 * Value to set to GNUNET_YES if an equivalent block was found.
123 */ 147 */
124 int found; 148 int found;
@@ -149,13 +173,20 @@ put_cb (void *cls,
149 put_ctx->found = GNUNET_YES; 173 put_ctx->found = GNUNET_YES;
150 val->discard_time = GNUNET_TIME_absolute_max (val->discard_time, 174 val->discard_time = GNUNET_TIME_absolute_max (val->discard_time,
151 put_ctx->discard_time); 175 put_ctx->discard_time);
176 /* replace old path with new path */
177 GNUNET_array_grow (val->path_info,
178 val->path_info_len,
179 put_ctx->path_info_len);
180 memcpy (val->path_info,
181 put_ctx->path_info,
182 put_ctx->path_info_len * sizeof (struct GNUNET_PeerIdentity));
152 GNUNET_CONTAINER_heap_update_cost (put_ctx->heap, 183 GNUNET_CONTAINER_heap_update_cost (put_ctx->heap,
153 val->hn, 184 val->hn,
154 val->discard_time.abs_value); 185 val->discard_time.abs_value);
155 return GNUNET_NO; 186 return GNUNET_NO;
156 } 187 }
157 if (val->type == put_ctx->type) 188 if (val->type == put_ctx->type)
158 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "Got another value for key %s and type %d (size %u vs %u)\n", 190 "Got another value for key %s and type %d (size %u vs %u)\n",
160 GNUNET_h2s (key), 191 GNUNET_h2s (key),
161 val->type, 192 val->type,
@@ -174,12 +205,16 @@ put_cb (void *cls,
174 * @param data data to store 205 * @param data data to store
175 * @param type type of the value 206 * @param type type of the value
176 * @param discard_time when to discard the value in any case 207 * @param discard_time when to discard the value in any case
177 * @return 0 on error, number of bytes used otherwise 208 * @param path_info_len number of entries in 'path_info'
209 * @param path_info a path through the network
210 * @return 0 if duplicate, -1 on error, number of bytes used otherwise
178 */ 211 */
179static size_t 212static ssize_t
180heap_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size, 213heap_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size,
181 const char *data, enum GNUNET_BLOCK_Type type, 214 const char *data, enum GNUNET_BLOCK_Type type,
182 struct GNUNET_TIME_Absolute discard_time) 215 struct GNUNET_TIME_Absolute discard_time,
216 unsigned int path_info_len,
217 const struct GNUNET_PeerIdentity *path_info)
183{ 218{
184 struct Plugin *plugin = cls; 219 struct Plugin *plugin = cls;
185 struct Value *val; 220 struct Value *val;
@@ -189,6 +224,8 @@ heap_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size,
189 put_ctx.heap = plugin->heap; 224 put_ctx.heap = plugin->heap;
190 put_ctx.data = data; 225 put_ctx.data = data;
191 put_ctx.size = size; 226 put_ctx.size = size;
227 put_ctx.path_info = path_info;
228 put_ctx.path_info_len = path_info_len;
192 put_ctx.discard_time = discard_time; 229 put_ctx.discard_time = discard_time;
193 put_ctx.type = type; 230 put_ctx.type = type;
194 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->map, 231 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->map,
@@ -203,6 +240,11 @@ heap_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size,
203 val->type = type; 240 val->type = type;
204 val->discard_time = discard_time; 241 val->discard_time = discard_time;
205 val->size = size; 242 val->size = size;
243 GNUNET_array_grow (val->path_info,
244 val->path_info_len,
245 path_info_len);
246 memcpy (val->path_info, path_info,
247 path_info_len * sizeof (struct GNUNET_PeerIdentity));
206 (void) GNUNET_CONTAINER_multihashmap_put (plugin->map, 248 (void) GNUNET_CONTAINER_multihashmap_put (plugin->map,
207 &val->key, 249 &val->key,
208 val, 250 val,
@@ -210,7 +252,7 @@ heap_plugin_put (void *cls, const struct GNUNET_HashCode * key, size_t size,
210 val->hn = GNUNET_CONTAINER_heap_insert (plugin->heap, 252 val->hn = GNUNET_CONTAINER_heap_insert (plugin->heap,
211 val, 253 val,
212 val->discard_time.abs_value); 254 val->discard_time.abs_value);
213 return size; 255 return size + OVERHEAD;
214} 256}
215 257
216 258
@@ -263,13 +305,17 @@ get_cb (void *cls,
263 if ( (get_ctx->type != val->type) && 305 if ( (get_ctx->type != val->type) &&
264 (GNUNET_BLOCK_TYPE_ANY != get_ctx->type) ) 306 (GNUNET_BLOCK_TYPE_ANY != get_ctx->type) )
265 return GNUNET_OK; 307 return GNUNET_OK;
266 ret = get_ctx->iter (get_ctx->iter_cls, 308 if (NULL != get_ctx->iter)
309 ret = get_ctx->iter (get_ctx->iter_cls,
310 key,
311 val->size,
312 (const char *) &val[1],
313 val->type,
267 val->discard_time, 314 val->discard_time,
268 key, 315 val->path_info_len,
269 val->size, 316 val->path_info);
270 (const char *) &val[1], 317 else
271 val->type); 318 ret = GNUNET_YES;
272
273 get_ctx->cnt++; 319 get_ctx->cnt++;
274 return ret; 320 return ret;
275} 321}
@@ -328,7 +374,8 @@ heap_plugin_del (void *cls)
328 val)); 374 val));
329 plugin->env->delete_notify (plugin->env->cls, 375 plugin->env->delete_notify (plugin->env->cls,
330 &val->key, 376 &val->key,
331 val->size); 377 val->size + OVERHEAD);
378 GNUNET_free_non_null (val->path_info);
332 GNUNET_free (val); 379 GNUNET_free (val);
333 return GNUNET_OK; 380 return GNUNET_OK;
334} 381}