aboutsummaryrefslogtreecommitdiff
path: root/src/block/block.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/block/block.c')
-rw-r--r--src/block/block.c132
1 files changed, 59 insertions, 73 deletions
diff --git a/src/block/block.c b/src/block/block.c
index 24bde02ac..bdef55aa3 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -37,9 +37,9 @@ struct Plugin
37{ 37{
38 /** 38 /**
39 * Name of the shared library. 39 * Name of the shared library.
40 */ 40 */
41 char *library_name; 41 char *library_name;
42 42
43 /** 43 /**
44 * Plugin API. 44 * Plugin API.
45 */ 45 */
@@ -59,7 +59,7 @@ struct GNUNET_BLOCK_Context
59 59
60 /** 60 /**
61 * Our configuration. 61 * Our configuration.
62 */ 62 */
63 const struct GNUNET_CONFIGURATION_Handle *cfg; 63 const struct GNUNET_CONFIGURATION_Handle *cfg;
64}; 64};
65 65
@@ -73,14 +73,11 @@ struct GNUNET_BLOCK_Context
73 */ 73 */
74void 74void
75GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, 75GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in,
76 uint32_t mingle_number, 76 uint32_t mingle_number, GNUNET_HashCode * hc)
77 GNUNET_HashCode * hc)
78{ 77{
79 GNUNET_HashCode m; 78 GNUNET_HashCode m;
80 79
81 GNUNET_CRYPTO_hash (&mingle_number, 80 GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m);
82 sizeof (uint32_t),
83 &m);
84 GNUNET_CRYPTO_hash_xor (&m, in, hc); 81 GNUNET_CRYPTO_hash_xor (&m, in, hc);
85} 82}
86 83
@@ -106,39 +103,33 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
106 ctx->cfg = cfg; 103 ctx->cfg = cfg;
107 num_plugins = 0; 104 num_plugins = 0;
108 if (GNUNET_OK == 105 if (GNUNET_OK ==
109 GNUNET_CONFIGURATION_get_value_string (cfg, 106 GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs))
110 "block", "PLUGINS", &plugs)) 107 {
108 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
109 _("Loading block plugins `%s'\n"), plugs);
110 pos = strtok (plugs, " ");
111 while (pos != NULL)
111 { 112 {
112 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 113 GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
113 _("Loading block plugins `%s'\n"), plugs); 114 api = GNUNET_PLUGIN_load (libname, NULL);
114 pos = strtok (plugs, " "); 115 if (api == NULL)
115 while (pos != NULL) 116 {
116 { 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos); 118 _("Failed to load block plugin `%s'\n"), pos);
118 api = GNUNET_PLUGIN_load (libname, NULL); 119 GNUNET_free (libname);
119 if (api == NULL) 120 }
120 { 121 else
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 122 {
122 _("Failed to load block plugin `%s'\n"), 123 plugin = GNUNET_malloc (sizeof (struct Plugin));
123 pos); 124 plugin->api = api;
124 GNUNET_free (libname); 125 plugin->library_name = libname;
125 } 126 GNUNET_array_append (ctx->plugins, num_plugins, plugin);
126 else 127 }
127 { 128 pos = strtok (NULL, " ");
128 plugin = GNUNET_malloc (sizeof (struct Plugin));
129 plugin->api = api;
130 plugin->library_name = libname;
131 GNUNET_array_append (ctx->plugins,
132 num_plugins,
133 plugin);
134 }
135 pos = strtok (NULL, " ");
136 }
137 GNUNET_free (plugs);
138 } 129 }
139 GNUNET_array_append (ctx->plugins, 130 GNUNET_free (plugs);
140 num_plugins, 131 }
141 NULL); 132 GNUNET_array_append (ctx->plugins, num_plugins, NULL);
142 return ctx; 133 return ctx;
143} 134}
144 135
@@ -156,14 +147,13 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
156 147
157 i = 0; 148 i = 0;
158 while (NULL != (plugin = ctx->plugins[i])) 149 while (NULL != (plugin = ctx->plugins[i]))
159 { 150 {
160 GNUNET_break (NULL == 151 GNUNET_break (NULL ==
161 GNUNET_PLUGIN_unload (plugin->library_name, 152 GNUNET_PLUGIN_unload (plugin->library_name, plugin->api));
162 plugin->api)); 153 GNUNET_free (plugin->library_name);
163 GNUNET_free (plugin->library_name); 154 GNUNET_free (plugin);
164 GNUNET_free (plugin); 155 i++;
165 i++; 156 }
166 }
167 GNUNET_free (ctx->plugins); 157 GNUNET_free (ctx->plugins);
168 GNUNET_free (ctx); 158 GNUNET_free (ctx);
169} 159}
@@ -177,8 +167,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
177 * @return NULL if no matching plugin exists 167 * @return NULL if no matching plugin exists
178 */ 168 */
179static struct GNUNET_BLOCK_PluginFunctions * 169static struct GNUNET_BLOCK_PluginFunctions *
180find_plugin (struct GNUNET_BLOCK_Context *ctx, 170find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
181 enum GNUNET_BLOCK_Type type)
182{ 171{
183 struct Plugin *plugin; 172 struct Plugin *plugin;
184 unsigned int i; 173 unsigned int i;
@@ -186,16 +175,16 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
186 175
187 i = 0; 176 i = 0;
188 while (NULL != (plugin = ctx->plugins[i])) 177 while (NULL != (plugin = ctx->plugins[i]))
178 {
179 j = 0;
180 while (0 != (plugin->api->types[j]))
189 { 181 {
190 j = 0; 182 if (type == plugin->api->types[j])
191 while (0 != (plugin->api->types[j])) 183 return plugin->api;
192 { 184 j++;
193 if (type == plugin->api->types[j])
194 return plugin->api;
195 j++;
196 }
197 i++;
198 } 185 }
186 i++;
187 }
199 return NULL; 188 return NULL;
200} 189}
201 190
@@ -220,22 +209,21 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
220 */ 209 */
221enum GNUNET_BLOCK_EvaluationResult 210enum GNUNET_BLOCK_EvaluationResult
222GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, 211GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
223 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
224 const GNUNET_HashCode *query, 213 const GNUNET_HashCode * query,
225 struct GNUNET_CONTAINER_BloomFilter **bf, 214 struct GNUNET_CONTAINER_BloomFilter **bf,
226 int32_t bf_mutator, 215 int32_t bf_mutator,
227 const void *xquery, 216 const void *xquery,
228 size_t xquery_size, 217 size_t xquery_size,
229 const void *reply_block, 218 const void *reply_block, size_t reply_block_size)
230 size_t reply_block_size)
231{ 219{
232 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type); 220 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
233 221
234 if (plugin == NULL) 222 if (plugin == NULL)
235 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 223 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
236 return plugin->evaluate (plugin->cls, 224 return plugin->evaluate (plugin->cls,
237 type, query, bf, bf_mutator, 225 type, query, bf, bf_mutator,
238 xquery, xquery_size, reply_block, reply_block_size); 226 xquery, xquery_size, reply_block, reply_block_size);
239} 227}
240 228
241 229
@@ -252,17 +240,15 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
252 */ 240 */
253int 241int
254GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, 242GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
255 enum GNUNET_BLOCK_Type type, 243 enum GNUNET_BLOCK_Type type,
256 const void *block, 244 const void *block,
257 size_t block_size, 245 size_t block_size, GNUNET_HashCode * key)
258 GNUNET_HashCode *key)
259{ 246{
260 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type); 247 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
261 248
262 if (plugin == NULL) 249 if (plugin == NULL)
263 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 250 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
264 return plugin->get_key (plugin->cls, 251 return plugin->get_key (plugin->cls, type, block, block_size, key);
265 type, block, block_size, key);
266} 252}
267 253
268 254