diff options
author | Julius Bünger <buenger@mytum.de> | 2015-02-05 17:47:52 +0000 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2015-02-05 17:47:52 +0000 |
commit | c23aa9e8572045fb4774f8dd7a1c9975e51dae01 (patch) | |
tree | baa7280a3b21f044f24c2fb34d743ffac2872af6 /src | |
parent | b77d690bf430df4240abc0bece33e45e44a754f5 (diff) | |
download | gnunet-c23aa9e8572045fb4774f8dd7a1c9975e51dae01.tar.gz gnunet-c23aa9e8572045fb4774f8dd7a1c9975e51dae01.zip |
- trying to fix coverity defects
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 127 | ||||
-rw-r--r-- | src/rps/test_rps_multipeer.c | 9 |
2 files changed, 76 insertions, 60 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 297c96ba1..388111f69 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -419,6 +419,8 @@ get_rand_peer_ignore_list (const struct GNUNET_PeerIdentity *peer_list, | |||
419 | struct GNUNET_PeerIdentity *peer; | 419 | struct GNUNET_PeerIdentity *peer; |
420 | 420 | ||
421 | GNUNET_assert (NULL != peer_list); | 421 | GNUNET_assert (NULL != peer_list); |
422 | if (0 == list_size) | ||
423 | return NULL; | ||
422 | 424 | ||
423 | tmp_size = 0; | 425 | tmp_size = 0; |
424 | tmp_peer_list = NULL; | 426 | tmp_peer_list = NULL; |
@@ -426,27 +428,32 @@ get_rand_peer_ignore_list (const struct GNUNET_PeerIdentity *peer_list, | |||
426 | memcpy (tmp_peer_list, peer_list, list_size * sizeof (struct GNUNET_PeerIdentity)); | 428 | memcpy (tmp_peer_list, peer_list, list_size * sizeof (struct GNUNET_PeerIdentity)); |
427 | peer = GNUNET_new (struct GNUNET_PeerIdentity); | 429 | peer = GNUNET_new (struct GNUNET_PeerIdentity); |
428 | 430 | ||
429 | do | 431 | /**; |
432 | * Choose the r_index of the peer we want to return | ||
433 | * at random from the interval of the gossip list | ||
434 | */ | ||
435 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | ||
436 | tmp_size); | ||
437 | *peer = tmp_peer_list[r_index]; | ||
438 | |||
439 | while (in_arr (ignore_list, ignore_size, peer)) | ||
430 | { | 440 | { |
441 | rem_from_list (tmp_peer_list, &tmp_size, peer); | ||
442 | |||
443 | if (0 == tmp_size) | ||
444 | return NULL; | ||
445 | |||
431 | /**; | 446 | /**; |
432 | * Choose the r_index of the peer we want to return | 447 | * Choose the r_index of the peer we want to return |
433 | * at random from the interval of the gossip list | 448 | * at random from the interval of the gossip list |
434 | */ | 449 | */ |
435 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 450 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, |
436 | tmp_size); | 451 | tmp_size); |
437 | |||
438 | *peer = tmp_peer_list[r_index]; | 452 | *peer = tmp_peer_list[r_index]; |
439 | if (in_arr (ignore_list, ignore_size, peer)) | 453 | } |
440 | { | ||
441 | rem_from_list (tmp_peer_list, &tmp_size, peer); | ||
442 | if (0 == tmp_size) | ||
443 | return NULL; | ||
444 | continue; | ||
445 | } | ||
446 | 454 | ||
447 | } while (NULL == peer); | ||
448 | 455 | ||
449 | GNUNET_free (tmp_peer_list); | 456 | GNUNET_array_grow (tmp_peer_list, tmp_size, 0); |
450 | 457 | ||
451 | return peer; | 458 | return peer; |
452 | } | 459 | } |
@@ -1079,7 +1086,7 @@ handle_peer_pull_reply (void *cls, | |||
1079 | // FIXME wait for cadet to change this function | 1086 | // FIXME wait for cadet to change this function |
1080 | sender_ctx = get_peer_ctx (peer_map, sender); | 1087 | sender_ctx = get_peer_ctx (peer_map, sender); |
1081 | 1088 | ||
1082 | if (0 == (peer_ctx->peer_flags || PULL_REPLY_PENDING)) | 1089 | if (0 == (sender_ctx->peer_flags || PULL_REPLY_PENDING)) |
1083 | { | 1090 | { |
1084 | GNUNET_break_op (0); | 1091 | GNUNET_break_op (0); |
1085 | return GNUNET_OK; | 1092 | return GNUNET_OK; |
@@ -1098,6 +1105,7 @@ handle_peer_pull_reply (void *cls, | |||
1098 | else if (GNUNET_NO == insert_in_pull_list_scheduled (peer_ctx)) | 1105 | else if (GNUNET_NO == insert_in_pull_list_scheduled (peer_ctx)) |
1099 | { | 1106 | { |
1100 | out_op.op = insert_in_pull_list; | 1107 | out_op.op = insert_in_pull_list; |
1108 | out_op.op_cls = NULL; | ||
1101 | GNUNET_array_append (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, out_op); | 1109 | GNUNET_array_append (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, out_op); |
1102 | } | 1110 | } |
1103 | } | 1111 | } |
@@ -1123,12 +1131,17 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1123 | unsigned int *permut; | 1131 | unsigned int *permut; |
1124 | unsigned int n_peers; /* Number of peers we send pushes/pulls to */ | 1132 | unsigned int n_peers; /* Number of peers we send pushes/pulls to */ |
1125 | struct GNUNET_MQ_Envelope *ev; | 1133 | struct GNUNET_MQ_Envelope *ev; |
1126 | const struct GNUNET_PeerIdentity *peer; | 1134 | struct GNUNET_PeerIdentity peer; |
1135 | struct GNUNET_PeerIdentity *tmp_peer; | ||
1127 | struct GNUNET_MQ_Handle *mq; | 1136 | struct GNUNET_MQ_Handle *mq; |
1128 | 1137 | ||
1138 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1139 | "Printing gossip list:\n"); | ||
1140 | for (i = 0 ; i < gossip_list_size ; i++) | ||
1141 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1142 | "\t%s\n", GNUNET_i2s (&gossip_list[i])); | ||
1129 | // TODO log lists, ... | 1143 | // TODO log lists, ... |
1130 | 1144 | ||
1131 | |||
1132 | /* Would it make sense to have one shuffeled gossip list and then | 1145 | /* Would it make sense to have one shuffeled gossip list and then |
1133 | * to send PUSHes to first alpha peers, PULL requests to next beta peers and | 1146 | * to send PUSHes to first alpha peers, PULL requests to next beta peers and |
1134 | * use the rest to update sampler? | 1147 | * use the rest to update sampler? |
@@ -1139,24 +1152,22 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1139 | { | 1152 | { |
1140 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, | 1153 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, |
1141 | (unsigned int) gossip_list_size); | 1154 | (unsigned int) gossip_list_size); |
1142 | if (0 != gossip_list_size) | 1155 | n_peers = ceil (alpha * gossip_list_size); |
1156 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1157 | "Going to send pushes to %u ceil (%f * %u) peers.\n", | ||
1158 | n_peers, alpha, gossip_list_size); | ||
1159 | for (i = 0 ; i < n_peers ; i++) | ||
1143 | { | 1160 | { |
1144 | n_peers = round (alpha * gossip_list_size); | 1161 | peer = gossip_list[permut[i]]; |
1145 | if (0 == n_peers) | 1162 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO |
1146 | n_peers = 1; | 1163 | { // FIXME if this fails schedule/loop this for later |
1147 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to send pushes to %u (%f * %u) peers.\n", | 1164 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1148 | n_peers, alpha, gossip_list_size); | 1165 | "Sending PUSH to peer %s of gossiped list.\n", |
1149 | for ( i = 0 ; i < n_peers ; i++ ) | 1166 | GNUNET_i2s (&peer)); |
1150 | { | 1167 | |
1151 | peer = &gossip_list[permut[i]]; | 1168 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
1152 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, peer)) // TODO | 1169 | mq = get_mq (peer_map, &peer); |
1153 | { // FIXME if this fails schedule/loop this for later | 1170 | GNUNET_MQ_send (mq, ev); |
1154 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PUSH to peer %s of gossiped list.\n", GNUNET_i2s (peer)); | ||
1155 | |||
1156 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | ||
1157 | mq = get_mq (peer_map, peer); | ||
1158 | GNUNET_MQ_send (mq, ev); | ||
1159 | } | ||
1160 | } | 1171 | } |
1161 | } | 1172 | } |
1162 | GNUNET_free (permut); | 1173 | GNUNET_free (permut); |
@@ -1165,30 +1176,29 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1165 | 1176 | ||
1166 | /* Send PULL requests */ | 1177 | /* Send PULL requests */ |
1167 | //permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) sampler_list->size); | 1178 | //permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_STRONG, (unsigned int) sampler_list->size); |
1168 | if (0 != gossip_list_size) | 1179 | n_peers = ceil (beta * gossip_list_size); |
1180 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1181 | "Going to send pulls to %u ceil (%f * %u) peers.\n", | ||
1182 | n_peers, beta, gossip_list_size); | ||
1183 | for (i = 0 ; i < n_peers ; i++) | ||
1169 | { | 1184 | { |
1170 | n_peers = round (beta * gossip_list_size); | 1185 | tmp_peer = get_rand_peer_ignore_list (gossip_list, gossip_list_size, |
1171 | if (0 == n_peers) | 1186 | pending_pull_reply_list, pending_pull_reply_list_size); |
1172 | n_peers = 1; | 1187 | if (NULL != tmp_peer) |
1173 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to send pulls to %u (%f * %u) peers.\n", | ||
1174 | n_peers, beta, gossip_list_size); | ||
1175 | for ( i = 0 ; i < n_peers ; i++ ) | ||
1176 | { | 1188 | { |
1177 | peer = get_rand_peer_ignore_list (gossip_list, gossip_list_size, | 1189 | peer = *tmp_peer; |
1178 | pending_pull_reply_list, pending_pull_reply_list_size); | 1190 | GNUNET_free (tmp_peer); |
1179 | if (NULL != peer) | 1191 | GNUNET_array_append (pending_pull_reply_list, pending_pull_reply_list_size, peer); |
1180 | { | 1192 | |
1181 | GNUNET_array_append (pending_pull_reply_list, pending_pull_reply_list_size, *peer); | 1193 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) |
1182 | 1194 | { // FIXME if this fails schedule/loop this for later | |
1183 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, peer)) | 1195 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1184 | { // FIXME if this fails schedule/loop this for later | 1196 | "Sending PULL request to peer %s of gossiped list.\n", |
1185 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending PULL request to peer %s of gossiped list.\n", GNUNET_i2s (peer)); | 1197 | GNUNET_i2s (&peer)); |
1186 | 1198 | ||
1187 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 1199 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
1188 | //pull_msg = NULL; | 1200 | mq = get_mq (peer_map, &peer); |
1189 | mq = get_mq (peer_map, peer); | 1201 | GNUNET_MQ_send (mq, ev); |
1190 | GNUNET_MQ_send (mq, ev); | ||
1191 | } | ||
1192 | } | 1202 | } |
1193 | } | 1203 | } |
1194 | } | 1204 | } |
@@ -1206,12 +1216,12 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1206 | uint32_t first_border; | 1216 | uint32_t first_border; |
1207 | uint32_t second_border; | 1217 | uint32_t second_border; |
1208 | 1218 | ||
1209 | first_border = ceil (alpha * sampler_size_est_need); | 1219 | first_border = ceil (alpha * sampler_size_est_need); |
1210 | second_border = first_border + ceil (beta * sampler_size_est_need); | 1220 | second_border = first_border + ceil (beta * sampler_size_est_need); |
1211 | 1221 | ||
1212 | GNUNET_array_grow (gossip_list, gossip_list_size, second_border); | 1222 | GNUNET_array_grow (gossip_list, gossip_list_size, second_border); |
1213 | 1223 | ||
1214 | for ( i = 0 ; i < first_border ; i++ ) | 1224 | for (i = 0 ; i < first_border ; i++) |
1215 | { // TODO use RPS_sampler_get_n_rand_peers | 1225 | { // TODO use RPS_sampler_get_n_rand_peers |
1216 | /* Update gossip list with peers received through PUSHes */ | 1226 | /* Update gossip list with peers received through PUSHes */ |
1217 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 1227 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, |
@@ -1220,7 +1230,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1220 | // TODO change the peer_flags accordingly | 1230 | // TODO change the peer_flags accordingly |
1221 | } | 1231 | } |
1222 | 1232 | ||
1223 | for ( i = first_border ; i < second_border ; i++ ) | 1233 | for (i = first_border ; i < second_border ; i++) |
1224 | { | 1234 | { |
1225 | /* Update gossip list with peers received through PULLs */ | 1235 | /* Update gossip list with peers received through PULLs */ |
1226 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, | 1236 | r_index = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, |
@@ -1229,7 +1239,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1229 | // TODO change the peer_flags accordingly | 1239 | // TODO change the peer_flags accordingly |
1230 | } | 1240 | } |
1231 | 1241 | ||
1232 | for ( i = second_border ; i < gossip_list_size ; i++ ) | 1242 | for (i = second_border ; i < sampler_size_est_need ; i++) |
1233 | { | 1243 | { |
1234 | /* Update gossip list with peers from history */ | 1244 | /* Update gossip list with peers from history */ |
1235 | RPS_sampler_get_n_rand_peers (hist_update, NULL, 1, GNUNET_NO); | 1245 | RPS_sampler_get_n_rand_peers (hist_update, NULL, 1, GNUNET_NO); |
@@ -1368,6 +1378,7 @@ init_peer_cb (void *cls, | |||
1368 | if (GNUNET_NO == insert_in_gossip_list_scheduled (peer_ctx)) | 1378 | if (GNUNET_NO == insert_in_gossip_list_scheduled (peer_ctx)) |
1369 | { | 1379 | { |
1370 | out_op.op = insert_in_gossip_list; | 1380 | out_op.op = insert_in_gossip_list; |
1381 | out_op.op_cls = NULL; | ||
1371 | GNUNET_array_append (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, out_op); | 1382 | GNUNET_array_append (peer_ctx->outstanding_ops, peer_ctx->num_outstanding_ops, out_op); |
1372 | } | 1383 | } |
1373 | 1384 | ||
diff --git a/src/rps/test_rps_multipeer.c b/src/rps/test_rps_multipeer.c index 2a55eb49b..76e2fb2a9 100644 --- a/src/rps/test_rps_multipeer.c +++ b/src/rps/test_rps_multipeer.c | |||
@@ -121,8 +121,10 @@ request_peers (void *cls, | |||
121 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 121 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
122 | { | 122 | { |
123 | struct RPSPeer *peer = (struct RPSPeer *) cls; | 123 | struct RPSPeer *peer = (struct RPSPeer *) cls; |
124 | struct GNUNET_RPS_Request_Handle *req_handle; | ||
124 | 125 | ||
125 | GNUNET_RPS_request_peers (peer->rps_handle, 1, handle_reply, NULL); | 126 | req_handle = GNUNET_RPS_request_peers (peer->rps_handle, 1, handle_reply, NULL); |
127 | GNUNET_free (req_handle); | ||
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
@@ -187,6 +189,8 @@ rps_connect_complete_cb (void *cls, | |||
187 | { | 189 | { |
188 | struct RPSPeer *peer = cls; | 190 | struct RPSPeer *peer = cls; |
189 | struct GNUNET_RPS_Handle *rps = ca_result; | 191 | struct GNUNET_RPS_Handle *rps = ca_result; |
192 | struct GNUNET_RPS_Request_Handle *req_handle; | ||
193 | |||
190 | peer->rps_handle = rps; | 194 | peer->rps_handle = rps; |
191 | 195 | ||
192 | GNUNET_assert (op == peer->op); | 196 | GNUNET_assert (op == peer->op); |
@@ -201,7 +205,8 @@ rps_connect_complete_cb (void *cls, | |||
201 | } | 205 | } |
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); |
203 | 207 | ||
204 | GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); | 208 | req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); |
209 | GNUNET_free (req_handle); | ||
205 | 210 | ||
206 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 211 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), |
207 | request_peers, peer); | 212 | request_peers, peer); |