aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2016-04-08 18:27:44 +0000
committerJulius Bünger <buenger@mytum.de>2016-04-08 18:27:44 +0000
commit684b7dfb691609216c8ca553301161ed4fcd0091 (patch)
treed84b6ffacea1268f58ff50088ecde240f0c62086 /src/rps
parentb123807e9c7a7e3f57e41b54342bf7d676ad1639 (diff)
downloadgnunet-684b7dfb691609216c8ca553301161ed4fcd0091.tar.gz
gnunet-684b7dfb691609216c8ca553301161ed4fcd0091.zip
-rps: restructure gnunet-service-rps_peers
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c18
-rw-r--r--src/rps/gnunet-service-rps_peers.c34
-rw-r--r--src/rps/gnunet-service-rps_peers.h14
3 files changed, 52 insertions, 14 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 832b3579a..e3ddb4bff 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -678,7 +678,7 @@ insert_in_sampler (void *cls, const struct GNUNET_PeerIdentity *peer)
678 if (0 < RPS_sampler_count_id (prot_sampler, peer)) 678 if (0 < RPS_sampler_count_id (prot_sampler, peer))
679 { 679 {
680 /* Make sure we 'know' about this peer */ 680 /* Make sure we 'know' about this peer */
681 (void) Peers_insert_peer (peer); 681 (void) Peers_insert_peer_check_liveliness (peer);
682 /* Establish a channel towards that peer to indicate we are going to send 682 /* Establish a channel towards that peer to indicate we are going to send
683 * messages to it */ 683 * messages to it */
684 Peers_indicate_sending_intention (peer); 684 Peers_indicate_sending_intention (peer);
@@ -1123,7 +1123,7 @@ handle_client_seed (void *cls,
1123 i, 1123 i,
1124 GNUNET_i2s (&peers[i])); 1124 GNUNET_i2s (&peers[i]));
1125 1125
1126 if (GNUNET_YES == Peers_insert_peer (&peers[i])) 1126 if (GNUNET_YES == Peers_insert_peer_check_liveliness (&peers[i]))
1127 { 1127 {
1128 Peers_schedule_operation (&peers[i], insert_in_sampler); 1128 Peers_schedule_operation (&peers[i], insert_in_sampler);
1129 Peers_schedule_operation (&peers[i], insert_in_view); 1129 Peers_schedule_operation (&peers[i], insert_in_view);
@@ -1371,7 +1371,7 @@ handle_peer_pull_reply (void *cls,
1371 &peers[i])) 1371 &peers[i]))
1372 { 1372 {
1373 /* Make sure we 'know' about this peer */ 1373 /* Make sure we 'know' about this peer */
1374 (void) Peers_insert_peer (&peers[i]); 1374 (void) Peers_insert_peer_check_liveliness (&peers[i]);
1375 1375
1376 if (GNUNET_YES == Peers_check_peer_flag (&peers[i], Peers_VALID)) 1376 if (GNUNET_YES == Peers_check_peer_flag (&peers[i], Peers_VALID))
1377 { 1377 {
@@ -1589,7 +1589,7 @@ handle_client_act_malicious (void *cls,
1589 /* Set the flag of the attacked peer to valid to avoid problems */ 1589 /* Set the flag of the attacked peer to valid to avoid problems */
1590 if (GNUNET_NO == Peers_check_peer_known (&attacked_peer)) 1590 if (GNUNET_NO == Peers_check_peer_known (&attacked_peer))
1591 { 1591 {
1592 Peers_insert_peer (&attacked_peer); 1592 Peers_insert_peer_check_liveliness (&attacked_peer);
1593 Peers_issue_peer_liveliness_check (&attacked_peer); 1593 Peers_issue_peer_liveliness_check (&attacked_peer);
1594 } 1594 }
1595 1595
@@ -1679,7 +1679,7 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1679 * Send as many pushes to the attacked peer as possible 1679 * Send as many pushes to the attacked peer as possible
1680 * That is one push per round as it will ignore more. 1680 * That is one push per round as it will ignore more.
1681 */ 1681 */
1682 Peers_insert_peer (&attacked_peer); 1682 Peers_insert_peer_check_liveliness (&attacked_peer);
1683 if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_VALID)) 1683 if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_VALID))
1684 send_push (&attacked_peer); 1684 send_push (&attacked_peer);
1685 } 1685 }
@@ -1691,7 +1691,7 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1691 /* Send PUSH to attacked peers */ 1691 /* Send PUSH to attacked peers */
1692 if (GNUNET_YES == Peers_check_peer_known (&attacked_peer)) 1692 if (GNUNET_YES == Peers_check_peer_known (&attacked_peer))
1693 { 1693 {
1694 Peers_insert_peer (&attacked_peer); 1694 Peers_insert_peer_check_liveliness (&attacked_peer);
1695 if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_VALID)) 1695 if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_VALID))
1696 { 1696 {
1697 LOG (GNUNET_ERROR_TYPE_DEBUG, 1697 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1703,7 +1703,7 @@ do_mal_round (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1703 Peers_issue_peer_liveliness_check (&attacked_peer); 1703 Peers_issue_peer_liveliness_check (&attacked_peer);
1704 } 1704 }
1705 else 1705 else
1706 Peers_insert_peer (&attacked_peer); 1706 Peers_insert_peer_check_liveliness (&attacked_peer);
1707 Peers_issue_peer_liveliness_check (&attacked_peer); 1707 Peers_issue_peer_liveliness_check (&attacked_peer);
1708 1708
1709 /* The maximum of pushes we're going to send this round */ 1709 /* The maximum of pushes we're going to send this round */
@@ -1995,7 +1995,7 @@ init_peer_cb (void *cls,
1995 LOG (GNUNET_ERROR_TYPE_DEBUG, 1995 LOG (GNUNET_ERROR_TYPE_DEBUG,
1996 "Got peer_id %s from cadet\n", 1996 "Got peer_id %s from cadet\n",
1997 GNUNET_i2s (peer)); 1997 GNUNET_i2s (peer));
1998 Peers_insert_peer (peer); 1998 Peers_insert_peer_check_liveliness (peer);
1999 Peers_schedule_operation (peer, insert_in_sampler); 1999 Peers_schedule_operation (peer, insert_in_sampler);
2000 Peers_schedule_operation (peer, insert_in_view); 2000 Peers_schedule_operation (peer, insert_in_view);
2001 } 2001 }
@@ -2021,7 +2021,7 @@ process_peerinfo_peers (void *cls,
2021 LOG (GNUNET_ERROR_TYPE_DEBUG, 2021 LOG (GNUNET_ERROR_TYPE_DEBUG,
2022 "Got peer_id %s from peerinfo\n", 2022 "Got peer_id %s from peerinfo\n",
2023 GNUNET_i2s (peer)); 2023 GNUNET_i2s (peer));
2024 Peers_insert_peer (peer); 2024 Peers_insert_peer_check_liveliness (peer);
2025 Peers_schedule_operation (peer, insert_in_sampler); 2025 Peers_schedule_operation (peer, insert_in_sampler);
2026 Peers_schedule_operation (peer, insert_in_view); 2026 Peers_schedule_operation (peer, insert_in_view);
2027 } 2027 }
diff --git a/src/rps/gnunet-service-rps_peers.c b/src/rps/gnunet-service-rps_peers.c
index 84fbf7f74..c5a19d978 100644
--- a/src/rps/gnunet-service-rps_peers.c
+++ b/src/rps/gnunet-service-rps_peers.c
@@ -604,20 +604,44 @@ Peers_terminate ()
604int 604int
605Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) 605Peers_insert_peer (const struct GNUNET_PeerIdentity *peer)
606{ 606{
607 struct PeerContext *peer_ctx;
608
609 if ( (GNUNET_YES == Peers_check_peer_known (peer)) || 607 if ( (GNUNET_YES == Peers_check_peer_known (peer)) ||
610 (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity)) ) 608 (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity)) )
611 { 609 {
612 return GNUNET_NO; /* We already know this peer - nothing to do */ 610 return GNUNET_NO; /* We already know this peer - nothing to do */
613 } 611 }
614 peer_ctx = create_peer_ctx (peer); 612 (void) create_peer_ctx (peer);
615 // TODO LIVE 613 return GNUNET_YES;
614}
615
616
617/**
618 * @brief Add peer to known peers and check for liveliness.
619 *
620 * This function is called on new peer_ids from 'external' sources
621 * (client seed, cadet get_peers(), ...)
622 *
623 * @param peer the new #GNUNET_PeerIdentity
624 *
625 * @return #GNUNET_YES if peer was inserted
626 * #GNUNET_NO if peer was already known
627 */
628int
629Peers_insert_peer_check_liveliness (const struct GNUNET_PeerIdentity *peer)
630{
631 struct PeerContext *peer_ctx;
632 int ret;
633
634 ret = Peers_insert_peer (peer);
635 if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, own_identity))
636 {
637 return ret;
638 }
639 peer_ctx = get_peer_ctx (peer);
616 if (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_VALID)) 640 if (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_VALID))
617 { 641 {
618 check_peer_live (peer_ctx); 642 check_peer_live (peer_ctx);
619 } 643 }
620 return GNUNET_YES; 644 return ret;
621} 645}
622 646
623/** 647/**
diff --git a/src/rps/gnunet-service-rps_peers.h b/src/rps/gnunet-service-rps_peers.h
index 8465935fa..06e6fa89e 100644
--- a/src/rps/gnunet-service-rps_peers.h
+++ b/src/rps/gnunet-service-rps_peers.h
@@ -135,6 +135,20 @@ int
135Peers_insert_peer (const struct GNUNET_PeerIdentity *peer); 135Peers_insert_peer (const struct GNUNET_PeerIdentity *peer);
136 136
137/** 137/**
138 * @brief Add peer to known peers and check for liveliness.
139 *
140 * This function is called on new peer_ids from 'external' sources
141 * (client seed, cadet get_peers(), ...)
142 *
143 * @param peer the new #GNUNET_PeerIdentity
144 *
145 * @return #GNUNET_YES if peer was inserted
146 * #GNUNET_NO if peer was already known
147 */
148int
149Peers_insert_peer_check_liveliness (const struct GNUNET_PeerIdentity *peer);
150
151/**
138 * @brief Remove unecessary data 152 * @brief Remove unecessary data
139 * 153 *
140 * If the other peer is not intending to send messages, we have messages pending 154 * If the other peer is not intending to send messages, we have messages pending