aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2014-12-14 21:48:04 +0000
committerJulius Bünger <buenger@mytum.de>2014-12-14 21:48:04 +0000
commit3ad03dbd0a485123051dab90eadd95fbc38f8741 (patch)
tree38f50a6c8ac5847fcc190848fb765694960debea
parent6a74800a488adf754645249267e93e6c82d22219 (diff)
downloadgnunet-3ad03dbd0a485123051dab90eadd95fbc38f8741.tar.gz
gnunet-3ad03dbd0a485123051dab90eadd95fbc38f8741.zip
Got rid of SList
Signed-off-by: Julius Bünger <buenger@mytum.de>
-rw-r--r--src/rps/gnunet-service-rps.c257
1 files changed, 47 insertions, 210 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 386e97190..c7e18c9f0 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -441,105 +441,6 @@ SAMPLER_samplers_grow (struct Samplers * samplers, size_t new_size)
441 441
442 442
443/*********************************************************************** 443/***********************************************************************
444 * Peer list
445***********************************************************************/
446
447/**
448 * A struct that just holds the PeerID.
449 */
450struct PeerEntry
451{
452 /**
453 * The PeerID.
454 */
455 struct GNUNET_PeerIdentity *id;
456};
457
458/**
459 * A DLL holding PeerIDs.
460 */
461struct PeerList
462{
463 /**
464 * The size of the list.
465 */
466 size_t size;
467
468 /**
469 * Array of PeerIDs.
470 */
471 struct GNUNET_PeerIdentity *peer_ids;
472
473 /**
474 * Head of the DLL.
475 */
476 struct PeerEntry *head;
477
478 /**
479 * Tail of the DLL.
480 */
481 struct PeerEntry *tail;
482};
483
484/**
485 * Give back an empty PeerList.
486 */
487 struct PeerList*
488PeerList_init()
489{
490 struct PeerList *peer_list;
491
492 peer_list = GNUNET_new(struct PeerList);
493 peer_list->size = 0;
494 peer_list->peer_ids = NULL;
495 peer_list->head = peer_list->tail = NULL;
496
497 return peer_list;
498}
499
500/**
501 * Put one PeerID into the given PeerList.
502 */
503 void
504PeerList_put(struct PeerList *peer_list, struct GNUNET_PeerIdentity *id)
505{
506}
507
508///**
509// * Get one random peer out of the gossiped peer list.
510// */
511// struct GNUNET_PeerIdentity *
512//get_random_peer(struct GNUNET_CONTAINER_MultiPeerMap * lst)
513//{
514// size_t n;
515// struct GNUNET_CONTAINER_MultiPeerMapIterator *iter;
516// uint64_t index;
517// uint64_t i;
518// struct GNUNET_PeerIdentity *peer;
519//
520// n = (size_t) GNUNET_CONTAINER_multipeermap_size(lst);
521// index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG,
522// (uint64_t) n);
523// iter = GNUNET_CONTAINER_multipeermap_iterator_create(lst);
524//
525// for ( i = 0 ; i < index ; i++ ) {
526// GNUNET_CONTAINER_multipeermap_iterator_next(iter, NULL, NULL);
527// }
528//
529// peer = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
530// GNUNET_CONTAINER_multipeermap_iterator_next(iter, peer, NULL);
531//
532// return peer;
533//}
534
535
536/***********************************************************************
537 * /Peer list
538***********************************************************************/
539
540
541
542/***********************************************************************
543 * Housekeeping with peers 444 * Housekeeping with peers
544***********************************************************************/ 445***********************************************************************/
545 446
@@ -700,12 +601,22 @@ struct GNUNET_TIME_Relative round_interval;
700/** 601/**
701 * List to store peers received through pushes temporary. 602 * List to store peers received through pushes temporary.
702 */ 603 */
703struct GNUNET_CONTAINER_SList *push_list; 604struct GNUNET_PeerIdentity *push_list;
605
606/**
607 * Size of the push_list;
608 */
609size_t push_list_size;
704 610
705/** 611/**
706 * List to store peers received through pulls temporary. 612 * List to store peers received through pulls temporary.
707 */ 613 */
708struct GNUNET_CONTAINER_SList *pull_list; 614struct GNUNET_PeerIdentity *pull_list;
615
616/**
617 * Size of the pull_list;
618 */
619size_t pull_list_size;
709 620
710 621
711/** 622/**
@@ -916,9 +827,8 @@ handle_peer_push (void *cls,
916 peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info( channel, GNUNET_CADET_OPTION_PEER ); 827 peer = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info( channel, GNUNET_CADET_OPTION_PEER );
917 828
918 /* Add the sending peer to the push_list */ 829 /* Add the sending peer to the push_list */
919 GNUNET_CONTAINER_slist_add(push_list, 830 GNUNET_array_append(push_list, push_list_size, *peer);
920 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 831 push_list_size ++;
921 peer, sizeof(struct GNUNET_PeerIdentity));
922 832
923 return GNUNET_OK; 833 return GNUNET_OK;
924} 834}
@@ -999,11 +909,9 @@ handle_peer_pull_reply (void *cls,
999 // TODO check that we sent a request and that it is the first reply 909 // TODO check that we sent a request and that it is the first reply
1000 910
1001 in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg; 911 in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg;
1002 for ( i = 0 ; i < in_msg->num_peers ; i++ ) { 912 for ( i = 0 ; i < GNUNET_ntohll(in_msg->num_peers) ; i++ ) {
1003 GNUNET_CONTAINER_slist_add(pull_list, 913 GNUNET_array_append(pull_list, pull_list_size, in_msg[i]);
1004 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, 914 pull_list_size++;
1005 &in_msg[1] + i * sizeof(struct GNUNET_PeerIdentity),
1006 sizeof(struct GNUNET_PeerIdentity));
1007 } 915 }
1008 916
1009 // TODO maybe a disconnect happens here 917 // TODO maybe a disconnect happens here
@@ -1058,27 +966,6 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1058 // TODO check nse == 0! 966 // TODO check nse == 0!
1059 LOG(GNUNET_ERROR_TYPE_DEBUG, "Checking size estimate.\n"); 967 LOG(GNUNET_ERROR_TYPE_DEBUG, "Checking size estimate.\n");
1060 SAMPLER_samplers_grow(samplers, est_size); 968 SAMPLER_samplers_grow(samplers, est_size);
1061 //if ( sampler_list_size < est_size ) {
1062 // LOG(GNUNET_ERROR_TYPE_DEBUG, "Growing size.\n");
1063 // /* Grow the lists. */
1064 // for ( i = 0 ; i < est_size - sampler_list_size ; i++ ) {
1065 // s = SAMPLER_init();
1066 // GNUNET_CONTAINER_slist_add_end(sampler_list,
1067 // GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, // DEPRECATED
1068 // s,
1069 // sizeof(struct Sampler));
1070
1071 // // TODO add peers to gossiped ones?
1072 // }
1073 //} else if ( sampler_list_size > est_size ) {
1074 // LOG(GNUNET_ERROR_TYPE_DEBUG, "Shrinking size.\n");
1075 // /* Shrink the lists. */
1076 // for ( i = 0 ; i < sampler_list_size - est_size ; i++ ) {
1077 // *iter = GNUNET_CONTAINER_slist_begin(sampler_list);
1078 // GNUNET_CONTAINER_slist_erase(iter);
1079 // GNUNET_CONTAINER_slist_iter_destroy(iter); // Maybe unneeded but I don't know whether _erase() also deletes the iter
1080 // }
1081 //}
1082 969
1083 GNUNET_array_grow(gossip_list, gossip_list_size, est_size); // FIXME Do conversion correct or change type 970 GNUNET_array_grow(gossip_list, gossip_list_size, est_size); // FIXME Do conversion correct or change type
1084 971
@@ -1133,29 +1020,36 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1133 1020
1134 /* Update gossip list */ 1021 /* Update gossip list */
1135 uint64_t tmp_index; 1022 uint64_t tmp_index;
1023 uint64_t index;
1136 1024
1137 if ( GNUNET_CONTAINER_slist_count(push_list) <= alpha * gossip_list_size && 1025 if ( push_list_size <= alpha * gossip_list_size &&
1138 GNUNET_CONTAINER_slist_count(push_list) != 0 && 1026 push_list_size != 0 &&
1139 GNUNET_CONTAINER_slist_count(pull_list) != 0 ) { 1027 pull_list_size != 0 ) {
1140 LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the gossip list. ()\n"); 1028 LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the gossip list. ()\n");
1141 1029
1142 for ( i = 0 ; i < alpha * gossip_list_size ; i++ ) { // TODO use SAMPLER_get_n_rand_peers 1030 for ( i = 0 ; i < alpha * gossip_list_size ; i++ ) { // TODO use SAMPLER_get_n_rand_peers
1143 /* Update gossip list with peers received through PUSHes */ 1031 /* Update gossip list with peers received through PUSHes */
1144 gossip_list[i] = *SAMPLER_get_rand_peer(push_list); 1032 index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG,
1033 push_list_size);
1034 gossip_list[i] = push_list[index];
1145 // TODO change the in_flags accordingly 1035 // TODO change the in_flags accordingly
1146 } 1036 }
1147 1037
1148 for ( i = 0 ; i < beta * gossip_list_size ; i++ ) { 1038 for ( i = 0 ; i < beta * gossip_list_size ; i++ ) {
1149 /* Update gossip list with peers received through PULLs */ 1039 /* Update gossip list with peers received through PULLs */
1150 tmp_index = i + round(alpha * gossip_list_size); 1040 tmp_index = i + round(alpha * gossip_list_size);
1151 gossip_list[tmp_index] = *SAMPLER_get_rand_peer(pull_list); 1041 index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG,
1042 pull_list_size);
1043 gossip_list[tmp_index] = pull_list[index];
1152 // TODO change the in_flags accordingly 1044 // TODO change the in_flags accordingly
1153 } 1045 }
1154 1046
1155 for ( i = 0 ; i < (1 - (alpha + beta)) * gossip_list_size ; i++ ) { 1047 for ( i = 0 ; i < (1 - (alpha + beta)) * gossip_list_size ; i++ ) {
1156 /* Update gossip list with peers from history */ 1048 /* Update gossip list with peers from history */
1157 tmp_index = i + round((alpha + beta) * gossip_list_size); 1049 tmp_index = i + round((alpha + beta) * gossip_list_size);
1158 gossip_list[tmp_index] = *SAMPLER_get_rand_peer(sampler_list); 1050 index = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_STRONG,
1051 samplers->size);
1052 gossip_list[tmp_index] = samplers->peer_ids[index];
1159 // TODO change the in_flags accordingly 1053 // TODO change the in_flags accordingly
1160 } 1054 }
1161 1055
@@ -1168,56 +1062,30 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1168 1062
1169 /* Update samplers */ 1063 /* Update samplers */
1170 size_t size; 1064 size_t size;
1065 uint64_t i;
1171 1066
1172 if ( 0 < GNUNET_CONTAINER_slist_count(push_list) ) { 1067 for ( i = 0 ; i < push_list_size ; i++ )
1173 LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the sampler list from pushes.\n"); 1068 {
1174 1069 SAMPLER_update_list(samplers, push_list[i]);
1175 *iter = GNUNET_CONTAINER_slist_begin(push_list); 1070 // TODO set in_flag?
1176 size = sizeof(struct GNUNET_PeerIdentity);
1177
1178 while ( GNUNET_NO != GNUNET_CONTAINER_slist_next(iter) ) {
1179 peer = (struct GNUNET_PeerIdentity *) GNUNET_CONTAINER_slist_get(iter, &size);
1180 SAMPLER_update_list(sampler_list, peer, NULL, NULL);
1181 // TODO set in_flag
1182 }
1183 GNUNET_CONTAINER_slist_iter_destroy(iter);
1184
1185 } else {
1186 LOG(GNUNET_ERROR_TYPE_DEBUG, "No update of the sampler list - received no pushes.\n");
1187 } 1071 }
1188 1072
1189 if ( 0 < GNUNET_CONTAINER_slist_count(pull_list) ) { 1073 for ( i = 0 ; i < pull_list_size ; i++ )
1190 LOG(GNUNET_ERROR_TYPE_DEBUG, "Update of the sampler list - received no pushes.\n"); 1074 {
1191 1075 SAMPLER_update_list(samplers, pull_list[i]);
1192 *iter = GNUNET_CONTAINER_slist_begin(pull_list); 1076 // TODO set in_flag?
1193
1194 while ( GNUNET_NO != GNUNET_CONTAINER_slist_next(iter) ) {
1195 peer = (struct GNUNET_PeerIdentity *) GNUNET_CONTAINER_slist_get(iter, &size);
1196 SAMPLER_update_list(sampler_list, peer, NULL, NULL);
1197 // TODO set in_flag
1198 }
1199 GNUNET_CONTAINER_slist_iter_destroy(iter);
1200 } else {
1201 LOG(GNUNET_ERROR_TYPE_DEBUG, "No update of the sampler list - received no pulls.\n");
1202 } 1077 }
1203 1078
1204 1079
1205 GNUNET_free(iter);
1206
1207
1208 // TODO go over whole peer_map and do cleanups 1080 // TODO go over whole peer_map and do cleanups
1209 // delete unneeded peers, set in_flags, check channel/mq 1081 // delete unneeded peers, set in_flags, check channel/mq
1210 1082
1211 1083
1212
1213 /* Empty push/pull lists */ 1084 /* Empty push/pull lists */
1214 if ( 0 != GNUNET_CONTAINER_slist_count(push_list) ) { 1085 GNUNET_array_grow(push_list, push_list_size, 0);
1215 GNUNET_CONTAINER_slist_clear(push_list); 1086 push_list_size = 0;
1216 } 1087 GNUNET_array_grow(pull_list, pull_list_size, 0);
1217 1088 pull_list_size = 0;
1218 if ( 0 != GNUNET_CONTAINER_slist_count(push_list) ) {
1219 GNUNET_CONTAINER_slist_clear(push_list);
1220 }
1221 1089
1222 1090
1223 /* Schedule next round */ 1091 /* Schedule next round */
@@ -1500,40 +1368,12 @@ run (void *cls,
1500 /* Initialise sampler and gossip list */ 1368 /* Initialise sampler and gossip list */
1501 struct Sampler *s; 1369 struct Sampler *s;
1502 1370
1503 //sampler_list = GNUNET_CONTAINER_slist_create();
1504 samplers = SAMPLER_samplers_init(est_size); 1371 samplers = SAMPLER_samplers_init(est_size);
1505 1372
1506 //if ( gossip_list_size == sampler_list_size ) { 1373 push_list = NULL;
1507 // for ( i = 0 ; i < sampler_list_size ; i++ ) { 1374 push_list_size = 0;
1508 // /* Init sampler list */ 1375 pull_list = NULL;
1509 // s = SAMPLER_init(); 1376 pull_list_size = 0;
1510 // GNUNET_CONTAINER_slist_add(sampler_list,
1511 // GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, // TODO DEPRECATED
1512 // s,
1513 // sizeof(struct Sampler));
1514 // /* Init gossip list */
1515 // // TODO init gossip list
1516 // // What do we need to do here?
1517 // }
1518 //} else {
1519 // for ( i = 0 ; i < gossip_list_size ; i++ ) {
1520 // // TODO init gossip list
1521 // }
1522 // for ( i = 0 ; i < sampler_list_size ; i++ ) {
1523 // // TODO init RPF func
1524 // // TODO init Sample list
1525 // // TODO init Sampled list
1526 // }
1527 //}
1528 //uint64_t tmp_s = (uint64_t) GNUNET_CONTAINER_slist_count(sampler_list);
1529 //LOG(GNUNET_ERROR_TYPE_DEBUG, "Initialised sampler list %" PRIu64 "\n", tmp_s);
1530
1531
1532
1533 push_list = GNUNET_CONTAINER_slist_create();
1534 pull_list = GNUNET_CONTAINER_slist_create();
1535
1536
1537 1377
1538 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { 1378 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
1539 {&handle_peer_push , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH , 0}, 1379 {&handle_peer_push , GNUNET_MESSAGE_TYPE_RPS_PP_PUSH , 0},
@@ -1557,9 +1397,6 @@ run (void *cls,
1557 // FIXME use magic 0000 PeerID to _start_ the service 1397 // FIXME use magic 0000 PeerID to _start_ the service
1558 1398
1559 // TODO send push/pull to each of those peers? 1399 // TODO send push/pull to each of those peers?
1560
1561
1562
1563} 1400}
1564 1401
1565 1402