diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-07 22:12:26 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-07 22:12:26 +0000 |
commit | f4736ff5d86734375c446d80650742d57ebe0ee9 (patch) | |
tree | 1b06834b41018688a491dc0878f30051f422c27a /src/rps | |
parent | 48c87dc9de44e62a146399d1ed180da8a4c88f49 (diff) | |
download | gnunet-f4736ff5d86734375c446d80650742d57ebe0ee9.tar.gz gnunet-f4736ff5d86734375c446d80650742d57ebe0ee9.zip |
checking msg sizes, cosmetic changes
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 65 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 1 |
2 files changed, 39 insertions, 27 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 5d473a6e9..130fef535 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -54,6 +54,8 @@ | |||
54 | 54 | ||
55 | // TODO store peers somewhere | 55 | // TODO store peers somewhere |
56 | 56 | ||
57 | // TODO check that every id we get is valid - is it reachable? | ||
58 | |||
57 | // hist_size_init, hist_size_max | 59 | // hist_size_init, hist_size_max |
58 | 60 | ||
59 | /** | 61 | /** |
@@ -330,7 +332,7 @@ get_channel (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET | |||
330 | GNUNET_RPS_CADET_PORT, | 332 | GNUNET_RPS_CADET_PORT, |
331 | GNUNET_CADET_OPTION_RELIABLE); | 333 | GNUNET_CADET_OPTION_RELIABLE); |
332 | // do I have to explicitly put it in the peer_map? | 334 | // do I have to explicitly put it in the peer_map? |
333 | GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, | 335 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, |
334 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 336 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
335 | } | 337 | } |
336 | return ctx->to_channel; | 338 | return ctx->to_channel; |
@@ -354,7 +356,7 @@ get_mq (struct GNUNET_CONTAINER_MultiPeerMap *peer_map, const struct GNUNET_Peer | |||
354 | (void) get_channel (peer_map, peer_id); | 356 | (void) get_channel (peer_map, peer_id); |
355 | ctx->mq = GNUNET_CADET_mq_create (ctx->to_channel); | 357 | ctx->mq = GNUNET_CADET_mq_create (ctx->to_channel); |
356 | //do I have to explicitly put it in the peer_map? | 358 | //do I have to explicitly put it in the peer_map? |
357 | GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, ctx, | 359 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, peer_id, ctx, |
358 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 360 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
359 | } | 361 | } |
360 | return ctx->mq; | 362 | return ctx->mq; |
@@ -461,7 +463,7 @@ handle_cs_request (void *cls, | |||
461 | peers, | 463 | peers, |
462 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 464 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
463 | 465 | ||
464 | GNUNET_MQ_send(cli_ctx->mq, ev); | 466 | GNUNET_MQ_send (cli_ctx->mq, ev); |
465 | //GNUNET_MQ_destroy(mq); | 467 | //GNUNET_MQ_destroy(mq); |
466 | 468 | ||
467 | GNUNET_SERVER_receive_done (client, | 469 | GNUNET_SERVER_receive_done (client, |
@@ -489,6 +491,13 @@ handle_peer_push (void *cls, | |||
489 | 491 | ||
490 | // (check the proof of work) | 492 | // (check the proof of work) |
491 | 493 | ||
494 | // TODO accept empty message | ||
495 | if (ntohs(msg->size) != sizeof (struct GNUNET_RPS_P2P_PushMessage)) | ||
496 | { | ||
497 | GNUNET_break_op (0); // At the moment our own implementation seems to break that. | ||
498 | return GNUNET_SYSERR; | ||
499 | } | ||
500 | |||
492 | peer = (const struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); | 501 | peer = (const struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); |
493 | // FIXME wait for cadet to change this function | 502 | // FIXME wait for cadet to change this function |
494 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PUSH received (%s)\n", GNUNET_i2s (peer)); | 503 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PUSH received (%s)\n", GNUNET_i2s (peer)); |
@@ -517,27 +526,26 @@ handle_peer_pull_request (void *cls, | |||
517 | void **channel_ctx, | 526 | void **channel_ctx, |
518 | const struct GNUNET_MessageHeader *msg) | 527 | const struct GNUNET_MessageHeader *msg) |
519 | { | 528 | { |
520 | |||
521 | struct GNUNET_PeerIdentity *peer; | 529 | struct GNUNET_PeerIdentity *peer; |
522 | struct GNUNET_MQ_Handle *mq; | 530 | struct GNUNET_MQ_Handle *mq; |
523 | //struct GNUNET_RPS_P2P_PullRequestMessage *in_msg; | ||
524 | struct GNUNET_MQ_Envelope *ev; | 531 | struct GNUNET_MQ_Envelope *ev; |
525 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; | 532 | struct GNUNET_RPS_P2P_PullReplyMessage *out_msg; |
526 | 533 | ||
527 | // find some way to keep one peer from spamming with pull requests? | 534 | // assert that msg->size is 0 |
528 | // allow only one request per time interval ? | 535 | |
529 | // otherwise remove from peerlist? | 536 | // TODO accept empty message |
537 | if (ntohs(msg->size) != sizeof (struct GNUNET_RPS_P2P_PullRequestMessage)) | ||
538 | { | ||
539 | GNUNET_break_op (0); // At the moment our own implementation seems to break that. | ||
540 | return GNUNET_SYSERR; | ||
541 | } | ||
530 | 542 | ||
531 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); | 543 | peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (channel, GNUNET_CADET_OPTION_PEER); |
532 | // FIXME wait for cadet to change this function | 544 | // FIXME wait for cadet to change this function |
533 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REQUEST from peer %s received\n", GNUNET_i2s (peer)); | 545 | LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REQUEST from peer %s received\n", GNUNET_i2s (peer)); |
534 | 546 | ||
535 | //mq = GNUNET_CADET_mq_create(channel); // without mq? | ||
536 | mq = get_mq (peer_map, peer); | 547 | mq = get_mq (peer_map, peer); |
537 | 548 | ||
538 | //in_msg = (struct GNUNET_RPS_P2P_PullRequestMessage *) msg; | ||
539 | // TODO how many peers do we actually send? | ||
540 | // GNUNET_ntohll(in_msg->num_peers) | ||
541 | ev = GNUNET_MQ_msg_extra (out_msg, | 549 | ev = GNUNET_MQ_msg_extra (out_msg, |
542 | gossip_list_size * sizeof (struct GNUNET_PeerIdentity), | 550 | gossip_list_size * sizeof (struct GNUNET_PeerIdentity), |
543 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); | 551 | GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY); |
@@ -573,24 +581,28 @@ handle_peer_pull_reply (void *cls, | |||
573 | struct GNUNET_PeerIdentity *peers; | 581 | struct GNUNET_PeerIdentity *peers; |
574 | uint64_t i; | 582 | uint64_t i; |
575 | 583 | ||
576 | // TODO check that we sent a request and that it is the first reply | ||
577 | if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) < ntohs (msg->size)) | 584 | if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) < ntohs (msg->size)) |
578 | { | 585 | { |
579 | GNUNET_break_op (0); // At the moment our own implementation seems to break that. | 586 | GNUNET_break_op (0); // At the moment our own implementation seems to break that. |
580 | return GNUNET_SYSERR; | 587 | return GNUNET_SYSERR; |
581 | } | 588 | } |
582 | in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; | 589 | in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; |
583 | if (ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) / sizeof (struct GNUNET_PeerIdentity) != GNUNET_ntohll (in_msg->num_peers)) | 590 | if (ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) / sizeof (struct GNUNET_PeerIdentity) != GNUNET_ntohll (in_msg->num_peers)) |
584 | { | 591 | { |
585 | GNUNET_break_op (0); | 592 | GNUNET_break_op (0); |
586 | return GNUNET_SYSERR; | 593 | return GNUNET_SYSERR; |
587 | } | 594 | } |
595 | |||
596 | // TODO check that we sent a request and that it is the first reply | ||
597 | |||
588 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 598 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
589 | for ( i = 0 ; i < GNUNET_ntohll (in_msg->num_peers) ; i++ ) | 599 | for ( i = 0 ; i < GNUNET_ntohll (in_msg->num_peers) ; i++ ) |
590 | { | 600 | { |
591 | GNUNET_array_append (pull_list, pull_list_size, peers[i]); | 601 | GNUNET_array_append (pull_list, pull_list_size, peers[i]); |
592 | } | 602 | } |
593 | 603 | ||
604 | // TODO check that id is valid - whether it is reachable | ||
605 | |||
594 | return GNUNET_OK; | 606 | return GNUNET_OK; |
595 | } | 607 | } |
596 | 608 | ||
@@ -641,7 +653,8 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
641 | //ev = GNUNET_MQ_msg_extra(); | 653 | //ev = GNUNET_MQ_msg_extra(); |
642 | /* TODO Compute proof of work here | 654 | /* TODO Compute proof of work here |
643 | push_msg; */ | 655 | push_msg; */ |
644 | push_msg->placeholder = 0; | 656 | //push_msg->placeholder = 0; |
657 | push_msg = NULL; | ||
645 | // FIXME sometimes it returns a pointer to a freed mq | 658 | // FIXME sometimes it returns a pointer to a freed mq |
646 | mq = get_mq (peer_map, peer); | 659 | mq = get_mq (peer_map, peer); |
647 | GNUNET_MQ_send (mq, ev); | 660 | GNUNET_MQ_send (mq, ev); |
@@ -660,13 +673,12 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
660 | n_peers, beta, gossip_list_size); | 673 | n_peers, beta, gossip_list_size); |
661 | for ( i = 0 ; i < n_peers ; i++ ) | 674 | for ( i = 0 ; i < n_peers ; i++ ) |
662 | { // TODO compute length | 675 | { // TODO compute length |
663 | peer = get_rand_peer(gossip_list, gossip_list_size); | 676 | peer = get_rand_peer (gossip_list, gossip_list_size); |
664 | if (own_identity != peer) | 677 | if (own_identity != peer) |
665 | { // FIXME if this fails schedule/loop this for later | 678 | { // FIXME if this fails schedule/loop this for later |
666 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s (peer)); | 679 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s (peer)); |
667 | 680 | ||
668 | ev = GNUNET_MQ_msg(pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 681 | ev = GNUNET_MQ_msg (pull_msg, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
669 | //ev = GNUNET_MQ_msg_extra(); | ||
670 | //pull_msg->placeholder = 0; | 682 | //pull_msg->placeholder = 0; |
671 | pull_msg = NULL; | 683 | pull_msg = NULL; |
672 | mq = get_mq (peer_map, peer); | 684 | mq = get_mq (peer_map, peer); |
@@ -713,7 +725,7 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
713 | for ( i = second_border ; i < gossip_list_size ; i++ ) | 725 | for ( i = second_border ; i < gossip_list_size ; i++ ) |
714 | { | 726 | { |
715 | /* Update gossip list with peers from history */ | 727 | /* Update gossip list with peers from history */ |
716 | peer = RPS_sampler_get_rand_peer (); | 728 | peer = RPS_sampler_get_n_rand_peers (1), |
717 | gossip_list[i] = *peer; | 729 | gossip_list[i] = *peer; |
718 | // TODO change the in_flags accordingly | 730 | // TODO change the in_flags accordingly |
719 | } | 731 | } |
@@ -743,9 +755,7 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
743 | 755 | ||
744 | /* Empty push/pull lists */ | 756 | /* Empty push/pull lists */ |
745 | GNUNET_array_grow (push_list, push_list_size, 0); | 757 | GNUNET_array_grow (push_list, push_list_size, 0); |
746 | push_list_size = 0; // I guess that's not necessary but doesn't hurt | ||
747 | GNUNET_array_grow (pull_list, pull_list_size, 0); | 758 | GNUNET_array_grow (pull_list, pull_list_size, 0); |
748 | pull_list_size = 0; // I guess that's not necessary but doesn't hurt | ||
749 | 759 | ||
750 | 760 | ||
751 | /* Schedule next round */ | 761 | /* Schedule next round */ |
@@ -753,6 +763,7 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
753 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); | 763 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); |
754 | } | 764 | } |
755 | 765 | ||
766 | |||
756 | /** | 767 | /** |
757 | * Open a connection to given peer and store channel and mq. | 768 | * Open a connection to given peer and store channel and mq. |
758 | */ | 769 | */ |
@@ -763,6 +774,7 @@ insertCB (void *cls, const struct GNUNET_PeerIdentity *id) | |||
763 | (void) get_channel (peer_map, id); | 774 | (void) get_channel (peer_map, id); |
764 | } | 775 | } |
765 | 776 | ||
777 | |||
766 | /** | 778 | /** |
767 | * Close the connection to given peer and delete channel and mq. | 779 | * Close the connection to given peer and delete channel and mq. |
768 | */ | 780 | */ |
@@ -788,7 +800,7 @@ removeCB (void *cls, const struct GNUNET_PeerIdentity *id) | |||
788 | //GNUNET_CADET_channel_destroy (ctx->to_channel); | 800 | //GNUNET_CADET_channel_destroy (ctx->to_channel); |
789 | } | 801 | } |
790 | // TODO cleanup peer | 802 | // TODO cleanup peer |
791 | GNUNET_CONTAINER_multipeermap_remove_all(peer_map, id); | 803 | (void) GNUNET_CONTAINER_multipeermap_remove_all (peer_map, id); |
792 | } | 804 | } |
793 | } | 805 | } |
794 | } | 806 | } |
@@ -835,7 +847,7 @@ init_peer_cb (void *cls, | |||
835 | if (ipc->i < gossip_list_size) | 847 | if (ipc->i < gossip_list_size) |
836 | { | 848 | { |
837 | memcpy(&gossip_list[ipc->i], | 849 | memcpy(&gossip_list[ipc->i], |
838 | RPS_sampler_get_rand_peer (), | 850 | RPS_sampler_get_n_rand_peers (1), |
839 | (gossip_list_size - ipc->i) * sizeof(struct GNUNET_PeerIdentity)); | 851 | (gossip_list_size - ipc->i) * sizeof(struct GNUNET_PeerIdentity)); |
840 | } | 852 | } |
841 | rps_start (ipc->server); | 853 | rps_start (ipc->server); |
@@ -919,7 +931,7 @@ handle_inbound_channel (void *cls, | |||
919 | //ctx->in_flags = in_other_gossip_list; | 931 | //ctx->in_flags = in_other_gossip_list; |
920 | ctx->mq = NULL; // TODO create mq? | 932 | ctx->mq = NULL; // TODO create mq? |
921 | 933 | ||
922 | GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, ctx, | 934 | (void) GNUNET_CONTAINER_multipeermap_put (peer_map, initiator, ctx, |
923 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 935 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
924 | return NULL; // TODO | 936 | return NULL; // TODO |
925 | } | 937 | } |
@@ -951,9 +963,10 @@ cleanup_channel(void *cls, | |||
951 | */ | 963 | */ |
952 | static void | 964 | static void |
953 | rps_start (struct GNUNET_SERVER_Handle *server) | 965 | rps_start (struct GNUNET_SERVER_Handle *server) |
954 | { // TODO get msg sizes right | 966 | { |
955 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 967 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
956 | {&handle_cs_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, 0}, | 968 | {&handle_cs_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST, |
969 | sizeof (struct GNUNET_RPS_CS_RequestMessage)}, | ||
957 | {NULL, NULL, 0, 0} | 970 | {NULL, NULL, 0, 0} |
958 | }; | 971 | }; |
959 | 972 | ||
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index a74d304df..f1496f53a 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -513,7 +513,6 @@ RPS_sampler_get_rand_peer_ () | |||
513 | sampler->sampler_elements[r_index]->last_request = GNUNET_TIME_absolute_get(); | 513 | sampler->sampler_elements[r_index]->last_request = GNUNET_TIME_absolute_get(); |
514 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: Returning PeerID %s\n", GNUNET_i2s(peer)); | 514 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: Returning PeerID %s\n", GNUNET_i2s(peer)); |
515 | 515 | ||
516 | |||
517 | return peer; | 516 | return peer; |
518 | } | 517 | } |
519 | 518 | ||