diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-06-03 10:53:49 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-06-03 10:53:49 +0000 |
commit | 68403fa780bf94ace2ebc13c2c09463cbbc0b57c (patch) | |
tree | 3442e4f25de90eab67c4f9813cb6e433c50b7482 /src/set/gnunet-service-set.c | |
parent | fae7f583f2e11cac15fefcbefef64287ab6915d3 (diff) | |
download | gnunet-68403fa780bf94ace2ebc13c2c09463cbbc0b57c.tar.gz gnunet-68403fa780bf94ace2ebc13c2c09463cbbc0b57c.zip |
- conclude for SET
- consensus with SET
Diffstat (limited to 'src/set/gnunet-service-set.c')
-rw-r--r-- | src/set/gnunet-service-set.c | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/src/set/gnunet-service-set.c b/src/set/gnunet-service-set.c index 2aea50365..4da718879 100644 --- a/src/set/gnunet-service-set.c +++ b/src/set/gnunet-service-set.c | |||
@@ -226,6 +226,23 @@ destroy_incoming (struct Incoming *incoming) | |||
226 | GNUNET_free (incoming); | 226 | GNUNET_free (incoming); |
227 | } | 227 | } |
228 | 228 | ||
229 | static struct Listener * | ||
230 | get_listener_by_target (enum GNUNET_SET_OperationType op, | ||
231 | const struct GNUNET_HashCode *app_id) | ||
232 | { | ||
233 | struct Listener *l; | ||
234 | |||
235 | for (l = listeners_head; NULL != l; l = l->next) | ||
236 | { | ||
237 | if (l->operation != op) | ||
238 | continue; | ||
239 | if (0 != GNUNET_CRYPTO_hash_cmp (app_id, &l->app_id)) | ||
240 | continue; | ||
241 | return l; | ||
242 | } | ||
243 | return NULL; | ||
244 | } | ||
245 | |||
229 | 246 | ||
230 | /** | 247 | /** |
231 | * Handle a request for a set operation from | 248 | * Handle a request for a set operation from |
@@ -240,62 +257,33 @@ handle_p2p_operation_request (void *cls, const struct GNUNET_MessageHeader *mh) | |||
240 | struct Incoming *incoming = cls; | 257 | struct Incoming *incoming = cls; |
241 | const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh; | 258 | const struct OperationRequestMessage *msg = (const struct OperationRequestMessage *) mh; |
242 | struct GNUNET_MQ_Message *mqm; | 259 | struct GNUNET_MQ_Message *mqm; |
243 | struct RequestMessage *cmsg; | 260 | struct GNUNET_SET_RequestMessage *cmsg; |
244 | struct Listener *listener; | 261 | struct Listener *listener; |
245 | const struct GNUNET_MessageHeader *context_msg; | 262 | const struct GNUNET_MessageHeader *context_msg; |
246 | 263 | ||
247 | if (ntohs (mh->size) < sizeof *msg) | 264 | context_msg = GNUNET_MQ_extract_nested_mh (msg); |
265 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received P2P operation request (op %u, app %s)\n", | ||
266 | ntohs (msg->operation), GNUNET_h2s (&msg->app_id)); | ||
267 | listener = get_listener_by_target (ntohs (msg->operation), &msg->app_id); | ||
268 | if (NULL == listener) | ||
248 | { | 269 | { |
249 | /* message is to small for its type */ | 270 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
250 | GNUNET_break (0); | 271 | "set operation request from peer failed: " |
251 | destroy_incoming (incoming); | 272 | "no set with matching application ID and operation type\n"); |
252 | return; | 273 | return; |
253 | } | 274 | } |
254 | else if (ntohs (mh->size) == sizeof *msg) | 275 | mqm = GNUNET_MQ_msg_nested_mh (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST, context_msg); |
255 | { | 276 | if (NULL == mqm) |
256 | /* there is no context message */ | ||
257 | context_msg = NULL; | ||
258 | } | ||
259 | else | ||
260 | { | 277 | { |
261 | context_msg = &msg[1].header; | 278 | /* FIXME: disconnect the peer */ |
262 | if ((ntohs (context_msg->size) + sizeof *msg) != ntohs (msg->header.size)) | 279 | GNUNET_break_op (0); |
263 | { | ||
264 | /* size of context message is invalid */ | ||
265 | GNUNET_break (0); | ||
266 | destroy_incoming (incoming); | ||
267 | return; | ||
268 | } | ||
269 | } | ||
270 | |||
271 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "received P2P operation request (op %u, app %s)\n", | ||
272 | ntohs (msg->operation), GNUNET_h2s (&msg->app_id)); | ||
273 | |||
274 | /* find the appropriate listener */ | ||
275 | for (listener = listeners_head; | ||
276 | listener != NULL; | ||
277 | listener = listener->next) | ||
278 | { | ||
279 | if ( (0 != GNUNET_CRYPTO_hash_cmp (&msg->app_id, &listener->app_id)) || | ||
280 | (ntohs (msg->operation) != listener->operation) ) | ||
281 | continue; | ||
282 | mqm = GNUNET_MQ_msg (cmsg, GNUNET_MESSAGE_TYPE_SET_REQUEST); | ||
283 | if (GNUNET_OK != GNUNET_MQ_nest_mh (mqm, context_msg)) | ||
284 | { | ||
285 | /* FIXME: disconnect the peer */ | ||
286 | GNUNET_MQ_discard (mqm); | ||
287 | GNUNET_break (0); | ||
288 | return; | ||
289 | } | ||
290 | incoming->accept_id = accept_id++; | ||
291 | cmsg->accept_id = htonl (incoming->accept_id); | ||
292 | GNUNET_MQ_send (listener->client_mq, mqm); | ||
293 | return; | 280 | return; |
294 | } | 281 | } |
295 | 282 | incoming->accept_id = accept_id++; | |
296 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 283 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "sending request with accept id %u\n", incoming->accept_id); |
297 | "set operation request from peer failed: " | 284 | cmsg->accept_id = htonl (incoming->accept_id); |
298 | "no set with matching application ID and operation type\n"); | 285 | cmsg->peer_id = incoming->peer; |
286 | GNUNET_MQ_send (listener->client_mq, mqm); | ||
299 | } | 287 | } |
300 | 288 | ||
301 | 289 | ||
@@ -311,7 +299,7 @@ handle_client_create (void *cls, | |||
311 | struct GNUNET_SERVER_Client *client, | 299 | struct GNUNET_SERVER_Client *client, |
312 | const struct GNUNET_MessageHeader *m) | 300 | const struct GNUNET_MessageHeader *m) |
313 | { | 301 | { |
314 | struct SetCreateMessage *msg = (struct SetCreateMessage *) m; | 302 | struct GNUNET_SET_CreateMessage *msg = (struct GNUNET_SET_CreateMessage *) m; |
315 | struct Set *set; | 303 | struct Set *set; |
316 | 304 | ||
317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client created new set (operation %u)\n", | 305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client created new set (operation %u)\n", |
@@ -363,7 +351,7 @@ handle_client_listen (void *cls, | |||
363 | struct GNUNET_SERVER_Client *client, | 351 | struct GNUNET_SERVER_Client *client, |
364 | const struct GNUNET_MessageHeader *m) | 352 | const struct GNUNET_MessageHeader *m) |
365 | { | 353 | { |
366 | struct ListenMessage *msg = (struct ListenMessage *) m; | 354 | struct GNUNET_SET_ListenMessage *msg = (struct GNUNET_SET_ListenMessage *) m; |
367 | struct Listener *listener; | 355 | struct Listener *listener; |
368 | 356 | ||
369 | if (NULL != get_listener (client)) | 357 | if (NULL != get_listener (client)) |
@@ -410,7 +398,7 @@ handle_client_remove (void *cls, | |||
410 | switch (set->operation) | 398 | switch (set->operation) |
411 | { | 399 | { |
412 | case GNUNET_SET_OPERATION_UNION: | 400 | case GNUNET_SET_OPERATION_UNION: |
413 | _GSS_union_remove ((struct ElementMessage *) m, set); | 401 | _GSS_union_remove ((struct GNUNET_SET_ElementMessage *) m, set); |
414 | case GNUNET_SET_OPERATION_INTERSECTION: | 402 | case GNUNET_SET_OPERATION_INTERSECTION: |
415 | /* FIXME: cfuchs */ | 403 | /* FIXME: cfuchs */ |
416 | break; | 404 | break; |
@@ -423,6 +411,38 @@ handle_client_remove (void *cls, | |||
423 | } | 411 | } |
424 | 412 | ||
425 | 413 | ||
414 | |||
415 | /** | ||
416 | * Called when the client wants to reject an operation | ||
417 | * request from another peer. | ||
418 | * | ||
419 | * @param cls unused | ||
420 | * @param client client that sent the message | ||
421 | * @param m message sent by the client | ||
422 | */ | ||
423 | static void | ||
424 | handle_client_reject (void *cls, | ||
425 | struct GNUNET_SERVER_Client *client, | ||
426 | const struct GNUNET_MessageHeader *m) | ||
427 | { | ||
428 | struct Incoming *incoming; | ||
429 | struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) m; | ||
430 | |||
431 | GNUNET_break (0 == ntohl (msg->request_id)); | ||
432 | |||
433 | incoming = get_incoming (ntohl (msg->accept_reject_id)); | ||
434 | if (NULL == incoming) | ||
435 | { | ||
436 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
437 | return; | ||
438 | } | ||
439 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "peer request rejected by client\n"); | ||
440 | destroy_incoming (incoming); | ||
441 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
442 | } | ||
443 | |||
444 | |||
445 | |||
426 | /** | 446 | /** |
427 | * Called when a client wants to add an element to a | 447 | * Called when a client wants to add an element to a |
428 | * set it inhabits. | 448 | * set it inhabits. |
@@ -448,7 +468,7 @@ handle_client_add (void *cls, | |||
448 | switch (set->operation) | 468 | switch (set->operation) |
449 | { | 469 | { |
450 | case GNUNET_SET_OPERATION_UNION: | 470 | case GNUNET_SET_OPERATION_UNION: |
451 | _GSS_union_add ((struct ElementMessage *) m, set); | 471 | _GSS_union_add ((struct GNUNET_SET_ElementMessage *) m, set); |
452 | case GNUNET_SET_OPERATION_INTERSECTION: | 472 | case GNUNET_SET_OPERATION_INTERSECTION: |
453 | /* FIXME: cfuchs */ | 473 | /* FIXME: cfuchs */ |
454 | break; | 474 | break; |
@@ -490,7 +510,7 @@ handle_client_evaluate (void *cls, | |||
490 | /* FIXME: cfuchs */ | 510 | /* FIXME: cfuchs */ |
491 | break; | 511 | break; |
492 | case GNUNET_SET_OPERATION_UNION: | 512 | case GNUNET_SET_OPERATION_UNION: |
493 | _GSS_union_evaluate ((struct EvaluateMessage *) m, set); | 513 | _GSS_union_evaluate ((struct GNUNET_SET_EvaluateMessage *) m, set); |
494 | break; | 514 | break; |
495 | default: | 515 | default: |
496 | GNUNET_assert (0); | 516 | GNUNET_assert (0); |
@@ -502,23 +522,6 @@ handle_client_evaluate (void *cls, | |||
502 | 522 | ||
503 | 523 | ||
504 | /** | 524 | /** |
505 | * Handle a cancel request from a client. | ||
506 | * | ||
507 | * @param cls unused | ||
508 | * @param client the client | ||
509 | * @param m the cancel message | ||
510 | */ | ||
511 | static void | ||
512 | handle_client_cancel (void *cls, | ||
513 | struct GNUNET_SERVER_Client *client, | ||
514 | const struct GNUNET_MessageHeader *m) | ||
515 | { | ||
516 | /* FIXME: implement */ | ||
517 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
518 | } | ||
519 | |||
520 | |||
521 | /** | ||
522 | * Handle an ack from a client. | 525 | * Handle an ack from a client. |
523 | * | 526 | * |
524 | * @param cls unused | 527 | * @param cls unused |
@@ -550,25 +553,20 @@ handle_client_accept (void *cls, | |||
550 | { | 553 | { |
551 | struct Set *set; | 554 | struct Set *set; |
552 | struct Incoming *incoming; | 555 | struct Incoming *incoming; |
553 | struct AcceptMessage *msg = (struct AcceptMessage *) mh; | 556 | struct GNUNET_SET_AcceptRejectMessage *msg = (struct GNUNET_SET_AcceptRejectMessage *) mh; |
554 | 557 | ||
558 | incoming = get_incoming (ntohl (msg->accept_reject_id)); | ||
555 | 559 | ||
556 | incoming = get_incoming (ntohl (msg->accept_id)); | 560 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "client accepting %u\n", ntohl (msg->accept_reject_id)); |
557 | 561 | ||
558 | if (NULL == incoming) | 562 | if (NULL == incoming) |
559 | { | 563 | { |
564 | |||
560 | GNUNET_break (0); | 565 | GNUNET_break (0); |
561 | GNUNET_SERVER_client_disconnect (client); | 566 | GNUNET_SERVER_client_disconnect (client); |
562 | return; | 567 | return; |
563 | } | 568 | } |
564 | 569 | ||
565 | if (0 == ntohl (msg->request_id)) | ||
566 | { | ||
567 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "peer request rejected by client\n"); | ||
568 | destroy_incoming (incoming); | ||
569 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
570 | return; | ||
571 | } | ||
572 | 570 | ||
573 | set = get_set (client); | 571 | set = get_set (client); |
574 | 572 | ||
@@ -687,14 +685,14 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
687 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 685 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
688 | { | 686 | { |
689 | static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { | 687 | static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { |
688 | {handle_client_accept, NULL, GNUNET_MESSAGE_TYPE_SET_ACCEPT, 0}, | ||
689 | {handle_client_ack, NULL, GNUNET_MESSAGE_TYPE_SET_ACK, 0}, | ||
690 | {handle_client_add, NULL, GNUNET_MESSAGE_TYPE_SET_ADD, 0}, | ||
690 | {handle_client_create, NULL, GNUNET_MESSAGE_TYPE_SET_CREATE, 0}, | 691 | {handle_client_create, NULL, GNUNET_MESSAGE_TYPE_SET_CREATE, 0}, |
692 | {handle_client_evaluate, NULL, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 0}, | ||
691 | {handle_client_listen, NULL, GNUNET_MESSAGE_TYPE_SET_LISTEN, 0}, | 693 | {handle_client_listen, NULL, GNUNET_MESSAGE_TYPE_SET_LISTEN, 0}, |
692 | {handle_client_add, NULL, GNUNET_MESSAGE_TYPE_SET_ADD, 0}, | 694 | {handle_client_reject, NULL, GNUNET_MESSAGE_TYPE_SET_REJECT, 0}, |
693 | {handle_client_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0}, | 695 | {handle_client_remove, NULL, GNUNET_MESSAGE_TYPE_SET_REMOVE, 0}, |
694 | {handle_client_cancel, NULL, GNUNET_MESSAGE_TYPE_SET_CANCEL, 0}, | ||
695 | {handle_client_evaluate, NULL, GNUNET_MESSAGE_TYPE_SET_EVALUATE, 0}, | ||
696 | {handle_client_ack, NULL, GNUNET_MESSAGE_TYPE_SET_ACK, 0}, | ||
697 | {handle_client_accept, NULL, GNUNET_MESSAGE_TYPE_SET_ACCEPT, 0}, | ||
698 | {NULL, NULL, 0, 0} | 696 | {NULL, NULL, 0, 0} |
699 | }; | 697 | }; |
700 | 698 | ||
@@ -705,6 +703,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
705 | stream_listen_socket = GNUNET_STREAM_listen (cfg, GNUNET_APPLICATION_TYPE_SET, | 703 | stream_listen_socket = GNUNET_STREAM_listen (cfg, GNUNET_APPLICATION_TYPE_SET, |
706 | &stream_listen_cb, NULL, | 704 | &stream_listen_cb, NULL, |
707 | GNUNET_STREAM_OPTION_END); | 705 | GNUNET_STREAM_OPTION_END); |
706 | |||
707 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set service running\n"); | ||
708 | } | 708 | } |
709 | 709 | ||
710 | 710 | ||