diff options
Diffstat (limited to 'src/vpn/gnunet-service-vpn.c')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 162 |
1 files changed, 15 insertions, 147 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 030816797..2b5b41e14 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -204,23 +204,12 @@ struct TunnelState | |||
204 | struct TunnelMessageQueueEntry *tmq_tail; | 204 | struct TunnelMessageQueueEntry *tmq_tail; |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Client that needs to be notified about the tunnel being | ||
208 | * up as soon as a peer is connected; NULL for none. | ||
209 | */ | ||
210 | struct GNUNET_SERVER_Client *client; | ||
211 | |||
212 | /** | ||
213 | * Destination entry that has a pointer to this tunnel state; | 207 | * Destination entry that has a pointer to this tunnel state; |
214 | * NULL if this tunnel state is in the tunnel map. | 208 | * NULL if this tunnel state is in the tunnel map. |
215 | */ | 209 | */ |
216 | struct DestinationEntry *destination_container; | 210 | struct DestinationEntry *destination_container; |
217 | 211 | ||
218 | /** | 212 | /** |
219 | * ID of the client request that caused us to setup this entry. | ||
220 | */ | ||
221 | uint64_t request_id; | ||
222 | |||
223 | /** | ||
224 | * Destination to which this tunnel leads. Note that | 213 | * Destination to which this tunnel leads. Note that |
225 | * this struct is NOT in the destination_map (but a | 214 | * this struct is NOT in the destination_map (but a |
226 | * local copy) and that the 'heap_node' should always | 215 | * local copy) and that the 'heap_node' should always |
@@ -636,40 +625,6 @@ tunnel_peer_disconnect_handler (void *cls, | |||
636 | 625 | ||
637 | 626 | ||
638 | /** | 627 | /** |
639 | * Method called whenever a peer has connected to the tunnel. Notifies | ||
640 | * the waiting client that the tunnel is now up. | ||
641 | * | ||
642 | * FIXME merge with tunnel_create | ||
643 | * | ||
644 | * @param cls closure | ||
645 | * @param peer peer identity the tunnel was created to, NULL on timeout | ||
646 | * @param atsi performance data for the connection | ||
647 | */ | ||
648 | void | ||
649 | tunnel_peer_connect_handler (void *cls, | ||
650 | const struct GNUNET_PeerIdentity *peer, | ||
651 | const struct | ||
652 | GNUNET_ATS_Information * atsi) | ||
653 | { | ||
654 | struct TunnelState *ts = cls; | ||
655 | |||
656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
657 | "Peer %s connected to tunnel.\n", | ||
658 | GNUNET_i2s (peer)); | ||
659 | GNUNET_STATISTICS_update (stats, | ||
660 | gettext_noop ("# peers connected to mesh tunnels"), | ||
661 | 1, GNUNET_NO); | ||
662 | if (NULL == ts->client) | ||
663 | return; /* nothing to do */ | ||
664 | send_client_reply (ts->client, | ||
665 | ts->request_id, | ||
666 | ts->af, | ||
667 | &ts->destination_ip); | ||
668 | ts->client = NULL; | ||
669 | } | ||
670 | |||
671 | |||
672 | /** | ||
673 | * Send a message from the message queue via mesh. | 628 | * Send a message from the message queue via mesh. |
674 | * | 629 | * |
675 | * @param cls the `struct TunnelState` with the message queue | 630 | * @param cls the `struct TunnelState` with the message queue |
@@ -796,14 +751,12 @@ handle_regex_result (void *cls, | |||
796 | * Initialize the given destination entry's mesh tunnel. | 751 | * Initialize the given destination entry's mesh tunnel. |
797 | * | 752 | * |
798 | * @param de destination entry for which we need to setup a tunnel | 753 | * @param de destination entry for which we need to setup a tunnel |
799 | * @param client client to notify on successful tunnel setup, or NULL for none | ||
800 | * @param client_af address family of the address returned to the client | 754 | * @param client_af address family of the address returned to the client |
801 | * @param request_id request ID to send in client notification (unused if client is NULL) | 755 | * @param request_id request ID to send in client notification (unused if client is NULL) |
802 | * @return tunnel state of the tunnel that was created | 756 | * @return tunnel state of the tunnel that was created |
803 | */ | 757 | */ |
804 | static struct TunnelState * | 758 | static struct TunnelState * |
805 | create_tunnel_to_destination (struct DestinationEntry *de, | 759 | create_tunnel_to_destination (struct DestinationEntry *de, |
806 | struct GNUNET_SERVER_Client *client, | ||
807 | int client_af, | 760 | int client_af, |
808 | uint64_t request_id) | 761 | uint64_t request_id) |
809 | { | 762 | { |
@@ -815,11 +768,6 @@ create_tunnel_to_destination (struct DestinationEntry *de, | |||
815 | GNUNET_assert (NULL == de->ts); | 768 | GNUNET_assert (NULL == de->ts); |
816 | ts = GNUNET_new (struct TunnelState); | 769 | ts = GNUNET_new (struct TunnelState); |
817 | ts->af = client_af; | 770 | ts->af = client_af; |
818 | if (NULL != client) | ||
819 | { | ||
820 | ts->request_id = request_id; | ||
821 | ts->client = client; | ||
822 | } | ||
823 | ts->destination = *de; | 771 | ts->destination = *de; |
824 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ | 772 | ts->destination.heap_node = NULL; /* copy is NOT in destination heap */ |
825 | de->ts = ts; | 773 | de->ts = ts; |
@@ -1093,7 +1041,7 @@ route_packet (struct DestinationEntry *destination, | |||
1093 | available) or create a fresh one */ | 1041 | available) or create a fresh one */ |
1094 | is_new = GNUNET_YES; | 1042 | is_new = GNUNET_YES; |
1095 | if (NULL == destination->ts) | 1043 | if (NULL == destination->ts) |
1096 | ts = create_tunnel_to_destination (destination, NULL, af, 0); | 1044 | ts = create_tunnel_to_destination (destination, af, 0); |
1097 | else | 1045 | else |
1098 | ts = destination->ts; | 1046 | ts = destination->ts; |
1099 | if (NULL == ts) | 1047 | if (NULL == ts) |
@@ -2579,16 +2527,17 @@ allocate_response_ip (int *result_af, | |||
2579 | 2527 | ||
2580 | 2528 | ||
2581 | /** | 2529 | /** |
2582 | * A client asks us to setup a redirection via some exit | 2530 | * A client asks us to setup a redirection via some exit node to a |
2583 | * node to a particular IP. Setup the redirection and | 2531 | * particular IP. Setup the redirection and give the client the |
2584 | * give the client the allocated IP. | 2532 | * allocated IP. |
2585 | * | 2533 | * |
2586 | * @param cls unused | 2534 | * @param cls unused |
2587 | * @param client requesting client | 2535 | * @param client requesting client |
2588 | * @param message redirection request (a `struct RedirectToIpRequestMessage`) | 2536 | * @param message redirection request (a `struct RedirectToIpRequestMessage`) |
2589 | */ | 2537 | */ |
2590 | static void | 2538 | static void |
2591 | service_redirect_to_ip (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Client *client, | 2539 | service_redirect_to_ip (void *cls, |
2540 | struct GNUNET_SERVER_Client *client, | ||
2592 | const struct GNUNET_MessageHeader *message) | 2541 | const struct GNUNET_MessageHeader *message) |
2593 | { | 2542 | { |
2594 | size_t mlen; | 2543 | size_t mlen; |
@@ -2647,15 +2596,11 @@ service_redirect_to_ip (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Client *cl | |||
2647 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2596 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2648 | return; | 2597 | return; |
2649 | } | 2598 | } |
2650 | if ( (result_af == AF_UNSPEC) || | 2599 | /* send reply with our IP address */ |
2651 | (GNUNET_NO == ntohl (msg->nac)) ) | 2600 | send_client_reply (client, |
2652 | { | 2601 | msg->request_id, |
2653 | /* send reply "instantly" */ | 2602 | result_af, |
2654 | send_client_reply (client, | 2603 | addr); |
2655 | msg->request_id, | ||
2656 | result_af, | ||
2657 | addr); | ||
2658 | } | ||
2659 | if (result_af == AF_UNSPEC) | 2604 | if (result_af == AF_UNSPEC) |
2660 | { | 2605 | { |
2661 | /* failure, we're done */ | 2606 | /* failure, we're done */ |
@@ -2701,7 +2646,6 @@ service_redirect_to_ip (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Client *cl | |||
2701 | 2646 | ||
2702 | /* setup tunnel to destination */ | 2647 | /* setup tunnel to destination */ |
2703 | ts = create_tunnel_to_destination (de, | 2648 | ts = create_tunnel_to_destination (de, |
2704 | (GNUNET_NO == ntohl (msg->nac)) ? NULL : client, | ||
2705 | result_af, | 2649 | result_af, |
2706 | msg->request_id); | 2650 | msg->request_id); |
2707 | switch (result_af) | 2651 | switch (result_af) |
@@ -2754,15 +2698,10 @@ service_redirect_to_service (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Clien | |||
2754 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2698 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2755 | return; | 2699 | return; |
2756 | } | 2700 | } |
2757 | if ( (result_af == AF_UNSPEC) || | 2701 | send_client_reply (client, |
2758 | (GNUNET_NO == ntohl (msg->nac)) ) | 2702 | msg->request_id, |
2759 | { | 2703 | result_af, |
2760 | /* send reply "instantly" */ | 2704 | addr); |
2761 | send_client_reply (client, | ||
2762 | msg->request_id, | ||
2763 | result_af, | ||
2764 | addr); | ||
2765 | } | ||
2766 | if (result_af == AF_UNSPEC) | 2705 | if (result_af == AF_UNSPEC) |
2767 | { | 2706 | { |
2768 | /* failure, we're done */ | 2707 | /* failure, we're done */ |
@@ -2802,7 +2741,6 @@ service_redirect_to_service (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Clien | |||
2802 | while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) | 2741 | while (GNUNET_CONTAINER_multihashmap_size (destination_map) > max_destination_mappings) |
2803 | expire_destination (de); | 2742 | expire_destination (de); |
2804 | ts = create_tunnel_to_destination (de, | 2743 | ts = create_tunnel_to_destination (de, |
2805 | (GNUNET_NO == ntohl (msg->nac)) ? NULL : client, | ||
2806 | result_af, | 2744 | result_af, |
2807 | msg->request_id); | 2745 | msg->request_id); |
2808 | switch (result_af) | 2746 | switch (result_af) |
@@ -2948,75 +2886,6 @@ cleanup (void *cls, | |||
2948 | 2886 | ||
2949 | 2887 | ||
2950 | /** | 2888 | /** |
2951 | * A client disconnected, clean up all references to it. | ||
2952 | * | ||
2953 | * @param cls the client that disconnected | ||
2954 | * @param key unused | ||
2955 | * @param value a `struct TunnelState *` | ||
2956 | * @return #GNUNET_OK (continue to iterate) | ||
2957 | */ | ||
2958 | static int | ||
2959 | cleanup_tunnel_client (void *cls, | ||
2960 | const struct GNUNET_HashCode *key, | ||
2961 | void *value) | ||
2962 | { | ||
2963 | struct GNUNET_SERVER_Client *client = cls; | ||
2964 | struct TunnelState *ts = value; | ||
2965 | |||
2966 | if (client == ts->client) | ||
2967 | ts->client = NULL; | ||
2968 | return GNUNET_OK; | ||
2969 | } | ||
2970 | |||
2971 | |||
2972 | /** | ||
2973 | * A client disconnected, clean up all references to it. | ||
2974 | * | ||
2975 | * @param cls the client that disconnected | ||
2976 | * @param key unused | ||
2977 | * @param value a `struct DestinationEntry *` | ||
2978 | * @return #GNUNET_OK (continue to iterate) | ||
2979 | */ | ||
2980 | static int | ||
2981 | cleanup_destination_client (void *cls, | ||
2982 | const struct GNUNET_HashCode *key, | ||
2983 | void *value) | ||
2984 | { | ||
2985 | struct GNUNET_SERVER_Client *client = cls; | ||
2986 | struct DestinationEntry *de = value; | ||
2987 | struct TunnelState *ts; | ||
2988 | |||
2989 | if (NULL == (ts = de->ts)) | ||
2990 | return GNUNET_OK; | ||
2991 | if (client == ts->client) | ||
2992 | ts->client = NULL; | ||
2993 | return GNUNET_OK; | ||
2994 | } | ||
2995 | |||
2996 | |||
2997 | /** | ||
2998 | * A client has disconnected from us. If we are currently building | ||
2999 | * a tunnel for it, cancel the operation. | ||
3000 | * | ||
3001 | * @param cls unused | ||
3002 | * @param client handle to the client that disconnected | ||
3003 | */ | ||
3004 | static void | ||
3005 | client_disconnect (void *cls, | ||
3006 | struct GNUNET_SERVER_Client *client) | ||
3007 | { | ||
3008 | if (NULL != tunnel_map) | ||
3009 | GNUNET_CONTAINER_multihashmap_iterate (tunnel_map, | ||
3010 | &cleanup_tunnel_client, | ||
3011 | client); | ||
3012 | if (NULL != destination_map) | ||
3013 | GNUNET_CONTAINER_multihashmap_iterate (destination_map, | ||
3014 | &cleanup_destination_client, | ||
3015 | client); | ||
3016 | } | ||
3017 | |||
3018 | |||
3019 | /** | ||
3020 | * Main function that will be run by the scheduler. | 2889 | * Main function that will be run by the scheduler. |
3021 | * | 2890 | * |
3022 | * @param cls closure | 2891 | * @param cls closure |
@@ -3176,7 +3045,6 @@ run (void *cls, | |||
3176 | &message_token, NULL, NULL); | 3045 | &message_token, NULL, NULL); |
3177 | nc = GNUNET_SERVER_notification_context_create (server, 1); | 3046 | nc = GNUNET_SERVER_notification_context_create (server, 1); |
3178 | GNUNET_SERVER_add_handlers (server, service_handlers); | 3047 | GNUNET_SERVER_add_handlers (server, service_handlers); |
3179 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); | ||
3180 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); | 3048 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); |
3181 | } | 3049 | } |
3182 | 3050 | ||