diff options
author | Julius Bünger <buenger@mytum.de> | 2015-01-07 17:18:02 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-01-07 17:18:02 +0000 |
commit | 4d370bed62e5f6a47faba53fe3446a2d2a59d1ae (patch) | |
tree | e1ccd871c41b8b9e9d5003551510ad01086a2c78 /src/rps | |
parent | a028cee62cf2fa931a20281d7323437d615801c4 (diff) | |
download | gnunet-4d370bed62e5f6a47faba53fe3446a2d2a59d1ae.tar.gz gnunet-4d370bed62e5f6a47faba53fe3446a2d2a59d1ae.zip |
different fixes and cosmetic changes
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 68 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 7 |
2 files changed, 44 insertions, 31 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 5efc062bb..1897f3e57 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -52,6 +52,7 @@ | |||
52 | 52 | ||
53 | // TODO Change API to accept good peers 'friends' | 53 | // TODO Change API to accept good peers 'friends' |
54 | 54 | ||
55 | // TODO store peers somewhere | ||
55 | 56 | ||
56 | // hist_size_init, hist_size_max | 57 | // hist_size_init, hist_size_max |
57 | 58 | ||
@@ -469,9 +470,10 @@ handle_cs_request (void *cls, | |||
469 | struct GNUNET_MQ_Envelope *ev; | 470 | struct GNUNET_MQ_Envelope *ev; |
470 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; | 471 | struct GNUNET_RPS_CS_ReplyMessage *out_msg; |
471 | uint64_t num_peers; | 472 | uint64_t num_peers; |
473 | const struct GNUNET_PeerIdentity *peers; | ||
472 | //uint64_t i; | 474 | //uint64_t i; |
473 | 475 | ||
474 | // TODO | 476 | // TODO check message size |
475 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; | 477 | msg = (struct GNUNET_RPS_CS_RequestMessage *) message; |
476 | cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct client_ctx); | 478 | cli_ctx = GNUNET_SERVER_client_get_user_context (client, struct client_ctx); |
477 | if ( NULL == cli_ctx ) { | 479 | if ( NULL == cli_ctx ) { |
@@ -483,15 +485,17 @@ handle_cs_request (void *cls, | |||
483 | // How many peers do we give back? | 485 | // How many peers do we give back? |
484 | // Wait until we have enough random peers? | 486 | // Wait until we have enough random peers? |
485 | 487 | ||
488 | num_peers = GNUNET_ntohll (msg->num_peers); | ||
489 | |||
486 | ev = GNUNET_MQ_msg_extra (out_msg, | 490 | ev = GNUNET_MQ_msg_extra (out_msg, |
487 | GNUNET_ntohll (msg->num_peers) * sizeof (struct GNUNET_PeerIdentity), | 491 | num_peers * sizeof (struct GNUNET_PeerIdentity), |
488 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); | 492 | GNUNET_MESSAGE_TYPE_RPS_CS_REPLY); |
489 | out_msg->num_peers = msg->num_peers; // No conversion between network and host order | 493 | out_msg->num_peers = msg->num_peers; // No conversion between network and network order |
490 | 494 | ||
491 | num_peers = GNUNET_ntohll (msg->num_peers); | 495 | //&out_msg[1] = RPS_sampler_get_n_rand_peers (num_peers); |
492 | //&out_msg[1] = RPS_sampler_get_n_rand_peers(sampler_list, num_peers); | 496 | peers = RPS_sampler_get_n_rand_peers (num_peers); |
493 | memcpy(&out_msg[1], | 497 | memcpy(&out_msg[1], |
494 | RPS_sampler_get_n_rand_peers (num_peers), | 498 | peers, |
495 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 499 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
496 | 500 | ||
497 | GNUNET_MQ_send(cli_ctx->mq, ev); | 501 | GNUNET_MQ_send(cli_ctx->mq, ev); |
@@ -709,9 +713,6 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
709 | } | 713 | } |
710 | 714 | ||
711 | 715 | ||
712 | GNUNET_array_grow(gossip_list, gossip_list_size, est_size); | ||
713 | |||
714 | |||
715 | /* Update gossip list */ | 716 | /* Update gossip list */ |
716 | uint64_t r_index; | 717 | uint64_t r_index; |
717 | 718 | ||
@@ -723,6 +724,8 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
723 | 724 | ||
724 | uint64_t first_border; | 725 | uint64_t first_border; |
725 | uint64_t second_border; | 726 | uint64_t second_border; |
727 | |||
728 | GNUNET_array_grow(gossip_list, gossip_list_size, est_size); | ||
726 | 729 | ||
727 | first_border = round(alpha * gossip_list_size); | 730 | first_border = round(alpha * gossip_list_size); |
728 | for ( i = 0 ; i < first_border ; i++ ) | 731 | for ( i = 0 ; i < first_border ; i++ ) |
@@ -747,7 +750,7 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
747 | for ( i = second_border ; i < gossip_list_size ; i++ ) | 750 | for ( i = second_border ; i < gossip_list_size ; i++ ) |
748 | { | 751 | { |
749 | /* Update gossip list with peers from history */ | 752 | /* Update gossip list with peers from history */ |
750 | peer = RPS_sampler_get_rand_peer(); | 753 | peer = RPS_sampler_get_rand_peer (); |
751 | gossip_list[i] = *peer; | 754 | gossip_list[i] = *peer; |
752 | // TODO change the in_flags accordingly | 755 | // TODO change the in_flags accordingly |
753 | } | 756 | } |
@@ -818,7 +821,8 @@ removeCB (void *cls, const struct GNUNET_PeerIdentity *id) | |||
818 | { | 821 | { |
819 | GNUNET_MQ_destroy (ctx->mq); | 822 | GNUNET_MQ_destroy (ctx->mq); |
820 | } | 823 | } |
821 | GNUNET_CADET_channel_destroy (ctx->to_channel); | 824 | // may already be freed at shutdown of cadet |
825 | //GNUNET_CADET_channel_destroy (ctx->to_channel); | ||
822 | } | 826 | } |
823 | // TODO cleanup peer | 827 | // TODO cleanup peer |
824 | GNUNET_CONTAINER_multipeermap_remove_all(peer_map, id); | 828 | GNUNET_CONTAINER_multipeermap_remove_all(peer_map, id); |
@@ -848,12 +852,18 @@ init_peer_cb (void *cls, | |||
848 | ipc = (struct init_peer_cls *) cls; | 852 | ipc = (struct init_peer_cls *) cls; |
849 | if ( NULL != peer ) | 853 | if ( NULL != peer ) |
850 | { | 854 | { |
851 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Got peer %s (at %p) from CADET\n", GNUNET_i2s(peer), peer); | 855 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
852 | RPS_sampler_update_list(peer); | 856 | "Got %" PRIX32 ". peer %s (at %p) from CADET (gossip_list_size: %u)\n", |
853 | touch_peer_ctx(peer_map, peer); // unneeded? -> insertCB | 857 | ipc->i, GNUNET_i2s (peer), peer, gossip_list_size); |
858 | RPS_sampler_update_list (peer); | ||
859 | touch_peer_ctx (peer_map, peer); // unneeded? -> insertCB | ||
854 | 860 | ||
855 | gossip_list[ipc->i] = *peer; | 861 | if (ipc->i < gossip_list_size) |
856 | ipc->i++; | 862 | { |
863 | gossip_list[ipc->i] = *peer; // FIXME sometimes we're writing to invalid space here | ||
864 | // not sure whether fixed | ||
865 | ipc->i++; | ||
866 | } | ||
857 | 867 | ||
858 | // send push/pull to each of those peers? | 868 | // send push/pull to each of those peers? |
859 | } | 869 | } |
@@ -862,10 +872,11 @@ init_peer_cb (void *cls, | |||
862 | if (ipc->i < gossip_list_size) | 872 | if (ipc->i < gossip_list_size) |
863 | { | 873 | { |
864 | memcpy(&gossip_list[ipc->i], | 874 | memcpy(&gossip_list[ipc->i], |
865 | RPS_sampler_get_rand_peer(), | 875 | RPS_sampler_get_rand_peer (), |
866 | (gossip_list_size - ipc->i) * sizeof(struct GNUNET_PeerIdentity)); | 876 | (gossip_list_size - ipc->i) * sizeof(struct GNUNET_PeerIdentity)); |
867 | } | 877 | } |
868 | rps_start (ipc->server); | 878 | rps_start (ipc->server); |
879 | GNUNET_free (ipc); | ||
869 | } | 880 | } |
870 | } | 881 | } |
871 | 882 | ||
@@ -969,7 +980,7 @@ cleanup_channel(void *cls, | |||
969 | (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER); | 980 | (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER); |
970 | // Guess simply casting isn't the nicest way... | 981 | // Guess simply casting isn't the nicest way... |
971 | // FIXME wait for cadet to change this function | 982 | // FIXME wait for cadet to change this function |
972 | RPS_sampler_reinitialise_by_value(peer); | 983 | RPS_sampler_reinitialise_by_value (peer); |
973 | } | 984 | } |
974 | 985 | ||
975 | /** | 986 | /** |
@@ -1013,7 +1024,7 @@ run (void *cls, | |||
1013 | { | 1024 | { |
1014 | // TODO check what this does -- copied from gnunet-boss | 1025 | // TODO check what this does -- copied from gnunet-boss |
1015 | // - seems to work as expected | 1026 | // - seems to work as expected |
1016 | GNUNET_log_setup("rps", GNUNET_error_type_to_string(GNUNET_ERROR_TYPE_DEBUG), NULL); | 1027 | GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL); |
1017 | 1028 | ||
1018 | LOG(GNUNET_ERROR_TYPE_DEBUG, "RPS started\n"); | 1029 | LOG(GNUNET_ERROR_TYPE_DEBUG, "RPS started\n"); |
1019 | 1030 | ||
@@ -1023,10 +1034,10 @@ run (void *cls, | |||
1023 | 1034 | ||
1024 | 1035 | ||
1025 | /* Get own ID */ | 1036 | /* Get own ID */ |
1026 | own_identity = GNUNET_new(struct GNUNET_PeerIdentity); | 1037 | own_identity = GNUNET_new (struct GNUNET_PeerIdentity); |
1027 | GNUNET_CRYPTO_get_peer_identity(cfg, own_identity); // TODO check return value | 1038 | GNUNET_CRYPTO_get_peer_identity (cfg, own_identity); // TODO check return value |
1028 | GNUNET_assert(NULL != own_identity); | 1039 | GNUNET_assert (NULL != own_identity); |
1029 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Own identity is %s (at %p).\n", GNUNET_i2s(own_identity), own_identity); | 1040 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Own identity is %s (at %p).\n", GNUNET_i2s(own_identity), own_identity); |
1030 | 1041 | ||
1031 | 1042 | ||
1032 | /* Get time interval from the configuration */ | 1043 | /* Get time interval from the configuration */ |
@@ -1034,7 +1045,7 @@ run (void *cls, | |||
1034 | "ROUNDINTERVAL", | 1045 | "ROUNDINTERVAL", |
1035 | &round_interval)) | 1046 | &round_interval)) |
1036 | { | 1047 | { |
1037 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Failed to read ROUNDINTERVAL from config\n"); | 1048 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to read ROUNDINTERVAL from config\n"); |
1038 | GNUNET_SCHEDULER_shutdown(); | 1049 | GNUNET_SCHEDULER_shutdown(); |
1039 | return; | 1050 | return; |
1040 | } | 1051 | } |
@@ -1044,17 +1055,16 @@ run (void *cls, | |||
1044 | "INITSIZE", | 1055 | "INITSIZE", |
1045 | (long long unsigned int *) &est_size)) | 1056 | (long long unsigned int *) &est_size)) |
1046 | { | 1057 | { |
1047 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Failed to read INITSIZE from config\n"); | 1058 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to read INITSIZE from config\n"); |
1048 | GNUNET_SCHEDULER_shutdown(); | 1059 | GNUNET_SCHEDULER_shutdown (); |
1049 | return; | 1060 | return; |
1050 | } | 1061 | } |
1051 | LOG(GNUNET_ERROR_TYPE_DEBUG, "INITSIZE is %" PRIu64 "\n", est_size); | 1062 | LOG (GNUNET_ERROR_TYPE_DEBUG, "INITSIZE is %" PRIu64 "\n", est_size); |
1052 | 1063 | ||
1053 | //gossip_list_size = est_size; // TODO rename est_size | 1064 | //gossip_list_size = est_size; // TODO rename est_size |
1054 | 1065 | ||
1055 | gossip_list = NULL; | 1066 | gossip_list = NULL; |
1056 | 1067 | GNUNET_array_grow (gossip_list, gossip_list_size, est_size); | |
1057 | GNUNET_array_grow(gossip_list, gossip_list_size, est_size); | ||
1058 | 1068 | ||
1059 | 1069 | ||
1060 | /* connect to NSE */ | 1070 | /* connect to NSE */ |
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index b5eb17a2d..952ed8794 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -615,13 +615,16 @@ RPS_sampler_get_n_rand_peers (uint64_t n) | |||
615 | // TODO check if we have too much (distinct) sampled peers | 615 | // TODO check if we have too much (distinct) sampled peers |
616 | // If we are not ready yet maybe schedule for later | 616 | // If we are not ready yet maybe schedule for later |
617 | struct GNUNET_PeerIdentity *peers; | 617 | struct GNUNET_PeerIdentity *peers; |
618 | const struct GNUNET_PeerIdentity *peer; | ||
618 | uint64_t i; | 619 | uint64_t i; |
619 | 620 | ||
620 | peers = GNUNET_malloc (n * sizeof(struct GNUNET_PeerIdentity)); | 621 | peers = GNUNET_malloc (n * sizeof (struct GNUNET_PeerIdentity)); |
621 | 622 | ||
622 | for ( i = 0 ; i < n ; i++ ) { | 623 | for ( i = 0 ; i < n ; i++ ) { |
623 | //peers[i] = RPS_sampler_get_rand_peer_(sampler->sampler_elements); | 624 | //peers[i] = RPS_sampler_get_rand_peer_(sampler->sampler_elements); |
624 | memcpy (&peers[i], RPS_sampler_get_rand_peer (), sizeof (struct GNUNET_PeerIdentity)); | 625 | peer = RPS_sampler_get_rand_peer (); |
626 | memcpy (&peers[i], peer, sizeof (struct GNUNET_PeerIdentity)); | ||
627 | //GNUNET_free (peer); | ||
625 | } | 628 | } |
626 | return peers; | 629 | return peers; |
627 | } | 630 | } |