diff options
Diffstat (limited to 'src/ats/gnunet-service-ats_connectivity.c')
-rw-r--r-- | src/ats/gnunet-service-ats_connectivity.c | 121 |
1 files changed, 60 insertions, 61 deletions
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c index 3853aeb0e..f71d18e82 100644 --- a/src/ats/gnunet-service-ats_connectivity.c +++ b/src/ats/gnunet-service-ats_connectivity.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_connectivity.c | 22 | * @file ats/gnunet-service-ats_connectivity.c |
@@ -35,8 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * Active connection requests. | 36 | * Active connection requests. |
37 | */ | 37 | */ |
38 | struct ConnectionRequest | 38 | struct ConnectionRequest { |
39 | { | ||
40 | /** | 39 | /** |
41 | * Client that made the request. | 40 | * Client that made the request. |
42 | */ | 41 | */ |
@@ -61,14 +60,14 @@ static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests; | |||
61 | * @return #GNUNET_YES if so, #GNUNET_NO if not | 60 | * @return #GNUNET_YES if so, #GNUNET_NO if not |
62 | */ | 61 | */ |
63 | unsigned int | 62 | unsigned int |
64 | GAS_connectivity_has_peer (void *cls, | 63 | GAS_connectivity_has_peer(void *cls, |
65 | const struct GNUNET_PeerIdentity *peer) | 64 | const struct GNUNET_PeerIdentity *peer) |
66 | { | 65 | { |
67 | if (NULL == connection_requests) | 66 | if (NULL == connection_requests) |
68 | return 0; | 67 | return 0; |
69 | /* TODO: return sum of 'strength's of connectivity requests */ | 68 | /* TODO: return sum of 'strength's of connectivity requests */ |
70 | return GNUNET_CONTAINER_multipeermap_contains (connection_requests, | 69 | return GNUNET_CONTAINER_multipeermap_contains(connection_requests, |
71 | peer); | 70 | peer); |
72 | } | 71 | } |
73 | 72 | ||
74 | 73 | ||
@@ -79,22 +78,22 @@ GAS_connectivity_has_peer (void *cls, | |||
79 | * @param message the request message | 78 | * @param message the request message |
80 | */ | 79 | */ |
81 | void | 80 | void |
82 | GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | 81 | GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, |
83 | const struct RequestAddressMessage *msg) | 82 | const struct RequestAddressMessage *msg) |
84 | { | 83 | { |
85 | struct ConnectionRequest *cr; | 84 | struct ConnectionRequest *cr; |
86 | 85 | ||
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
88 | "Received `%s' message\n", | 87 | "Received `%s' message\n", |
89 | "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); | 88 | "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); |
90 | /* FIXME: should not ignore "msg->strength" */ | 89 | /* FIXME: should not ignore "msg->strength" */ |
91 | cr = GNUNET_new (struct ConnectionRequest); | 90 | cr = GNUNET_new(struct ConnectionRequest); |
92 | cr->client = client; | 91 | cr->client = client; |
93 | (void) GNUNET_CONTAINER_multipeermap_put (connection_requests, | 92 | (void)GNUNET_CONTAINER_multipeermap_put(connection_requests, |
94 | &msg->peer, | 93 | &msg->peer, |
95 | cr, | 94 | cr, |
96 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 95 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
97 | GAS_plugin_request_connect_start (&msg->peer); | 96 | GAS_plugin_request_connect_start(&msg->peer); |
98 | } | 97 | } |
99 | 98 | ||
100 | 99 | ||
@@ -108,25 +107,25 @@ GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | |||
108 | * @return #GNUNET_OK (continue to iterate) | 107 | * @return #GNUNET_OK (continue to iterate) |
109 | */ | 108 | */ |
110 | static int | 109 | static int |
111 | free_matching_requests (void *cls, | 110 | free_matching_requests(void *cls, |
112 | const struct GNUNET_PeerIdentity *pid, | 111 | const struct GNUNET_PeerIdentity *pid, |
113 | void *value) | 112 | void *value) |
114 | { | 113 | { |
115 | struct GNUNET_SERVICE_Client *client = cls; | 114 | struct GNUNET_SERVICE_Client *client = cls; |
116 | struct ConnectionRequest *cr = value; | 115 | struct ConnectionRequest *cr = value; |
117 | 116 | ||
118 | if (cr->client == client) | 117 | if (cr->client == client) |
119 | { | 118 | { |
120 | GAS_plugin_request_connect_stop (pid); | 119 | GAS_plugin_request_connect_stop(pid); |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
122 | "Removed request pending for peer `%s\n", | 121 | "Removed request pending for peer `%s\n", |
123 | GNUNET_i2s (pid)); | 122 | GNUNET_i2s(pid)); |
124 | GNUNET_assert (GNUNET_YES == | 123 | GNUNET_assert(GNUNET_YES == |
125 | GNUNET_CONTAINER_multipeermap_remove (connection_requests, | 124 | GNUNET_CONTAINER_multipeermap_remove(connection_requests, |
126 | pid, | 125 | pid, |
127 | cr)); | 126 | cr)); |
128 | GNUNET_free (cr); | 127 | GNUNET_free(cr); |
129 | } | 128 | } |
130 | return GNUNET_OK; | 129 | return GNUNET_OK; |
131 | } | 130 | } |
132 | 131 | ||
@@ -139,17 +138,17 @@ free_matching_requests (void *cls, | |||
139 | * @param msg the request message | 138 | * @param msg the request message |
140 | */ | 139 | */ |
141 | void | 140 | void |
142 | GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | 141 | GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, |
143 | const struct RequestAddressMessage *msg) | 142 | const struct RequestAddressMessage *msg) |
144 | { | 143 | { |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
146 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", | 145 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", |
147 | GNUNET_i2s (&msg->peer)); | 146 | GNUNET_i2s(&msg->peer)); |
148 | GNUNET_break (0 == ntohl (msg->strength)); | 147 | GNUNET_break(0 == ntohl(msg->strength)); |
149 | GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests, | 148 | GNUNET_CONTAINER_multipeermap_get_multiple(connection_requests, |
150 | &msg->peer, | 149 | &msg->peer, |
151 | &free_matching_requests, | 150 | &free_matching_requests, |
152 | client); | 151 | client); |
153 | } | 152 | } |
154 | 153 | ||
155 | 154 | ||
@@ -160,11 +159,11 @@ GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | |||
160 | * @param client handle of the (now dead) client | 159 | * @param client handle of the (now dead) client |
161 | */ | 160 | */ |
162 | void | 161 | void |
163 | GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client) | 162 | GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client) |
164 | { | 163 | { |
165 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | 164 | GNUNET_CONTAINER_multipeermap_iterate(connection_requests, |
166 | &free_matching_requests, | 165 | &free_matching_requests, |
167 | client); | 166 | client); |
168 | } | 167 | } |
169 | 168 | ||
170 | 169 | ||
@@ -172,11 +171,11 @@ GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client) | |||
172 | * Shutdown connectivity subsystem. | 171 | * Shutdown connectivity subsystem. |
173 | */ | 172 | */ |
174 | void | 173 | void |
175 | GAS_connectivity_init () | 174 | GAS_connectivity_init() |
176 | { | 175 | { |
177 | connection_requests | 176 | connection_requests |
178 | = GNUNET_CONTAINER_multipeermap_create (32, | 177 | = GNUNET_CONTAINER_multipeermap_create(32, |
179 | GNUNET_NO); | 178 | GNUNET_NO); |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
@@ -189,15 +188,15 @@ GAS_connectivity_init () | |||
189 | * @return #GNUNET_OK (continue to iterate) | 188 | * @return #GNUNET_OK (continue to iterate) |
190 | */ | 189 | */ |
191 | static int | 190 | static int |
192 | free_request (void *cls, | 191 | free_request(void *cls, |
193 | const struct GNUNET_PeerIdentity *pid, | 192 | const struct GNUNET_PeerIdentity *pid, |
194 | void *value) | 193 | void *value) |
195 | { | 194 | { |
196 | struct ConnectionRequest *cr = value; | 195 | struct ConnectionRequest *cr = value; |
197 | 196 | ||
198 | free_matching_requests (cr->client, | 197 | free_matching_requests(cr->client, |
199 | pid, | 198 | pid, |
200 | cr); | 199 | cr); |
201 | return GNUNET_OK; | 200 | return GNUNET_OK; |
202 | } | 201 | } |
203 | 202 | ||
@@ -206,14 +205,14 @@ free_request (void *cls, | |||
206 | * Shutdown connectivity subsystem. | 205 | * Shutdown connectivity subsystem. |
207 | */ | 206 | */ |
208 | void | 207 | void |
209 | GAS_connectivity_done () | 208 | GAS_connectivity_done() |
210 | { | 209 | { |
211 | GAS_plugin_solver_lock (); | 210 | GAS_plugin_solver_lock(); |
212 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | 211 | GNUNET_CONTAINER_multipeermap_iterate(connection_requests, |
213 | &free_request, | 212 | &free_request, |
214 | NULL); | 213 | NULL); |
215 | GAS_plugin_solver_unlock (); | 214 | GAS_plugin_solver_unlock(); |
216 | GNUNET_CONTAINER_multipeermap_destroy (connection_requests); | 215 | GNUNET_CONTAINER_multipeermap_destroy(connection_requests); |
217 | connection_requests = NULL; | 216 | connection_requests = NULL; |
218 | } | 217 | } |
219 | 218 | ||