aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-08-13 14:32:07 +0200
committerJulius Bünger <buenger@mytum.de>2018-08-13 14:33:05 +0200
commitbe3250261ec4a398feecf23dca236ab847515d8e (patch)
tree2992f17f4e5f6484db3c2721c7b896b81354edaf
parent0d0cf87380b06ee7a268bb5326787a12b17fbafe (diff)
downloadgnunet-be3250261ec4a398feecf23dca236ab847515d8e.tar.gz
gnunet-be3250261ec4a398feecf23dca236ab847515d8e.zip
Refactor, simplify, delete code
-rw-r--r--src/rps/gnunet-service-rps.c611
1 files changed, 234 insertions, 377 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 807e2bc12..18b9b792b 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -84,7 +84,7 @@ static struct GNUNET_HashCode port;
84/** 84/**
85 * Set a peer flag of given peer context. 85 * Set a peer flag of given peer context.
86 */ 86 */
87#define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) 87#define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask))
88 88
89/** 89/**
90 * Get peer flag of given peer context. 90 * Get peer flag of given peer context.
@@ -95,7 +95,7 @@ static struct GNUNET_HashCode port;
95/** 95/**
96 * Unset flag of given peer context. 96 * Unset flag of given peer context.
97 */ 97 */
98#define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) 98#define UNSET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask))
99 99
100/** 100/**
101 * Get channel flag of given channel context. 101 * Get channel flag of given channel context.
@@ -336,7 +336,7 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
336 * #GNUNET_NO if peer is not knwon 336 * #GNUNET_NO if peer is not knwon
337 */ 337 */
338static int 338static int
339Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) 339check_peer_known (const struct GNUNET_PeerIdentity *peer)
340{ 340{
341 if (NULL != peer_map) 341 if (NULL != peer_map)
342 { 342 {
@@ -361,7 +361,7 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
361 struct PeerContext *ctx; 361 struct PeerContext *ctx;
362 int ret; 362 int ret;
363 363
364 GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer)); 364 GNUNET_assert (GNUNET_NO == check_peer_known (peer));
365 365
366 ctx = GNUNET_new (struct PeerContext); 366 ctx = GNUNET_new (struct PeerContext);
367 ctx->peer_id = *peer; 367 ctx->peer_id = *peer;
@@ -382,7 +382,7 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer)
382static struct PeerContext * 382static struct PeerContext *
383create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) 383create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
384{ 384{
385 if (GNUNET_NO == Peers_check_peer_known (peer)) 385 if (GNUNET_NO == check_peer_known (peer))
386 { 386 {
387 return create_peer_ctx (peer); 387 return create_peer_ctx (peer);
388 } 388 }
@@ -391,37 +391,6 @@ create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer)
391 391
392 392
393/** 393/**
394 * @brief unset flags on a given peer.
395 *
396 * @param peer the peer to unset flags on
397 * @param flags the flags
398 */
399static void
400Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
401{
402 struct PeerContext *peer_ctx;
403
404 peer_ctx = get_peer_ctx (peer);
405 unset_peer_flag (peer_ctx, flags);
406}
407
408
409/**
410 * @brief set flags on a given peer.
411 *
412 * @param peer the peer to set flags on
413 * @param flags the flags
414 */
415static void
416Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
417{
418 struct PeerContext *peer_ctx;
419
420 peer_ctx = get_peer_ctx (peer);
421 set_peer_flag (peer_ctx, flags);
422}
423
424/**
425 * @brief Check whether we have a connection to this @a peer 394 * @brief Check whether we have a connection to this @a peer
426 * 395 *
427 * Also sets the #Peers_ONLINE flag accordingly 396 * Also sets the #Peers_ONLINE flag accordingly
@@ -432,12 +401,12 @@ Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlag
432 * #GNUNET_NO otherwise 401 * #GNUNET_NO otherwise
433 */ 402 */
434static int 403static int
435Peers_check_connected (const struct GNUNET_PeerIdentity *peer) 404check_connected (const struct GNUNET_PeerIdentity *peer)
436{ 405{
437 const struct PeerContext *peer_ctx; 406 struct PeerContext *peer_ctx;
438 407
439 /* If we don't know about this peer we don't know whether it's online */ 408 /* If we don't know about this peer we don't know whether it's online */
440 if (GNUNET_NO == Peers_check_peer_known (peer)) 409 if (GNUNET_NO == check_peer_known (peer))
441 { 410 {
442 return GNUNET_NO; 411 return GNUNET_NO;
443 } 412 }
@@ -447,11 +416,11 @@ Peers_check_connected (const struct GNUNET_PeerIdentity *peer)
447 if ( (NULL == peer_ctx->send_channel_ctx) && 416 if ( (NULL == peer_ctx->send_channel_ctx) &&
448 (NULL == peer_ctx->recv_channel_ctx) ) 417 (NULL == peer_ctx->recv_channel_ctx) )
449 { 418 {
450 Peers_unset_peer_flag (peer, Peers_ONLINE); 419 UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
451 return GNUNET_NO; 420 return GNUNET_NO;
452 } 421 }
453 /* Otherwise (if we have a channel, we know that it's online */ 422 /* Otherwise (if we have a channel, we know that it's online */
454 Peers_set_peer_flag (peer, Peers_ONLINE); 423 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
455 return GNUNET_YES; 424 return GNUNET_YES;
456} 425}
457 426
@@ -595,7 +564,7 @@ set_peer_live (struct PeerContext *peer_ctx)
595 } 564 }
596 565
597 (void) add_valid_peer (peer); 566 (void) add_valid_peer (peer);
598 set_peer_flag (peer_ctx, Peers_ONLINE); 567 SET_PEER_FLAG (peer_ctx, Peers_ONLINE);
599 568
600 /* Call pending operations */ 569 /* Call pending operations */
601 for (i = 0; i < peer_ctx->num_pending_ops; i++) 570 for (i = 0; i < peer_ctx->num_pending_ops; i++)
@@ -640,7 +609,14 @@ handle_peer_pull_reply (void *cls,
640 * @return The channel context 609 * @return The channel context
641 */ 610 */
642static struct ChannelCtx * 611static struct ChannelCtx *
643add_channel_ctx (struct PeerContext *peer_ctx); 612add_channel_ctx (struct PeerContext *peer_ctx)
613{
614 struct ChannelCtx *channel_ctx;
615 channel_ctx = GNUNET_new (struct ChannelCtx);
616 channel_ctx->peer_ctx = peer_ctx;
617 return channel_ctx;
618}
619
644 620
645/** 621/**
646 * @brief Remove the channel context from the DLL and free the memory. 622 * @brief Remove the channel context from the DLL and free the memory.
@@ -648,7 +624,26 @@ add_channel_ctx (struct PeerContext *peer_ctx);
648 * @param channel_ctx The channel context. 624 * @param channel_ctx The channel context.
649 */ 625 */
650static void 626static void
651remove_channel_ctx (struct ChannelCtx *channel_ctx); 627remove_channel_ctx (struct ChannelCtx *channel_ctx)
628{
629 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
630
631 if (channel_ctx == peer_ctx->send_channel_ctx)
632 {
633 GNUNET_free (channel_ctx);
634 peer_ctx->send_channel_ctx = NULL;
635 peer_ctx->mq = NULL;
636 }
637 else if (channel_ctx == peer_ctx->recv_channel_ctx)
638 {
639 GNUNET_free (channel_ctx);
640 peer_ctx->recv_channel_ctx = NULL;
641 }
642 else
643 {
644 GNUNET_assert (0);
645 }
646}
652 647
653 648
654/** 649/**
@@ -859,8 +854,107 @@ check_operation_scheduled (const struct GNUNET_PeerIdentity *peer,
859 return GNUNET_NO; 854 return GNUNET_NO;
860} 855}
861 856
857/**
858 * @brief Callback for scheduler to destroy a channel
859 *
860 * @param cls Context of the channel
861 */
862static void
863destroy_channel (struct ChannelCtx *channel_ctx)
864{
865 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
866
867 GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx ||
868 channel_ctx == peer_ctx->recv_channel_ctx);
869
870 GNUNET_CADET_channel_destroy (channel_ctx->channel);
871 remove_channel_ctx (channel_ctx);
872}
873
874
875/**
876 * @brief Remove peer
877 *
878 * @param peer the peer to clean
879 * @return #GNUNET_YES if peer was removed
880 * #GNUNET_NO otherwise
881 */
862static int 882static int
863Peers_remove_peer (const struct GNUNET_PeerIdentity *peer); 883destroy_peer (struct PeerContext *peer_ctx)
884{
885 GNUNET_assert (NULL != peer_ctx);
886 GNUNET_assert (NULL != peer_map);
887 if (GNUNET_NO ==
888 GNUNET_CONTAINER_multipeermap_contains (peer_map,
889 &peer_ctx->peer_id))
890 {
891 return GNUNET_NO;
892 }
893 SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY);
894 LOG (GNUNET_ERROR_TYPE_DEBUG,
895 "Going to remove peer %s\n",
896 GNUNET_i2s (&peer_ctx->peer_id));
897 UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE);
898
899 /* Clear list of pending operations */
900 // TODO this probably leaks memory
901 // ('only' the cls to the function. Not sure what to do with it)
902 GNUNET_array_grow (peer_ctx->pending_ops,
903 peer_ctx->num_pending_ops,
904 0);
905 /* Remove all pending messages */
906 while (NULL != peer_ctx->pending_messages_head)
907 {
908 LOG (GNUNET_ERROR_TYPE_DEBUG,
909 "Removing unsent %s\n",
910 peer_ctx->pending_messages_head->type);
911 /* Cancle pending message, too */
912 if ( (NULL != peer_ctx->liveliness_check_pending) &&
913 (0 == memcmp (peer_ctx->pending_messages_head,
914 peer_ctx->liveliness_check_pending,
915 sizeof (struct PendingMessage))) )
916 {
917 // TODO this may leak memory
918 peer_ctx->liveliness_check_pending = NULL;
919 }
920 remove_pending_message (peer_ctx->pending_messages_head,
921 GNUNET_YES);
922 }
923
924 /* If we are still waiting for notification whether this peer is live
925 * cancel the according task */
926 if (NULL != peer_ctx->liveliness_check_pending)
927 {
928 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
929 "Removing pending liveliness check for peer %s\n",
930 GNUNET_i2s (&peer_ctx->peer_id));
931 // TODO wait until cadet sets mq->cancel_impl
932 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
933 remove_pending_message (peer_ctx->liveliness_check_pending,
934 GNUNET_YES);
935 peer_ctx->liveliness_check_pending = NULL;
936 }
937
938 if (NULL != peer_ctx->send_channel_ctx)
939 {
940 destroy_channel (peer_ctx->send_channel_ctx);
941 }
942 if (NULL != peer_ctx->recv_channel_ctx)
943 {
944 destroy_channel (peer_ctx->recv_channel_ctx);
945 }
946
947 if (GNUNET_YES !=
948 GNUNET_CONTAINER_multipeermap_remove_all (peer_map,
949 &peer_ctx->peer_id))
950 {
951 LOG (GNUNET_ERROR_TYPE_WARNING,
952 "removing peer from peer_map failed\n");
953 }
954 GNUNET_free (peer_ctx);
955 return GNUNET_YES;
956}
957
864 958
865/** 959/**
866 * Iterator over hash map entries. Deletes all contexts of peers. 960 * Iterator over hash map entries. Deletes all contexts of peers.
@@ -876,7 +970,7 @@ peermap_clear_iterator (void *cls,
876 const struct GNUNET_PeerIdentity *key, 970 const struct GNUNET_PeerIdentity *key,
877 void *value) 971 void *value)
878{ 972{
879 Peers_remove_peer (key); 973 destroy_peer (get_peer_ctx (key));
880 return GNUNET_YES; 974 return GNUNET_YES;
881} 975}
882 976
@@ -1121,7 +1215,7 @@ restore_valid_peers ()
1121 * @param own_id own peer identity 1215 * @param own_id own peer identity
1122 */ 1216 */
1123static void 1217static void
1124Peers_initialise (char* fn_valid_peers, 1218initialise_peers (char* fn_valid_peers,
1125 struct GNUNET_CADET_Handle *cadet_h) 1219 struct GNUNET_CADET_Handle *cadet_h)
1126{ 1220{
1127 filename_valid_peers = GNUNET_strdup (fn_valid_peers); 1221 filename_valid_peers = GNUNET_strdup (fn_valid_peers);
@@ -1133,7 +1227,7 @@ Peers_initialise (char* fn_valid_peers,
1133 1227
1134 1228
1135/** 1229/**
1136 * @brief Delete storage of peers that was created with #Peers_initialise () 1230 * @brief Delete storage of peers that was created with #initialise_peers ()
1137 */ 1231 */
1138static void 1232static void
1139peers_terminate () 1233peers_terminate ()
@@ -1187,8 +1281,8 @@ valid_peer_iterator (void *cls,
1187 * #GNUNET_SYSERR if it aborted iteration 1281 * #GNUNET_SYSERR if it aborted iteration
1188 */ 1282 */
1189static int 1283static int
1190Peers_get_valid_peers (PeersIterator iterator, 1284get_valid_peers (PeersIterator iterator,
1191 void *it_cls) 1285 void *it_cls)
1192{ 1286{
1193 struct PeersIteratorCls *cls; 1287 struct PeersIteratorCls *cls;
1194 int ret; 1288 int ret;
@@ -1216,9 +1310,9 @@ Peers_get_valid_peers (PeersIterator iterator,
1216 * #GNUNET_NO otherwise 1310 * #GNUNET_NO otherwise
1217 */ 1311 */
1218static int 1312static int
1219Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) 1313insert_peer (const struct GNUNET_PeerIdentity *peer)
1220{ 1314{
1221 if (GNUNET_YES == Peers_check_peer_known (peer)) 1315 if (GNUNET_YES == check_peer_known (peer))
1222 { 1316 {
1223 return GNUNET_NO; /* We already know this peer - nothing to do */ 1317 return GNUNET_NO; /* We already know this peer - nothing to do */
1224 } 1318 }
@@ -1226,8 +1320,30 @@ Peers_insert_peer (const struct GNUNET_PeerIdentity *peer)
1226 return GNUNET_YES; 1320 return GNUNET_YES;
1227} 1321}
1228 1322
1323
1324/**
1325 * @brief Check whether flags on a peer are set.
1326 *
1327 * @param peer the peer to check the flag of
1328 * @param flags the flags to check
1329 *
1330 * @return #GNUNET_SYSERR if peer is not known
1331 * #GNUNET_YES if all given flags are set
1332 * #GNUNET_NO otherwise
1333 */
1229static int 1334static int
1230Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); 1335check_peer_flag (const struct GNUNET_PeerIdentity *peer,
1336 enum Peers_PeerFlags flags)
1337{
1338 struct PeerContext *peer_ctx;
1339
1340 if (GNUNET_NO == check_peer_known (peer))
1341 {
1342 return GNUNET_SYSERR;
1343 }
1344 peer_ctx = get_peer_ctx (peer);
1345 return check_peer_flag_set (peer_ctx, flags);
1346}
1231 1347
1232/** 1348/**
1233 * @brief Try connecting to a peer to see whether it is online 1349 * @brief Try connecting to a peer to see whether it is online
@@ -1239,14 +1355,14 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl
1239 * #GNUNET_NO otherwise 1355 * #GNUNET_NO otherwise
1240 */ 1356 */
1241static int 1357static int
1242Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) 1358issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1243{ 1359{
1244 struct PeerContext *peer_ctx; 1360 struct PeerContext *peer_ctx;
1245 int ret; 1361 int ret;
1246 1362
1247 ret = Peers_insert_peer (peer); 1363 ret = insert_peer (peer);
1248 peer_ctx = get_peer_ctx (peer); 1364 peer_ctx = get_peer_ctx (peer);
1249 if ( (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) && 1365 if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) &&
1250 (NULL == peer_ctx->liveliness_check_pending) ) 1366 (NULL == peer_ctx->liveliness_check_pending) )
1251 { 1367 {
1252 check_peer_live (peer_ctx); 1368 check_peer_live (peer_ctx);
@@ -1269,7 +1385,7 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer)
1269 * #GNUNET_SYSERR if peer is not known 1385 * #GNUNET_SYSERR if peer is not known
1270 */ 1386 */
1271static int 1387static int
1272Peers_check_removable (const struct GNUNET_PeerIdentity *peer) 1388check_removable (const struct GNUNET_PeerIdentity *peer)
1273{ 1389{
1274 struct PeerContext *peer_ctx; 1390 struct PeerContext *peer_ctx;
1275 1391
@@ -1288,162 +1404,6 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer)
1288 return GNUNET_YES; 1404 return GNUNET_YES;
1289} 1405}
1290 1406
1291static uint32_t *
1292Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer,
1293 enum Peers_ChannelRole role);
1294
1295static int
1296Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
1297
1298/**
1299 * @brief Callback for the scheduler to destroy the knowledge of a peer.
1300 *
1301 * @param cls Context of the peer
1302 */
1303static void
1304destroy_peer (void *cls)
1305{
1306 struct PeerContext *peer_ctx = cls;
1307
1308 GNUNET_assert (NULL != peer_ctx);
1309 Peers_remove_peer (&peer_ctx->peer_id);
1310}
1311
1312
1313/**
1314 * @brief Callback for scheduler to destroy a channel
1315 *
1316 * @param cls Context of the channel
1317 */
1318static void
1319destroy_channel (void *cls)
1320{
1321 struct ChannelCtx *channel_ctx = cls;
1322 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
1323
1324 GNUNET_assert (channel_ctx == peer_ctx->send_channel_ctx ||
1325 channel_ctx == peer_ctx->recv_channel_ctx);
1326
1327 GNUNET_CADET_channel_destroy (channel_ctx->channel);
1328 remove_channel_ctx (peer_ctx->send_channel_ctx);
1329}
1330
1331
1332/**
1333 * @brief Remove peer
1334 *
1335 * @param peer the peer to clean
1336 * @return #GNUNET_YES if peer was removed
1337 * #GNUNET_NO otherwise
1338 */
1339static int
1340Peers_remove_peer (const struct GNUNET_PeerIdentity *peer)
1341{
1342 struct PeerContext *peer_ctx;
1343
1344 GNUNET_assert (NULL != peer_map);
1345 if (GNUNET_NO ==
1346 GNUNET_CONTAINER_multipeermap_contains (peer_map,
1347 peer))
1348 {
1349 return GNUNET_NO;
1350 }
1351 peer_ctx = get_peer_ctx (peer);
1352 set_peer_flag (peer_ctx, Peers_TO_DESTROY);
1353 LOG (GNUNET_ERROR_TYPE_DEBUG,
1354 "Going to remove peer %s\n",
1355 GNUNET_i2s (&peer_ctx->peer_id));
1356 Peers_unset_peer_flag (peer, Peers_ONLINE);
1357
1358 /* Clear list of pending operations */
1359 // TODO this probably leaks memory
1360 // ('only' the cls to the function. Not sure what to do with it)
1361 GNUNET_array_grow (peer_ctx->pending_ops,
1362 peer_ctx->num_pending_ops,
1363 0);
1364 /* Remove all pending messages */
1365 while (NULL != peer_ctx->pending_messages_head)
1366 {
1367 LOG (GNUNET_ERROR_TYPE_DEBUG,
1368 "Removing unsent %s\n",
1369 peer_ctx->pending_messages_head->type);
1370 /* Cancle pending message, too */
1371 if ( (NULL != peer_ctx->liveliness_check_pending) &&
1372 (0 == memcmp (peer_ctx->pending_messages_head,
1373 peer_ctx->liveliness_check_pending,
1374 sizeof (struct PendingMessage))) )
1375 {
1376 // TODO this may leak memory
1377 peer_ctx->liveliness_check_pending = NULL;
1378 }
1379 remove_pending_message (peer_ctx->pending_messages_head,
1380 GNUNET_YES);
1381 }
1382
1383 /* If we are still waiting for notification whether this peer is live
1384 * cancel the according task */
1385 if (NULL != peer_ctx->liveliness_check_pending)
1386 {
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Removing pending liveliness check for peer %s\n",
1389 GNUNET_i2s (&peer_ctx->peer_id));
1390 // TODO wait until cadet sets mq->cancel_impl
1391 //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev);
1392 remove_pending_message (peer_ctx->liveliness_check_pending,
1393 GNUNET_YES);
1394 peer_ctx->liveliness_check_pending = NULL;
1395 }
1396
1397
1398 /* Do we still have to wait for destruction of channels
1399 * or issue the destruction? */
1400 if (NULL != peer_ctx->send_channel_ctx)
1401 {
1402 destroy_channel (peer_ctx->send_channel_ctx);
1403 return GNUNET_NO;
1404 }
1405 if (NULL != peer_ctx->recv_channel_ctx)
1406 {
1407 destroy_channel (peer_ctx->recv_channel_ctx);
1408 return GNUNET_NO;
1409 }
1410 destroy_peer (peer_ctx);
1411
1412 if (GNUNET_YES !=
1413 GNUNET_CONTAINER_multipeermap_remove_all (peer_map,
1414 &peer_ctx->peer_id))
1415 {
1416 LOG (GNUNET_ERROR_TYPE_WARNING,
1417 "removing peer from peer_map failed\n");
1418 }
1419 GNUNET_free (peer_ctx);
1420 return GNUNET_YES;
1421}
1422
1423
1424/**
1425 * @brief Check whether flags on a peer are set.
1426 *
1427 * @param peer the peer to check the flag of
1428 * @param flags the flags to check
1429 *
1430 * @return #GNUNET_SYSERR if peer is not known
1431 * #GNUNET_YES if all given flags are set
1432 * #GNUNET_NO otherwise
1433 */
1434static int
1435Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags)
1436{
1437 struct PeerContext *peer_ctx;
1438
1439 if (GNUNET_NO == Peers_check_peer_known (peer))
1440 {
1441 return GNUNET_SYSERR;
1442 }
1443 peer_ctx = get_peer_ctx (peer);
1444 return check_peer_flag_set (peer_ctx, flags);
1445}
1446
1447 1407
1448/** 1408/**
1449 * @brief Check whether @a peer is actually a peer. 1409 * @brief Check whether @a peer is actually a peer.
@@ -1456,7 +1416,7 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl
1456 * #GNUNET_NO if peer is not valid 1416 * #GNUNET_NO if peer is not valid
1457 */ 1417 */
1458static int 1418static int
1459Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) 1419check_peer_valid (const struct GNUNET_PeerIdentity *peer)
1460{ 1420{
1461 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); 1421 return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer);
1462} 1422}
@@ -1470,9 +1430,9 @@ Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer)
1470 * @param peer the peer to establish channel to 1430 * @param peer the peer to establish channel to
1471 */ 1431 */
1472static void 1432static void
1473Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) 1433indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
1474{ 1434{
1475 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); 1435 GNUNET_assert (GNUNET_YES == check_peer_known (peer));
1476 (void) get_channel (peer); 1436 (void) get_channel (peer);
1477} 1437}
1478 1438
@@ -1487,7 +1447,7 @@ Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer)
1487 * #GNUNET_NO otherwise 1447 * #GNUNET_NO otherwise
1488 */ 1448 */
1489static int 1449static int
1490Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) 1450check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1491{ 1451{
1492 const struct PeerContext *peer_ctx; 1452 const struct PeerContext *peer_ctx;
1493 1453
@@ -1511,9 +1471,9 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer)
1511 * (can be NULL -- that's not an error) 1471 * (can be NULL -- that's not an error)
1512 */ 1472 */
1513static void * 1473static void *
1514Peers_handle_inbound_channel (void *cls, 1474handle_inbound_channel (void *cls,
1515 struct GNUNET_CADET_Channel *channel, 1475 struct GNUNET_CADET_Channel *channel,
1516 const struct GNUNET_PeerIdentity *initiator) 1476 const struct GNUNET_PeerIdentity *initiator)
1517{ 1477{
1518 struct PeerContext *peer_ctx; 1478 struct PeerContext *peer_ctx;
1519 struct GNUNET_PeerIdentity *ctx_peer; 1479 struct GNUNET_PeerIdentity *ctx_peer;
@@ -1531,14 +1491,12 @@ Peers_handle_inbound_channel (void *cls,
1531 channel_ctx = add_channel_ctx (peer_ctx); 1491 channel_ctx = add_channel_ctx (peer_ctx);
1532 channel_ctx->channel = channel; 1492 channel_ctx->channel = channel;
1533 /* We only accept one incoming channel per peer */ 1493 /* We only accept one incoming channel per peer */
1534 if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) 1494 if (GNUNET_YES == check_peer_send_intention (initiator))
1535 { 1495 {
1536 LOG (GNUNET_ERROR_TYPE_WARNING, 1496 LOG (GNUNET_ERROR_TYPE_WARNING,
1537 "Already got one receive channel. Destroying old one.\n"); 1497 "Already got one receive channel. Destroying old one.\n");
1538 GNUNET_break_op (0); 1498 GNUNET_break_op (0);
1539 GNUNET_CADET_channel_destroy (peer_ctx->recv_channel_ctx->channel); 1499 destroy_channel (peer_ctx->recv_channel_ctx);
1540 peer_ctx->recv_channel_ctx->channel = NULL;
1541 remove_channel_ctx (peer_ctx->recv_channel_ctx);
1542 peer_ctx->recv_channel_ctx = channel_ctx; 1500 peer_ctx->recv_channel_ctx = channel_ctx;
1543 /* return the channel context */ 1501 /* return the channel context */
1544 return channel_ctx; 1502 return channel_ctx;
@@ -1557,11 +1515,11 @@ Peers_handle_inbound_channel (void *cls,
1557 * #GNUNET_NO otherwise 1515 * #GNUNET_NO otherwise
1558 */ 1516 */
1559static int 1517static int
1560Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) 1518check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
1561{ 1519{
1562 struct PeerContext *peer_ctx; 1520 struct PeerContext *peer_ctx;
1563 1521
1564 if (GNUNET_NO == Peers_check_peer_known (peer)) 1522 if (GNUNET_NO == check_peer_known (peer))
1565 { /* If no such peer exists, there is no channel */ 1523 { /* If no such peer exists, there is no channel */
1566 return GNUNET_NO; 1524 return GNUNET_NO;
1567 } 1525 }
@@ -1575,46 +1533,6 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer)
1575 1533
1576 1534
1577/** 1535/**
1578 * @brief check whether the given channel is the sending channel of the given
1579 * peer
1580 *
1581 * @param peer the peer in question
1582 * @param channel the channel to check for
1583 * @param role either #Peers_CHANNEL_ROLE_SENDING, or
1584 * #Peers_CHANNEL_ROLE_RECEIVING
1585 *
1586 * @return #GNUNET_YES if the given chennel is the sending channel of the peer
1587 * #GNUNET_NO otherwise
1588 */
1589static int
1590Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
1591 const struct GNUNET_CADET_Channel *channel,
1592 enum Peers_ChannelRole role)
1593{
1594 const struct PeerContext *peer_ctx;
1595
1596 if (GNUNET_NO == Peers_check_peer_known (peer))
1597 {
1598 return GNUNET_NO;
1599 }
1600 peer_ctx = get_peer_ctx (peer);
1601 if ( (Peers_CHANNEL_ROLE_SENDING == role) &&
1602 (NULL != peer_ctx->send_channel_ctx) &&
1603 (channel == peer_ctx->send_channel_ctx->channel) )
1604 {
1605 return GNUNET_YES;
1606 }
1607 if ( (Peers_CHANNEL_ROLE_RECEIVING == role) &&
1608 (NULL != peer_ctx->recv_channel_ctx) &&
1609 (channel == peer_ctx->recv_channel_ctx->channel) )
1610 {
1611 return GNUNET_YES;
1612 }
1613 return GNUNET_NO;
1614}
1615
1616
1617/**
1618 * @brief Destroy the send channel of a peer e.g. stop indicating a sending 1536 * @brief Destroy the send channel of a peer e.g. stop indicating a sending
1619 * intention to another peer 1537 * intention to another peer
1620 * 1538 *
@@ -1627,11 +1545,11 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
1627 * #GNUNET_NO otherwise 1545 * #GNUNET_NO otherwise
1628 */ 1546 */
1629static int 1547static int
1630Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) 1548destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1631{ 1549{
1632 struct PeerContext *peer_ctx; 1550 struct PeerContext *peer_ctx;
1633 1551
1634 if (GNUNET_NO == Peers_check_peer_known (peer)) 1552 if (GNUNET_NO == check_peer_known (peer))
1635 { 1553 {
1636 return GNUNET_NO; 1554 return GNUNET_NO;
1637 } 1555 }
@@ -1639,7 +1557,7 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1639 if (NULL != peer_ctx->send_channel_ctx) 1557 if (NULL != peer_ctx->send_channel_ctx)
1640 { 1558 {
1641 destroy_channel (peer_ctx->send_channel_ctx); 1559 destroy_channel (peer_ctx->send_channel_ctx);
1642 (void) Peers_check_connected (peer); 1560 (void) check_connected (peer);
1643 return GNUNET_YES; 1561 return GNUNET_YES;
1644 } 1562 }
1645 return GNUNET_NO; 1563 return GNUNET_NO;
@@ -1656,9 +1574,9 @@ Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer)
1656 * @param type type of the message 1574 * @param type type of the message
1657 */ 1575 */
1658static void 1576static void
1659Peers_send_message (const struct GNUNET_PeerIdentity *peer, 1577send_message (const struct GNUNET_PeerIdentity *peer,
1660 struct GNUNET_MQ_Envelope *ev, 1578 struct GNUNET_MQ_Envelope *ev,
1661 const char *type) 1579 const char *type)
1662{ 1580{
1663 struct PendingMessage *pending_msg; 1581 struct PendingMessage *pending_msg;
1664 struct GNUNET_MQ_Handle *mq; 1582 struct GNUNET_MQ_Handle *mq;
@@ -1686,13 +1604,13 @@ Peers_send_message (const struct GNUNET_PeerIdentity *peer,
1686 * #GNUNET_NO otherwise 1604 * #GNUNET_NO otherwise
1687 */ 1605 */
1688static int 1606static int
1689Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, 1607schedule_operation (const struct GNUNET_PeerIdentity *peer,
1690 const PeerOp peer_op) 1608 const PeerOp peer_op)
1691{ 1609{
1692 struct PeerPendingOp pending_op; 1610 struct PeerPendingOp pending_op;
1693 struct PeerContext *peer_ctx; 1611 struct PeerContext *peer_ctx;
1694 1612
1695 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); 1613 GNUNET_assert (GNUNET_YES == check_peer_known (peer));
1696 1614
1697 //TODO if LIVE/ONLINE execute immediately 1615 //TODO if LIVE/ONLINE execute immediately
1698 1616
@@ -1709,24 +1627,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
1709 return GNUNET_NO; 1627 return GNUNET_NO;
1710} 1628}
1711 1629
1712/**
1713 * @brief Get the recv_channel of @a peer.
1714 * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming
1715 * messages.
1716 *
1717 * @param peer The peer to get the recv_channel from.
1718 *
1719 * @return The recv_channel.
1720 */
1721static struct GNUNET_CADET_Channel *
1722Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer)
1723{
1724 struct PeerContext *peer_ctx;
1725
1726 GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer));
1727 peer_ctx = get_peer_ctx (peer);
1728 return peer_ctx->recv_channel_ctx->channel;
1729}
1730/*********************************************************************** 1630/***********************************************************************
1731 * /Old gnunet-service-rps_peers.c 1631 * /Old gnunet-service-rps_peers.c
1732***********************************************************************/ 1632***********************************************************************/
@@ -2182,16 +2082,16 @@ insert_in_view (const struct GNUNET_PeerIdentity *peer)
2182{ 2082{
2183 int online; 2083 int online;
2184 2084
2185 online = Peers_check_peer_flag (peer, Peers_ONLINE); 2085 online = check_peer_flag (peer, Peers_ONLINE);
2186 if ( (GNUNET_NO == online) || 2086 if ( (GNUNET_NO == online) ||
2187 (GNUNET_SYSERR == online) ) /* peer is not even known */ 2087 (GNUNET_SYSERR == online) ) /* peer is not even known */
2188 { 2088 {
2189 (void) Peers_issue_peer_liveliness_check (peer); 2089 (void) issue_peer_liveliness_check (peer);
2190 (void) Peers_schedule_operation (peer, insert_in_view_op); 2090 (void) schedule_operation (peer, insert_in_view_op);
2191 return GNUNET_NO; 2091 return GNUNET_NO;
2192 } 2092 }
2193 /* Open channel towards peer to keep connection open */ 2093 /* Open channel towards peer to keep connection open */
2194 Peers_indicate_sending_intention (peer); 2094 indicate_sending_intention (peer);
2195 return View_put (peer); 2095 return View_put (peer);
2196} 2096}
2197 2097
@@ -2384,7 +2284,7 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id,
2384 GNUNET_memcpy (&out_msg[1], peer_ids, 2284 GNUNET_memcpy (&out_msg[1], peer_ids,
2385 send_size * sizeof (struct GNUNET_PeerIdentity)); 2285 send_size * sizeof (struct GNUNET_PeerIdentity));
2386 2286
2387 Peers_send_message (peer_id, ev, "PULL REPLY"); 2287 send_message (peer_id, ev, "PULL REPLY");
2388 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); 2288 GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO);
2389 // TODO check with send intention: as send_channel is used/opened we indicate 2289 // TODO check with send intention: as send_channel is used/opened we indicate
2390 // a sending intention without intending it. 2290 // a sending intention without intending it.
@@ -2435,10 +2335,10 @@ insert_in_sampler (void *cls,
2435 if (0 < RPS_sampler_count_id (prot_sampler, peer)) 2335 if (0 < RPS_sampler_count_id (prot_sampler, peer))
2436 { 2336 {
2437 /* Make sure we 'know' about this peer */ 2337 /* Make sure we 'know' about this peer */
2438 (void) Peers_issue_peer_liveliness_check (peer); 2338 (void) issue_peer_liveliness_check (peer);
2439 /* Establish a channel towards that peer to indicate we are going to send 2339 /* Establish a channel towards that peer to indicate we are going to send
2440 * messages to it */ 2340 * messages to it */
2441 //Peers_indicate_sending_intention (peer); 2341 //indicate_sending_intention (peer);
2442 } 2342 }
2443 #ifdef TO_FILE 2343 #ifdef TO_FILE
2444 num_observed_peers++; 2344 num_observed_peers++;
@@ -2470,10 +2370,10 @@ static void
2470got_peer (const struct GNUNET_PeerIdentity *peer) 2370got_peer (const struct GNUNET_PeerIdentity *peer)
2471{ 2371{
2472 /* If we did not know this peer already, insert it into sampler and view */ 2372 /* If we did not know this peer already, insert it into sampler and view */
2473 if (GNUNET_YES == Peers_issue_peer_liveliness_check (peer)) 2373 if (GNUNET_YES == issue_peer_liveliness_check (peer))
2474 { 2374 {
2475 Peers_schedule_operation (peer, insert_in_sampler); 2375 schedule_operation (peer, insert_in_sampler);
2476 Peers_schedule_operation (peer, insert_in_view_op); 2376 schedule_operation (peer, insert_in_view_op);
2477 } 2377 }
2478} 2378}
2479 2379
@@ -2488,17 +2388,17 @@ static int
2488check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) 2388check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer)
2489{ 2389{
2490 /* struct GNUNET_CADET_Channel *channel; */ 2390 /* struct GNUNET_CADET_Channel *channel; */
2491 if (GNUNET_NO == Peers_check_peer_known (peer)) 2391 if (GNUNET_NO == check_peer_known (peer))
2492 { 2392 {
2493 return GNUNET_NO; 2393 return GNUNET_NO;
2494 } 2394 }
2495 if (GNUNET_YES == Peers_check_sending_channel_exists (peer)) 2395 if (GNUNET_YES == check_sending_channel_exists (peer))
2496 { 2396 {
2497 if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || 2397 if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) ||
2498 (GNUNET_YES == View_contains_peer (peer)) || 2398 (GNUNET_YES == View_contains_peer (peer)) ||
2499 (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || 2399 (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) ||
2500 (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || 2400 (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) ||
2501 (GNUNET_YES == Peers_check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) 2401 (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING)))
2502 { /* If we want to keep the connection to peer open */ 2402 { /* If we want to keep the connection to peer open */
2503 return GNUNET_YES; 2403 return GNUNET_YES;
2504 } 2404 }
@@ -2542,19 +2442,19 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
2542 GNUNET_i2s (peer)); 2442 GNUNET_i2s (peer));
2543 #ifdef ENABLE_MALICIOUS 2443 #ifdef ENABLE_MALICIOUS
2544 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) 2444 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer))
2545 (void) Peers_destroy_sending_channel (peer); 2445 (void) destroy_sending_channel (peer);
2546 #else /* ENABLE_MALICIOUS */ 2446 #else /* ENABLE_MALICIOUS */
2547 (void) Peers_destroy_sending_channel (peer); 2447 (void) destroy_sending_channel (peer);
2548 #endif /* ENABLE_MALICIOUS */ 2448 #endif /* ENABLE_MALICIOUS */
2549 } 2449 }
2550 2450
2551 if ( (GNUNET_NO == Peers_check_peer_send_intention (peer)) && 2451 if ( (GNUNET_NO == check_peer_send_intention (peer)) &&
2552 (GNUNET_NO == View_contains_peer (peer)) && 2452 (GNUNET_NO == View_contains_peer (peer)) &&
2553 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && 2453 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
2554 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && 2454 (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) &&
2555 (0 == RPS_sampler_count_id (prot_sampler, peer)) && 2455 (0 == RPS_sampler_count_id (prot_sampler, peer)) &&
2556 (0 == RPS_sampler_count_id (client_sampler, peer)) && 2456 (0 == RPS_sampler_count_id (client_sampler, peer)) &&
2557 (GNUNET_NO != Peers_check_removable (peer)) ) 2457 (GNUNET_NO != check_removable (peer)) )
2558 { /* We can safely remove this peer */ 2458 { /* We can safely remove this peer */
2559 LOG (GNUNET_ERROR_TYPE_DEBUG, 2459 LOG (GNUNET_ERROR_TYPE_DEBUG,
2560 "Going to remove peer %s\n", 2460 "Going to remove peer %s\n",
@@ -2564,49 +2464,6 @@ clean_peer (const struct GNUNET_PeerIdentity *peer)
2564 } 2464 }
2565} 2465}
2566 2466
2567/**
2568 * @brief Allocate memory for a new channel context and insert it into DLL
2569 *
2570 * @param peer_ctx context of the according peer
2571 *
2572 * @return The channel context
2573 */
2574static struct ChannelCtx *
2575add_channel_ctx (struct PeerContext *peer_ctx)
2576{
2577 struct ChannelCtx *channel_ctx;
2578 channel_ctx = GNUNET_new (struct ChannelCtx);
2579 channel_ctx->peer_ctx = peer_ctx;
2580 return channel_ctx;
2581}
2582
2583
2584/**
2585 * @brief Remove the channel context from the DLL and free the memory.
2586 *
2587 * @param channel_ctx The channel context.
2588 */
2589static void
2590remove_channel_ctx (struct ChannelCtx *channel_ctx)
2591{
2592 struct PeerContext *peer_ctx = channel_ctx->peer_ctx;
2593
2594 GNUNET_free (channel_ctx);
2595 if (channel_ctx == peer_ctx->send_channel_ctx)
2596 {
2597 peer_ctx->send_channel_ctx = NULL;
2598 peer_ctx->mq = NULL;
2599 }
2600 else if (channel_ctx == peer_ctx->recv_channel_ctx)
2601 {
2602 peer_ctx->recv_channel_ctx = NULL;
2603 }
2604 else
2605 {
2606 GNUNET_assert (0);
2607 }
2608}
2609
2610 2467
2611/** 2468/**
2612 * @brief This is called when a channel is destroyed. 2469 * @brief This is called when a channel is destroyed.
@@ -3096,7 +2953,7 @@ handle_peer_push (void *cls,
3096 /* Add the sending peer to the push_map */ 2953 /* Add the sending peer to the push_map */
3097 CustomPeerMap_put (push_map, peer); 2954 CustomPeerMap_put (push_map, peer);
3098 2955
3099 GNUNET_break_op (Peers_check_peer_known (peer)); 2956 GNUNET_break_op (check_peer_known (peer));
3100 GNUNET_CADET_receive_done (channel_ctx->channel); 2957 GNUNET_CADET_receive_done (channel_ctx->channel);
3101} 2958}
3102 2959
@@ -3136,7 +2993,7 @@ handle_peer_pull_request (void *cls,
3136 } 2993 }
3137 #endif /* ENABLE_MALICIOUS */ 2994 #endif /* ENABLE_MALICIOUS */
3138 2995
3139 GNUNET_break_op (Peers_check_peer_known (peer)); 2996 GNUNET_break_op (check_peer_known (peer));
3140 GNUNET_CADET_receive_done (channel_ctx->channel); 2997 GNUNET_CADET_receive_done (channel_ctx->channel);
3141 view_array = View_get_as_array (); 2998 view_array = View_get_as_array ();
3142 send_pull_reply (peer, view_array, View_size ()); 2999 send_pull_reply (peer, view_array, View_size ());
@@ -3174,7 +3031,7 @@ check_peer_pull_reply (void *cls,
3174 return GNUNET_SYSERR; 3031 return GNUNET_SYSERR;
3175 } 3032 }
3176 3033
3177 if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) 3034 if (GNUNET_YES != check_peer_flag (sender, Peers_PULL_REPLY_PENDING))
3178 { 3035 {
3179 LOG (GNUNET_ERROR_TYPE_WARNING, 3036 LOG (GNUNET_ERROR_TYPE_WARNING,
3180 "Received a pull reply from a peer (%s) we didn't request one from!\n", 3037 "Received a pull reply from a peer (%s) we didn't request one from!\n",
@@ -3248,23 +3105,23 @@ handle_peer_pull_reply (void *cls,
3248 } 3105 }
3249 #endif /* ENABLE_MALICIOUS */ 3106 #endif /* ENABLE_MALICIOUS */
3250 /* Make sure we 'know' about this peer */ 3107 /* Make sure we 'know' about this peer */
3251 (void) Peers_insert_peer (&peers[i]); 3108 (void) insert_peer (&peers[i]);
3252 3109
3253 if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) 3110 if (GNUNET_YES == check_peer_valid (&peers[i]))
3254 { 3111 {
3255 CustomPeerMap_put (pull_map, &peers[i]); 3112 CustomPeerMap_put (pull_map, &peers[i]);
3256 } 3113 }
3257 else 3114 else
3258 { 3115 {
3259 Peers_schedule_operation (&peers[i], insert_in_pull_map); 3116 schedule_operation (&peers[i], insert_in_pull_map);
3260 (void) Peers_issue_peer_liveliness_check (&peers[i]); 3117 (void) issue_peer_liveliness_check (&peers[i]);
3261 } 3118 }
3262 } 3119 }
3263 3120
3264 Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING); 3121 UNSET_PEER_FLAG (get_peer_ctx (sender), Peers_PULL_REPLY_PENDING);
3265 clean_peer (sender); 3122 clean_peer (sender);
3266 3123
3267 GNUNET_break_op (Peers_check_peer_known (sender)); 3124 GNUNET_break_op (check_peer_known (sender));
3268 GNUNET_CADET_receive_done (channel_ctx->channel); 3125 GNUNET_CADET_receive_done (channel_ctx->channel);
3269} 3126}
3270 3127
@@ -3328,16 +3185,16 @@ send_pull_request (const struct GNUNET_PeerIdentity *peer)
3328{ 3185{
3329 struct GNUNET_MQ_Envelope *ev; 3186 struct GNUNET_MQ_Envelope *ev;
3330 3187
3331 GNUNET_assert (GNUNET_NO == Peers_check_peer_flag (peer, 3188 GNUNET_assert (GNUNET_NO == check_peer_flag (peer,
3332 Peers_PULL_REPLY_PENDING)); 3189 Peers_PULL_REPLY_PENDING));
3333 Peers_set_peer_flag (peer, Peers_PULL_REPLY_PENDING); 3190 SET_PEER_FLAG (get_peer_ctx (peer), Peers_PULL_REPLY_PENDING);
3334 3191
3335 LOG (GNUNET_ERROR_TYPE_DEBUG, 3192 LOG (GNUNET_ERROR_TYPE_DEBUG,
3336 "Going to send PULL REQUEST to peer %s.\n", 3193 "Going to send PULL REQUEST to peer %s.\n",
3337 GNUNET_i2s (peer)); 3194 GNUNET_i2s (peer));
3338 3195
3339 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); 3196 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
3340 Peers_send_message (peer, ev, "PULL REQUEST"); 3197 send_message (peer, ev, "PULL REQUEST");
3341 GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); 3198 GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO);
3342} 3199}
3343 3200
@@ -3357,7 +3214,7 @@ send_push (const struct GNUNET_PeerIdentity *peer_id)
3357 GNUNET_i2s (peer_id)); 3214 GNUNET_i2s (peer_id));
3358 3215
3359 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); 3216 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
3360 Peers_send_message (peer_id, ev, "PUSH"); 3217 send_message (peer_id, ev, "PUSH");
3361 GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); 3218 GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO);
3362} 3219}
3363 3220
@@ -3481,9 +3338,9 @@ handle_client_act_malicious (void *cls,
3481 &msg->attacked_peer, 3338 &msg->attacked_peer,
3482 sizeof (struct GNUNET_PeerIdentity)); 3339 sizeof (struct GNUNET_PeerIdentity));
3483 /* Set the flag of the attacked peer to valid to avoid problems */ 3340 /* Set the flag of the attacked peer to valid to avoid problems */
3484 if (GNUNET_NO == Peers_check_peer_known (&attacked_peer)) 3341 if (GNUNET_NO == check_peer_known (&attacked_peer))
3485 { 3342 {
3486 (void) Peers_issue_peer_liveliness_check (&attacked_peer); 3343 (void) issue_peer_liveliness_check (&attacked_peer);
3487 } 3344 }
3488 3345
3489 LOG (GNUNET_ERROR_TYPE_DEBUG, 3346 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -3573,8 +3430,8 @@ do_mal_round (void *cls)
3573 * Send as many pushes to the attacked peer as possible 3430 * Send as many pushes to the attacked peer as possible
3574 * That is one push per round as it will ignore more. 3431 * That is one push per round as it will ignore more.
3575 */ 3432 */
3576 (void) Peers_issue_peer_liveliness_check (&attacked_peer); 3433 (void) issue_peer_liveliness_check (&attacked_peer);
3577 if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) 3434 if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE))
3578 send_push (&attacked_peer); 3435 send_push (&attacked_peer);
3579 } 3436 }
3580 3437
@@ -3583,10 +3440,10 @@ do_mal_round (void *cls)
3583 { /* Combined attack */ 3440 { /* Combined attack */
3584 3441
3585 /* Send PUSH to attacked peers */ 3442 /* Send PUSH to attacked peers */
3586 if (GNUNET_YES == Peers_check_peer_known (&attacked_peer)) 3443 if (GNUNET_YES == check_peer_known (&attacked_peer))
3587 { 3444 {
3588 (void) Peers_issue_peer_liveliness_check (&attacked_peer); 3445 (void) issue_peer_liveliness_check (&attacked_peer);
3589 if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) 3446 if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE))
3590 { 3447 {
3591 LOG (GNUNET_ERROR_TYPE_DEBUG, 3448 LOG (GNUNET_ERROR_TYPE_DEBUG,
3592 "Goding to send push to attacked peer (%s)\n", 3449 "Goding to send push to attacked peer (%s)\n",
@@ -3594,7 +3451,7 @@ do_mal_round (void *cls)
3594 send_push (&attacked_peer); 3451 send_push (&attacked_peer);
3595 } 3452 }
3596 } 3453 }
3597 (void) Peers_issue_peer_liveliness_check (&attacked_peer); 3454 (void) issue_peer_liveliness_check (&attacked_peer);
3598 3455
3599 /* The maximum of pushes we're going to send this round */ 3456 /* The maximum of pushes we're going to send this round */
3600 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, 3457 num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1,
@@ -3711,7 +3568,7 @@ do_round (void *cls)
3711 for (i = first_border; i < second_border; i++) 3568 for (i = first_border; i < second_border; i++)
3712 { 3569 {
3713 peer = view_array[permut[i]]; 3570 peer = view_array[permut[i]];
3714 if ( GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) 3571 if ( GNUNET_NO == check_peer_flag (&peer, Peers_PULL_REPLY_PENDING))
3715 { // FIXME if this fails schedule/loop this for later 3572 { // FIXME if this fails schedule/loop this for later
3716 send_pull_request (&peer); 3573 send_pull_request (&peer);
3717 } 3574 }
@@ -4227,7 +4084,7 @@ run (void *cls,
4227 &port); 4084 &port);
4228 cadet_port = GNUNET_CADET_open_port (cadet_handle, 4085 cadet_port = GNUNET_CADET_open_port (cadet_handle,
4229 &port, 4086 &port,
4230 &Peers_handle_inbound_channel, /* Connect handler */ 4087 &handle_inbound_channel, /* Connect handler */
4231 NULL, /* cls */ 4088 NULL, /* cls */
4232 NULL, /* WindowSize handler */ 4089 NULL, /* WindowSize handler */
4233 &cleanup_destroyed_channel, /* Disconnect handler */ 4090 &cleanup_destroyed_channel, /* Disconnect handler */
@@ -4242,7 +4099,7 @@ run (void *cls,
4242 4099
4243 4100
4244 peerinfo_handle = GNUNET_PEERINFO_connect (cfg); 4101 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
4245 Peers_initialise (fn_valid_peers, cadet_handle); 4102 initialise_peers (fn_valid_peers, cadet_handle);
4246 GNUNET_free (fn_valid_peers); 4103 GNUNET_free (fn_valid_peers);
4247 4104
4248 /* Initialise sampler */ 4105 /* Initialise sampler */
@@ -4265,7 +4122,7 @@ run (void *cls,
4265 // TODO send push/pull to each of those peers? 4122 // TODO send push/pull to each of those peers?
4266 // TODO read stored valid peers from last run 4123 // TODO read stored valid peers from last run
4267 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); 4124 LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
4268 Peers_get_valid_peers (valid_peers_iterator, NULL); 4125 get_valid_peers (valid_peers_iterator, NULL);
4269 4126
4270 peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, 4127 peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg,
4271 GNUNET_NO, 4128 GNUNET_NO,