diff options
Diffstat (limited to 'src/rps/gnunet-service-rps.c')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 109 |
1 files changed, 105 insertions, 4 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index b890a96c8..9b6b3b7c6 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -452,8 +452,10 @@ struct GNUNET_CADET_Handle *cadet_handle; | |||
452 | */ | 452 | */ |
453 | struct GNUNET_CORE_Handle *core_handle; | 453 | struct GNUNET_CORE_Handle *core_handle; |
454 | 454 | ||
455 | /** | ||
456 | * @brief PeerMap to keep track of connected peers. | ||
457 | */ | ||
455 | struct GNUNET_CONTAINER_MultiPeerMap *map_single_hop; | 458 | struct GNUNET_CONTAINER_MultiPeerMap *map_single_hop; |
456 | struct GNUNET_CONTAINER_MultiPeerMap *map_multi_hop; | ||
457 | 459 | ||
458 | /** | 460 | /** |
459 | * Our own identity. | 461 | * Our own identity. |
@@ -1375,6 +1377,13 @@ mq_notify_sent_cb (void *cls) | |||
1375 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); | 1377 | GNUNET_STATISTICS_update(stats, "# pull requests sent", 1, GNUNET_NO); |
1376 | if (0 == strncmp ("PUSH", pending_msg->type, 4)) | 1378 | if (0 == strncmp ("PUSH", pending_msg->type, 4)) |
1377 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); | 1379 | GNUNET_STATISTICS_update(stats, "# pushes sent", 1, GNUNET_NO); |
1380 | if (0 == strncmp ("PULL REQUEST", pending_msg->type, 12) && | ||
1381 | GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
1382 | &pending_msg->peer_ctx->peer_id)) | ||
1383 | GNUNET_STATISTICS_update(stats, | ||
1384 | "# pull requests sent (multi-hop peer)", | ||
1385 | 1, | ||
1386 | GNUNET_NO); | ||
1378 | } | 1387 | } |
1379 | /* Do not cancle message */ | 1388 | /* Do not cancle message */ |
1380 | remove_pending_message (pending_msg, GNUNET_NO); | 1389 | remove_pending_message (pending_msg, GNUNET_NO); |
@@ -2989,6 +2998,73 @@ destroy_sub (struct Sub *sub) | |||
2989 | ***********************************************************************/ | 2998 | ***********************************************************************/ |
2990 | 2999 | ||
2991 | 3000 | ||
3001 | /*********************************************************************** | ||
3002 | * Core handlers | ||
3003 | ***********************************************************************/ | ||
3004 | |||
3005 | /** | ||
3006 | * @brief Callback on initialisation of Core. | ||
3007 | * | ||
3008 | * @param cls - unused | ||
3009 | * @param my_identity - unused | ||
3010 | */ | ||
3011 | void | ||
3012 | core_init (void *cls, | ||
3013 | const struct GNUNET_PeerIdentity *my_identity) | ||
3014 | { | ||
3015 | (void) cls; | ||
3016 | (void) my_identity; | ||
3017 | |||
3018 | map_single_hop = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | ||
3019 | } | ||
3020 | |||
3021 | |||
3022 | /** | ||
3023 | * @brief Callback for core. | ||
3024 | * Method called whenever a given peer connects. | ||
3025 | * | ||
3026 | * @param cls closure - unused | ||
3027 | * @param peer peer identity this notification is about | ||
3028 | * @return closure given to #core_disconnects as peer_cls | ||
3029 | */ | ||
3030 | void * | ||
3031 | core_connects (void *cls, | ||
3032 | const struct GNUNET_PeerIdentity *peer, | ||
3033 | struct GNUNET_MQ_Handle *mq) | ||
3034 | { | ||
3035 | (void) cls; | ||
3036 | (void) mq; | ||
3037 | |||
3038 | GNUNET_CONTAINER_multipeermap_put (map_single_hop, peer, NULL, | ||
3039 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
3040 | return NULL; | ||
3041 | } | ||
3042 | |||
3043 | |||
3044 | /** | ||
3045 | * @brief Callback for core. | ||
3046 | * Method called whenever a peer disconnects. | ||
3047 | * | ||
3048 | * @param cls closure - unused | ||
3049 | * @param peer peer identity this notification is about | ||
3050 | * @param peer_cls closure given in #core_connects - unused | ||
3051 | */ | ||
3052 | void | ||
3053 | core_disconnects (void *cls, | ||
3054 | const struct GNUNET_PeerIdentity *peer, | ||
3055 | void *peer_cls) | ||
3056 | { | ||
3057 | (void) cls; | ||
3058 | (void) peer_cls; | ||
3059 | |||
3060 | GNUNET_CONTAINER_multipeermap_remove_all (map_single_hop, peer); | ||
3061 | } | ||
3062 | |||
3063 | /*********************************************************************** | ||
3064 | * /Core handlers | ||
3065 | ***********************************************************************/ | ||
3066 | |||
3067 | |||
2992 | /** | 3068 | /** |
2993 | * @brief Destroy the context for a (connected) client | 3069 | * @brief Destroy the context for a (connected) client |
2994 | * | 3070 | * |
@@ -3432,6 +3508,14 @@ handle_peer_pull_request (void *cls, | |||
3432 | "# pull request message received", | 3508 | "# pull request message received", |
3433 | 1, | 3509 | 1, |
3434 | GNUNET_NO); | 3510 | GNUNET_NO); |
3511 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3512 | &peer_ctx->peer_id)) | ||
3513 | { | ||
3514 | GNUNET_STATISTICS_update (stats, | ||
3515 | "# pull request message received (multi-hop peer)", | ||
3516 | 1, | ||
3517 | GNUNET_NO); | ||
3518 | } | ||
3435 | } | 3519 | } |
3436 | 3520 | ||
3437 | #ifdef ENABLE_MALICIOUS | 3521 | #ifdef ENABLE_MALICIOUS |
@@ -3687,6 +3771,14 @@ send_pull_request (struct PeerContext *peer_ctx) | |||
3687 | "# pull request send issued", | 3771 | "# pull request send issued", |
3688 | 1, | 3772 | 1, |
3689 | GNUNET_NO); | 3773 | GNUNET_NO); |
3774 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (map_single_hop, | ||
3775 | &peer_ctx->peer_id)) | ||
3776 | { | ||
3777 | GNUNET_STATISTICS_update (stats, | ||
3778 | "# pull request send issued (multi-hop peer)", | ||
3779 | 1, | ||
3780 | GNUNET_NO); | ||
3781 | } | ||
3690 | } | 3782 | } |
3691 | } | 3783 | } |
3692 | 3784 | ||
@@ -4421,6 +4513,15 @@ shutdown_task (void *cls) | |||
4421 | GNUNET_PEERINFO_disconnect (peerinfo_handle); | 4513 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
4422 | peerinfo_handle = NULL; | 4514 | peerinfo_handle = NULL; |
4423 | GNUNET_NSE_disconnect (nse); | 4515 | GNUNET_NSE_disconnect (nse); |
4516 | if (NULL != map_single_hop) | ||
4517 | { | ||
4518 | /* core_init was called - core was initialised */ | ||
4519 | /* disconnect first, so no callback tries to access missing peermap */ | ||
4520 | GNUNET_CORE_disconnect (core_handle); | ||
4521 | core_handle = NULL; | ||
4522 | GNUNET_CONTAINER_multipeermap_destroy (map_single_hop); | ||
4523 | map_single_hop = NULL; | ||
4524 | } | ||
4424 | 4525 | ||
4425 | if (NULL != stats) | 4526 | if (NULL != stats) |
4426 | { | 4527 | { |
@@ -4577,9 +4678,9 @@ run (void *cls, | |||
4577 | GNUNET_assert (NULL != cadet_handle); | 4678 | GNUNET_assert (NULL != cadet_handle); |
4578 | core_handle = GNUNET_CORE_connect (cfg, | 4679 | core_handle = GNUNET_CORE_connect (cfg, |
4579 | NULL, /* cls */ | 4680 | NULL, /* cls */ |
4580 | NULL, /* init */ | 4681 | core_init, /* init */ |
4581 | NULL, /* connects */ | 4682 | core_connects, /* connects */ |
4582 | NULL, /* disconnects */ | 4683 | core_disconnects, /* disconnects */ |
4583 | NULL); /* handlers */ | 4684 | NULL); /* handlers */ |
4584 | GNUNET_assert (NULL != core_handle); | 4685 | GNUNET_assert (NULL != core_handle); |
4585 | 4686 | ||