diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_connectivity.c')
-rw-r--r-- | src/ats/gnunet-service-ats_connectivity.c | 222 |
1 files changed, 0 insertions, 222 deletions
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c deleted file mode 100644 index 5ee9b60f5..000000000 --- a/src/ats/gnunet-service-ats_connectivity.c +++ /dev/null | |||
@@ -1,222 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2011-2015 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file ats/gnunet-service-ats_connectivity.c | ||
23 | * @brief ats service, interaction with 'connecivity' API | ||
24 | * @author Matthias Wachs | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #include "platform.h" | ||
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" | ||
32 | #include "ats.h" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Active connection requests. | ||
37 | */ | ||
38 | struct ConnectionRequest | ||
39 | { | ||
40 | /** | ||
41 | * Client that made the request. | ||
42 | */ | ||
43 | struct GNUNET_SERVICE_Client *client; | ||
44 | |||
45 | /* TODO: allow client to express a 'strength' for this request */ | ||
46 | }; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Address suggestion requests by peer. | ||
51 | */ | ||
52 | static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Is the given peer in the list of peers for which we | ||
57 | * have an address request? | ||
58 | * | ||
59 | * @param cls unused, NULL | ||
60 | * @param peer peer to query for | ||
61 | * @return #GNUNET_YES if so, #GNUNET_NO if not | ||
62 | */ | ||
63 | unsigned int | ||
64 | GAS_connectivity_has_peer (void *cls, | ||
65 | const struct GNUNET_PeerIdentity *peer) | ||
66 | { | ||
67 | if (NULL == connection_requests) | ||
68 | return 0; | ||
69 | /* TODO: return sum of 'strength's of connectivity requests */ | ||
70 | return GNUNET_CONTAINER_multipeermap_contains (connection_requests, | ||
71 | peer); | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Handle #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients. | ||
77 | * | ||
78 | * @param client client that sent the request | ||
79 | * @param message the request message | ||
80 | */ | ||
81 | void | ||
82 | GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | ||
83 | const struct RequestAddressMessage *msg) | ||
84 | { | ||
85 | struct ConnectionRequest *cr; | ||
86 | |||
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
88 | "Received `%s' message\n", | ||
89 | "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); | ||
90 | /* FIXME: should not ignore "msg->strength" */ | ||
91 | cr = GNUNET_new (struct ConnectionRequest); | ||
92 | cr->client = client; | ||
93 | (void) GNUNET_CONTAINER_multipeermap_put (connection_requests, | ||
94 | &msg->peer, | ||
95 | cr, | ||
96 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
97 | GAS_plugin_request_connect_start (&msg->peer); | ||
98 | } | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Free the connection request from the map if the | ||
103 | * closure matches the client. | ||
104 | * | ||
105 | * @param cls the client to match | ||
106 | * @param pid peer for which the request was made | ||
107 | * @param value the `struct ConnectionRequest` | ||
108 | * @return #GNUNET_OK (continue to iterate) | ||
109 | */ | ||
110 | static int | ||
111 | free_matching_requests (void *cls, | ||
112 | const struct GNUNET_PeerIdentity *pid, | ||
113 | void *value) | ||
114 | { | ||
115 | struct GNUNET_SERVICE_Client *client = cls; | ||
116 | struct ConnectionRequest *cr = value; | ||
117 | |||
118 | if (cr->client == client) | ||
119 | { | ||
120 | GAS_plugin_request_connect_stop (pid); | ||
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
122 | "Removed request pending for peer `%s\n", | ||
123 | GNUNET_i2s (pid)); | ||
124 | GNUNET_assert (GNUNET_YES == | ||
125 | GNUNET_CONTAINER_multipeermap_remove (connection_requests, | ||
126 | pid, | ||
127 | cr)); | ||
128 | GNUNET_free (cr); | ||
129 | } | ||
130 | return GNUNET_OK; | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Handle #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL messages | ||
136 | * from clients. | ||
137 | * | ||
138 | * @param client the client that sent the request | ||
139 | * @param msg the request message | ||
140 | */ | ||
141 | void | ||
142 | GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | ||
143 | const struct RequestAddressMessage *msg) | ||
144 | { | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
146 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", | ||
147 | GNUNET_i2s (&msg->peer)); | ||
148 | GNUNET_break (0 == ntohl (msg->strength)); | ||
149 | GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests, | ||
150 | &msg->peer, | ||
151 | &free_matching_requests, | ||
152 | client); | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Unregister a client (which may have been a connectivity client, | ||
158 | * but this is not assured). | ||
159 | * | ||
160 | * @param client handle of the (now dead) client | ||
161 | */ | ||
162 | void | ||
163 | GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client) | ||
164 | { | ||
165 | if (NULL != connection_requests) | ||
166 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | ||
167 | &free_matching_requests, | ||
168 | client); | ||
169 | } | ||
170 | |||
171 | |||
172 | /** | ||
173 | * Shutdown connectivity subsystem. | ||
174 | */ | ||
175 | void | ||
176 | GAS_connectivity_init () | ||
177 | { | ||
178 | connection_requests | ||
179 | = GNUNET_CONTAINER_multipeermap_create (32, | ||
180 | GNUNET_NO); | ||
181 | } | ||
182 | |||
183 | |||
184 | /** | ||
185 | * Free the connection request from the map. | ||
186 | * | ||
187 | * @param cls NULL | ||
188 | * @param pid peer for which the request was made | ||
189 | * @param value the `struct ConnectionRequest` | ||
190 | * @return #GNUNET_OK (continue to iterate) | ||
191 | */ | ||
192 | static int | ||
193 | free_request (void *cls, | ||
194 | const struct GNUNET_PeerIdentity *pid, | ||
195 | void *value) | ||
196 | { | ||
197 | struct ConnectionRequest *cr = value; | ||
198 | |||
199 | free_matching_requests (cr->client, | ||
200 | pid, | ||
201 | cr); | ||
202 | return GNUNET_OK; | ||
203 | } | ||
204 | |||
205 | |||
206 | /** | ||
207 | * Shutdown connectivity subsystem. | ||
208 | */ | ||
209 | void | ||
210 | GAS_connectivity_done () | ||
211 | { | ||
212 | GAS_plugin_solver_lock (); | ||
213 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | ||
214 | &free_request, | ||
215 | NULL); | ||
216 | GAS_plugin_solver_unlock (); | ||
217 | GNUNET_CONTAINER_multipeermap_destroy (connection_requests); | ||
218 | connection_requests = NULL; | ||
219 | } | ||
220 | |||
221 | |||
222 | /* end of gnunet-service-ats_connectivity.c */ | ||