diff options
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 67 |
1 files changed, 25 insertions, 42 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 84fb33be2..db09c68d2 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -1045,12 +1045,10 @@ restore_valid_peers () | |||
1045 | */ | 1045 | */ |
1046 | void | 1046 | void |
1047 | Peers_initialise (char* fn_valid_peers, | 1047 | Peers_initialise (char* fn_valid_peers, |
1048 | struct GNUNET_CADET_Handle *cadet_h, | 1048 | struct GNUNET_CADET_Handle *cadet_h) |
1049 | const struct GNUNET_PeerIdentity *own_id) | ||
1050 | { | 1049 | { |
1051 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); | 1050 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); |
1052 | cadet_handle = cadet_h; | 1051 | cadet_handle = cadet_h; |
1053 | own_identity = *own_id; | ||
1054 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1052 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1055 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1053 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1056 | restore_valid_peers (); | 1054 | restore_valid_peers (); |
@@ -1136,14 +1134,12 @@ Peers_get_valid_peers (PeersIterator iterator, | |||
1136 | * @param peer the new #GNUNET_PeerIdentity | 1134 | * @param peer the new #GNUNET_PeerIdentity |
1137 | * | 1135 | * |
1138 | * @return #GNUNET_YES if peer was inserted | 1136 | * @return #GNUNET_YES if peer was inserted |
1139 | * #GNUNET_NO otherwise (if peer was already known or | 1137 | * #GNUNET_NO otherwise |
1140 | * peer was #own_identity) | ||
1141 | */ | 1138 | */ |
1142 | int | 1139 | int |
1143 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | 1140 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) |
1144 | { | 1141 | { |
1145 | if ( (GNUNET_YES == Peers_check_peer_known (peer)) || | 1142 | if (GNUNET_YES == Peers_check_peer_known (peer)) |
1146 | (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) ) | ||
1147 | { | 1143 | { |
1148 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1144 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1149 | } | 1145 | } |
@@ -1161,8 +1157,7 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl | |||
1161 | * | 1157 | * |
1162 | * @param peer the peer whose liveliness is to be checked | 1158 | * @param peer the peer whose liveliness is to be checked |
1163 | * @return #GNUNET_YES if peer had to be inserted | 1159 | * @return #GNUNET_YES if peer had to be inserted |
1164 | * #GNUNET_NO otherwise (if peer was already known or | 1160 | * #GNUNET_NO otherwise |
1165 | * peer was #own_identity) | ||
1166 | */ | 1161 | */ |
1167 | int | 1162 | int |
1168 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | 1163 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) |
@@ -1170,10 +1165,6 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | |||
1170 | struct PeerContext *peer_ctx; | 1165 | struct PeerContext *peer_ctx; |
1171 | int ret; | 1166 | int ret; |
1172 | 1167 | ||
1173 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | ||
1174 | { | ||
1175 | return GNUNET_NO; | ||
1176 | } | ||
1177 | ret = Peers_insert_peer (peer); | 1168 | ret = Peers_insert_peer (peer); |
1178 | peer_ctx = get_peer_ctx (peer); | 1169 | peer_ctx = get_peer_ctx (peer); |
1179 | if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) | 1170 | if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) |
@@ -1666,10 +1657,11 @@ Peers_cleanup_destroyed_channel (void *cls, | |||
1666 | { | 1657 | { |
1667 | struct GNUNET_PeerIdentity *peer = cls; | 1658 | struct GNUNET_PeerIdentity *peer = cls; |
1668 | struct PeerContext *peer_ctx; | 1659 | struct PeerContext *peer_ctx; |
1660 | uint32_t *channel_flag; | ||
1669 | 1661 | ||
1670 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1662 | if (GNUNET_NO == Peers_check_peer_known (peer)) |
1671 | {/* We don't want to implicitly create a context that we're about to kill */ | 1663 | {/* We don't want to implicitly create a context that we're about to kill */ |
1672 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1664 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1673 | "channel (%s) without associated context was destroyed\n", | 1665 | "channel (%s) without associated context was destroyed\n", |
1674 | GNUNET_i2s (peer)); | 1666 | GNUNET_i2s (peer)); |
1675 | return; | 1667 | return; |
@@ -1697,12 +1689,16 @@ Peers_cleanup_destroyed_channel (void *cls, | |||
1697 | if (NULL != peer_ctx->send_channel) | 1689 | if (NULL != peer_ctx->send_channel) |
1698 | { | 1690 | { |
1699 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | 1691 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); |
1692 | channel_flag = Peers_get_channel_flag (&peer_ctx->peer_id, Peers_CHANNEL_ROLE_SENDING); | ||
1693 | Peers_set_channel_flag (channel_flag, Peers_CHANNEL_DESTROING); | ||
1700 | peer_ctx->send_channel = NULL; | 1694 | peer_ctx->send_channel = NULL; |
1701 | peer_ctx->mq = NULL; | 1695 | peer_ctx->mq = NULL; |
1702 | } | 1696 | } |
1703 | if (NULL != peer_ctx->recv_channel) | 1697 | if (NULL != peer_ctx->recv_channel) |
1704 | { | 1698 | { |
1705 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | 1699 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); |
1700 | channel_flag = Peers_get_channel_flag (&peer_ctx->peer_id, Peers_CHANNEL_ROLE_RECEIVING); | ||
1701 | Peers_set_channel_flag (channel_flag, Peers_CHANNEL_DESTROING); | ||
1706 | peer_ctx->recv_channel = NULL; | 1702 | peer_ctx->recv_channel = NULL; |
1707 | } | 1703 | } |
1708 | /* Set the #Peers_ONLINE flag accordingly */ | 1704 | /* Set the #Peers_ONLINE flag accordingly */ |
@@ -1786,10 +1782,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | |||
1786 | struct PeerPendingOp pending_op; | 1782 | struct PeerPendingOp pending_op; |
1787 | struct PeerContext *peer_ctx; | 1783 | struct PeerContext *peer_ctx; |
1788 | 1784 | ||
1789 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | ||
1790 | { | ||
1791 | return GNUNET_NO; | ||
1792 | } | ||
1793 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1785 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); |
1794 | 1786 | ||
1795 | //TODO if LIVE/ONLINE execute immediately | 1787 | //TODO if LIVE/ONLINE execute immediately |
@@ -3368,9 +3360,7 @@ handle_peer_pull_reply (void *cls, | |||
3368 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, | 3360 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, |
3369 | &peers[i]) | 3361 | &peers[i]) |
3370 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, | 3362 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, |
3371 | &peers[i]) | 3363 | &peers[i])) |
3372 | && 0 != GNUNET_CRYPTO_cmp_peer_identity (&peers[i], | ||
3373 | &own_identity)) | ||
3374 | { | 3364 | { |
3375 | tmp_att_peer = GNUNET_new (struct AttackedPeer); | 3365 | tmp_att_peer = GNUNET_new (struct AttackedPeer); |
3376 | tmp_att_peer->peer_id = peers[i]; | 3366 | tmp_att_peer->peer_id = peers[i]; |
@@ -3382,21 +3372,17 @@ handle_peer_pull_reply (void *cls, | |||
3382 | continue; | 3372 | continue; |
3383 | } | 3373 | } |
3384 | #endif /* ENABLE_MALICIOUS */ | 3374 | #endif /* ENABLE_MALICIOUS */ |
3385 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, | 3375 | /* Make sure we 'know' about this peer */ |
3386 | &peers[i])) | 3376 | (void) Peers_insert_peer (&peers[i]); |
3387 | { | ||
3388 | /* Make sure we 'know' about this peer */ | ||
3389 | (void) Peers_insert_peer (&peers[i]); | ||
3390 | 3377 | ||
3391 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) | 3378 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) |
3392 | { | 3379 | { |
3393 | CustomPeerMap_put (pull_map, &peers[i]); | 3380 | CustomPeerMap_put (pull_map, &peers[i]); |
3394 | } | 3381 | } |
3395 | else | 3382 | else |
3396 | { | 3383 | { |
3397 | Peers_schedule_operation (&peers[i], insert_in_pull_map); | 3384 | Peers_schedule_operation (&peers[i], insert_in_pull_map); |
3398 | (void) Peers_issue_peer_liveliness_check (&peers[i]); | 3385 | (void) Peers_issue_peer_liveliness_check (&peers[i]); |
3399 | } | ||
3400 | } | 3386 | } |
3401 | } | 3387 | } |
3402 | 3388 | ||
@@ -3831,10 +3817,8 @@ do_round (void *cls) | |||
3831 | for (i = 0; i < a_peers; i++) | 3817 | for (i = 0; i < a_peers; i++) |
3832 | { | 3818 | { |
3833 | peer = view_array[permut[i]]; | 3819 | peer = view_array[permut[i]]; |
3834 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO | 3820 | // FIXME if this fails schedule/loop this for later |
3835 | { // FIXME if this fails schedule/loop this for later | 3821 | send_push (&peer); |
3836 | send_push (&peer); | ||
3837 | } | ||
3838 | } | 3822 | } |
3839 | 3823 | ||
3840 | /* Send PULL requests */ | 3824 | /* Send PULL requests */ |
@@ -3852,8 +3836,7 @@ do_round (void *cls) | |||
3852 | for (i = first_border; i < second_border; i++) | 3836 | for (i = first_border; i < second_border; i++) |
3853 | { | 3837 | { |
3854 | peer = view_array[permut[i]]; | 3838 | peer = view_array[permut[i]]; |
3855 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer) && | 3839 | if ( GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) |
3856 | GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) // TODO | ||
3857 | { // FIXME if this fails schedule/loop this for later | 3840 | { // FIXME if this fails schedule/loop this for later |
3858 | send_pull_request (&peer); | 3841 | send_pull_request (&peer); |
3859 | } | 3842 | } |
@@ -4367,7 +4350,7 @@ run (void *cls, | |||
4367 | 4350 | ||
4368 | 4351 | ||
4369 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 4352 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
4370 | Peers_initialise (fn_valid_peers, cadet_handle, &own_identity); | 4353 | Peers_initialise (fn_valid_peers, cadet_handle); |
4371 | GNUNET_free (fn_valid_peers); | 4354 | GNUNET_free (fn_valid_peers); |
4372 | 4355 | ||
4373 | /* Initialise sampler */ | 4356 | /* Initialise sampler */ |