diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-01-22 17:27:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-01-22 17:27:16 +0000 |
commit | 07632b2d9509b0e425967cbc80d2abd6ffc81c9d (patch) | |
tree | 905060f30d74d05304a448fe3e3cd06dad583328 /src | |
parent | 068bd6929580eb6521c7ac40c8ae05eb632f6c58 (diff) | |
download | gnunet-07632b2d9509b0e425967cbc80d2abd6ffc81c9d.tar.gz gnunet-07632b2d9509b0e425967cbc80d2abd6ffc81c9d.zip |
use new APIs for connect/disconnect
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core_api_peer_request.c | 64 | ||||
-rw-r--r-- | src/core/gnunet-service-core.c | 27 | ||||
-rw-r--r-- | src/include/gnunet_core_service.h | 36 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 5 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 7 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 62 |
6 files changed, 36 insertions, 165 deletions
diff --git a/src/core/core_api_peer_request.c b/src/core/core_api_peer_request.c index 58837c773..7a76a91df 100644 --- a/src/core/core_api_peer_request.c +++ b/src/core/core_api_peer_request.c | |||
@@ -29,8 +29,8 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Handle for a request to the core to connect or disconnect | 32 | * Handle for a request to the core to connect to |
33 | * from a particular peer. Can be used to cancel the request | 33 | * a particular peer. Can be used to cancel the request |
34 | * (before the 'cont'inuation is called). | 34 | * (before the 'cont'inuation is called). |
35 | */ | 35 | */ |
36 | struct GNUNET_CORE_PeerRequestHandle | 36 | struct GNUNET_CORE_PeerRequestHandle |
@@ -57,7 +57,7 @@ struct GNUNET_CORE_PeerRequestHandle | |||
57 | void *cont_cls; | 57 | void *cont_cls; |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Identity of the peer to connect/disconnect. | 60 | * Identity of the peer to connect to. |
61 | */ | 61 | */ |
62 | struct GNUNET_PeerIdentity peer; | 62 | struct GNUNET_PeerIdentity peer; |
63 | 63 | ||
@@ -160,65 +160,13 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_SCHEDULER_Handle *sched, | |||
160 | 160 | ||
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Request that the core should try to disconnect from a particular | 163 | * Cancel a pending request to connect to a particular peer. Must not |
164 | * peer. Once the request has been transmitted to the core, the | 164 | * be called after the 'cont' function was invoked. |
165 | * continuation function will be called. Note that this does NOT mean | ||
166 | * that a connection was successfully cut -- it only means that the | ||
167 | * core will now try. Typically this will work pretty much | ||
168 | * immediately, but it is at least in theory also possible that a | ||
169 | * reconnect is also triggered rather quickly. Successful creation | ||
170 | * and destruction of connections will be signalled to the 'connects' | ||
171 | * and 'disconnects' callback arguments of 'GNUNET_CORE_connect' only. | ||
172 | * If the core service does not respond to our connection attempt | ||
173 | * within the given time frame, 'cont' will be called with the TIMEOUT | ||
174 | * reason code. | ||
175 | * | ||
176 | * @param sched scheduler to use | ||
177 | * @param cfg configuration to use | ||
178 | * @param timeout how long to try to talk to core | ||
179 | * @param cont function to call once the request has been completed (or timed out) | ||
180 | * @param cont_cls closure for cont | ||
181 | * @return NULL on error (cont will not be called), otherwise handle for cancellation | ||
182 | */ | ||
183 | struct GNUNET_CORE_PeerRequestHandle * | ||
184 | GNUNET_CORE_peer_request_disconnect (struct GNUNET_SCHEDULER_Handle *sched, | ||
185 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
186 | struct GNUNET_TIME_Relative timeout, | ||
187 | const struct GNUNET_PeerIdentity * peer, | ||
188 | GNUNET_SCHEDULER_Task cont, | ||
189 | void *cont_cls) | ||
190 | { | ||
191 | struct GNUNET_CORE_PeerRequestHandle *ret; | ||
192 | struct GNUNET_CLIENT_Connection *client; | ||
193 | |||
194 | client = GNUNET_CLIENT_connect (sched, "core", cfg); | ||
195 | if (client == NULL) | ||
196 | return NULL; | ||
197 | ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle)); | ||
198 | ret->client = client; | ||
199 | ret->sched = sched; | ||
200 | ret->cont = cont; | ||
201 | ret->cont_cls = cont_cls; | ||
202 | ret->peer = *peer; | ||
203 | ret->type = GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT; | ||
204 | GNUNET_CLIENT_notify_transmit_ready (client, | ||
205 | sizeof (struct ConnectMessage), | ||
206 | timeout, | ||
207 | GNUNET_YES, | ||
208 | &send_request, | ||
209 | ret); | ||
210 | return ret; | ||
211 | } | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Cancel a pending request to connect or disconnect from/to a particular | ||
216 | * peer. Must not be called after the 'cont' function was invoked. | ||
217 | * | 165 | * |
218 | * @param req request handle that was returned for the original request | 166 | * @param req request handle that was returned for the original request |
219 | */ | 167 | */ |
220 | void | 168 | void |
221 | GNUNET_CORE_peer_request_cancel (struct GNUNET_CORE_PeerRequestHandle *req) | 169 | GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req) |
222 | { | 170 | { |
223 | GNUNET_CLIENT_disconnect (req->client); | 171 | GNUNET_CLIENT_disconnect (req->client); |
224 | GNUNET_free (req); | 172 | GNUNET_free (req); |
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index a3694e582..cb74fc8c2 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -1862,30 +1862,6 @@ handle_client_request_connect (void *cls, | |||
1862 | 1862 | ||
1863 | 1863 | ||
1864 | /** | 1864 | /** |
1865 | * Handle CORE_REQUEST_DISCONNECT request. | ||
1866 | * | ||
1867 | * @param cls unused | ||
1868 | * @param client the client issuing the request | ||
1869 | * @param message the "struct ConnectMessage" | ||
1870 | */ | ||
1871 | static void | ||
1872 | handle_client_request_disconnect (void *cls, | ||
1873 | struct GNUNET_SERVER_Client *client, | ||
1874 | const struct GNUNET_MessageHeader *message) | ||
1875 | { | ||
1876 | const struct ConnectMessage *cm = (const struct ConnectMessage*) message; | ||
1877 | struct Neighbour *n; | ||
1878 | |||
1879 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1880 | n = find_neighbour (&cm->peer); | ||
1881 | if (n == NULL) | ||
1882 | return; /* done */ | ||
1883 | /* FIXME: implement disconnect! */ | ||
1884 | } | ||
1885 | |||
1886 | |||
1887 | |||
1888 | /** | ||
1889 | * List of handlers for the messages understood by this | 1865 | * List of handlers for the messages understood by this |
1890 | * service. | 1866 | * service. |
1891 | */ | 1867 | */ |
@@ -1900,9 +1876,6 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { | |||
1900 | {&handle_client_request_connect, NULL, | 1876 | {&handle_client_request_connect, NULL, |
1901 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT, | 1877 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT, |
1902 | sizeof (struct ConnectMessage)}, | 1878 | sizeof (struct ConnectMessage)}, |
1903 | {&handle_client_request_disconnect, NULL, | ||
1904 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT, | ||
1905 | sizeof (struct ConnectMessage)}, | ||
1906 | {NULL, NULL, 0, 0} | 1879 | {NULL, NULL, 0, 0} |
1907 | }; | 1880 | }; |
1908 | 1881 | ||
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index 3ba4ef137..6f49dc71a 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h | |||
@@ -232,43 +232,13 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_SCHEDULER_Handle *sched, | |||
232 | 232 | ||
233 | 233 | ||
234 | /** | 234 | /** |
235 | * Request that the core should try to disconnect from a particular | 235 | * Cancel a pending request to connect to a particular peer. Must not |
236 | * peer. Once the request has been transmitted to the core, the | 236 | * be called after the 'cont' function was invoked. |
237 | * continuation function will be called. Note that this does NOT mean | ||
238 | * that a connection was successfully cut -- it only means that the | ||
239 | * core will now try. Typically this will work pretty much | ||
240 | * immediately, but it is at least in theory also possible that a | ||
241 | * reconnect is also triggered rather quickly. Successful creation | ||
242 | * and destruction of connections will be signalled to the 'connects' | ||
243 | * and 'disconnects' callback arguments of 'GNUNET_CORE_connect' only. | ||
244 | * If the core service does not respond to our connection attempt | ||
245 | * within the given time frame, 'cont' will be called with the TIMEOUT | ||
246 | * reason code. | ||
247 | * | ||
248 | * @param sched scheduler to use | ||
249 | * @param cfg configuration to use | ||
250 | * @param timeout how long to try to talk to core | ||
251 | * @param cont function to call once the request has been completed (or timed out) | ||
252 | * @param cont_cls closure for cont | ||
253 | * @return NULL on error (cont will not be called), otherwise handle for cancellation | ||
254 | */ | ||
255 | struct GNUNET_CORE_PeerRequestHandle * | ||
256 | GNUNET_CORE_peer_request_disconnect (struct GNUNET_SCHEDULER_Handle *sched, | ||
257 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
258 | struct GNUNET_TIME_Relative timeout, | ||
259 | const struct GNUNET_PeerIdentity * peer, | ||
260 | GNUNET_SCHEDULER_Task cont, | ||
261 | void *cont_cls); | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Cancel a pending request to connect or disconnect from/to a particular | ||
266 | * peer. Must not be called after the 'cont' function was invoked. | ||
267 | * | 237 | * |
268 | * @param req request handle that was returned for the original request | 238 | * @param req request handle that was returned for the original request |
269 | */ | 239 | */ |
270 | void | 240 | void |
271 | GNUNET_CORE_peer_request_cancel (struct GNUNET_CORE_PeerRequestHandle *req); | 241 | GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req); |
272 | 242 | ||
273 | 243 | ||
274 | /** | 244 | /** |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 85553bff0..779c16f73 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -307,11 +307,6 @@ extern "C" | |||
307 | */ | 307 | */ |
308 | #define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT 74 | 308 | #define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT 74 |
309 | 309 | ||
310 | /** | ||
311 | * Request from client asking to disconnect from a peer. | ||
312 | */ | ||
313 | #define GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT 75 | ||
314 | |||
315 | 310 | ||
316 | /** | 311 | /** |
317 | * Session key exchange between peers. | 312 | * Session key exchange between peers. |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index b86bb1663..650dd2e68 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -223,6 +223,13 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct | |||
223 | 223 | ||
224 | 224 | ||
225 | 225 | ||
226 | /** | ||
227 | * Function called whenever there is an update to the | ||
228 | * HELLO of this peer. | ||
229 | * | ||
230 | * @param cls closure | ||
231 | * @param hello our updated HELLO | ||
232 | */ | ||
226 | typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls, | 233 | typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls, |
227 | const struct GNUNET_MessageHeader *hello); | 234 | const struct GNUNET_MessageHeader *hello); |
228 | 235 | ||
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index a636360d6..3bcc29704 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -87,7 +87,7 @@ struct PeerList | |||
87 | * Our handle for the request to connect to this peer; NULL if no | 87 | * Our handle for the request to connect to this peer; NULL if no |
88 | * such request is pending. | 88 | * such request is pending. |
89 | */ | 89 | */ |
90 | struct GNUNET_CORE_TransmitHandle *connect_req; | 90 | struct GNUNET_CORE_PeerRequestHandle *connect_req; |
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Pointer to the HELLO message of this peer; can be NULL. | 93 | * Pointer to the HELLO message of this peer; can be NULL. |
@@ -158,8 +158,8 @@ struct DisconnectList | |||
158 | /** | 158 | /** |
159 | * Our request handle. | 159 | * Our request handle. |
160 | */ | 160 | */ |
161 | struct GNUNET_CORE_PeerRequestHandle *rh; | 161 | struct GNUNET_TRANSPORT_BlacklistRequest *rh; |
162 | 162 | ||
163 | /** | 163 | /** |
164 | * Peer we tried to disconnect. | 164 | * Peer we tried to disconnect. |
165 | */ | 165 | */ |
@@ -268,9 +268,7 @@ disconnect_done (void *cls, | |||
268 | 268 | ||
269 | 269 | ||
270 | /** | 270 | /** |
271 | * Force a disconnect from the specified peer. This is currently done by | 271 | * Force a disconnect from the specified peer. |
272 | * changing the bandwidth policy to 0 bytes per second. | ||
273 | * FIXME: maybe we want a nicer CORE API for both connect and disconnect... | ||
274 | * FIXME: this policy change is never undone; how do we reconnect ever? | 272 | * FIXME: this policy change is never undone; how do we reconnect ever? |
275 | */ | 273 | */ |
276 | static void | 274 | static void |
@@ -283,43 +281,25 @@ force_disconnect (const struct GNUNET_PeerIdentity *peer) | |||
283 | GNUNET_CONTAINER_DLL_insert (disconnect_head, | 281 | GNUNET_CONTAINER_DLL_insert (disconnect_head, |
284 | disconnect_tail, | 282 | disconnect_tail, |
285 | dl); | 283 | dl); |
286 | dl->rh = GNUNET_CORE_peer_request_disconnect (sched, cfg, | 284 | dl->rh = GNUNET_TRANSPORT_blacklist (sched, cfg, |
287 | GNUNET_TIME_UNIT_FOREVER_REL, | 285 | peer, |
288 | peer, | 286 | GNUNET_TIME_UNIT_FOREVER_REL, |
289 | &disconnect_done, | 287 | GNUNET_TIME_UNIT_FOREVER_REL, |
290 | dl); | 288 | &disconnect_done, |
289 | dl); | ||
291 | } | 290 | } |
292 | 291 | ||
293 | 292 | ||
294 | /** | 293 | /** |
295 | * Function called by core when our attempt to connect succeeded. | 294 | * Function called by core when our attempt to connect succeeded. |
296 | * Transmits a 'DUMMY' message to trigger the session key exchange. | ||
297 | * FIXME: this is an issue with the current CORE API. | ||
298 | */ | 295 | */ |
299 | static size_t | 296 | static void |
300 | ready_callback (void *cls, | 297 | connect_completed_callback (void *cls, |
301 | size_t size, void *buf) | 298 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
302 | { | 299 | { |
303 | struct PeerList *pos = cls; | 300 | struct PeerList *pos = cls; |
304 | struct GNUNET_MessageHeader hdr; | ||
305 | 301 | ||
306 | pos->connect_req = NULL; | 302 | pos->connect_req = NULL; |
307 | if (buf == NULL) | ||
308 | { | ||
309 | #if DEBUG_TOPOLOGY | ||
310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
311 | "Core told us that our attempt to connect failed.\n"); | ||
312 | #endif | ||
313 | return 0; | ||
314 | } | ||
315 | #if DEBUG_TOPOLOGY | ||
316 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
317 | "Sending dummy message to establish connection.\n"); | ||
318 | #endif | ||
319 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
320 | hdr.type = htons (GNUNET_MESSAGE_TYPE_TOPOLOGY_DUMMY); | ||
321 | memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader)); | ||
322 | return sizeof (struct GNUNET_MessageHeader); | ||
323 | } | 303 | } |
324 | 304 | ||
325 | 305 | ||
@@ -340,13 +320,11 @@ attempt_connect (struct PeerList *pos) | |||
340 | "Asking core to connect to `%s'\n", | 320 | "Asking core to connect to `%s'\n", |
341 | GNUNET_i2s (&pos->id)); | 321 | GNUNET_i2s (&pos->id)); |
342 | #endif | 322 | #endif |
343 | pos->connect_req = GNUNET_CORE_notify_transmit_ready (handle, | 323 | pos->connect_req = GNUNET_CORE_peer_request_connect (sched, cfg, |
344 | 0 /* priority */, | 324 | GNUNET_TIME_UNIT_MINUTES, |
345 | GNUNET_TIME_UNIT_MINUTES, | 325 | &pos->id, |
346 | &pos->id, | 326 | &connect_completed_callback, |
347 | sizeof(struct GNUNET_MessageHeader), | 327 | pos); |
348 | &ready_callback, | ||
349 | pos); | ||
350 | } | 328 | } |
351 | 329 | ||
352 | 330 | ||
@@ -457,7 +435,7 @@ free_peer (struct PeerList *peer) | |||
457 | if (pos->hello_req != NULL) | 435 | if (pos->hello_req != NULL) |
458 | GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); | 436 | GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); |
459 | if (pos->connect_req != NULL) | 437 | if (pos->connect_req != NULL) |
460 | GNUNET_CORE_notify_transmit_ready_cancel (pos->connect_req); | 438 | GNUNET_CORE_peer_request_connect_cancel (pos->connect_req); |
461 | if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) | 439 | if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) |
462 | GNUNET_SCHEDULER_cancel (sched, | 440 | GNUNET_SCHEDULER_cancel (sched, |
463 | pos->hello_delay_task); | 441 | pos->hello_delay_task); |
@@ -1203,7 +1181,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1203 | GNUNET_CONTAINER_DLL_remove (disconnect_head, | 1181 | GNUNET_CONTAINER_DLL_remove (disconnect_head, |
1204 | disconnect_tail, | 1182 | disconnect_tail, |
1205 | dl); | 1183 | dl); |
1206 | GNUNET_CORE_peer_request_cancel (dl->rh); | 1184 | GNUNET_TRANSPORT_blacklist_cancel (dl->rh); |
1207 | GNUNET_free (dl); | 1185 | GNUNET_free (dl); |
1208 | } | 1186 | } |
1209 | } | 1187 | } |