summaryrefslogtreecommitdiff
path: root/src/dht/plugin_block_dht.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/plugin_block_dht.c')
-rw-r--r--src/dht/plugin_block_dht.c191
1 files changed, 95 insertions, 96 deletions
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index 918a18eb6..084384146 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -53,38 +53,38 @@
53 * by this @a type of block (this is not an error) 53 * by this @a type of block (this is not an error)
54 */ 54 */
55static struct GNUNET_BLOCK_Group * 55static struct GNUNET_BLOCK_Group *
56block_plugin_dht_create_group(void *cls, 56block_plugin_dht_create_group (void *cls,
57 enum GNUNET_BLOCK_Type type, 57 enum GNUNET_BLOCK_Type type,
58 uint32_t nonce, 58 uint32_t nonce,
59 const void *raw_data, 59 const void *raw_data,
60 size_t raw_data_size, 60 size_t raw_data_size,
61 va_list va) 61 va_list va)
62{ 62{
63 unsigned int bf_size; 63 unsigned int bf_size;
64 const char *guard; 64 const char *guard;
65 65
66 guard = va_arg(va, const char *); 66 guard = va_arg (va, const char *);
67 if (0 == strcmp(guard, 67 if (0 == strcmp (guard,
68 "seen-set-size")) 68 "seen-set-size"))
69 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, 69 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va,
70 unsigned int), 70 unsigned int),
71 BLOOMFILTER_K); 71 BLOOMFILTER_K);
72 else if (0 == strcmp(guard, 72 else if (0 == strcmp (guard,
73 "filter-size")) 73 "filter-size"))
74 bf_size = va_arg(va, unsigned int); 74 bf_size = va_arg (va, unsigned int);
75 else 75 else
76 { 76 {
77 GNUNET_break(0); 77 GNUNET_break (0);
78 bf_size = 8; 78 bf_size = 8;
79 } 79 }
80 GNUNET_break(NULL == va_arg(va, const char *)); 80 GNUNET_break (NULL == va_arg (va, const char *));
81 return GNUNET_BLOCK_GROUP_bf_create(cls, 81 return GNUNET_BLOCK_GROUP_bf_create (cls,
82 bf_size, 82 bf_size,
83 BLOOMFILTER_K, 83 BLOOMFILTER_K,
84 type, 84 type,
85 nonce, 85 nonce,
86 raw_data, 86 raw_data,
87 raw_data_size); 87 raw_data_size);
88} 88}
89 89
90 90
@@ -105,16 +105,16 @@ block_plugin_dht_create_group(void *cls,
105 * @return characterization of result 105 * @return characterization of result
106 */ 106 */
107static enum GNUNET_BLOCK_EvaluationResult 107static enum GNUNET_BLOCK_EvaluationResult
108block_plugin_dht_evaluate(void *cls, 108block_plugin_dht_evaluate (void *cls,
109 struct GNUNET_BLOCK_Context *ctx, 109 struct GNUNET_BLOCK_Context *ctx,
110 enum GNUNET_BLOCK_Type type, 110 enum GNUNET_BLOCK_Type type,
111 struct GNUNET_BLOCK_Group *group, 111 struct GNUNET_BLOCK_Group *group,
112 enum GNUNET_BLOCK_EvaluationOptions eo, 112 enum GNUNET_BLOCK_EvaluationOptions eo,
113 const struct GNUNET_HashCode *query, 113 const struct GNUNET_HashCode *query,
114 const void *xquery, 114 const void *xquery,
115 size_t xquery_size, 115 size_t xquery_size,
116 const void *reply_block, 116 const void *reply_block,
117 size_t reply_block_size) 117 size_t reply_block_size)
118{ 118{
119 const struct GNUNET_HELLO_Message *hello; 119 const struct GNUNET_HELLO_Message *hello;
120 struct GNUNET_PeerIdentity pid; 120 struct GNUNET_PeerIdentity pid;
@@ -124,35 +124,35 @@ block_plugin_dht_evaluate(void *cls,
124 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 124 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
126 if (0 != xquery_size) 126 if (0 != xquery_size)
127 { 127 {
128 GNUNET_break_op(0); 128 GNUNET_break_op (0);
129 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 129 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
130 } 130 }
131 if (NULL == reply_block) 131 if (NULL == reply_block)
132 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 132 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
133 if (reply_block_size < sizeof(struct GNUNET_MessageHeader)) 133 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
134 { 134 {
135 GNUNET_break_op(0); 135 GNUNET_break_op (0);
136 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 136 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
137 } 137 }
138 msg = reply_block; 138 msg = reply_block;
139 if (reply_block_size != ntohs(msg->size)) 139 if (reply_block_size != ntohs (msg->size))
140 { 140 {
141 GNUNET_break_op(0); 141 GNUNET_break_op (0);
142 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 142 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
143 } 143 }
144 hello = reply_block; 144 hello = reply_block;
145 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) 145 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
146 { 146 {
147 GNUNET_break_op(0); 147 GNUNET_break_op (0);
148 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 148 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
149 } 149 }
150 GNUNET_CRYPTO_hash(&pid, 150 GNUNET_CRYPTO_hash (&pid,
151 sizeof(pid), 151 sizeof(pid),
152 &phash); 152 &phash);
153 if (GNUNET_YES == 153 if (GNUNET_YES ==
154 GNUNET_BLOCK_GROUP_bf_test_and_set(group, 154 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
155 &phash)) 155 &phash))
156 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 156 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
157 return GNUNET_BLOCK_EVALUATION_OK_MORE; 157 return GNUNET_BLOCK_EVALUATION_OK_MORE;
158} 158}
@@ -170,11 +170,11 @@ block_plugin_dht_evaluate(void *cls,
170 * (or if extracting a key from a block of this type does not work) 170 * (or if extracting a key from a block of this type does not work)
171 */ 171 */
172static int 172static int
173block_plugin_dht_get_key(void *cls, 173block_plugin_dht_get_key (void *cls,
174 enum GNUNET_BLOCK_Type type, 174 enum GNUNET_BLOCK_Type type,
175 const void *block, 175 const void *block,
176 size_t block_size, 176 size_t block_size,
177 struct GNUNET_HashCode *key) 177 struct GNUNET_HashCode *key)
178{ 178{
179 const struct GNUNET_MessageHeader *msg; 179 const struct GNUNET_MessageHeader *msg;
180 const struct GNUNET_HELLO_Message *hello; 180 const struct GNUNET_HELLO_Message *hello;
@@ -183,33 +183,33 @@ block_plugin_dht_get_key(void *cls,
183 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 183 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
184 return GNUNET_SYSERR; 184 return GNUNET_SYSERR;
185 if (block_size < sizeof(struct GNUNET_MessageHeader)) 185 if (block_size < sizeof(struct GNUNET_MessageHeader))
186 { 186 {
187 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, 187 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
188 "block-dht", 188 "block-dht",
189 _("Block not of type %u\n"), 189 _ ("Block not of type %u\n"),
190 GNUNET_BLOCK_TYPE_DHT_HELLO); 190 GNUNET_BLOCK_TYPE_DHT_HELLO);
191 return GNUNET_NO; 191 return GNUNET_NO;
192 } 192 }
193 msg = block; 193 msg = block;
194 if (block_size != ntohs(msg->size)) 194 if (block_size != ntohs (msg->size))
195 { 195 {
196 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
197 "block-dht", 197 "block-dht",
198 _("Size mismatch for block\n"), 198 _ ("Size mismatch for block\n"),
199 GNUNET_BLOCK_TYPE_DHT_HELLO); 199 GNUNET_BLOCK_TYPE_DHT_HELLO);
200 return GNUNET_NO; 200 return GNUNET_NO;
201 } 201 }
202 hello = block; 202 hello = block;
203 memset(key, 0, sizeof(*key)); 203 memset (key, 0, sizeof(*key));
204 pid = (struct GNUNET_PeerIdentity *)key; 204 pid = (struct GNUNET_PeerIdentity *) key;
205 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, pid)) 205 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
206 { 206 {
207 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, 207 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
208 "block-dht", 208 "block-dht",
209 _("Block of type %u is malformed\n"), 209 _ ("Block of type %u is malformed\n"),
210 GNUNET_BLOCK_TYPE_DHT_HELLO); 210 GNUNET_BLOCK_TYPE_DHT_HELLO);
211 return GNUNET_NO; 211 return GNUNET_NO;
212 } 212 }
213 return GNUNET_OK; 213 return GNUNET_OK;
214} 214}
215 215
@@ -218,16 +218,15 @@ block_plugin_dht_get_key(void *cls,
218 * Entry point for the plugin. 218 * Entry point for the plugin.
219 */ 219 */
220void * 220void *
221libgnunet_plugin_block_dht_init(void *cls) 221libgnunet_plugin_block_dht_init (void *cls)
222{ 222{
223 static enum GNUNET_BLOCK_Type types[] = 223 static enum GNUNET_BLOCK_Type types[] = {
224 {
225 GNUNET_BLOCK_TYPE_DHT_HELLO, 224 GNUNET_BLOCK_TYPE_DHT_HELLO,
226 GNUNET_BLOCK_TYPE_ANY /* end of list */ 225 GNUNET_BLOCK_TYPE_ANY /* end of list */
227 }; 226 };
228 struct GNUNET_BLOCK_PluginFunctions *api; 227 struct GNUNET_BLOCK_PluginFunctions *api;
229 228
230 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); 229 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
231 api->evaluate = &block_plugin_dht_evaluate; 230 api->evaluate = &block_plugin_dht_evaluate;
232 api->get_key = &block_plugin_dht_get_key; 231 api->get_key = &block_plugin_dht_get_key;
233 api->create_group = &block_plugin_dht_create_group; 232 api->create_group = &block_plugin_dht_create_group;
@@ -240,11 +239,11 @@ libgnunet_plugin_block_dht_init(void *cls)
240 * Exit point from the plugin. 239 * Exit point from the plugin.
241 */ 240 */
242void * 241void *
243libgnunet_plugin_block_dht_done(void *cls) 242libgnunet_plugin_block_dht_done (void *cls)
244{ 243{
245 struct GNUNET_BLOCK_PluginFunctions *api = cls; 244 struct GNUNET_BLOCK_PluginFunctions *api = cls;
246 245
247 GNUNET_free(api); 246 GNUNET_free (api);
248 return NULL; 247 return NULL;
249} 248}
250 249