aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-service-set.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/gnunet-service-set.c')
-rw-r--r--src/set/gnunet-service-set.c74
1 files changed, 40 insertions, 34 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c
index d6258aa78..314e7719d 100644
--- a/src/set/gnunet-service-set.c
+++ b/src/set/gnunet-service-set.c
@@ -84,7 +84,7 @@ static uint32_t request_id = 1;
84 * @param client the client to disconnect 84 * @param client the client to disconnect
85 */ 85 */
86void 86void
87client_disconnect (struct GNUNET_SERVER_Client *client) 87_GSS_client_disconnect (struct GNUNET_SERVER_Client *client)
88{ 88{
89 /* FIXME: clean up any data structures belonging to the client */ 89 /* FIXME: clean up any data structures belonging to the client */
90 GNUNET_SERVER_client_disconnect (client); 90 GNUNET_SERVER_client_disconnect (client);
@@ -170,6 +170,7 @@ destroy_incoming (struct Incoming *incoming)
170 * @param cls the incoming socket 170 * @param cls the incoming socket
171 * @param mh the message 171 * @param mh the message
172 */ 172 */
173
173static void 174static void
174handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh) 175handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh)
175{ 176{
@@ -180,6 +181,8 @@ handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh)
180 struct Listener *listener; 181 struct Listener *listener;
181 const struct GNUNET_MessageHeader *context_msg; 182 const struct GNUNET_MessageHeader *context_msg;
182 183
184 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "got operation request\n");
185
183 if (ntohs (mh->size) < sizeof *msg) 186 if (ntohs (mh->size) < sizeof *msg)
184 { 187 {
185 GNUNET_break (0); 188 GNUNET_break (0);
@@ -201,18 +204,28 @@ handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh)
201 return; 204 return;
202 } 205 }
203 } 206 }
204 207 /* find the appropriate listener */
205 for (listener = listeners_head; listener != NULL; listener = listener->next) 208 for (listener = listeners_head;
209 listener != NULL;
210 listener = listener->next)
206 { 211 {
207 if ( (0 != GNUNET_CRYPTO_hash_cmp (&msg->app_id, &listener->app_id)) || 212 if ( (0 != GNUNET_CRYPTO_hash_cmp (&msg->app_id, &listener->app_id)) ||
208 (htons (msg->operation) != listener->operation) ) 213 (htons (msg->operation) != listener->operation) )
209 continue; 214 continue;
210 mqm = GNUNET_MQ_msg_concat (cmsg, context_msg, GNUNET_MESSAGE_TYPE_SET_REQUEST); 215 mqm = GNUNET_MQ_msg (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST);
216 if (GNUNET_OK !=
217 GNUNET_MQ_nest (mqm, context_msg))
218 {
219 /* FIXME: disconnect the peer */
220 GNUNET_MQ_discard (mqm);
221 GNUNET_break (0);
222 }
211 incoming->request_id = request_id++; 223 incoming->request_id = request_id++;
212 cmsg->request_id = htonl (incoming->request_id); 224 cmsg->request_id = htonl (incoming->request_id);
213 GNUNET_MQ_send (listener->client_mq, mqm); 225 GNUNET_MQ_send (listener->client_mq, mqm);
214 return; 226 return;
215 } 227 }
228 /* FIXME: send a reject message */
216} 229}
217 230
218 231
@@ -249,7 +262,7 @@ handle_client_create (void *cls,
249 GNUNET_assert (0); 262 GNUNET_assert (0);
250 break; 263 break;
251 case GNUNET_SET_OPERATION_UNION: 264 case GNUNET_SET_OPERATION_UNION:
252 set = union_set_create (); 265 set = _GSS_union_set_create ();
253 break; 266 break;
254 default: 267 default:
255 GNUNET_free (set); 268 GNUNET_free (set);
@@ -261,7 +274,7 @@ handle_client_create (void *cls,
261 set->client = client; 274 set->client = client;
262 set->client_mq = GNUNET_MQ_queue_for_server_client (client); 275 set->client_mq = GNUNET_MQ_queue_for_server_client (client);
263 GNUNET_CONTAINER_DLL_insert (sets_head, sets_tail, set); 276 GNUNET_CONTAINER_DLL_insert (sets_head, sets_tail, set);
264 277
265 GNUNET_SERVER_receive_done (client, GNUNET_OK); 278 GNUNET_SERVER_receive_done (client, GNUNET_OK);
266} 279}
267 280
@@ -292,6 +305,8 @@ handle_client_listen (void *cls,
292 listener->app_id = msg->app_id; 305 listener->app_id = msg->app_id;
293 listener->operation = msg->operation; 306 listener->operation = msg->operation;
294 GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener); 307 GNUNET_CONTAINER_DLL_insert_tail (listeners_head, listeners_tail, listener);
308
309 GNUNET_SERVER_receive_done (client, GNUNET_OK);
295} 310}
296 311
297 312
@@ -313,14 +328,13 @@ handle_client_add (void *cls,
313 if (NULL == set) 328 if (NULL == set)
314 { 329 {
315 GNUNET_break (0); 330 GNUNET_break (0);
316 client_disconnect (client); 331 _GSS_client_disconnect (client);
317 return; 332 return;
318 } 333 }
319 switch (set->operation) 334 switch (set->operation)
320 { 335 {
321 case GNUNET_SET_OPERATION_UNION: 336 case GNUNET_SET_OPERATION_UNION:
322 union_add (set, (struct ElementMessage *) m); 337 _GSS_union_add ((struct ElementMessage *) m, set);
323 break;
324 case GNUNET_SET_OPERATION_INTERSECTION: 338 case GNUNET_SET_OPERATION_INTERSECTION:
325 /* FIXME: cfuchs */ 339 /* FIXME: cfuchs */
326 break; 340 break;
@@ -328,6 +342,8 @@ handle_client_add (void *cls,
328 GNUNET_assert (0); 342 GNUNET_assert (0);
329 break; 343 break;
330 } 344 }
345
346 GNUNET_SERVER_receive_done (client, GNUNET_OK);
331} 347}
332 348
333 349
@@ -344,24 +360,15 @@ handle_client_evaluate (void *cls,
344 const struct GNUNET_MessageHeader *m) 360 const struct GNUNET_MessageHeader *m)
345{ 361{
346 struct Set *set; 362 struct Set *set;
347 struct EvaluateMessage *msg = (struct EvaluateMessage *) m;
348 struct EvaluateOperation *eo;
349 363
350 set = get_set (client); 364 set = get_set (client);
351
352 if (NULL == set) 365 if (NULL == set)
353 { 366 {
354 GNUNET_break (0); 367 GNUNET_break (0);
355 client_disconnect (client); 368 _GSS_client_disconnect (client);
356 return; 369 return;
357 } 370 }
358 371
359 eo = GNUNET_new (struct EvaluateOperation);
360 eo->peer = msg->peer;
361 eo->app_id = msg->app_id;
362 eo->request_id = msg->request_id;
363 eo->context_msg = GNUNET_copy_message (&msg[1].header);
364 eo->set = set;
365 372
366 switch (set->operation) 373 switch (set->operation)
367 { 374 {
@@ -369,12 +376,14 @@ handle_client_evaluate (void *cls,
369 /* FIXME: cfuchs */ 376 /* FIXME: cfuchs */
370 break; 377 break;
371 case GNUNET_SET_OPERATION_UNION: 378 case GNUNET_SET_OPERATION_UNION:
372 union_evaluate (eo); 379 _GSS_union_evaluate ((struct EvaluateMessage *) m, set);
373 break; 380 break;
374 default: 381 default:
375 GNUNET_assert (0); 382 GNUNET_assert (0);
376 break; 383 break;
377 } 384 }
385
386 GNUNET_SERVER_receive_done (client, GNUNET_OK);
378} 387}
379 388
380 389
@@ -391,6 +400,7 @@ handle_client_cancel (void *cls,
391 const struct GNUNET_MessageHeader *m) 400 const struct GNUNET_MessageHeader *m)
392{ 401{
393 /* FIXME: implement */ 402 /* FIXME: implement */
403 GNUNET_SERVER_receive_done (client, GNUNET_OK);
394} 404}
395 405
396 406
@@ -407,6 +417,7 @@ handle_client_ack (void *cls,
407 const struct GNUNET_MessageHeader *m) 417 const struct GNUNET_MessageHeader *m)
408{ 418{
409 /* FIXME: implement */ 419 /* FIXME: implement */
420 GNUNET_SERVER_receive_done (client, GNUNET_OK);
410} 421}
411 422
412 423
@@ -421,19 +432,18 @@ handle_client_ack (void *cls,
421static void 432static void
422handle_client_accept (void *cls, 433handle_client_accept (void *cls,
423 struct GNUNET_SERVER_Client *client, 434 struct GNUNET_SERVER_Client *client,
424 const struct GNUNET_MessageHeader *m) 435 const struct GNUNET_MessageHeader *mh)
425{ 436{
426 struct AcceptMessage *msg = (struct AcceptMessage *) m;
427 struct Set *set; 437 struct Set *set;
428 struct Incoming *incoming; 438 struct Incoming *incoming;
429 struct EvaluateOperation *eo; 439 struct AcceptMessage *msg = (struct AcceptMessage *) mh;
430 440
431 set = get_set (client); 441 set = get_set (client);
432 442
433 if (NULL == set) 443 if (NULL == set)
434 { 444 {
435 GNUNET_break (0); 445 GNUNET_break (0);
436 client_disconnect (client); 446 _GSS_client_disconnect (client);
437 return; 447 return;
438 } 448 }
439 449
@@ -443,16 +453,10 @@ handle_client_accept (void *cls,
443 (incoming->operation != set->operation) ) 453 (incoming->operation != set->operation) )
444 { 454 {
445 GNUNET_break (0); 455 GNUNET_break (0);
446 client_disconnect (client); 456 _GSS_client_disconnect (client);
447 return; 457 return;
448 } 458 }
449 459
450 eo = GNUNET_new (struct EvaluateOperation);
451 eo->peer = incoming->peer;
452 eo->app_id = incoming->app_id;
453 eo->request_id = msg->request_id;
454 eo->set = set;
455
456 switch (set->operation) 460 switch (set->operation)
457 { 461 {
458 case GNUNET_SET_OPERATION_INTERSECTION: 462 case GNUNET_SET_OPERATION_INTERSECTION:
@@ -460,12 +464,15 @@ handle_client_accept (void *cls,
460 GNUNET_assert (0); 464 GNUNET_assert (0);
461 break; 465 break;
462 case GNUNET_SET_OPERATION_UNION: 466 case GNUNET_SET_OPERATION_UNION:
463 union_accept (eo, incoming); 467 _GSS_union_accept (msg, set, incoming);
464 break; 468 break;
465 default: 469 default:
466 GNUNET_assert (0); 470 GNUNET_assert (0);
467 break; 471 break;
468 } 472 }
473 /* FIXME: destroy incoming */
474
475 GNUNET_SERVER_receive_done (client, GNUNET_OK);
469} 476}
470 477
471 478
@@ -522,7 +529,7 @@ shutdown_task (void *cls,
522 { 529 {
523 GNUNET_STREAM_listen_close (stream_listen_socket); 530 GNUNET_STREAM_listen_close (stream_listen_socket);
524 stream_listen_socket = NULL; 531 stream_listen_socket = NULL;
525 } 532 }
526 533
527 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "handled shutdown request\n"); 534 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "handled shutdown request\n");
528} 535}
@@ -575,4 +582,3 @@ main (int argc, char *const *argv)
575 return (GNUNET_OK == ret) ? 0 : 1; 582 return (GNUNET_OK == ret) ? 0 : 1;
576} 583}
577 584
578