aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-03-25 17:17:18 +0000
committerJulius Bünger <buenger@mytum.de>2015-03-25 17:17:18 +0000
commitc18be283dc4b5d1e2381fc0b665f16b0e88b1934 (patch)
tree95c3eb82ecf4a27e943a06344343f2158fe55c83 /src
parent4ef920e458c83feb09f599c6fa8b1b3d8505cee8 (diff)
downloadgnunet-c18be283dc4b5d1e2381fc0b665f16b0e88b1934.tar.gz
gnunet-c18be283dc4b5d1e2381fc0b665f16b0e88b1934.zip
-further implemented mal peer, restructured code
Diffstat (limited to 'src')
-rw-r--r--src/rps/gnunet-service-rps.c263
1 files changed, 188 insertions, 75 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 889f7b658..5911bb93e 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -369,17 +369,56 @@ uint32_t mal_type = 0;
369/** 369/**
370 * Other malicious peers 370 * Other malicious peers
371 */ 371 */
372static struct GNUNET_PeerIdentity *mal_peers; 372static struct GNUNET_PeerIdentity *mal_peers = NULL;
373 373
374/** 374/**
375 * Number of other malicious peers 375 * Number of other malicious peers
376 */ 376 */
377static uint32_t num_mal_peers; 377static uint32_t num_mal_peers = 0;
378
379
380/**
381 * If type is 2 This struct is used to store the attacked peers in a DLL
382 */
383struct AttackedPeer
384{
385 /**
386 * DLL
387 */
388 struct AttackedPeer *next;
389 struct AttackedPeer *prev;
390
391 /**
392 * PeerID
393 */
394 struct GNUNET_PeerIdentity *peer_id;
395};
396
397/**
398 * If type is 2 this is the DLL of attacked peers
399 */
400//static struct AttackedPeer *att_peers_head = NULL;
401//static struct AttackedPeer *att_peers_tail = NULL;
378 402
379/** 403/**
380 * If type is 2 this is the attacked peer 404 * Number of attacked peers
405 */
406//static uint32_t num_attacked_peers = 0;
407
408
409/**
410 * If type is 1 this is the attacked peer
381 */ 411 */
382static struct GNUNET_PeerIdentity attacked_peer; 412static struct GNUNET_PeerIdentity attacked_peer;
413
414/**
415 * The limit of PUSHes we can send in one round.
416 * This is an assumption of the Brahms protocol and either implemented
417 * via proof of work
418 * or
419 * assumend to be the bandwidth limitation.
420 */
421static uint32_t push_limit = 10000;
383#endif /* ENABLE_MALICIOUS */ 422#endif /* ENABLE_MALICIOUS */
384 423
385 424
@@ -411,6 +450,10 @@ static struct GNUNET_PeerIdentity attacked_peer;
411 */ 450 */
412#define unset_peer_flag(peer_ctx, mask) (peer_ctx->peer_flags &= (~mask)) 451#define unset_peer_flag(peer_ctx, mask) (peer_ctx->peer_flags &= (~mask))
413 452
453/**
454 * Compute the minimum of two ints
455 */
456#define min(x, y) ((x < y) ? x : y)
414 457
415/** 458/**
416 * Clean the send channel of a peer 459 * Clean the send channel of a peer
@@ -1336,6 +1379,96 @@ handle_peer_pull_reply (void *cls,
1336} 1379}
1337 1380
1338 1381
1382/**
1383 * Compute a random delay.
1384 * A uniformly distributed value between mean + spread and mean - spread.
1385 *
1386 * For example for mean 4 min and spread 2 the minimum is (4 min - (1/2 * 4 min))
1387 * It would return a random value between 2 and 6 min.
1388 *
1389 * @param mean the mean
1390 * @param spread the inverse amount of deviation from the mean
1391 */
1392static struct GNUNET_TIME_Relative
1393compute_rand_delay (struct GNUNET_TIME_Relative mean, unsigned int spread)
1394{
1395 struct GNUNET_TIME_Relative half_interval;
1396 struct GNUNET_TIME_Relative ret;
1397 unsigned int rand_delay;
1398 unsigned int max_rand_delay;
1399
1400 if (0 == spread)
1401 {
1402 LOG (GNUNET_ERROR_TYPE_WARNING,
1403 "Not accepting spread of 0\n");
1404 GNUNET_break (0);
1405 }
1406
1407 /* Compute random time value between spread * mean and spread * mean */
1408 half_interval = GNUNET_TIME_relative_divide (mean, spread);
1409
1410 max_rand_delay = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us / mean.rel_value_us * (2/spread);
1411 /**
1412 * Compute random value between (0 and 1) * round_interval
1413 * via multiplying round_interval with a 'fraction' (0 to value)/value
1414 */
1415 rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, max_rand_delay);
1416 ret = GNUNET_TIME_relative_multiply (mean, rand_delay);
1417 ret = GNUNET_TIME_relative_divide (ret, max_rand_delay);
1418 ret = GNUNET_TIME_relative_add (ret, half_interval);
1419
1420 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == ret.rel_value_us)
1421 LOG (GNUNET_ERROR_TYPE_WARNING,
1422 "Returning FOREVER_REL\n");
1423
1424 return ret;
1425}
1426
1427
1428/**
1429 * Send single pull request
1430 *
1431 * @param peer_id the peer to send the pull request to.
1432 */
1433static void
1434send_pull_request (struct GNUNET_PeerIdentity *peer_id)
1435{
1436 struct GNUNET_MQ_Envelope *ev;
1437 struct GNUNET_MQ_Handle *mq;
1438
1439 LOG (GNUNET_ERROR_TYPE_DEBUG,
1440 "Sending PULL request to peer %s of gossiped list.\n",
1441 GNUNET_i2s (peer_id));
1442
1443 GNUNET_array_append (pending_pull_reply_list, pending_pull_reply_list_size, *peer_id);
1444
1445 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
1446 mq = get_mq (peer_map, peer_id);
1447 GNUNET_MQ_send (mq, ev);
1448}
1449
1450
1451/**
1452 * Send single push
1453 *
1454 * @param peer_id the peer to send the push to.
1455 */
1456static void
1457send_push (struct GNUNET_PeerIdentity *peer_id)
1458{
1459 struct GNUNET_MQ_Envelope *ev;
1460 struct GNUNET_MQ_Handle *mq;
1461
1462 LOG (GNUNET_ERROR_TYPE_DEBUG,
1463 "Sending PUSH to peer %s of gossiped list.\n",
1464 GNUNET_i2s (peer_id));
1465
1466 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
1467 mq = get_mq (peer_map, peer_id);
1468 GNUNET_MQ_send (mq, ev);
1469}
1470
1471
1339static void 1472static void
1340do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 1473do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
1341 1474
@@ -1359,6 +1492,8 @@ handle_client_act_malicious (void *cls,
1359{ 1492{
1360 struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg; 1493 struct GNUNET_RPS_CS_ActMaliciousMessage *in_msg;
1361 struct GNUNET_PeerIdentity *peers; 1494 struct GNUNET_PeerIdentity *peers;
1495 uint32_t num_mal_peers_sent;
1496 uint32_t num_mal_peers_old;
1362 1497
1363 /* Check for protocol violation */ 1498 /* Check for protocol violation */
1364 if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size)) 1499 if (sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage) > ntohs (msg->size))
@@ -1381,10 +1516,7 @@ handle_client_act_malicious (void *cls,
1381 1516
1382 /* Do actual logic */ 1517 /* Do actual logic */
1383 peers = (struct GNUNET_PeerIdentity *) &msg[1]; 1518 peers = (struct GNUNET_PeerIdentity *) &msg[1];
1384 num_mal_peers = ntohl (in_msg->num_peers);
1385 mal_type = ntohl (in_msg->type); 1519 mal_type = ntohl (in_msg->type);
1386 num_attacked_peers = 0;
1387 attacked_peers = NULL;
1388 1520
1389 LOG (GNUNET_ERROR_TYPE_DEBUG, 1521 LOG (GNUNET_ERROR_TYPE_DEBUG,
1390 "Now acting malicious type %" PRIu32 "\n", 1522 "Now acting malicious type %" PRIu32 "\n",
@@ -1392,10 +1524,15 @@ handle_client_act_malicious (void *cls,
1392 1524
1393 if (1 == mal_type) 1525 if (1 == mal_type)
1394 { /* Try to maximise representation */ 1526 { /* Try to maximise representation */
1395 num_mal_peers = ntohl (in_msg->num_peers); 1527 /* Add other malicious peers to those we already know */
1396 mal_peers = GNUNET_new_array (num_mal_peers, 1528 num_mal_peers_sent = ntohl (in_msg->num_peers);
1397 struct GNUNET_PeerIdentity); 1529 num_mal_peers_old = num_mal_peers;
1398 memcpy (mal_peers, peers, num_mal_peers * sizeof (struct GNUNET_PeerIdentity)); 1530 GNUNET_array_grow (mal_peers,
1531 num_mal_peers,
1532 num_mal_peers + num_mal_peers_sent);
1533 memcpy (&mal_peers[num_mal_peers_old],
1534 peers,
1535 num_mal_peers_sent * sizeof (struct GNUNET_PeerIdentity));
1399 1536
1400 /* Substitute do_round () with do_mal_round () */ 1537 /* Substitute do_round () with do_mal_round () */
1401 GNUNET_SCHEDULER_cancel (do_round_task); 1538 GNUNET_SCHEDULER_cancel (do_round_task);
@@ -1403,13 +1540,24 @@ handle_client_act_malicious (void *cls,
1403 } 1540 }
1404 else if (2 == mal_type) 1541 else if (2 == mal_type)
1405 { /* Try to partition the network */ 1542 { /* Try to partition the network */
1406 num_mal_peers = ntohl (in_msg->num_peers) - 1; 1543 /* Add other malicious peers to those we already know */
1407 mal_peers = GNUNET_new_array (num_mal_peers, 1544 num_mal_peers_sent = ntohl (in_msg->num_peers) - 1;
1408 struct GNUNET_PeerIdentity); 1545 num_mal_peers_old = num_mal_peers;
1409 memcpy (mal_peers, peers, num_mal_peers); 1546 GNUNET_array_grow (mal_peers,
1547 num_mal_peers,
1548 num_mal_peers + num_mal_peers_sent);
1549 memcpy (&mal_peers[num_mal_peers_old],
1550 peers,
1551 num_mal_peers_sent * sizeof (struct GNUNET_PeerIdentity));
1552
1553 /* Store the one attacked peer */
1554 memcpy (&attacked_peer,
1555 &peers[num_mal_peers_sent],
1556 sizeof (struct GNUNET_PeerIdentity));
1410 1557
1411 GNUNET_array_grow (attacked_peers, num_attacked_peers, 1); 1558 LOG (GNUNET_ERROR_TYPE_DEBUG,
1412 memcpy (attacked_peers, &peers[num_mal_peers], 1 * sizeof (struct GNUNET_PeerIdentity)); 1559 "Attacked peer is %s\n",
1560 GNUNET_i2s (&attacked_peer));
1413 1561
1414 /* Substitute do_round () with do_mal_round () */ 1562 /* Substitute do_round () with do_mal_round () */
1415 GNUNET_SCHEDULER_cancel (do_round_task); 1563 GNUNET_SCHEDULER_cancel (do_round_task);
@@ -1428,7 +1576,6 @@ handle_client_act_malicious (void *cls,
1428 { 1576 {
1429 GNUNET_break (0); 1577 GNUNET_break (0);
1430 } 1578 }
1431
1432} 1579}
1433 1580
1434 1581
@@ -1442,8 +1589,6 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1442{ 1589{
1443 uint32_t num_pushes; 1590 uint32_t num_pushes;
1444 uint32_t i; 1591 uint32_t i;
1445 unsigned int rand_delay;
1446 struct GNUNET_TIME_Relative half_round_interval;
1447 struct GNUNET_TIME_Relative time_next_round; 1592 struct GNUNET_TIME_Relative time_next_round;
1448 1593
1449 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n"); 1594 LOG (GNUNET_ERROR_TYPE_DEBUG, "Going to execute next round maliciously.\n");
@@ -1453,31 +1598,27 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1453 { /* Try to maximise representation */ 1598 { /* Try to maximise representation */
1454 num_pushes = min (min (push_limit, /* FIXME: attacked peer */ num_mal_peers), GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE); 1599 num_pushes = min (min (push_limit, /* FIXME: attacked peer */ num_mal_peers), GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE);
1455 for (i = 0 ; i < num_pushes ; i++) 1600 for (i = 0 ; i < num_pushes ; i++)
1456 { /* Send PUSH to attacked peer */ 1601 { /* Send PUSHes to attacked peers */
1457 //GNUNET_CONTAINER_multihashmap_iterator_create 1602 //GNUNET_CONTAINER_multihashmap_iterator_create
1603 //send_push ();
1604
1605 // TODO send pulls
1606 // send_pull_request
1458 } 1607 }
1459 } 1608 }
1460 else if (2 == mal_type) 1609 else if (2 == mal_type)
1461 { /* Try to partition the network */ 1610 { /**
1462 /* Send as many pushes to attacked peer as possible */ 1611 * Try to partition the network
1612 * Send as many pushes to attacked peer as possible
1613 */
1614 send_push (&attacked_peer);
1463 } 1615 }
1464 1616
1465 /* Compute random time value between .5 * round_interval and 1.5 *round_interval */
1466 half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2);
1467 do
1468 {
1469 /*
1470 * Compute random value between (0 and 1) * round_interval
1471 * via multiplying round_interval with a 'fraction' (0 to value)/value
1472 */
1473 rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT_MAX/10);
1474 time_next_round = GNUNET_TIME_relative_multiply (round_interval, rand_delay);
1475 time_next_round = GNUNET_TIME_relative_divide (time_next_round, UINT_MAX/10);
1476 time_next_round = GNUNET_TIME_relative_add (time_next_round, half_round_interval);
1477 } while (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == time_next_round.rel_value_us);
1478
1479 /* Schedule next round */ 1617 /* Schedule next round */
1480 do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round, NULL); 1618 time_next_round = compute_rand_delay (round_interval, 2);
1619
1620 //do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_mal_round, NULL);
1621 do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_mal_round, NULL);
1481 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); 1622 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
1482} 1623}
1483#endif /* ENABLE_MALICIOUS */ 1624#endif /* ENABLE_MALICIOUS */
@@ -1496,10 +1637,8 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1496 uint32_t i; 1637 uint32_t i;
1497 unsigned int *permut; 1638 unsigned int *permut;
1498 unsigned int n_peers; /* Number of peers we send pushes/pulls to */ 1639 unsigned int n_peers; /* Number of peers we send pushes/pulls to */
1499 struct GNUNET_MQ_Envelope *ev;
1500 struct GNUNET_PeerIdentity peer; 1640 struct GNUNET_PeerIdentity peer;
1501 struct GNUNET_PeerIdentity *tmp_peer; 1641 struct GNUNET_PeerIdentity *tmp_peer;
1502 struct GNUNET_MQ_Handle *mq;
1503 1642
1504 LOG (GNUNET_ERROR_TYPE_DEBUG, 1643 LOG (GNUNET_ERROR_TYPE_DEBUG,
1505 "Printing gossip list:\n"); 1644 "Printing gossip list:\n");
@@ -1527,13 +1666,7 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1527 peer = gossip_list[permut[i]]; 1666 peer = gossip_list[permut[i]];
1528 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO 1667 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO
1529 { // FIXME if this fails schedule/loop this for later 1668 { // FIXME if this fails schedule/loop this for later
1530 LOG (GNUNET_ERROR_TYPE_DEBUG, 1669 send_push (&peer);
1531 "Sending PUSH to peer %s of gossiped list.\n",
1532 GNUNET_i2s (&peer));
1533
1534 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH);
1535 mq = get_mq (peer_map, &peer);
1536 GNUNET_MQ_send (mq, ev);
1537 } 1670 }
1538 } 1671 }
1539 GNUNET_free (permut); 1672 GNUNET_free (permut);
@@ -1555,17 +1688,9 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1555 peer = *tmp_peer; 1688 peer = *tmp_peer;
1556 GNUNET_free (tmp_peer); 1689 GNUNET_free (tmp_peer);
1557 1690
1558 GNUNET_array_append (pending_pull_reply_list, pending_pull_reply_list_size, peer);
1559
1560 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) 1691 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer))
1561 { // FIXME if this fails schedule/loop this for later 1692 {
1562 LOG (GNUNET_ERROR_TYPE_DEBUG, 1693 send_pull_request (&peer);
1563 "Sending PULL request to peer %s of gossiped list.\n",
1564 GNUNET_i2s (&peer));
1565
1566 ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST);
1567 mq = get_mq (peer_map, &peer);
1568 GNUNET_MQ_send (mq, ev);
1569 } 1694 }
1570 } 1695 }
1571 } 1696 }
@@ -1665,26 +1790,12 @@ do_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1665 GNUNET_array_grow (pull_list, pull_list_size, 0); 1790 GNUNET_array_grow (pull_list, pull_list_size, 0);
1666 1791
1667 struct GNUNET_TIME_Relative time_next_round; 1792 struct GNUNET_TIME_Relative time_next_round;
1668 struct GNUNET_TIME_Relative half_round_interval;
1669 unsigned int rand_delay;
1670 1793
1671 1794 time_next_round = compute_rand_delay (round_interval, 2);
1672 /* Compute random time value between .5 * round_interval and 1.5 *round_interval */
1673 half_round_interval = GNUNET_TIME_relative_divide (round_interval, 2);
1674 do
1675 {
1676 /*
1677 * Compute random value between (0 and 1) * round_interval
1678 * via multiplying round_interval with a 'fraction' (0 to value)/value
1679 */
1680 rand_delay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT_MAX/10);
1681 time_next_round = GNUNET_TIME_relative_multiply (round_interval, rand_delay);
1682 time_next_round = GNUNET_TIME_relative_divide (time_next_round, UINT_MAX/10);
1683 time_next_round = GNUNET_TIME_relative_add (time_next_round, half_round_interval);
1684 } while (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == time_next_round.rel_value_us);
1685 1795
1686 /* Schedule next round */ 1796 /* Schedule next round */
1687 do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_round, NULL); 1797 //do_round_task = GNUNET_SCHEDULER_add_delayed (round_interval, &do_round, NULL);
1798 do_round_task = GNUNET_SCHEDULER_add_delayed (time_next_round, &do_round, NULL);
1688 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n"); 1799 LOG (GNUNET_ERROR_TYPE_DEBUG, "Finished round\n");
1689} 1800}
1690 1801
@@ -1872,6 +1983,10 @@ shutdown_task (void *cls,
1872 GNUNET_array_grow (gossip_list, gossip_list_size, 0); 1983 GNUNET_array_grow (gossip_list, gossip_list_size, 0);
1873 GNUNET_array_grow (push_list, push_list_size, 0); 1984 GNUNET_array_grow (push_list, push_list_size, 0);
1874 GNUNET_array_grow (pull_list, pull_list_size, 0); 1985 GNUNET_array_grow (pull_list, pull_list_size, 0);
1986 #ifdef ENABLE_MALICIOUS
1987 GNUNET_array_grow (mal_peers, num_mal_peers, 0);
1988 // TODO empty attacked_peers DLL
1989 #endif /* ENABLE_MALICIOUS */
1875} 1990}
1876 1991
1877 1992
@@ -1925,8 +2040,6 @@ handle_inbound_channel (void *cls,
1925 //} 2040 //}
1926 peer_ctx->recv_channel = channel; 2041 peer_ctx->recv_channel = channel;
1927 2042
1928 peer_ctx->mq = NULL;
1929
1930 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, &peer, peer_ctx, 2043 (void) GNUNET_CONTAINER_multipeermap_put (peer_map, &peer, peer_ctx,
1931 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 2044 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1932 2045