2 This file is part of GNUnet.
3 (C) 2011-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file ats/gnunet-service-ats_connectivity.c
23 * @brief ats service, interaction with 'connecivity' API
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet-service-ats.h"
29 #include "gnunet-service-ats_addresses.h"
30 #include "gnunet-service-ats_connectivity.h"
31 #include "gnunet-service-ats_plugins.h"
36 * Active connection requests.
38 struct ConnectionRequest
41 * Client that made the request.
43 struct GNUNET_SERVER_Client *client;
48 * Address suggestion requests by peer.
50 static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests;
54 * Handle 'request address' messages from clients.
56 * @param cls unused, NULL
57 * @param client client that sent the request
58 * @param message the request message
61 GAS_handle_request_address (void *cls,
62 struct GNUNET_SERVER_Client *client,
63 const struct GNUNET_MessageHeader *message)
65 const struct RequestAddressMessage *msg =
66 (const struct RequestAddressMessage *) message;
67 struct ConnectionRequest *cr;
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Received `%s' message\n",
72 GNUNET_break (0 == ntohl (msg->reserved));
73 cr = GNUNET_new (struct ConnectionRequest);
75 (void) GNUNET_CONTAINER_multipeermap_put (connection_requests,
78 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
79 GAS_plugin_request_connect_start (&msg->peer);
80 GNUNET_SERVER_receive_done (client, GNUNET_OK);
85 * Free the connection request from the map if the
86 * closure matches the client.
88 * @param cls the client to match
89 * @param pid peer for which the request was made
90 * @param value the `struct ConnectionRequest`
91 * @return #GNUNET_OK (continue to iterate)
94 free_matching_requests (void *cls,
95 const struct GNUNET_PeerIdentity *pid,
98 struct GNUNET_SERVER_Client *client = cls;
99 struct ConnectionRequest *cr = value;
101 if (cr->client == client)
103 GAS_plugin_request_connect_stop (pid);
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Removed request pending for peer `%s\n",
107 GNUNET_assert (GNUNET_YES ==
108 GNUNET_CONTAINER_multipeermap_remove (connection_requests,
118 * Handle 'request address cancel' messages from clients.
120 * @param cls unused, NULL
121 * @param client client that sent the request
122 * @param message the request message
125 GAS_handle_request_address_cancel (void *cls,
126 struct GNUNET_SERVER_Client *client,
127 const struct GNUNET_MessageHeader *message)
129 const struct RequestAddressMessage *msg =
130 (const struct RequestAddressMessage *) message;
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
133 "Received REQUEST_ADDRESS_CANCEL message for peer %s\n",
134 GNUNET_i2s (&msg->peer));
135 GNUNET_break (0 == ntohl (msg->reserved));
136 GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests,
138 &free_matching_requests,
140 GNUNET_SERVER_receive_done (client, GNUNET_OK);
145 * Unregister a client (which may have been a connectivity client,
146 * but this is not assured).
148 * @param client handle of the (now dead) client
151 GAS_connectivity_remove_client (struct GNUNET_SERVER_Client *client)
153 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
154 &free_matching_requests,
160 * Shutdown connectivity subsystem.
163 GAS_connectivity_init ()
165 connection_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_NO);
170 * Free the connection request from the map.
173 * @param pid peer for which the request was made
174 * @param value the `struct ConnectionRequest`
175 * @return #GNUNET_OK (continue to iterate)
178 free_request (void *cls,
179 const struct GNUNET_PeerIdentity *pid,
182 struct ConnectionRequest *cr = value;
184 free_matching_requests (cr->client,
192 * Shutdown connectivity subsystem.
195 GAS_connectivity_done ()
197 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
200 GNUNET_CONTAINER_multipeermap_destroy (connection_requests);
204 /* end of gnunet-service-ats_connectivity.c */