diff options
-rw-r--r-- | src/dv/plugin_transport_dv.c | 42 | ||||
-rw-r--r-- | src/include/gnunet_transport_plugin.h | 209 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 14 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 12 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 12 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 58 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 386 | ||||
-rw-r--r-- | src/transport/plugin_transport_smtp.c | 2 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 69 | ||||
-rw-r--r-- | src/transport/plugin_transport_template.c | 83 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 202 | ||||
-rw-r--r-- | src/transport/plugin_transport_unix.c | 76 | ||||
-rw-r--r-- | src/transport/plugin_transport_wlan.c | 38 | ||||
-rw-r--r-- | src/transport/test_plugin_transport.c | 4 |
14 files changed, 679 insertions, 528 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 1f9a32fe4..93792e0d9 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c | |||
@@ -429,7 +429,7 @@ free_session (struct Session *session) | |||
429 | */ | 429 | */ |
430 | static void | 430 | static void |
431 | handle_dv_disconnect (void *cls, | 431 | handle_dv_disconnect (void *cls, |
432 | const struct GNUNET_PeerIdentity *peer) | 432 | const struct GNUNET_PeerIdentity *peer) |
433 | { | 433 | { |
434 | struct Plugin *plugin = cls; | 434 | struct Plugin *plugin = cls; |
435 | struct Session *session; | 435 | struct Session *session; |
@@ -543,8 +543,8 @@ dv_plugin_send (void *cls, | |||
543 | * @param target peer from which to disconnect | 543 | * @param target peer from which to disconnect |
544 | */ | 544 | */ |
545 | static void | 545 | static void |
546 | dv_plugin_disconnect (void *cls, | 546 | dv_plugin_disconnect_peer (void *cls, |
547 | const struct GNUNET_PeerIdentity *target) | 547 | const struct GNUNET_PeerIdentity *target) |
548 | { | 548 | { |
549 | struct Plugin *plugin = cls; | 549 | struct Plugin *plugin = cls; |
550 | struct Session *session; | 550 | struct Session *session; |
@@ -572,6 +572,39 @@ dv_plugin_disconnect (void *cls, | |||
572 | 572 | ||
573 | 573 | ||
574 | /** | 574 | /** |
575 | * Function that can be used to force the plugin to disconnect | ||
576 | * from the given peer and cancel all previous transmissions | ||
577 | * (and their continuations). | ||
578 | * | ||
579 | * @param cls closure with the `struct Plugin *` | ||
580 | * @param session which session to disconnect | ||
581 | * @return #GNUNET_OK | ||
582 | */ | ||
583 | static int | ||
584 | dv_plugin_disconnect_session (void *cls, | ||
585 | struct Session *session) | ||
586 | { | ||
587 | struct PendingRequest *pr; | ||
588 | |||
589 | while (NULL != (pr = session->pr_head)) | ||
590 | { | ||
591 | GNUNET_CONTAINER_DLL_remove (session->pr_head, | ||
592 | session->pr_tail, | ||
593 | pr); | ||
594 | GNUNET_DV_send_cancel (pr->th); | ||
595 | pr->th = NULL; | ||
596 | if (NULL != pr->transmit_cont) | ||
597 | pr->transmit_cont (pr->transmit_cont_cls, | ||
598 | &session->sender, | ||
599 | GNUNET_SYSERR, 0, 0); | ||
600 | GNUNET_free (pr); | ||
601 | } | ||
602 | session->active = GNUNET_NO; | ||
603 | return GNUNET_OK; | ||
604 | } | ||
605 | |||
606 | |||
607 | /** | ||
575 | * Convert the transports address to a nice, human-readable | 608 | * Convert the transports address to a nice, human-readable |
576 | * format. | 609 | * format. |
577 | * | 610 | * |
@@ -759,7 +792,8 @@ libgnunet_plugin_transport_dv_init (void *cls) | |||
759 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 792 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
760 | api->cls = plugin; | 793 | api->cls = plugin; |
761 | api->send = &dv_plugin_send; | 794 | api->send = &dv_plugin_send; |
762 | api->disconnect = &dv_plugin_disconnect; | 795 | api->disconnect_peer = &dv_plugin_disconnect_peer; |
796 | api->disconnect_session = &dv_plugin_disconnect_session; | ||
763 | api->address_pretty_printer = &dv_plugin_address_pretty_printer; | 797 | api->address_pretty_printer = &dv_plugin_address_pretty_printer; |
764 | api->check_address = &dv_plugin_check_address; | 798 | api->check_address = &dv_plugin_check_address; |
765 | api->address_to_string = &dv_plugin_address_to_string; | 799 | api->address_to_string = &dv_plugin_address_to_string; |
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 7df04edfe..6bf365243 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h | |||
@@ -62,6 +62,7 @@ struct SessionHeader | |||
62 | /* empty, for now */ | 62 | /* empty, for now */ |
63 | }; | 63 | }; |
64 | 64 | ||
65 | |||
65 | /** | 66 | /** |
66 | * Function that will be called whenever the plugin internally | 67 | * Function that will be called whenever the plugin internally |
67 | * cleans up a session pointer and hence the service needs to | 68 | * cleans up a session pointer and hence the service needs to |
@@ -75,9 +76,10 @@ struct SessionHeader | |||
75 | * @param peer which peer was the session for | 76 | * @param peer which peer was the session for |
76 | * @param session which session is being destoyed | 77 | * @param session which session is being destoyed |
77 | */ | 78 | */ |
78 | typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls, | 79 | typedef void |
79 | const struct GNUNET_PeerIdentity *peer, | 80 | (*GNUNET_TRANSPORT_SessionEnd) (void *cls, |
80 | struct Session * session); | 81 | const struct GNUNET_PeerIdentity *peer, |
82 | struct Session *session); | ||
81 | 83 | ||
82 | 84 | ||
83 | /** | 85 | /** |
@@ -93,17 +95,18 @@ typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls, | |||
93 | * @param address_len length of the @a address | 95 | * @param address_len length of the @a address |
94 | * @param session session | 96 | * @param session session |
95 | * @param ats ATS information | 97 | * @param ats ATS information |
96 | * @param ats_count number of ATS information contained | 98 | * @param ats_count number of entries in @a ats array |
97 | */ | 99 | */ |
98 | typedef void | 100 | typedef void |
99 | (*GNUNET_TRANSPORT_SessionStart) (void *cls, | 101 | (*GNUNET_TRANSPORT_SessionStart) (void *cls, |
100 | const struct GNUNET_PeerIdentity *peer, | 102 | const struct GNUNET_PeerIdentity *peer, |
101 | const char *plugin, | 103 | const char *plugin, |
102 | const void *address, | 104 | const void *address, |
103 | uint16_t address_len, | 105 | uint16_t address_len, |
104 | struct Session *session, | 106 | struct Session *session, |
105 | const struct GNUNET_ATS_Information *ats, | 107 | const struct GNUNET_ATS_Information *ats, |
106 | uint32_t ats_count); | 108 | uint32_t ats_count); |
109 | |||
107 | 110 | ||
108 | /** | 111 | /** |
109 | * Function called by the transport for each received message. | 112 | * Function called by the transport for each received message. |
@@ -123,16 +126,17 @@ typedef void | |||
123 | * that we could establish ourselves a connection to that | 126 | * that we could establish ourselves a connection to that |
124 | * IP address and get the same system) | 127 | * IP address and get the same system) |
125 | * @param sender_address_len number of bytes in @a sender_address | 128 | * @param sender_address_len number of bytes in @a sender_address |
126 | * @return how long the plugin should wait until receiving more data | 129 | * @return how long the plugin should wait until receiving more data; |
127 | * (plugins that do not support this, can ignore the return value) | 130 | * returning #GNUNET_TIME_UNIT_FOREVER_REL means that the |
131 | * connection should be closed | ||
128 | */ | 132 | */ |
129 | typedef struct | 133 | typedef struct GNUNET_TIME_Relative |
130 | GNUNET_TIME_Relative (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, | 134 | (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, |
131 | const struct GNUNET_PeerIdentity *peer, | 135 | const struct GNUNET_PeerIdentity *peer, |
132 | const struct GNUNET_MessageHeader *message, | 136 | const struct GNUNET_MessageHeader *message, |
133 | struct Session *session, | 137 | struct Session *session, |
134 | const char *sender_address, | 138 | const char *sender_address, |
135 | uint16_t sender_address_len); | 139 | uint16_t sender_address_len); |
136 | 140 | ||
137 | 141 | ||
138 | /** | 142 | /** |
@@ -159,7 +163,7 @@ typedef struct GNUNET_ATS_Information | |||
159 | * @param address_len length of the @a address | 163 | * @param address_len length of the @a address |
160 | * @param session session | 164 | * @param session session |
161 | * @param ats ATS information | 165 | * @param ats ATS information |
162 | * @param ats_count number of ATS information contained in @a ats | 166 | * @param ats_count number entries in the @a ats array |
163 | */ | 167 | */ |
164 | typedef void | 168 | typedef void |
165 | (*GNUNET_TRANSPORT_UpdateAddressMetrics) (void *cls, | 169 | (*GNUNET_TRANSPORT_UpdateAddressMetrics) (void *cls, |
@@ -175,18 +179,19 @@ typedef void | |||
175 | * is aware that it might be reachable under. | 179 | * is aware that it might be reachable under. |
176 | * | 180 | * |
177 | * @param cls closure | 181 | * @param cls closure |
178 | * @param add_remove should the address added (YES) or removed (NO) from the | 182 | * @param add_remove should the address added (#GNUNET_YES) or removed (#GNUNET_NO) from the |
179 | * set of valid addresses? | 183 | * set of valid addresses? |
180 | * @param addr one of the addresses of the host | 184 | * @param addr one of the addresses of the host |
181 | * the specific address format depends on the transport | 185 | * the specific address format depends on the transport |
182 | * @param addrlen length of the address | 186 | * @param addrlen length of the @a addr |
183 | * @param dest_plugin plugin to use this address with | 187 | * @param dest_plugin plugin to use this address with |
184 | */ | 188 | */ |
185 | typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, | 189 | typedef void |
186 | int add_remove, | 190 | (*GNUNET_TRANSPORT_AddressNotification) (void *cls, |
187 | const void *addr, | 191 | int add_remove, |
188 | size_t addrlen, | 192 | const void *addr, |
189 | const char *dest_plugin); | 193 | size_t addrlen, |
194 | const char *dest_plugin); | ||
190 | 195 | ||
191 | 196 | ||
192 | /** | 197 | /** |
@@ -202,18 +207,20 @@ typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, | |||
202 | * @param peer which peer did we read data from | 207 | * @param peer which peer did we read data from |
203 | * @param amount_recved number of bytes read (can be zero) | 208 | * @param amount_recved number of bytes read (can be zero) |
204 | * @return how long to wait until reading more from this peer | 209 | * @return how long to wait until reading more from this peer |
205 | * (to enforce inbound quotas) | 210 | * (to enforce inbound quotas); returning #GNUNET_TIME_UNIT_FOREVER_REL |
211 | * means that the connection should be closed | ||
206 | */ | 212 | */ |
207 | typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_TrafficReport) (void *cls, | 213 | typedef struct GNUNET_TIME_Relative |
208 | const struct GNUNET_PeerIdentity* peer, | 214 | (*GNUNET_TRANSPORT_TrafficReport) (void *cls, |
209 | size_t amount_recved); | 215 | const struct GNUNET_PeerIdentity *peer, |
216 | size_t amount_recved); | ||
210 | 217 | ||
211 | 218 | ||
212 | /** | 219 | /** |
213 | * Function that returns a HELLO message. | 220 | * Function that returns a HELLO message. |
214 | */ | 221 | */ |
215 | typedef const struct GNUNET_MessageHeader * | 222 | typedef const struct GNUNET_MessageHeader * |
216 | (*GNUNET_TRANSPORT_GetHelloCallback) (void); | 223 | (*GNUNET_TRANSPORT_GetHelloCallback) (void); |
217 | 224 | ||
218 | 225 | ||
219 | /** | 226 | /** |
@@ -253,7 +260,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
253 | */ | 260 | */ |
254 | GNUNET_TRANSPORT_PluginReceiveCallback receive; | 261 | GNUNET_TRANSPORT_PluginReceiveCallback receive; |
255 | 262 | ||
256 | |||
257 | /** | 263 | /** |
258 | * Function that returns our HELLO. | 264 | * Function that returns our HELLO. |
259 | */ | 265 | */ |
@@ -302,7 +308,7 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
302 | 308 | ||
303 | 309 | ||
304 | /** | 310 | /** |
305 | * Function called by the GNUNET_TRANSPORT_TransmitFunction | 311 | * Function called by the #GNUNET_TRANSPORT_TransmitFunction |
306 | * upon "completion". In the case that a peer disconnects, | 312 | * upon "completion". In the case that a peer disconnects, |
307 | * this function must be called for each pending request | 313 | * this function must be called for each pending request |
308 | * (with a 'failure' indication) AFTER notifying the service | 314 | * (with a 'failure' indication) AFTER notifying the service |
@@ -320,11 +326,13 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
320 | * @param size_on_wire bytes required on wire for transmission, | 326 | * @param size_on_wire bytes required on wire for transmission, |
321 | * 0 if result == #GNUNET_SYSERR | 327 | * 0 if result == #GNUNET_SYSERR |
322 | */ | 328 | */ |
323 | typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, | 329 | typedef void |
324 | const struct GNUNET_PeerIdentity *target, | 330 | (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, |
325 | int result, | 331 | const struct GNUNET_PeerIdentity *target, |
326 | size_t size_payload, | 332 | int result, |
327 | size_t size_on_wire); | 333 | size_t size_payload, |
334 | size_t size_on_wire); | ||
335 | |||
328 | 336 | ||
329 | /** | 337 | /** |
330 | * The new send function with just the session and no address | 338 | * The new send function with just the session and no address |
@@ -350,19 +358,37 @@ typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, | |||
350 | * been transmitted (or if the transport is ready | 358 | * been transmitted (or if the transport is ready |
351 | * for the next transmission call; or if the | 359 | * for the next transmission call; or if the |
352 | * peer disconnected...); can be NULL | 360 | * peer disconnected...); can be NULL |
353 | * @param cont_cls closure for cont | 361 | * @param cont_cls closure for @a cont |
354 | * @return number of bytes used (on the physical network, with overheads); | 362 | * @return number of bytes used (on the physical network, with overheads); |
355 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 363 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
356 | * and does NOT mean that the message was not transmitted (DV) | 364 | * and does NOT mean that the message was not transmitted (DV) |
357 | */ | 365 | */ |
358 | typedef ssize_t (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, | 366 | typedef ssize_t |
359 | struct Session *session, | 367 | (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, |
360 | const char *msgbuf, | 368 | struct Session *session, |
361 | size_t msgbuf_size, | 369 | const char *msgbuf, |
362 | unsigned int priority, | 370 | size_t msgbuf_size, |
363 | struct GNUNET_TIME_Relative to, | 371 | unsigned int priority, |
364 | GNUNET_TRANSPORT_TransmitContinuation cont, | 372 | struct GNUNET_TIME_Relative to, |
365 | void *cont_cls); | 373 | GNUNET_TRANSPORT_TransmitContinuation cont, |
374 | void *cont_cls); | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Function that can be called to force a disconnect from the | ||
379 | * specified neighbour for the given session only. . This should | ||
380 | * also cancel all previously scheduled transmissions for this | ||
381 | * session. Obviously the transmission may have been partially | ||
382 | * completed already, which is OK. The plugin is supposed to close | ||
383 | * the connection (if applicable). | ||
384 | * | ||
385 | * @param cls closure with the `struct Plugin` | ||
386 | * @param session session to destroy | ||
387 | * @return #GNUNET_OK on success | ||
388 | */ | ||
389 | typedef int | ||
390 | (*GNUNET_TRANSPORT_DisconnectSessionFunction) (void *cls, | ||
391 | struct Session *session); | ||
366 | 392 | ||
367 | 393 | ||
368 | /** | 394 | /** |
@@ -373,16 +399,13 @@ typedef ssize_t (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, | |||
373 | * to close the connection (if applicable) and no longer call the | 399 | * to close the connection (if applicable) and no longer call the |
374 | * transmit continuation(s). | 400 | * transmit continuation(s). |
375 | * | 401 | * |
376 | * Finally, plugin MUST NOT call the services's receive function to | ||
377 | * notify the service that the connection to the specified target was | ||
378 | * closed after a getting this call. | ||
379 | * | ||
380 | * @param cls closure | 402 | * @param cls closure |
381 | * @param target peer for which the last transmission is | 403 | * @param target peer for which the last transmission is |
382 | * to be cancelled | 404 | * to be cancelled |
383 | */ | 405 | */ |
384 | typedef void (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, | 406 | typedef void |
385 | const struct GNUNET_PeerIdentity *target); | 407 | (*GNUNET_TRANSPORT_DisconnectPeerFunction) (void *cls, |
408 | const struct GNUNET_PeerIdentity *target); | ||
386 | 409 | ||
387 | 410 | ||
388 | /** | 411 | /** |
@@ -393,8 +416,9 @@ typedef void (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, | |||
393 | * @param address one of the names for the host, NULL | 416 | * @param address one of the names for the host, NULL |
394 | * on the last call to the callback | 417 | * on the last call to the callback |
395 | */ | 418 | */ |
396 | typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, | 419 | typedef void |
397 | const char *address); | 420 | (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, |
421 | const char *address); | ||
398 | 422 | ||
399 | 423 | ||
400 | /** | 424 | /** |
@@ -405,20 +429,21 @@ typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls, | |||
405 | * @param type name of the transport that generated the address | 429 | * @param type name of the transport that generated the address |
406 | * @param addr one of the addresses of the host, NULL for the last address | 430 | * @param addr one of the addresses of the host, NULL for the last address |
407 | * the specific address format depends on the transport | 431 | * the specific address format depends on the transport |
408 | * @param addrlen length of the address | 432 | * @param addrlen length of the @a addr |
409 | * @param numeric should (IP) addresses be displayed in numeric form? | 433 | * @param numeric should (IP) addresses be displayed in numeric form? |
410 | * @param timeout after how long should we give up? | 434 | * @param timeout after how long should we give up? |
411 | * @param asc function to call on each string | 435 | * @param asc function to call on each string |
412 | * @param asc_cls closure for @a asc | 436 | * @param asc_cls closure for @a asc |
413 | */ | 437 | */ |
414 | typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, | 438 | typedef void |
415 | const char *type, | 439 | (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, |
416 | const void *addr, | 440 | const char *type, |
417 | size_t addrlen, | 441 | const void *addr, |
418 | int numeric, | 442 | size_t addrlen, |
419 | struct GNUNET_TIME_Relative timeout, | 443 | int numeric, |
420 | GNUNET_TRANSPORT_AddressStringCallback asc, | 444 | struct GNUNET_TIME_Relative timeout, |
421 | void *asc_cls); | 445 | GNUNET_TRANSPORT_AddressStringCallback asc, |
446 | void *asc_cls); | ||
422 | 447 | ||
423 | 448 | ||
424 | /** | 449 | /** |
@@ -435,9 +460,11 @@ typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, | |||
435 | * @return #GNUNET_OK if this is a plausible address for this peer | 460 | * @return #GNUNET_OK if this is a plausible address for this peer |
436 | * and transport, #GNUNET_SYSERR if not | 461 | * and transport, #GNUNET_SYSERR if not |
437 | */ | 462 | */ |
438 | typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls, | 463 | typedef int |
439 | const void *addr, | 464 | (*GNUNET_TRANSPORT_CheckAddress) (void *cls, |
440 | size_t addrlen); | 465 | const void *addr, |
466 | size_t addrlen); | ||
467 | |||
441 | 468 | ||
442 | /** | 469 | /** |
443 | * Create a new session to transmit data to the target | 470 | * Create a new session to transmit data to the target |
@@ -448,8 +475,9 @@ typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls, | |||
448 | * @param address the hello address | 475 | * @param address the hello address |
449 | * @return the session if the address is valid, NULL otherwise | 476 | * @return the session if the address is valid, NULL otherwise |
450 | */ | 477 | */ |
451 | typedef struct Session * (*GNUNET_TRANSPORT_CreateSession) (void *cls, | 478 | typedef struct Session * |
452 | const struct GNUNET_HELLO_Address *address); | 479 | (*GNUNET_TRANSPORT_CreateSession) (void *cls, |
480 | const struct GNUNET_HELLO_Address *address); | ||
453 | 481 | ||
454 | 482 | ||
455 | /** | 483 | /** |
@@ -460,30 +488,33 @@ typedef struct Session * (*GNUNET_TRANSPORT_CreateSession) (void *cls, | |||
460 | * | 488 | * |
461 | * @param cls closure | 489 | * @param cls closure |
462 | * @param addr binary address | 490 | * @param addr binary address |
463 | * @param addr_len length of the address | 491 | * @param addr_len length of the @a addr |
464 | * @return string representing the same address | 492 | * @return string representing the same address |
465 | */ | 493 | */ |
466 | typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls, | 494 | typedef const char * |
467 | const void *addr, | 495 | (*GNUNET_TRANSPORT_AddressToString) (void *cls, |
468 | size_t addrlen); | 496 | const void *addr, |
497 | size_t addrlen); | ||
498 | |||
469 | 499 | ||
470 | /** | 500 | /** |
471 | * Function called to convert a string address to | 501 | * Function called to convert a string address to |
472 | * a binary address. | 502 | * a binary address. |
473 | * | 503 | * |
474 | * @param cls closure ('struct Plugin*') | 504 | * @param cls closure (`struct Plugin*`) |
475 | * @param addr string address | 505 | * @param addr string address |
476 | * @param addrlen length of the address including '\0' termination | 506 | * @param addrlen length of the @a addr including \0 termination |
477 | * @param buf location to store the buffer | 507 | * @param buf location to store the buffer |
478 | * If the function returns #GNUNET_SYSERR, its contents are undefined. | 508 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
479 | * @param added length of created address | 509 | * @param added length of created address |
480 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 510 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
481 | */ | 511 | */ |
482 | typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls, | 512 | typedef int |
483 | const char *addr, | 513 | (*GNUNET_TRANSPORT_StringToAddress) (void *cls, |
484 | uint16_t addrlen, | 514 | const char *addr, |
485 | void **buf, | 515 | uint16_t addrlen, |
486 | size_t *added); | 516 | void **buf, |
517 | size_t *added); | ||
487 | 518 | ||
488 | 519 | ||
489 | /** | 520 | /** |
@@ -493,8 +524,9 @@ typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls, | |||
493 | * @param session the session | 524 | * @param session the session |
494 | * @return the network type | 525 | * @return the network type |
495 | */ | 526 | */ |
496 | typedef enum GNUNET_ATS_Network_Type (*GNUNET_TRANSPORT_GetNetworkType) (void *cls, | 527 | typedef enum GNUNET_ATS_Network_Type |
497 | struct Session *session); | 528 | (*GNUNET_TRANSPORT_GetNetworkType) (void *cls, |
529 | struct Session *session); | ||
498 | 530 | ||
499 | 531 | ||
500 | /** | 532 | /** |
@@ -523,7 +555,14 @@ struct GNUNET_TRANSPORT_PluginFunctions | |||
523 | * the given peer and cancel all previous transmissions (and their | 555 | * the given peer and cancel all previous transmissions (and their |
524 | * continuations). | 556 | * continuations). |
525 | */ | 557 | */ |
526 | GNUNET_TRANSPORT_DisconnectFunction disconnect; | 558 | GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer; |
559 | |||
560 | /** | ||
561 | * Function that can be used to force the plugin to disconnect from | ||
562 | * the given peer and cancel all previous transmissions (and their | ||
563 | * continuations). | ||
564 | */ | ||
565 | GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session; | ||
527 | 566 | ||
528 | /** | 567 | /** |
529 | * Function to pretty-print addresses. NOTE: this function is not | 568 | * Function to pretty-print addresses. NOTE: this function is not |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 7eb7660ce..c2b62419d 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -454,10 +454,10 @@ get_nick_record (const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone) | |||
454 | 454 | ||
455 | static void | 455 | static void |
456 | merge_with_nick_records ( const struct GNUNET_GNSRECORD_Data *nick_rd, | 456 | merge_with_nick_records ( const struct GNUNET_GNSRECORD_Data *nick_rd, |
457 | unsigned int rdc2, | 457 | unsigned int rdc2, |
458 | const struct GNUNET_GNSRECORD_Data *rd2, | 458 | const struct GNUNET_GNSRECORD_Data *rd2, |
459 | unsigned int *rdc_res, | 459 | unsigned int *rdc_res, |
460 | struct GNUNET_GNSRECORD_Data **rd_res) | 460 | struct GNUNET_GNSRECORD_Data **rd_res) |
461 | { | 461 | { |
462 | uint64_t latest_expiration; | 462 | uint64_t latest_expiration; |
463 | int c; | 463 | int c; |
@@ -675,7 +675,7 @@ refresh_block (struct GNUNET_SERVER_Client *client, | |||
675 | 675 | ||
676 | nick = get_nick_record (zone_key); | 676 | nick = get_nick_record (zone_key); |
677 | res_count = rd_count; | 677 | res_count = rd_count; |
678 | res = rd; | 678 | res = (struct GNUNET_GNSRECORD_Data *) rd; /* fixme: a bit unclean... */ |
679 | if (NULL != nick) | 679 | if (NULL != nick) |
680 | { | 680 | { |
681 | nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | 681 | nick->flags = (nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; |
@@ -754,8 +754,8 @@ lookup_it (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, | |||
754 | rdc_res = 0; | 754 | rdc_res = 0; |
755 | rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; | 755 | rlc->nick->flags = (rlc->nick->flags | GNUNET_GNSRECORD_RF_PRIVATE) ^ GNUNET_GNSRECORD_RF_PRIVATE; |
756 | merge_with_nick_records ( rlc->nick, | 756 | merge_with_nick_records ( rlc->nick, |
757 | rd_count, rd, | 757 | rd_count, rd, |
758 | &rdc_res, &rd_res); | 758 | &rdc_res, &rd_res); |
759 | 759 | ||
760 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res); | 760 | rlc->rd_ser_len = GNUNET_GNSRECORD_records_get_size (rdc_res, rd_res); |
761 | rlc->res_rd_count = rdc_res; | 761 | rlc->res_rd_count = rdc_res; |
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index a55e6a07d..a3b5639a0 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -817,6 +817,7 @@ set_address (struct NeighbourAddress *na, | |||
817 | int is_active) | 817 | int is_active) |
818 | { | 818 | { |
819 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | 819 | struct GNUNET_TRANSPORT_PluginFunctions *papi; |
820 | |||
820 | if (NULL == (papi = GST_plugins_find (address->transport_name))) | 821 | if (NULL == (papi = GST_plugins_find (address->transport_name))) |
821 | { | 822 | { |
822 | GNUNET_break (0); | 823 | GNUNET_break (0); |
@@ -918,13 +919,8 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) | |||
918 | free_address (&n->primary_address); | 919 | free_address (&n->primary_address); |
919 | free_address (&n->alternative_address); | 920 | free_address (&n->alternative_address); |
920 | 921 | ||
921 | /* FIXME-PLUGIN-API: This does not seem to guarantee that all | 922 | /* FIXME: Note that if we are switching between two TCP sessions to |
922 | transport sessions eventually get killed due to inactivity; they | 923 | the same peer, we might want to selectively kill only one of |
923 | MUST have their own timeout logic (but at least TCP doesn't have | ||
924 | one yet). Are we sure that EVERY 'session' of a plugin is | ||
925 | actually cleaned up this way!? Note that if we are switching | ||
926 | between two TCP sessions to the same peer, the existing plugin | ||
927 | API gives us not even the means to selectively kill only one of | ||
928 | them! Killing all sessions like this seems to be very, very | 924 | them! Killing all sessions like this seems to be very, very |
929 | wrong. */ | 925 | wrong. */ |
930 | 926 | ||
@@ -932,7 +928,7 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) | |||
932 | if ((GNUNET_NO == keep_sessions) && | 928 | if ((GNUNET_NO == keep_sessions) && |
933 | (NULL != backup_primary) && | 929 | (NULL != backup_primary) && |
934 | (NULL != (papi = GST_plugins_find (backup_primary->transport_name)))) | 930 | (NULL != (papi = GST_plugins_find (backup_primary->transport_name)))) |
935 | papi->disconnect (papi->cls, &n->id); | 931 | papi->disconnect_peer (papi->cls, &n->id); |
936 | 932 | ||
937 | GNUNET_free_non_null (backup_primary); | 933 | GNUNET_free_non_null (backup_primary); |
938 | 934 | ||
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index 83c062ec3..34f409255 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c | |||
@@ -219,12 +219,20 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | |||
219 | "send", | 219 | "send", |
220 | plug->lib_name); | 220 | plug->lib_name); |
221 | } | 221 | } |
222 | if (NULL == plug->api->disconnect) | 222 | if (NULL == plug->api->disconnect_peer) |
223 | { | 223 | { |
224 | fail = GNUNET_YES; | 224 | fail = GNUNET_YES; |
225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
226 | _("Missing function `%s' in transport plugin for `%s'\n"), | 226 | _("Missing function `%s' in transport plugin for `%s'\n"), |
227 | "disconnect", | 227 | "disconnect_peer", |
228 | plug->lib_name); | ||
229 | } | ||
230 | if (NULL == plug->api->disconnect_session) | ||
231 | { | ||
232 | fail = GNUNET_YES; | ||
233 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
234 | _("Missing function `%s' in transport plugin for `%s'\n"), | ||
235 | "disconnect_session", | ||
228 | plug->lib_name); | 236 | plug->lib_name); |
229 | } | 237 | } |
230 | if (GNUNET_YES == fail) | 238 | if (GNUNET_YES == fail) |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index c3a34a3fd..07a0de2ac 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -107,6 +107,7 @@ struct HTTP_Message | |||
107 | */ | 107 | */ |
108 | struct Session; | 108 | struct Session; |
109 | 109 | ||
110 | |||
110 | /** | 111 | /** |
111 | * A connection handle | 112 | * A connection handle |
112 | * | 113 | * |
@@ -125,7 +126,6 @@ struct ConnectionHandle | |||
125 | }; | 126 | }; |
126 | 127 | ||
127 | 128 | ||
128 | |||
129 | /** | 129 | /** |
130 | * Session handle for connections. | 130 | * Session handle for connections. |
131 | */ | 131 | */ |
@@ -623,12 +623,12 @@ client_delete_session (struct Session *s) | |||
623 | * Disconnect a session | 623 | * Disconnect a session |
624 | * | 624 | * |
625 | * @param s session | 625 | * @param s session |
626 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 626 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
627 | */ | 627 | */ |
628 | static int | 628 | static int |
629 | client_disconnect (struct Session *s) | 629 | http_client_session_disconnect (struct HTTP_Client_Plugin *plugin, |
630 | struct Session *s) | ||
630 | { | 631 | { |
631 | struct HTTP_Client_Plugin *plugin = s->plugin; | ||
632 | struct HTTP_Message *msg; | 632 | struct HTTP_Message *msg; |
633 | struct HTTP_Message *t; | 633 | struct HTTP_Message *t; |
634 | int res = GNUNET_OK; | 634 | int res = GNUNET_OK; |
@@ -730,7 +730,8 @@ client_disconnect (struct Session *s) | |||
730 | * @param target peer from which to disconnect | 730 | * @param target peer from which to disconnect |
731 | */ | 731 | */ |
732 | static void | 732 | static void |
733 | http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 733 | http_client_peer_disconnect (void *cls, |
734 | const struct GNUNET_PeerIdentity *target) | ||
734 | { | 735 | { |
735 | struct HTTP_Client_Plugin *plugin = cls; | 736 | struct HTTP_Client_Plugin *plugin = cls; |
736 | struct Session *next = NULL; | 737 | struct Session *next = NULL; |
@@ -749,12 +750,13 @@ http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
749 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 750 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
750 | "Disconnecting session %p to `%pos'\n", | 751 | "Disconnecting session %p to `%pos'\n", |
751 | pos, GNUNET_i2s (target)); | 752 | pos, GNUNET_i2s (target)); |
752 | GNUNET_assert (GNUNET_OK == client_disconnect (pos)); | 753 | GNUNET_assert (GNUNET_OK == http_client_session_disconnect (plugin, |
754 | pos)); | ||
753 | } | 755 | } |
754 | } | 756 | } |
755 | |||
756 | } | 757 | } |
757 | 758 | ||
759 | |||
758 | /** | 760 | /** |
759 | * Check if a sessions exists for an specific address | 761 | * Check if a sessions exists for an specific address |
760 | * | 762 | * |
@@ -1221,7 +1223,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1221 | /* Disconnect other transmission direction and tell transport */ | 1223 | /* Disconnect other transmission direction and tell transport */ |
1222 | s->get.easyhandle = NULL; | 1224 | s->get.easyhandle = NULL; |
1223 | s->get.s = NULL; | 1225 | s->get.s = NULL; |
1224 | client_disconnect (s); | 1226 | http_client_session_disconnect (plugin, s); |
1225 | } | 1227 | } |
1226 | } | 1228 | } |
1227 | } | 1229 | } |
@@ -1535,8 +1537,8 @@ http_client_plugin_get_session (void *cls, | |||
1535 | return NULL; | 1537 | return NULL; |
1536 | } | 1538 | } |
1537 | 1539 | ||
1538 | s = GNUNET_malloc (sizeof (struct Session)); | 1540 | s = GNUNET_new (struct Session); |
1539 | memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity)); | 1541 | s->target = address->peer; |
1540 | s->plugin = plugin; | 1542 | s->plugin = plugin; |
1541 | s->addr = GNUNET_malloc (address->address_length); | 1543 | s->addr = GNUNET_malloc (address->address_length); |
1542 | memcpy (s->addr, address->address, address->address_length); | 1544 | memcpy (s->addr, address->address, address->address_length); |
@@ -1574,7 +1576,7 @@ http_client_plugin_get_session (void *cls, | |||
1574 | * Setup http_client plugin | 1576 | * Setup http_client plugin |
1575 | * | 1577 | * |
1576 | * @param plugin the plugin handle | 1578 | * @param plugin the plugin handle |
1577 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 1579 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1578 | */ | 1580 | */ |
1579 | static int | 1581 | static int |
1580 | client_start (struct HTTP_Client_Plugin *plugin) | 1582 | client_start (struct HTTP_Client_Plugin *plugin) |
@@ -1598,7 +1600,6 @@ client_start (struct HTTP_Client_Plugin *plugin) | |||
1598 | static void | 1600 | static void |
1599 | client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1601 | client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1600 | { | 1602 | { |
1601 | GNUNET_assert (NULL != cls); | ||
1602 | struct Session *s = cls; | 1603 | struct Session *s = cls; |
1603 | 1604 | ||
1604 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1605 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -1609,7 +1610,8 @@ client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1609 | GNUNET_YES)); | 1610 | GNUNET_YES)); |
1610 | 1611 | ||
1611 | /* call session destroy function */ | 1612 | /* call session destroy function */ |
1612 | GNUNET_assert (GNUNET_OK == client_disconnect (s)); | 1613 | GNUNET_assert (GNUNET_OK == http_client_session_disconnect (s->plugin, |
1614 | s)); | ||
1613 | } | 1615 | } |
1614 | 1616 | ||
1615 | 1617 | ||
@@ -1729,13 +1731,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1729 | next = plugin->head; | 1731 | next = plugin->head; |
1730 | while (NULL != (pos = next)) | 1732 | while (NULL != (pos = next)) |
1731 | { | 1733 | { |
1732 | next = pos->next; | 1734 | next = pos->next; |
1733 | client_disconnect (pos); | 1735 | http_client_session_disconnect (plugin, pos); |
1734 | } | 1736 | } |
1735 | if (GNUNET_SCHEDULER_NO_TASK != plugin->client_perform_task) | 1737 | if (GNUNET_SCHEDULER_NO_TASK != plugin->client_perform_task) |
1736 | { | 1738 | { |
1737 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); | 1739 | GNUNET_SCHEDULER_cancel (plugin->client_perform_task); |
1738 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; | 1740 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
1739 | } | 1741 | } |
1740 | 1742 | ||
1741 | 1743 | ||
@@ -1760,7 +1762,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1760 | * Configure plugin | 1762 | * Configure plugin |
1761 | * | 1763 | * |
1762 | * @param plugin the plugin handle | 1764 | * @param plugin the plugin handle |
1763 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1765 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1764 | */ | 1766 | */ |
1765 | static int | 1767 | static int |
1766 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) | 1768 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) |
@@ -1780,13 +1782,16 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1780 | return GNUNET_OK; | 1782 | return GNUNET_OK; |
1781 | } | 1783 | } |
1782 | 1784 | ||
1783 | const char *http_plugin_address_to_string (void *cls, | 1785 | |
1784 | const void *addr, | 1786 | static const char * |
1785 | size_t addrlen) | 1787 | http_plugin_address_to_string (void *cls, |
1788 | const void *addr, | ||
1789 | size_t addrlen) | ||
1786 | { | 1790 | { |
1787 | return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen); | 1791 | return http_common_plugin_address_to_string (cls, PLUGIN_NAME, addr, addrlen); |
1788 | } | 1792 | } |
1789 | 1793 | ||
1794 | |||
1790 | /** | 1795 | /** |
1791 | * Entry point for the plugin. | 1796 | * Entry point for the plugin. |
1792 | */ | 1797 | */ |
@@ -1801,7 +1806,7 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1801 | { | 1806 | { |
1802 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 1807 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
1803 | initialze the plugin or the API */ | 1808 | initialze the plugin or the API */ |
1804 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1809 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1805 | api->cls = NULL; | 1810 | api->cls = NULL; |
1806 | api->address_to_string = &http_plugin_address_to_string; | 1811 | api->address_to_string = &http_plugin_address_to_string; |
1807 | api->string_to_address = &http_common_plugin_string_to_address; | 1812 | api->string_to_address = &http_common_plugin_string_to_address; |
@@ -1809,13 +1814,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1809 | return api; | 1814 | return api; |
1810 | } | 1815 | } |
1811 | 1816 | ||
1812 | plugin = GNUNET_malloc (sizeof (struct HTTP_Client_Plugin)); | 1817 | plugin = GNUNET_new (struct HTTP_Client_Plugin); |
1813 | p = plugin; | 1818 | p = plugin; |
1814 | plugin->env = env; | 1819 | plugin->env = env; |
1815 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1820 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1816 | api->cls = plugin; | 1821 | api->cls = plugin; |
1817 | api->send = &http_client_plugin_send; | 1822 | api->send = &http_client_plugin_send; |
1818 | api->disconnect = &http_client_plugin_disconnect; | 1823 | api->disconnect_session = &http_client_session_disconnect; |
1824 | api->disconnect_peer = &http_client_peer_disconnect; | ||
1819 | api->check_address = &http_client_plugin_address_suggested; | 1825 | api->check_address = &http_client_plugin_address_suggested; |
1820 | api->get_session = &http_client_plugin_get_session; | 1826 | api->get_session = &http_client_plugin_get_session; |
1821 | api->address_to_string = &http_plugin_address_to_string; | 1827 | api->address_to_string = &http_plugin_address_to_string; |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 6d706efba..72562607d 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -23,7 +23,6 @@ | |||
23 | * @brief HTTP/S server transport plugin | 23 | * @brief HTTP/S server transport plugin |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | */ | 25 | */ |
26 | |||
27 | #include "platform.h" | 26 | #include "platform.h" |
28 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_statistics_service.h" | 28 | #include "gnunet_statistics_service.h" |
@@ -49,7 +48,9 @@ | |||
49 | #define _SEND 1 | 48 | #define _SEND 1 |
50 | 49 | ||
51 | 50 | ||
52 | /* Enable output for debbuging URL's of incoming requests */ | 51 | /** |
52 | * Enable output for debbuging URL's of incoming requests | ||
53 | */ | ||
53 | #define DEBUG_URL_PARSE GNUNET_NO | 54 | #define DEBUG_URL_PARSE GNUNET_NO |
54 | 55 | ||
55 | 56 | ||
@@ -159,22 +160,34 @@ struct Session | |||
159 | 160 | ||
160 | struct ServerConnection | 161 | struct ServerConnection |
161 | { | 162 | { |
162 | /* _RECV or _SEND */ | 163 | /** |
164 | * _RECV or _SEND | ||
165 | */ | ||
163 | int direction; | 166 | int direction; |
164 | 167 | ||
165 | /* Should this connection get disconnected? GNUNET_YES/NO */ | 168 | /** |
169 | * Should this connection get disconnected? GNUNET_YES/NO | ||
170 | */ | ||
166 | int disconnect; | 171 | int disconnect; |
167 | 172 | ||
168 | /* For PUT connections: Is this the first or last callback with size 0 */ | 173 | /** |
174 | * For PUT connections: Is this the first or last callback with size 0 | ||
175 | */ | ||
169 | int connected; | 176 | int connected; |
170 | 177 | ||
171 | /* The session this server connection belongs to */ | 178 | /** |
179 | * The session this server connection belongs to | ||
180 | */ | ||
172 | struct Session *session; | 181 | struct Session *session; |
173 | 182 | ||
174 | /* The MHD connection */ | 183 | /** |
184 | * The MHD connection | ||
185 | */ | ||
175 | struct MHD_Connection *mhd_conn; | 186 | struct MHD_Connection *mhd_conn; |
176 | 187 | ||
177 | /* The MHD daemon */ | 188 | /** |
189 | * The MHD daemon | ||
190 | */ | ||
178 | struct MHD_Daemon *mhd_daemon; | 191 | struct MHD_Daemon *mhd_daemon; |
179 | }; | 192 | }; |
180 | 193 | ||
@@ -192,7 +205,6 @@ struct HTTP_Server_Plugin | |||
192 | /** | 205 | /** |
193 | * Linked list head of open sessions. | 206 | * Linked list head of open sessions. |
194 | */ | 207 | */ |
195 | |||
196 | struct Session *head; | 208 | struct Session *head; |
197 | 209 | ||
198 | /** | 210 | /** |
@@ -225,7 +237,6 @@ struct HTTP_Server_Plugin | |||
225 | */ | 237 | */ |
226 | int verify_external_hostname; | 238 | int verify_external_hostname; |
227 | 239 | ||
228 | |||
229 | /** | 240 | /** |
230 | * Maximum number of sockets the plugin can use | 241 | * Maximum number of sockets the plugin can use |
231 | * Each http inbound /outbound connections are two connections | 242 | * Each http inbound /outbound connections are two connections |
@@ -440,12 +451,6 @@ struct HTTP_Message | |||
440 | 451 | ||
441 | 452 | ||
442 | /** | 453 | /** |
443 | * The http_server plugin handle | ||
444 | */ | ||
445 | static struct HTTP_Server_Plugin * p; | ||
446 | |||
447 | |||
448 | /** | ||
449 | * Start session timeout for session s | 454 | * Start session timeout for session s |
450 | * @param s the session | 455 | * @param s the session |
451 | */ | 456 | */ |
@@ -470,11 +475,15 @@ server_stop_session_timeout (struct Session *s); | |||
470 | 475 | ||
471 | 476 | ||
472 | /** | 477 | /** |
473 | * Disconnect a session s | 478 | * Disconnect session @a s |
479 | * | ||
480 | * @param cls closure with the `struct HTTP_Server_Plugin` | ||
474 | * @param s the session | 481 | * @param s the session |
482 | * @return #GNUNET_OK on success | ||
475 | */ | 483 | */ |
476 | static int | 484 | static int |
477 | server_disconnect (struct Session *s); | 485 | http_server_plugin_disconnect_session (void *cls, |
486 | struct Session *s); | ||
478 | 487 | ||
479 | 488 | ||
480 | /** | 489 | /** |
@@ -482,7 +491,7 @@ server_disconnect (struct Session *s); | |||
482 | * | 491 | * |
483 | * @param plugin the plugin handle | 492 | * @param plugin the plugin handle |
484 | * @param s the session | 493 | * @param s the session |
485 | * @return GNUNET_YES on success, GNUNET_NO on error | 494 | * @return #GNUNET_YES on success, #GNUNET_NO on error |
486 | */ | 495 | */ |
487 | static int | 496 | static int |
488 | server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); | 497 | server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); |
@@ -492,12 +501,13 @@ server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s); | |||
492 | * Reschedule the execution of both IPv4 and IPv6 server | 501 | * Reschedule the execution of both IPv4 and IPv6 server |
493 | * @param plugin the plugin | 502 | * @param plugin the plugin |
494 | * @param server which server to schedule v4 or v6? | 503 | * @param server which server to schedule v4 or v6? |
495 | * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait | 504 | * @param now #GNUNET_YES to schedule execution immediately, #GNUNET_NO to wait |
496 | * until timeout | 505 | * until timeout |
497 | */ | 506 | */ |
498 | static void | 507 | static void |
499 | server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | 508 | server_reschedule (struct HTTP_Server_Plugin *plugin, |
500 | int now); | 509 | struct MHD_Daemon *server, |
510 | int now); | ||
501 | 511 | ||
502 | 512 | ||
503 | /** | 513 | /** |
@@ -511,7 +521,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | |||
511 | * @param cls closure | 521 | * @param cls closure |
512 | * @param session which session must be used | 522 | * @param session which session must be used |
513 | * @param msgbuf the message to transmit | 523 | * @param msgbuf the message to transmit |
514 | * @param msgbuf_size number of bytes in 'msgbuf' | 524 | * @param msgbuf_size number of bytes in @a msgbuf |
515 | * @param priority how important is the message (most plugins will | 525 | * @param priority how important is the message (most plugins will |
516 | * ignore message priority and just FIFO) | 526 | * ignore message priority and just FIFO) |
517 | * @param to how long to wait at most for the transmission (does not | 527 | * @param to how long to wait at most for the transmission (does not |
@@ -522,7 +532,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | |||
522 | * been transmitted (or if the transport is ready | 532 | * been transmitted (or if the transport is ready |
523 | * for the next transmission call; or if the | 533 | * for the next transmission call; or if the |
524 | * peer disconnected...); can be NULL | 534 | * peer disconnected...); can be NULL |
525 | * @param cont_cls closure for cont | 535 | * @param cont_cls closure for @a cont |
526 | * @return number of bytes used (on the physical network, with overheads); | 536 | * @return number of bytes used (on the physical network, with overheads); |
527 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 537 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
528 | * and does NOT mean that the message was not transmitted (DV) | 538 | * and does NOT mean that the message was not transmitted (DV) |
@@ -562,8 +572,8 @@ http_server_plugin_send (void *cls, | |||
562 | } | 572 | } |
563 | else | 573 | else |
564 | { | 574 | { |
565 | if (GNUNET_YES == session->server_send->disconnect) | 575 | if (GNUNET_YES == session->server_send->disconnect) |
566 | return GNUNET_SYSERR; | 576 | return GNUNET_SYSERR; |
567 | } | 577 | } |
568 | 578 | ||
569 | 579 | ||
@@ -592,16 +602,15 @@ http_server_plugin_send (void *cls, | |||
592 | 602 | ||
593 | if (NULL != session->server_send) | 603 | if (NULL != session->server_send) |
594 | { | 604 | { |
595 | server_reschedule (session->plugin, | 605 | server_reschedule (session->plugin, |
596 | session->server_send->mhd_daemon, | 606 | session->server_send->mhd_daemon, |
597 | GNUNET_YES); | 607 | GNUNET_YES); |
598 | server_reschedule_session_timeout (session); | 608 | server_reschedule_session_timeout (session); |
599 | } | 609 | } |
600 | return bytes_sent; | 610 | return bytes_sent; |
601 | } | 611 | } |
602 | 612 | ||
603 | 613 | ||
604 | |||
605 | /** | 614 | /** |
606 | * Function that can be used to force the plugin to disconnect | 615 | * Function that can be used to force the plugin to disconnect |
607 | * from the given peer and cancel all previous transmissions | 616 | * from the given peer and cancel all previous transmissions |
@@ -611,16 +620,16 @@ http_server_plugin_send (void *cls, | |||
611 | * @param target peer from which to disconnect | 620 | * @param target peer from which to disconnect |
612 | */ | 621 | */ |
613 | static void | 622 | static void |
614 | http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 623 | http_server_plugin_disconnect_peer (void *cls, |
624 | const struct GNUNET_PeerIdentity *target) | ||
615 | { | 625 | { |
616 | struct HTTP_Server_Plugin *plugin = cls; | 626 | struct HTTP_Server_Plugin *plugin = cls; |
617 | struct Session *next = NULL; | 627 | struct Session *next; |
618 | struct Session *pos = NULL; | 628 | struct Session *pos; |
619 | 629 | ||
620 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 630 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
621 | "Transport tells me to disconnect `%s'\n", | 631 | "Transport tells me to disconnect `%s'\n", |
622 | GNUNET_i2s (target)); | 632 | GNUNET_i2s (target)); |
623 | |||
624 | next = plugin->head; | 633 | next = plugin->head; |
625 | while (NULL != (pos = next)) | 634 | while (NULL != (pos = next)) |
626 | { | 635 | { |
@@ -630,10 +639,9 @@ http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
630 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 639 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
631 | "Disconnecting session %p to `%s'\n", | 640 | "Disconnecting session %p to `%s'\n", |
632 | pos, GNUNET_i2s (target)); | 641 | pos, GNUNET_i2s (target)); |
633 | server_disconnect (pos); | 642 | http_server_plugin_disconnect_session (plugin, pos); |
634 | } | 643 | } |
635 | } | 644 | } |
636 | |||
637 | } | 645 | } |
638 | 646 | ||
639 | 647 | ||
@@ -645,41 +653,42 @@ http_server_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
645 | * | 653 | * |
646 | * @param cls closure | 654 | * @param cls closure |
647 | * @param addr pointer to the address | 655 | * @param addr pointer to the address |
648 | * @param addrlen length of addr | 656 | * @param addrlen length of @a addr |
649 | * @return GNUNET_OK if this is a plausible address for this peer | 657 | * @return #GNUNET_OK if this is a plausible address for this peer |
650 | * and transport | 658 | * and transport |
651 | */ | 659 | */ |
652 | static int | 660 | static int |
653 | http_server_plugin_address_suggested (void *cls, const void *addr, | 661 | http_server_plugin_address_suggested (void *cls, |
654 | size_t addrlen) | 662 | const void *addr, |
663 | size_t addrlen) | ||
655 | { | 664 | { |
656 | struct HttpAddressWrapper *next; | 665 | struct HTTP_Server_Plugin *plugin = cls; |
657 | struct HttpAddressWrapper *pos; | 666 | struct HttpAddressWrapper *next; |
658 | const struct HttpAddress *haddr = addr; | 667 | struct HttpAddressWrapper *pos; |
659 | 668 | const struct HttpAddress *haddr = addr; | |
660 | if ((NULL != p->ext_addr) && | 669 | |
661 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, | 670 | if ((NULL != plugin->ext_addr) && |
662 | p->ext_addr, p->ext_addr_len))) | 671 | GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, |
663 | { | 672 | plugin->ext_addr, |
664 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ | 673 | plugin->ext_addr_len))) |
665 | if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != | 674 | { |
666 | (p->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | 675 | /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ |
667 | return GNUNET_NO; /* VERIFY option not set as required! */ | 676 | if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != |
668 | return GNUNET_OK; | 677 | (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
669 | } | 678 | return GNUNET_NO; /* VERIFY option not set as required! */ |
670 | 679 | return GNUNET_OK; | |
671 | next = p->addr_head; | 680 | } |
672 | while (NULL != (pos = next)) | 681 | next = plugin->addr_head; |
673 | { | 682 | while (NULL != (pos = next)) |
674 | next = pos->next; | 683 | { |
675 | if (GNUNET_YES == (http_common_cmp_addresses(addr, | 684 | next = pos->next; |
676 | addrlen, | 685 | if (GNUNET_YES == (http_common_cmp_addresses(addr, |
677 | pos->address, | 686 | addrlen, |
678 | pos->addrlen))) | 687 | pos->address, |
679 | return GNUNET_OK; | 688 | pos->addrlen))) |
680 | 689 | return GNUNET_OK; | |
681 | } | 690 | } |
682 | return GNUNET_NO; | 691 | return GNUNET_NO; |
683 | } | 692 | } |
684 | 693 | ||
685 | 694 | ||
@@ -705,33 +714,32 @@ http_server_plugin_get_session (void *cls, | |||
705 | * Deleting the session | 714 | * Deleting the session |
706 | * Must not be used afterwards | 715 | * Must not be used afterwards |
707 | * | 716 | * |
717 | * @param cls closure with the `struct HTTP_ServerPlugin` | ||
708 | * @param s the session to delete | 718 | * @param s the session to delete |
719 | * @return #GNUNET_OK on success | ||
709 | */ | 720 | */ |
710 | static void | 721 | static int |
711 | server_delete_session (struct Session *s) | 722 | server_delete_session (void *cls, |
723 | struct Session *s) | ||
712 | { | 724 | { |
713 | struct HTTP_Server_Plugin *plugin = s->plugin; | 725 | struct HTTP_Server_Plugin *plugin = cls; |
714 | server_stop_session_timeout(s); | 726 | struct HTTP_Message *msg; |
727 | struct HTTP_Message *tmp; | ||
715 | 728 | ||
729 | server_stop_session_timeout(s); | ||
716 | GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); | 730 | GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s); |
717 | struct HTTP_Message *msg = s->msg_head; | 731 | msg = s->msg_head; |
718 | struct HTTP_Message *tmp = NULL; | 732 | while (NULL != msg) |
719 | |||
720 | while (msg != NULL) | ||
721 | { | 733 | { |
722 | tmp = msg->next; | 734 | tmp = msg->next; |
723 | |||
724 | GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); | 735 | GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg); |
725 | if (msg->transmit_cont != NULL) | 736 | if (NULL != msg->transmit_cont) |
726 | { | ||
727 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, | 737 | msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR, |
728 | msg->size, msg->pos + msg->overhead); | 738 | msg->size, msg->pos + msg->overhead); |
729 | } | ||
730 | GNUNET_free (msg); | 739 | GNUNET_free (msg); |
731 | msg = tmp; | 740 | msg = tmp; |
732 | } | 741 | } |
733 | 742 | if (NULL != s->msg_tk) | |
734 | if (s->msg_tk != NULL) | ||
735 | { | 743 | { |
736 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 744 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
737 | s->msg_tk = NULL; | 745 | s->msg_tk = NULL; |
@@ -739,9 +747,11 @@ server_delete_session (struct Session *s) | |||
739 | GNUNET_free (s->addr); | 747 | GNUNET_free (s->addr); |
740 | GNUNET_free_non_null (s->server_recv); | 748 | GNUNET_free_non_null (s->server_recv); |
741 | GNUNET_free_non_null (s->server_send); | 749 | GNUNET_free_non_null (s->server_send); |
742 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 750 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
751 | plugin->name, | ||
743 | "Session %p destroyed\n", s); | 752 | "Session %p destroyed\n", s); |
744 | GNUNET_free (s); | 753 | GNUNET_free (s); |
754 | return GNUNET_OK; | ||
745 | } | 755 | } |
746 | 756 | ||
747 | 757 | ||
@@ -770,11 +780,11 @@ server_stop_session_timeout (struct Session *s) | |||
770 | * @param plugin plugin | 780 | * @param plugin plugin |
771 | * @param daemon_handle the MHD daemon handle | 781 | * @param daemon_handle the MHD daemon handle |
772 | * @param now schedule immediately | 782 | * @param now schedule immediately |
773 | * @return gnunet task identifier | 783 | * @return task identifier |
774 | */ | 784 | */ |
775 | static GNUNET_SCHEDULER_TaskIdentifier | 785 | static GNUNET_SCHEDULER_TaskIdentifier |
776 | server_schedule (struct HTTP_Server_Plugin *plugin, | 786 | server_schedule (struct HTTP_Server_Plugin *plugin, |
777 | struct MHD_Daemon *daemon_handle, | 787 | struct MHD_Daemon *daemon_handle, |
778 | int now); | 788 | int now); |
779 | 789 | ||
780 | 790 | ||
@@ -782,12 +792,13 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
782 | * Reschedule the execution of both IPv4 and IPv6 server | 792 | * Reschedule the execution of both IPv4 and IPv6 server |
783 | * @param plugin the plugin | 793 | * @param plugin the plugin |
784 | * @param server which server to schedule v4 or v6? | 794 | * @param server which server to schedule v4 or v6? |
785 | * @param now GNUNET_YES to schedule execution immediately, GNUNET_NO to wait | 795 | * @param now #GNUNET_YES to schedule execution immediately, #GNUNET_NO to wait |
786 | * until timeout | 796 | * until timeout |
787 | */ | 797 | */ |
788 | static void | 798 | static void |
789 | server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | 799 | server_reschedule (struct HTTP_Server_Plugin *plugin, |
790 | int now) | 800 | struct MHD_Daemon *server, |
801 | int now) | ||
791 | { | 802 | { |
792 | if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) | 803 | if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) |
793 | { | 804 | { |
@@ -824,21 +835,24 @@ server_reschedule (struct HTTP_Server_Plugin *plugin, struct MHD_Daemon *server, | |||
824 | 835 | ||
825 | 836 | ||
826 | /** | 837 | /** |
827 | * Disconnect session s | 838 | * Disconnect session @a s |
828 | * | 839 | * |
840 | * @param cls closure with the `struct HTTP_Server_Plugin` | ||
829 | * @param s the session | 841 | * @param s the session |
830 | * @return GNUNET_OK on success | 842 | * @return #GNUNET_OK on success |
831 | */ | 843 | */ |
832 | static int | 844 | static int |
833 | server_disconnect (struct Session *s) | 845 | http_server_plugin_disconnect_session (void *cls, |
846 | struct Session *s) | ||
834 | { | 847 | { |
835 | struct ServerConnection * send = NULL; | 848 | struct HTTP_Server_Plugin *plugin = cls; |
836 | struct ServerConnection * recv = NULL; | 849 | struct ServerConnection * send; |
850 | struct ServerConnection * recv; | ||
837 | 851 | ||
838 | if (GNUNET_NO == server_exist_session (p, s)) | 852 | if (GNUNET_NO == server_exist_session (plugin, s)) |
839 | { | 853 | { |
840 | GNUNET_break (0); | 854 | GNUNET_break (0); |
841 | return GNUNET_SYSERR; | 855 | return GNUNET_SYSERR; |
842 | } | 856 | } |
843 | 857 | ||
844 | send = (struct ServerConnection *) s->server_send; | 858 | send = (struct ServerConnection *) s->server_send; |
@@ -849,10 +863,9 @@ server_disconnect (struct Session *s) | |||
849 | s, s->server_send, GNUNET_i2s (&s->target)); | 863 | s, s->server_send, GNUNET_i2s (&s->target)); |
850 | 864 | ||
851 | send->disconnect = GNUNET_YES; | 865 | send->disconnect = GNUNET_YES; |
852 | #if MHD_VERSION >= 0x00090E00 | 866 | MHD_set_connection_option (send->mhd_conn, |
853 | MHD_set_connection_option (send->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, | 867 | MHD_CONNECTION_OPTION_TIMEOUT, |
854 | 1); | 868 | 1); |
855 | #endif | ||
856 | server_reschedule (s->plugin, send->mhd_daemon, GNUNET_YES); | 869 | server_reschedule (s->plugin, send->mhd_daemon, GNUNET_YES); |
857 | } | 870 | } |
858 | 871 | ||
@@ -864,17 +877,15 @@ server_disconnect (struct Session *s) | |||
864 | s, s->server_recv, GNUNET_i2s (&s->target)); | 877 | s, s->server_recv, GNUNET_i2s (&s->target)); |
865 | 878 | ||
866 | recv->disconnect = GNUNET_YES; | 879 | recv->disconnect = GNUNET_YES; |
867 | #if MHD_VERSION >= 0x00090E00 | 880 | MHD_set_connection_option (recv->mhd_conn, |
868 | MHD_set_connection_option (recv->mhd_conn, MHD_CONNECTION_OPTION_TIMEOUT, | 881 | MHD_CONNECTION_OPTION_TIMEOUT, |
869 | 1); | 882 | 1); |
870 | #endif | ||
871 | server_reschedule (s->plugin, recv->mhd_daemon, GNUNET_YES); | 883 | server_reschedule (s->plugin, recv->mhd_daemon, GNUNET_YES); |
872 | } | 884 | } |
873 | return GNUNET_OK; | 885 | return GNUNET_OK; |
874 | } | 886 | } |
875 | 887 | ||
876 | 888 | ||
877 | |||
878 | /** | 889 | /** |
879 | * Tell MHD that the connection should timeout after @a to seconds. | 890 | * Tell MHD that the connection should timeout after @a to seconds. |
880 | * | 891 | * |
@@ -887,7 +898,6 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
887 | struct Session *s, | 898 | struct Session *s, |
888 | unsigned int to) | 899 | unsigned int to) |
889 | { | 900 | { |
890 | #if MHD_VERSION >= 0x00090E00 | ||
891 | /* Setting timeouts for other connections */ | 901 | /* Setting timeouts for other connections */ |
892 | if (NULL != s->server_recv) | 902 | if (NULL != s->server_recv) |
893 | { | 903 | { |
@@ -909,9 +919,9 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
909 | to); | 919 | to); |
910 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); | 920 | server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); |
911 | } | 921 | } |
912 | #endif | ||
913 | } | 922 | } |
914 | 923 | ||
924 | |||
915 | /** | 925 | /** |
916 | * Parse incoming URL for tag and target | 926 | * Parse incoming URL for tag and target |
917 | * | 927 | * |
@@ -919,9 +929,8 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, | |||
919 | * @param url incoming url | 929 | * @param url incoming url |
920 | * @param target where to store the target | 930 | * @param target where to store the target |
921 | * @param tag where to store the tag | 931 | * @param tag where to store the tag |
922 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 932 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
923 | */ | 933 | */ |
924 | |||
925 | static int | 934 | static int |
926 | server_parse_url (struct HTTP_Server_Plugin *plugin, | 935 | server_parse_url (struct HTTP_Server_Plugin *plugin, |
927 | const char *url, | 936 | const char *url, |
@@ -1136,7 +1145,7 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1136 | return NULL; | 1145 | return NULL; |
1137 | } | 1146 | } |
1138 | 1147 | ||
1139 | s = GNUNET_malloc (sizeof (struct Session)); | 1148 | s = GNUNET_new (struct Session); |
1140 | memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); | 1149 | memcpy (&s->target, &target, sizeof (struct GNUNET_PeerIdentity)); |
1141 | s->plugin = plugin; | 1150 | s->plugin = plugin; |
1142 | s->addr = addr; | 1151 | s->addr = addr; |
@@ -1155,9 +1164,11 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin, | |||
1155 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1164 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1156 | "Creating new session %p for peer `%s' connecting from `%s'\n", | 1165 | "Creating new session %p for peer `%s' connecting from `%s'\n", |
1157 | s, GNUNET_i2s (&target), | 1166 | s, GNUNET_i2s (&target), |
1158 | http_common_plugin_address_to_string (NULL, p->protocol, addr, addr_len)); | 1167 | http_common_plugin_address_to_string (NULL, |
1168 | plugin->protocol, | ||
1169 | addr, addr_len)); | ||
1159 | } | 1170 | } |
1160 | sc = GNUNET_malloc (sizeof (struct ServerConnection)); | 1171 | sc = GNUNET_new (struct ServerConnection); |
1161 | if (conn_info->client_addr->sa_family == AF_INET) | 1172 | if (conn_info->client_addr->sa_family == AF_INET) |
1162 | sc->mhd_daemon = plugin->server_v4; | 1173 | sc->mhd_daemon = plugin->server_v4; |
1163 | if (conn_info->client_addr->sa_family == AF_INET6) | 1174 | if (conn_info->client_addr->sa_family == AF_INET6) |
@@ -1218,19 +1229,16 @@ server_lookup_session (struct HTTP_Server_Plugin *plugin, | |||
1218 | return NULL; | 1229 | return NULL; |
1219 | } | 1230 | } |
1220 | 1231 | ||
1221 | int | 1232 | |
1222 | server_exist_session (struct HTTP_Server_Plugin *plugin, struct Session *s) | 1233 | static int |
1234 | server_exist_session (struct HTTP_Server_Plugin *plugin, | ||
1235 | struct Session *s) | ||
1223 | { | 1236 | { |
1224 | struct Session * head; | 1237 | struct Session * head; |
1225 | 1238 | ||
1226 | GNUNET_assert (NULL != plugin); | ||
1227 | GNUNET_assert (NULL != s); | ||
1228 | |||
1229 | for (head = plugin->head; head != NULL; head = head->next) | 1239 | for (head = plugin->head; head != NULL; head = head->next) |
1230 | { | ||
1231 | if (head == s) | 1240 | if (head == s) |
1232 | return GNUNET_YES; | 1241 | return GNUNET_YES; |
1233 | } | ||
1234 | return GNUNET_NO; | 1242 | return GNUNET_NO; |
1235 | } | 1243 | } |
1236 | 1244 | ||
@@ -1252,8 +1260,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1252 | struct HTTP_Message *msg; | 1260 | struct HTTP_Message *msg; |
1253 | char *stat_txt; | 1261 | char *stat_txt; |
1254 | 1262 | ||
1255 | GNUNET_assert (NULL != p); | 1263 | if (GNUNET_NO == server_exist_session (s->plugin, s)) |
1256 | if (GNUNET_NO == server_exist_session (p, s)) | ||
1257 | return 0; | 1264 | return 0; |
1258 | msg = s->msg_head; | 1265 | msg = s->msg_head; |
1259 | if (NULL != msg) | 1266 | if (NULL != msg) |
@@ -1278,12 +1285,14 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1278 | { | 1285 | { |
1279 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 1286 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
1280 | "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); | 1287 | "Sent %u bytes to peer `%s' with session %p \n", bytes_read, GNUNET_i2s (&s->target), s); |
1281 | GNUNET_asprintf (&stat_txt, "# bytes currently in %s_server buffers", p->protocol); | 1288 | GNUNET_asprintf (&stat_txt, "# bytes currently in %s_server buffers", |
1282 | GNUNET_STATISTICS_update (p->env->stats, | 1289 | s->plugin->protocol); |
1290 | GNUNET_STATISTICS_update (s->plugin->env->stats, | ||
1283 | stat_txt, -bytes_read, GNUNET_NO); | 1291 | stat_txt, -bytes_read, GNUNET_NO); |
1284 | GNUNET_free (stat_txt); | 1292 | GNUNET_free (stat_txt); |
1285 | GNUNET_asprintf (&stat_txt, "# bytes transmitted via %s_server", p->protocol); | 1293 | GNUNET_asprintf (&stat_txt, "# bytes transmitted via %s_server", |
1286 | GNUNET_STATISTICS_update (p->env->stats, | 1294 | s->plugin->protocol); |
1295 | GNUNET_STATISTICS_update (s->plugin->env->stats, | ||
1287 | stat_txt, bytes_read, GNUNET_NO); | 1296 | stat_txt, bytes_read, GNUNET_NO); |
1288 | GNUNET_free (stat_txt); | 1297 | GNUNET_free (stat_txt); |
1289 | } | 1298 | } |
@@ -1297,7 +1306,7 @@ server_send_callback (void *cls, uint64_t pos, char *buf, size_t max) | |||
1297 | * @param cls current session as closure | 1306 | * @param cls current session as closure |
1298 | * @param client client | 1307 | * @param client client |
1299 | * @param message the message to be forwarded to transport service | 1308 | * @param message the message to be forwarded to transport service |
1300 | * @return GNUNET_OK | 1309 | * @return #GNUNET_OK |
1301 | */ | 1310 | */ |
1302 | static int | 1311 | static int |
1303 | server_receive_mst_cb (void *cls, void *client, | 1312 | server_receive_mst_cb (void *cls, void *client, |
@@ -1309,8 +1318,7 @@ server_receive_mst_cb (void *cls, void *client, | |||
1309 | struct GNUNET_TIME_Relative delay; | 1318 | struct GNUNET_TIME_Relative delay; |
1310 | char *stat_txt; | 1319 | char *stat_txt; |
1311 | 1320 | ||
1312 | GNUNET_assert (NULL != p); | 1321 | if (GNUNET_NO == server_exist_session (s->plugin, s)) |
1313 | if (GNUNET_NO == server_exist_session(p, s)) | ||
1314 | return GNUNET_OK; | 1322 | return GNUNET_OK; |
1315 | 1323 | ||
1316 | 1324 | ||
@@ -1340,7 +1348,9 @@ server_receive_mst_cb (void *cls, void *client, | |||
1340 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1348 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1341 | "Peer `%s' address `%s' next read delayed for %s\n", | 1349 | "Peer `%s' address `%s' next read delayed for %s\n", |
1342 | GNUNET_i2s (&s->target), | 1350 | GNUNET_i2s (&s->target), |
1343 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen), | 1351 | http_common_plugin_address_to_string (NULL, |
1352 | plugin->protocol, | ||
1353 | s->addr, s->addrlen), | ||
1344 | GNUNET_STRINGS_relative_time_to_string (delay, | 1354 | GNUNET_STRINGS_relative_time_to_string (delay, |
1345 | GNUNET_YES)); | 1355 | GNUNET_YES)); |
1346 | } | 1356 | } |
@@ -1448,7 +1458,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1448 | s, sc, | 1458 | s, sc, |
1449 | GNUNET_i2s (&s->target), | 1459 | GNUNET_i2s (&s->target), |
1450 | http_common_plugin_address_to_string (NULL, | 1460 | http_common_plugin_address_to_string (NULL, |
1451 | p->protocol, | 1461 | plugin->protocol, |
1452 | s->addr, | 1462 | s->addr, |
1453 | s->addrlen)); | 1463 | s->addrlen)); |
1454 | sc->connected = GNUNET_YES; | 1464 | sc->connected = GNUNET_YES; |
@@ -1462,7 +1472,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1462 | s, sc, | 1472 | s, sc, |
1463 | GNUNET_i2s (&s->target), | 1473 | GNUNET_i2s (&s->target), |
1464 | http_common_plugin_address_to_string (NULL, | 1474 | http_common_plugin_address_to_string (NULL, |
1465 | p->protocol, | 1475 | plugin->protocol, |
1466 | s->addr, | 1476 | s->addr, |
1467 | s->addrlen)); | 1477 | s->addrlen)); |
1468 | sc->connected = GNUNET_NO; | 1478 | sc->connected = GNUNET_NO; |
@@ -1482,7 +1492,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1482 | s, sc, | 1492 | s, sc, |
1483 | GNUNET_i2s (&s->target), | 1493 | GNUNET_i2s (&s->target), |
1484 | http_common_plugin_address_to_string (NULL, | 1494 | http_common_plugin_address_to_string (NULL, |
1485 | p->protocol, | 1495 | plugin->protocol, |
1486 | s->addr, | 1496 | s->addr, |
1487 | s->addrlen), | 1497 | s->addrlen), |
1488 | *upload_data_size); | 1498 | *upload_data_size); |
@@ -1526,7 +1536,7 @@ server_access_cb (void *cls, struct MHD_Connection *mhd_connection, | |||
1526 | /** | 1536 | /** |
1527 | * Callback from MHD when a connection disconnects | 1537 | * Callback from MHD when a connection disconnects |
1528 | * | 1538 | * |
1529 | * @param cls closure | 1539 | * @param cls closure with the `struct HTTP_Server_Plugin *` |
1530 | * @param connection the disconnected MHD connection | 1540 | * @param connection the disconnected MHD connection |
1531 | * @param httpSessionCache the pointer to distinguish | 1541 | * @param httpSessionCache the pointer to distinguish |
1532 | */ | 1542 | */ |
@@ -1534,37 +1544,34 @@ static void | |||
1534 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, | 1544 | server_disconnect_cb (void *cls, struct MHD_Connection *connection, |
1535 | void **httpSessionCache) | 1545 | void **httpSessionCache) |
1536 | { | 1546 | { |
1547 | struct HTTP_Server_Plugin *plugin = cls; | ||
1537 | struct ServerConnection *sc = *httpSessionCache; | 1548 | struct ServerConnection *sc = *httpSessionCache; |
1538 | struct Session *s = NULL; | 1549 | struct Session *s = NULL; |
1539 | struct Session *t = NULL; | 1550 | struct Session *t = NULL; |
1540 | struct HTTP_Server_Plugin *plugin = NULL; | ||
1541 | 1551 | ||
1542 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, p->name, | 1552 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1553 | plugin->name, | ||
1543 | "Disconnect for connection %p \n", sc); | 1554 | "Disconnect for connection %p \n", sc); |
1544 | 1555 | ||
1545 | if (sc == NULL) | 1556 | if (sc == NULL) |
1546 | return; | 1557 | return; |
1547 | 1558 | ||
1548 | if (NULL == (s = server_lookup_session (p, sc))) | 1559 | if (NULL == (s = server_lookup_session (plugin, sc))) |
1549 | return; | 1560 | return; |
1550 | 1561 | for (t = plugin->head; t != NULL; t = t->next) | |
1551 | GNUNET_assert (NULL != p); | ||
1552 | for (t = p->head; t != NULL; t = t->next) | ||
1553 | { | ||
1554 | if (t == s) | 1562 | if (t == s) |
1555 | break; | 1563 | break; |
1556 | } | ||
1557 | if (NULL == t) | 1564 | if (NULL == t) |
1558 | return; | 1565 | return; |
1559 | 1566 | ||
1560 | plugin = s->plugin; | ||
1561 | if (sc->direction == _SEND) | 1567 | if (sc->direction == _SEND) |
1562 | { | 1568 | { |
1563 | |||
1564 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1569 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1565 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", | 1570 | "Peer `%s' connection %p, GET on address `%s' disconnected\n", |
1566 | GNUNET_i2s (&s->target), s->server_send, | 1571 | GNUNET_i2s (&s->target), s->server_send, |
1567 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); | 1572 | http_common_plugin_address_to_string (NULL, |
1573 | plugin->protocol, | ||
1574 | s->addr, s->addrlen)); | ||
1568 | s->server_send = NULL; | 1575 | s->server_send = NULL; |
1569 | if (NULL != (s->server_recv)) | 1576 | if (NULL != (s->server_recv)) |
1570 | { | 1577 | { |
@@ -1582,7 +1589,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1582 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1589 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1583 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", | 1590 | "Peer `%s' connection %p PUT on address `%s' disconnected\n", |
1584 | GNUNET_i2s (&s->target), s->server_recv, | 1591 | GNUNET_i2s (&s->target), s->server_recv, |
1585 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); | 1592 | http_common_plugin_address_to_string (NULL, |
1593 | plugin->protocol, | ||
1594 | s->addr, s->addrlen)); | ||
1586 | s->server_recv = NULL; | 1595 | s->server_recv = NULL; |
1587 | /* Do not terminate session when PUT disconnects | 1596 | /* Do not terminate session when PUT disconnects |
1588 | if (NULL != (s->server_send)) | 1597 | if (NULL != (s->server_send)) |
@@ -1610,7 +1619,9 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1610 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1619 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1611 | "Peer `%s' on address `%s' disconnected\n", | 1620 | "Peer `%s' on address `%s' disconnected\n", |
1612 | GNUNET_i2s (&s->target), | 1621 | GNUNET_i2s (&s->target), |
1613 | http_common_plugin_address_to_string (NULL, p->protocol, s->addr, s->addrlen)); | 1622 | http_common_plugin_address_to_string (NULL, |
1623 | plugin->protocol, | ||
1624 | s->addr, s->addrlen)); | ||
1614 | 1625 | ||
1615 | if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) | 1626 | if ((GNUNET_YES == s->session_passed) && (GNUNET_NO == s->session_ended)) |
1616 | { | 1627 | { |
@@ -1618,20 +1629,18 @@ server_disconnect_cb (void *cls, struct MHD_Connection *connection, | |||
1618 | s->session_ended = GNUNET_YES; | 1629 | s->session_ended = GNUNET_YES; |
1619 | plugin->env->session_end (plugin->env->cls, &s->target, s); | 1630 | plugin->env->session_end (plugin->env->cls, &s->target, s); |
1620 | } | 1631 | } |
1621 | server_delete_session (s); | 1632 | server_delete_session (plugin, s); |
1622 | } | 1633 | } |
1623 | |||
1624 | } | 1634 | } |
1625 | 1635 | ||
1626 | 1636 | ||
1627 | /** | 1637 | /** |
1628 | * Check if incoming connection is accepted. | 1638 | * Check if incoming connection is accepted. |
1629 | 1639 | * | |
1630 | * @param cls plugin as closure | 1640 | * @param cls plugin as closure |
1631 | * @param addr address of incoming connection | 1641 | * @param addr address of incoming connection |
1632 | * @param addr_len address length of incoming connection | 1642 | * @param addr_len address length of incoming connection |
1633 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected | 1643 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected |
1634 | * | ||
1635 | */ | 1644 | */ |
1636 | static int | 1645 | static int |
1637 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | 1646 | server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) |
@@ -1655,6 +1664,7 @@ server_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len) | |||
1655 | } | 1664 | } |
1656 | } | 1665 | } |
1657 | 1666 | ||
1667 | |||
1658 | static void | 1668 | static void |
1659 | server_log (void *arg, const char *fmt, va_list ap) | 1669 | server_log (void *arg, const char *fmt, va_list ap) |
1660 | { | 1670 | { |
@@ -1717,8 +1727,6 @@ server_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1717 | } | 1727 | } |
1718 | 1728 | ||
1719 | 1729 | ||
1720 | #define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG | ||
1721 | |||
1722 | /** | 1730 | /** |
1723 | * Function that queries MHD's select sets and | 1731 | * Function that queries MHD's select sets and |
1724 | * starts the task waiting for them. | 1732 | * starts the task waiting for them. |
@@ -1740,7 +1748,7 @@ server_schedule (struct HTTP_Server_Plugin *plugin, | |||
1740 | struct GNUNET_NETWORK_FDSet *wws; | 1748 | struct GNUNET_NETWORK_FDSet *wws; |
1741 | struct GNUNET_NETWORK_FDSet *wes; | 1749 | struct GNUNET_NETWORK_FDSet *wes; |
1742 | int max; | 1750 | int max; |
1743 | UNSIGNED_MHD_LONG_LONG timeout; | 1751 | MHD_UNSIGNED_LONG_LONG timeout; |
1744 | static unsigned long long last_timeout = 0; | 1752 | static unsigned long long last_timeout = 0; |
1745 | int haveto; | 1753 | int haveto; |
1746 | 1754 | ||
@@ -2158,8 +2166,6 @@ server_stop (struct HTTP_Server_Plugin *plugin) | |||
2158 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); | 2166 | GNUNET_SCHEDULER_cancel (plugin->server_v6_task); |
2159 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; | 2167 | plugin->server_v6_task = GNUNET_SCHEDULER_NO_TASK; |
2160 | } | 2168 | } |
2161 | p = NULL; | ||
2162 | |||
2163 | #if BUILD_HTTPS | 2169 | #if BUILD_HTTPS |
2164 | GNUNET_free_non_null (plugin->crypto_init); | 2170 | GNUNET_free_non_null (plugin->crypto_init); |
2165 | GNUNET_free_non_null (plugin->cert); | 2171 | GNUNET_free_non_null (plugin->cert); |
@@ -2198,7 +2204,9 @@ server_add_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2198 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); | 2204 | GNUNET_CONTAINER_DLL_insert(plugin->addr_head, plugin->addr_tail, w); |
2199 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2205 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2200 | "Notifying transport to add address `%s'\n", | 2206 | "Notifying transport to add address `%s'\n", |
2201 | http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen)); | 2207 | http_common_plugin_address_to_string (NULL, |
2208 | plugin->protocol, | ||
2209 | w->address, w->addrlen)); | ||
2202 | #if BUILD_HTTPS | 2210 | #if BUILD_HTTPS |
2203 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); | 2211 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); |
2204 | #else | 2212 | #else |
@@ -2240,7 +2248,9 @@ server_remove_address (void *cls, int add_remove, const struct sockaddr *addr, | |||
2240 | 2248 | ||
2241 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2249 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2242 | "Notifying transport to remove address `%s'\n", | 2250 | "Notifying transport to remove address `%s'\n", |
2243 | http_common_plugin_address_to_string (NULL, p->protocol, w->address, w->addrlen)); | 2251 | http_common_plugin_address_to_string (NULL, |
2252 | plugin->protocol, | ||
2253 | w->address, w->addrlen)); | ||
2244 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); | 2254 | GNUNET_CONTAINER_DLL_remove (plugin->addr_head, plugin->addr_tail, w); |
2245 | #if BUILD_HTTPS | 2255 | #if BUILD_HTTPS |
2246 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); | 2256 | plugin->env->notify_address (plugin->env->cls, add_remove, w->address, w->addrlen, "https_client"); |
@@ -2880,7 +2890,6 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin) | |||
2880 | static void | 2890 | static void |
2881 | server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2891 | server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2882 | { | 2892 | { |
2883 | GNUNET_assert (NULL != cls); | ||
2884 | struct Session *s = cls; | 2893 | struct Session *s = cls; |
2885 | 2894 | ||
2886 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 2895 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -2891,7 +2900,8 @@ server_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
2891 | GNUNET_YES)); | 2900 | GNUNET_YES)); |
2892 | 2901 | ||
2893 | /* call session destroy function */ | 2902 | /* call session destroy function */ |
2894 | GNUNET_assert (GNUNET_OK == server_disconnect (s)); | 2903 | GNUNET_assert (GNUNET_OK == |
2904 | http_server_plugin_disconnect_session (s->plugin, s)); | ||
2895 | } | 2905 | } |
2896 | 2906 | ||
2897 | 2907 | ||
@@ -2966,24 +2976,24 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
2966 | 2976 | ||
2967 | if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task) | 2977 | if (GNUNET_SCHEDULER_NO_TASK != plugin->notify_ext_task) |
2968 | { | 2978 | { |
2969 | GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); | 2979 | GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); |
2970 | plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; | 2980 | plugin->notify_ext_task = GNUNET_SCHEDULER_NO_TASK; |
2971 | } | 2981 | } |
2972 | 2982 | ||
2973 | if (NULL != plugin->ext_addr) | 2983 | if (NULL != plugin->ext_addr) |
2974 | { | 2984 | { |
2975 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 2985 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
2976 | "Notifying transport to remove address `%s'\n", | 2986 | "Notifying transport to remove address `%s'\n", |
2977 | http_common_plugin_address_to_string (NULL, | 2987 | http_common_plugin_address_to_string (NULL, |
2978 | p->protocol, | 2988 | plugin->protocol, |
2979 | plugin->ext_addr, | 2989 | plugin->ext_addr, |
2980 | plugin->ext_addr_len)); | 2990 | plugin->ext_addr_len)); |
2981 | #if BUILD_HTTPS | 2991 | #if BUILD_HTTPS |
2982 | plugin->env->notify_address (plugin->env->cls, | 2992 | plugin->env->notify_address (plugin->env->cls, |
2983 | GNUNET_NO, | 2993 | GNUNET_NO, |
2984 | plugin->ext_addr, | 2994 | plugin->ext_addr, |
2985 | plugin->ext_addr_len, | 2995 | plugin->ext_addr_len, |
2986 | "https_client"); | 2996 | "https_client"); |
2987 | #else | 2997 | #else |
2988 | plugin->env->notify_address (plugin->env->cls, | 2998 | plugin->env->notify_address (plugin->env->cls, |
2989 | GNUNET_NO, | 2999 | GNUNET_NO, |
@@ -2991,7 +3001,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
2991 | plugin->ext_addr_len, | 3001 | plugin->ext_addr_len, |
2992 | "http_client"); | 3002 | "http_client"); |
2993 | #endif | 3003 | #endif |
2994 | |||
2995 | } | 3004 | } |
2996 | 3005 | ||
2997 | /* Stop to report addresses to transport service */ | 3006 | /* Stop to report addresses to transport service */ |
@@ -3000,18 +3009,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
3000 | next = plugin->head; | 3009 | next = plugin->head; |
3001 | while (NULL != (pos = next)) | 3010 | while (NULL != (pos = next)) |
3002 | { | 3011 | { |
3003 | next = pos->next; | 3012 | next = pos->next; |
3004 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 3013 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
3005 | "Removing left over session %p\n", pos); | 3014 | "Removing left over session %p\n", pos); |
3006 | |||
3007 | if ((GNUNET_YES == pos->session_passed) && (GNUNET_NO == pos->session_ended)) | ||
3008 | { | ||
3009 | /* Notify transport immediately that this session is invalid */ | ||
3010 | pos->session_ended = GNUNET_YES; | ||
3011 | plugin->env->session_end (plugin->env->cls, &pos->target, pos); | ||
3012 | } | ||
3013 | 3015 | ||
3014 | server_delete_session (pos); | 3016 | if ((GNUNET_YES == pos->session_passed) && (GNUNET_NO == pos->session_ended)) |
3017 | { | ||
3018 | /* Notify transport immediately that this session is invalid */ | ||
3019 | pos->session_ended = GNUNET_YES; | ||
3020 | plugin->env->session_end (plugin->env->cls, &pos->target, pos); | ||
3021 | } | ||
3022 | server_delete_session (plugin, pos); | ||
3015 | } | 3023 | } |
3016 | 3024 | ||
3017 | /* Clean up */ | 3025 | /* Clean up */ |
@@ -3071,15 +3079,14 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3071 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 3079 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
3072 | struct HTTP_Server_Plugin *plugin; | 3080 | struct HTTP_Server_Plugin *plugin; |
3073 | 3081 | ||
3074 | plugin = GNUNET_malloc (sizeof (struct HTTP_Server_Plugin)); | 3082 | plugin = GNUNET_new (struct HTTP_Server_Plugin); |
3075 | plugin->env = env; | 3083 | plugin->env = env; |
3076 | p = plugin; | ||
3077 | 3084 | ||
3078 | if (NULL == env->receive) | 3085 | if (NULL == env->receive) |
3079 | { | 3086 | { |
3080 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 3087 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
3081 | initialze the plugin or the API */ | 3088 | initialze the plugin or the API */ |
3082 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3089 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3083 | api->cls = NULL; | 3090 | api->cls = NULL; |
3084 | api->address_to_string = &http_plugin_address_to_string; | 3091 | api->address_to_string = &http_plugin_address_to_string; |
3085 | api->string_to_address = &http_common_plugin_string_to_address; | 3092 | api->string_to_address = &http_common_plugin_string_to_address; |
@@ -3087,10 +3094,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
3087 | return api; | 3094 | return api; |
3088 | } | 3095 | } |
3089 | 3096 | ||
3090 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3097 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3091 | api->cls = plugin; | 3098 | api->cls = plugin; |
3092 | api->send = &http_server_plugin_send; | 3099 | api->send = &http_server_plugin_send; |
3093 | api->disconnect = &http_server_plugin_disconnect; | 3100 | api->disconnect_peer = &http_server_plugin_disconnect_peer; |
3101 | api->disconnect_session = &http_server_plugin_disconnect_session; | ||
3094 | api->check_address = &http_server_plugin_address_suggested; | 3102 | api->check_address = &http_server_plugin_address_suggested; |
3095 | api->get_session = &http_server_plugin_get_session; | 3103 | api->get_session = &http_server_plugin_get_session; |
3096 | 3104 | ||
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c index 740d25d00..c886fd132 100644 --- a/src/transport/plugin_transport_smtp.c +++ b/src/transport/plugin_transport_smtp.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other contributing authors) | 3 | (C) 2003-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 273d39873..bd624c1d5 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -298,12 +298,11 @@ struct Session | |||
298 | * call or on our 'accept' call). | 298 | * call or on our 'accept' call). |
299 | * | 299 | * |
300 | * struct IPv4TcpAddress or struct IPv6TcpAddress | 300 | * struct IPv4TcpAddress or struct IPv6TcpAddress |
301 | * | ||
302 | */ | 301 | */ |
303 | void *addr; | 302 | void *addr; |
304 | 303 | ||
305 | /** | 304 | /** |
306 | * Length of connect_addr. | 305 | * Length of @e addr. |
307 | */ | 306 | */ |
308 | size_t addrlen; | 307 | size_t addrlen; |
309 | 308 | ||
@@ -1019,12 +1018,14 @@ process_pending_messages (struct Session *session) | |||
1019 | * establish a connection. | 1018 | * establish a connection. |
1020 | * | 1019 | * |
1021 | * @param session session to close down | 1020 | * @param session session to close down |
1021 | * @return #GNUNET_OK on success | ||
1022 | */ | 1022 | */ |
1023 | static void | 1023 | static int |
1024 | disconnect_session (struct Session *session) | 1024 | tcp_disconnect_session (void *cls, |
1025 | struct Session *session) | ||
1025 | { | 1026 | { |
1027 | struct Plugin *plugin = cls; | ||
1026 | struct PendingMessage *pm; | 1028 | struct PendingMessage *pm; |
1027 | struct Plugin * plugin = session->plugin; | ||
1028 | 1029 | ||
1029 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1030 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1030 | "Disconnecting session of peer `%s' address `%s'\n", | 1031 | "Disconnecting session of peer `%s' address `%s'\n", |
@@ -1101,6 +1102,7 @@ disconnect_session (struct Session *session) | |||
1101 | GNUNET_free_non_null (session->addr); | 1102 | GNUNET_free_non_null (session->addr); |
1102 | GNUNET_assert (NULL == session->transmit_handle); | 1103 | GNUNET_assert (NULL == session->transmit_handle); |
1103 | GNUNET_free (session); | 1104 | GNUNET_free (session); |
1105 | return GNUNET_OK; | ||
1104 | } | 1106 | } |
1105 | 1107 | ||
1106 | 1108 | ||
@@ -1172,7 +1174,7 @@ find_session (struct Plugin *plugin, struct Session *session) | |||
1172 | * been transmitted (or if the transport is ready | 1174 | * been transmitted (or if the transport is ready |
1173 | * for the next transmission call; or if the | 1175 | * for the next transmission call; or if the |
1174 | * peer disconnected...); can be NULL | 1176 | * peer disconnected...); can be NULL |
1175 | * @param cont_cls closure for cont | 1177 | * @param cont_cls closure for @a cont |
1176 | * @return number of bytes used (on the physical network, with overheads); | 1178 | * @return number of bytes used (on the physical network, with overheads); |
1177 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 1179 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
1178 | * and does NOT mean that the message was not transmitted (DV) | 1180 | * and does NOT mean that the message was not transmitted (DV) |
@@ -1315,15 +1317,19 @@ session_lookup_it (void *cls, | |||
1315 | * Task cleaning up a NAT connection attempt after timeout | 1317 | * Task cleaning up a NAT connection attempt after timeout |
1316 | */ | 1318 | */ |
1317 | static void | 1319 | static void |
1318 | nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1320 | nat_connect_timeout (void *cls, |
1321 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1319 | { | 1322 | { |
1320 | struct Session *session = cls; | 1323 | struct Session *session = cls; |
1321 | 1324 | ||
1322 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; | 1325 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; |
1323 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1326 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1324 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", | 1327 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", |
1325 | GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen)); | 1328 | GNUNET_i2s (&session->target), |
1326 | disconnect_session (session); | 1329 | tcp_address_to_string (NULL, |
1330 | session->addr, session->addrlen)); | ||
1331 | tcp_disconnect_session (session->plugin, | ||
1332 | session); | ||
1327 | } | 1333 | } |
1328 | 1334 | ||
1329 | 1335 | ||
@@ -1491,7 +1497,7 @@ tcp_plugin_get_session (void *cls, | |||
1491 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1497 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1492 | "Running NAT client for `%4s' at `%s' failed\n", | 1498 | "Running NAT client for `%4s' at `%s' failed\n", |
1493 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); | 1499 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); |
1494 | disconnect_session (session); | 1500 | tcp_disconnect_session (plugin, session); |
1495 | return NULL; | 1501 | return NULL; |
1496 | } | 1502 | } |
1497 | } | 1503 | } |
@@ -1544,13 +1550,15 @@ session_disconnect_it (void *cls, | |||
1544 | const struct GNUNET_PeerIdentity *key, | 1550 | const struct GNUNET_PeerIdentity *key, |
1545 | void *value) | 1551 | void *value) |
1546 | { | 1552 | { |
1553 | struct Plugin *plugin = cls; | ||
1547 | struct Session *session = value; | 1554 | struct Session *session = value; |
1548 | 1555 | ||
1549 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1556 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1550 | gettext_noop | 1557 | gettext_noop |
1551 | ("# transport-service disconnect requests for TCP"), | 1558 | ("# transport-service disconnect requests for TCP"), |
1552 | 1, GNUNET_NO); | 1559 | 1, GNUNET_NO); |
1553 | disconnect_session (session); | 1560 | tcp_disconnect_session (plugin, |
1561 | session); | ||
1554 | return GNUNET_YES; | 1562 | return GNUNET_YES; |
1555 | } | 1563 | } |
1556 | 1564 | ||
@@ -1980,7 +1988,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, | |||
1980 | { | 1988 | { |
1981 | GNUNET_break (0); | 1989 | GNUNET_break (0); |
1982 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1990 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1983 | disconnect_session (session); | 1991 | tcp_disconnect_session (plugin, session); |
1984 | return; | 1992 | return; |
1985 | } | 1993 | } |
1986 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove | 1994 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_remove |
@@ -2021,7 +2029,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client, | |||
2021 | "Bad address for incoming connection!\n"); | 2029 | "Bad address for incoming connection!\n"); |
2022 | GNUNET_free (vaddr); | 2030 | GNUNET_free (vaddr); |
2023 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2031 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2024 | disconnect_session (session); | 2032 | tcp_disconnect_session (plugin, session); |
2025 | return; | 2033 | return; |
2026 | } | 2034 | } |
2027 | GNUNET_free (vaddr); | 2035 | GNUNET_free (vaddr); |
@@ -2334,18 +2342,18 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2334 | "*"); | 2342 | "*"); |
2335 | 2343 | ||
2336 | if (plugin->cur_connections == plugin->max_connections) | 2344 | if (plugin->cur_connections == plugin->max_connections) |
2337 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ | 2345 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ |
2338 | 2346 | ||
2339 | if (plugin->cur_connections < 1) | 2347 | if (plugin->cur_connections < 1) |
2340 | GNUNET_break (0); | 2348 | GNUNET_break (0); |
2341 | else | 2349 | else |
2342 | plugin->cur_connections--; | 2350 | plugin->cur_connections--; |
2343 | 2351 | ||
2344 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 2352 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
2345 | gettext_noop | 2353 | gettext_noop |
2346 | ("# network-level TCP disconnect events"), 1, | 2354 | ("# network-level TCP disconnect events"), 1, |
2347 | GNUNET_NO); | 2355 | GNUNET_NO); |
2348 | disconnect_session (session); | 2356 | tcp_disconnect_session (plugin, session); |
2349 | } | 2357 | } |
2350 | 2358 | ||
2351 | 2359 | ||
@@ -2451,7 +2459,7 @@ session_timeout (void *cls, | |||
2451 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 2459 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
2452 | GNUNET_YES)); | 2460 | GNUNET_YES)); |
2453 | /* call session destroy function */ | 2461 | /* call session destroy function */ |
2454 | disconnect_session (s); | 2462 | tcp_disconnect_session(s->plugin, s); |
2455 | } | 2463 | } |
2456 | 2464 | ||
2457 | 2465 | ||
@@ -2461,11 +2469,10 @@ session_timeout (void *cls, | |||
2461 | static void | 2469 | static void |
2462 | start_session_timeout (struct Session *s) | 2470 | start_session_timeout (struct Session *s) |
2463 | { | 2471 | { |
2464 | GNUNET_assert (NULL != s); | ||
2465 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); | 2472 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); |
2466 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 2473 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
2467 | &session_timeout, | 2474 | &session_timeout, |
2468 | s); | 2475 | s); |
2469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2470 | "Timeout for session %p set to %s\n", | 2477 | "Timeout for session %p set to %s\n", |
2471 | s, | 2478 | s, |
@@ -2567,7 +2574,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2567 | { | 2574 | { |
2568 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 2575 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
2569 | initialze the plugin or the API */ | 2576 | initialze the plugin or the API */ |
2570 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 2577 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2571 | api->cls = NULL; | 2578 | api->cls = NULL; |
2572 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2579 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
2573 | api->address_to_string = &tcp_address_to_string; | 2580 | api->address_to_string = &tcp_address_to_string; |
@@ -2592,8 +2599,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2592 | (aport > 65535))) | 2599 | (aport > 65535))) |
2593 | { | 2600 | { |
2594 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2601 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2595 | _ | 2602 | _("Require valid port number for service `%s' in configuration!\n"), |
2596 | ("Require valid port number for service `%s' in configuration!\n"), | ||
2597 | "transport-tcp"); | 2603 | "transport-tcp"); |
2598 | return NULL; | 2604 | return NULL; |
2599 | } | 2605 | } |
@@ -2617,7 +2623,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2617 | /* Initialize my flags */ | 2623 | /* Initialize my flags */ |
2618 | myoptions = 0; | 2624 | myoptions = 0; |
2619 | 2625 | ||
2620 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 2626 | plugin = GNUNET_new (struct Plugin); |
2621 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); | 2627 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); |
2622 | plugin->max_connections = max_connections; | 2628 | plugin->max_connections = max_connections; |
2623 | plugin->cur_connections = 0; | 2629 | plugin->cur_connections = 0; |
@@ -2659,14 +2665,15 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2659 | api->send = &tcp_plugin_send; | 2665 | api->send = &tcp_plugin_send; |
2660 | api->get_session = &tcp_plugin_get_session; | 2666 | api->get_session = &tcp_plugin_get_session; |
2661 | 2667 | ||
2662 | api->disconnect = &tcp_plugin_disconnect; | 2668 | api->disconnect_session = &tcp_disconnect_session; |
2669 | api->disconnect_peer = &tcp_plugin_disconnect; | ||
2663 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2670 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
2664 | api->check_address = &tcp_plugin_check_address; | 2671 | api->check_address = &tcp_plugin_check_address; |
2665 | api->address_to_string = &tcp_address_to_string; | 2672 | api->address_to_string = &tcp_address_to_string; |
2666 | api->string_to_address = &tcp_string_to_address; | 2673 | api->string_to_address = &tcp_string_to_address; |
2667 | api->get_network = &tcp_get_network; | 2674 | api->get_network = &tcp_get_network; |
2668 | plugin->service = service; | 2675 | plugin->service = service; |
2669 | if (service != NULL) | 2676 | if (NULL != service) |
2670 | { | 2677 | { |
2671 | plugin->server = GNUNET_SERVICE_get_server (service); | 2678 | plugin->server = GNUNET_SERVICE_get_server (service); |
2672 | } | 2679 | } |
@@ -2703,13 +2710,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2703 | _("TCP transport listening on port %llu\n"), bport); | 2710 | _("TCP transport listening on port %llu\n"), bport); |
2704 | else | 2711 | else |
2705 | LOG (GNUNET_ERROR_TYPE_INFO, | 2712 | LOG (GNUNET_ERROR_TYPE_INFO, |
2706 | _ | 2713 | _("TCP transport not listening on any port (client only)\n")); |
2707 | ("TCP transport not listening on any port (client only)\n")); | ||
2708 | if (aport != bport) | 2714 | if (aport != bport) |
2709 | LOG (GNUNET_ERROR_TYPE_INFO, | 2715 | LOG (GNUNET_ERROR_TYPE_INFO, |
2710 | _ | 2716 | _("TCP transport advertises itself as being on port %llu\n"), |
2711 | ("TCP transport advertises itself as being on port %llu\n"), | 2717 | aport); |
2712 | aport); | ||
2713 | /* Initially set connections to 0 */ | 2718 | /* Initially set connections to 0 */ |
2714 | GNUNET_assert (NULL != plugin->env->stats); | 2719 | GNUNET_assert (NULL != plugin->env->stats); |
2715 | GNUNET_STATISTICS_set (plugin->env->stats, | 2720 | GNUNET_STATISTICS_set (plugin->env->stats, |
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index dedc8e857..feb0802d9 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c | |||
@@ -152,7 +152,7 @@ struct Plugin | |||
152 | * @param cls closure | 152 | * @param cls closure |
153 | * @param session which session must be used | 153 | * @param session which session must be used |
154 | * @param msgbuf the message to transmit | 154 | * @param msgbuf the message to transmit |
155 | * @param msgbuf_size number of bytes in 'msgbuf' | 155 | * @param msgbuf_size number of bytes in @a msgbuf |
156 | * @param priority how important is the message (most plugins will | 156 | * @param priority how important is the message (most plugins will |
157 | * ignore message priority and just FIFO) | 157 | * ignore message priority and just FIFO) |
158 | * @param to how long to wait at most for the transmission (does not | 158 | * @param to how long to wait at most for the transmission (does not |
@@ -163,7 +163,7 @@ struct Plugin | |||
163 | * been transmitted (or if the transport is ready | 163 | * been transmitted (or if the transport is ready |
164 | * for the next transmission call; or if the | 164 | * for the next transmission call; or if the |
165 | * peer disconnected...); can be NULL | 165 | * peer disconnected...); can be NULL |
166 | * @param cont_cls closure for cont | 166 | * @param cont_cls closure for @a cont |
167 | * @return number of bytes used (on the physical network, with overheads); | 167 | * @return number of bytes used (on the physical network, with overheads); |
168 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 168 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
169 | * and does NOT mean that the message was not transmitted (DV) | 169 | * and does NOT mean that the message was not transmitted (DV) |
@@ -187,7 +187,6 @@ template_plugin_send (void *cls, | |||
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | |||
191 | /** | 190 | /** |
192 | * Function that can be used to force the plugin to disconnect | 191 | * Function that can be used to force the plugin to disconnect |
193 | * from the given peer and cancel all previous transmissions | 192 | * from the given peer and cancel all previous transmissions |
@@ -197,10 +196,30 @@ template_plugin_send (void *cls, | |||
197 | * @param target peer from which to disconnect | 196 | * @param target peer from which to disconnect |
198 | */ | 197 | */ |
199 | static void | 198 | static void |
200 | template_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 199 | template_plugin_disconnect_peer (void *cls, |
200 | const struct GNUNET_PeerIdentity *target) | ||
201 | { | ||
202 | // struct Plugin *plugin = cls; | ||
203 | // FIXME | ||
204 | } | ||
205 | |||
206 | |||
207 | /** | ||
208 | * Function that can be used to force the plugin to disconnect | ||
209 | * from the given peer and cancel all previous transmissions | ||
210 | * (and their continuationc). | ||
211 | * | ||
212 | * @param cls closure | ||
213 | * @param session session from which to disconnect | ||
214 | * @return #GNUNET_OK on success | ||
215 | */ | ||
216 | static int | ||
217 | template_plugin_disconnect_session (void *cls, | ||
218 | struct Session *session) | ||
201 | { | 219 | { |
202 | // struct Plugin *plugin = cls; | 220 | // struct Plugin *plugin = cls; |
203 | // FIXME | 221 | // FIXME |
222 | return GNUNET_SYSERR; | ||
204 | } | 223 | } |
205 | 224 | ||
206 | 225 | ||
@@ -242,11 +261,10 @@ template_plugin_address_pretty_printer (void *cls, const char *type, | |||
242 | GNUNET_TRANSPORT_AddressStringCallback | 261 | GNUNET_TRANSPORT_AddressStringCallback |
243 | asc, void *asc_cls) | 262 | asc, void *asc_cls) |
244 | { | 263 | { |
245 | if (0 == addrlen) | 264 | if (0 == addrlen) |
246 | { | 265 | { |
247 | asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); | 266 | asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING); |
248 | } | 267 | } |
249 | |||
250 | asc (asc_cls, NULL); | 268 | asc (asc_cls, NULL); |
251 | } | 269 | } |
252 | 270 | ||
@@ -261,7 +279,7 @@ template_plugin_address_pretty_printer (void *cls, const char *type, | |||
261 | * @param cls closure | 279 | * @param cls closure |
262 | * @param addr pointer to the address | 280 | * @param addr pointer to the address |
263 | * @param addrlen length of addr | 281 | * @param addrlen length of addr |
264 | * @return GNUNET_OK if this is a plausible address for this peer | 282 | * @return #GNUNET_OK if this is a plausible address for this peer |
265 | * and transport | 283 | * and transport |
266 | */ | 284 | */ |
267 | static int | 285 | static int |
@@ -288,14 +306,14 @@ template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) | |||
288 | static const char * | 306 | static const char * |
289 | template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | 307 | template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
290 | { | 308 | { |
291 | /* | 309 | /* |
292 | * Print address in format template.options.address | 310 | * Print address in format template.options.address |
293 | */ | 311 | */ |
294 | 312 | ||
295 | if (0 == addrlen) | 313 | if (0 == addrlen) |
296 | { | 314 | { |
297 | return TRANSPORT_SESSION_INBOUND_STRING; | 315 | return TRANSPORT_SESSION_INBOUND_STRING; |
298 | } | 316 | } |
299 | 317 | ||
300 | GNUNET_break (0); | 318 | GNUNET_break (0); |
301 | return NULL; | 319 | return NULL; |
@@ -308,22 +326,21 @@ template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) | |||
308 | * | 326 | * |
309 | * @param cls closure ('struct Plugin*') | 327 | * @param cls closure ('struct Plugin*') |
310 | * @param addr string address | 328 | * @param addr string address |
311 | * @param addrlen length of the address | 329 | * @param addrlen length of the @a addr |
312 | * @param buf location to store the buffer | 330 | * @param buf location to store the buffer |
313 | * @param added location to store the number of bytes in the buffer. | 331 | * @param added location to store the number of bytes in the buffer. |
314 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 332 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
315 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 333 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
316 | */ | 334 | */ |
317 | static int | 335 | static int |
318 | template_plugin_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 336 | template_plugin_string_to_address (void *cls, |
319 | void **buf, size_t *added) | 337 | const char *addr, |
338 | uint16_t addrlen, | ||
339 | void **buf, size_t *added) | ||
320 | { | 340 | { |
321 | 341 | /* | |
322 | /* | 342 | * Parse string in format template.options.address |
323 | * Parse string in format template.options.address | 343 | */ |
324 | */ | ||
325 | |||
326 | |||
327 | GNUNET_break (0); | 344 | GNUNET_break (0); |
328 | return GNUNET_SYSERR; | 345 | return GNUNET_SYSERR; |
329 | } | 346 | } |
@@ -346,6 +363,7 @@ template_plugin_get_session (void *cls, | |||
346 | return NULL; | 363 | return NULL; |
347 | } | 364 | } |
348 | 365 | ||
366 | |||
349 | /** | 367 | /** |
350 | * Entry point for the plugin. | 368 | * Entry point for the plugin. |
351 | */ | 369 | */ |
@@ -360,7 +378,7 @@ libgnunet_plugin_transport_template_init (void *cls) | |||
360 | { | 378 | { |
361 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 379 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
362 | initialze the plugin or the API */ | 380 | initialze the plugin or the API */ |
363 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 381 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
364 | api->cls = NULL; | 382 | api->cls = NULL; |
365 | api->address_to_string = &template_plugin_address_to_string; | 383 | api->address_to_string = &template_plugin_address_to_string; |
366 | api->string_to_address = &template_plugin_string_to_address; | 384 | api->string_to_address = &template_plugin_string_to_address; |
@@ -368,12 +386,13 @@ libgnunet_plugin_transport_template_init (void *cls) | |||
368 | return api; | 386 | return api; |
369 | } | 387 | } |
370 | 388 | ||
371 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 389 | plugin = GNUNET_new (struct Plugin); |
372 | plugin->env = env; | 390 | plugin->env = env; |
373 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 391 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
374 | api->cls = plugin; | 392 | api->cls = plugin; |
375 | api->send = &template_plugin_send; | 393 | api->send = &template_plugin_send; |
376 | api->disconnect = &template_plugin_disconnect; | 394 | api->disconnect_peer = &template_plugin_disconnect_peer; |
395 | api->disconnect_session = &template_plugin_disconnect_session; | ||
377 | api->address_pretty_printer = &template_plugin_address_pretty_printer; | 396 | api->address_pretty_printer = &template_plugin_address_pretty_printer; |
378 | api->check_address = &template_plugin_address_suggested; | 397 | api->check_address = &template_plugin_address_suggested; |
379 | api->address_to_string = &template_plugin_address_to_string; | 398 | api->address_to_string = &template_plugin_address_to_string; |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 9bc579b2f..99d4f9fb1 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -138,6 +138,7 @@ enum UDP_MessageType | |||
138 | MSG_BEACON = 5 | 138 | MSG_BEACON = 5 |
139 | }; | 139 | }; |
140 | 140 | ||
141 | |||
141 | struct Session | 142 | struct Session |
142 | { | 143 | { |
143 | /** | 144 | /** |
@@ -145,7 +146,15 @@ struct Session | |||
145 | */ | 146 | */ |
146 | struct GNUNET_PeerIdentity target; | 147 | struct GNUNET_PeerIdentity target; |
147 | 148 | ||
148 | struct UDP_FragmentationContext * frag_ctx; | 149 | /** |
150 | * Plugin this session belongs to. | ||
151 | */ | ||
152 | struct Plugin *plugin; | ||
153 | |||
154 | /** | ||
155 | * Context for dealing with fragments. | ||
156 | */ | ||
157 | struct UDP_FragmentationContext *frag_ctx; | ||
149 | 158 | ||
150 | /** | 159 | /** |
151 | * Address of the other peer | 160 | * Address of the other peer |
@@ -179,9 +188,11 @@ struct Session | |||
179 | 188 | ||
180 | struct GNUNET_ATS_Information ats; | 189 | struct GNUNET_ATS_Information ats; |
181 | 190 | ||
191 | /** | ||
192 | * Number of bytes in @e sock_addr. | ||
193 | */ | ||
182 | size_t addrlen; | 194 | size_t addrlen; |
183 | 195 | ||
184 | |||
185 | unsigned int rc; | 196 | unsigned int rc; |
186 | 197 | ||
187 | int in_destroy; | 198 | int in_destroy; |
@@ -214,6 +225,7 @@ struct SourceInformation | |||
214 | const void *arg; | 225 | const void *arg; |
215 | 226 | ||
216 | struct Session *session; | 227 | struct Session *session; |
228 | |||
217 | /** | 229 | /** |
218 | * Number of bytes in source address. | 230 | * Number of bytes in source address. |
219 | */ | 231 | */ |
@@ -240,7 +252,7 @@ struct FindReceiveContext | |||
240 | struct Session *session; | 252 | struct Session *session; |
241 | 253 | ||
242 | /** | 254 | /** |
243 | * Number of bytes in 'addr'. | 255 | * Number of bytes in @e addr. |
244 | */ | 256 | */ |
245 | socklen_t addr_len; | 257 | socklen_t addr_len; |
246 | 258 | ||
@@ -292,27 +304,27 @@ struct UDP_FragmentationContext | |||
292 | /** | 304 | /** |
293 | * Next in linked list | 305 | * Next in linked list |
294 | */ | 306 | */ |
295 | struct UDP_FragmentationContext * next; | 307 | struct UDP_FragmentationContext *next; |
296 | 308 | ||
297 | /** | 309 | /** |
298 | * Previous in linked list | 310 | * Previous in linked list |
299 | */ | 311 | */ |
300 | struct UDP_FragmentationContext * prev; | 312 | struct UDP_FragmentationContext *prev; |
301 | 313 | ||
302 | /** | 314 | /** |
303 | * The plugin | 315 | * The plugin |
304 | */ | 316 | */ |
305 | struct Plugin * plugin; | 317 | struct Plugin *plugin; |
306 | 318 | ||
307 | /** | 319 | /** |
308 | * Handle for GNUNET_FRAGMENT context | 320 | * Handle for GNUNET_FRAGMENT context |
309 | */ | 321 | */ |
310 | struct GNUNET_FRAGMENT_Context * frag; | 322 | struct GNUNET_FRAGMENT_Context *frag; |
311 | 323 | ||
312 | /** | 324 | /** |
313 | * The session this fragmentation context belongs to | 325 | * The session this fragmentation context belongs to |
314 | */ | 326 | */ |
315 | struct Session * session; | 327 | struct Session *session; |
316 | 328 | ||
317 | /** | 329 | /** |
318 | * Function to call upon completion of the transmission. | 330 | * Function to call upon completion of the transmission. |
@@ -320,7 +332,7 @@ struct UDP_FragmentationContext | |||
320 | GNUNET_TRANSPORT_TransmitContinuation cont; | 332 | GNUNET_TRANSPORT_TransmitContinuation cont; |
321 | 333 | ||
322 | /** | 334 | /** |
323 | * Closure for 'cont'. | 335 | * Closure for @e cont. |
324 | */ | 336 | */ |
325 | void *cont_cls; | 337 | void *cont_cls; |
326 | 338 | ||
@@ -1110,7 +1122,8 @@ free_session (struct Session *s) | |||
1110 | 1122 | ||
1111 | 1123 | ||
1112 | static void | 1124 | static void |
1113 | dequeue (struct Plugin *plugin, struct UDP_MessageWrapper * udpw) | 1125 | dequeue (struct Plugin *plugin, |
1126 | struct UDP_MessageWrapper * udpw) | ||
1114 | { | 1127 | { |
1115 | if (plugin->bytes_in_buffer < udpw->msg_size) | 1128 | if (plugin->bytes_in_buffer < udpw->msg_size) |
1116 | GNUNET_break (0); | 1129 | GNUNET_break (0); |
@@ -1195,28 +1208,33 @@ fragmented_message_done (struct UDP_FragmentationContext *fc, int result) | |||
1195 | &s->last_expected_msg_delay, | 1208 | &s->last_expected_msg_delay, |
1196 | &s->last_expected_ack_delay); | 1209 | &s->last_expected_ack_delay); |
1197 | s->frag_ctx = NULL; | 1210 | s->frag_ctx = NULL; |
1198 | GNUNET_free (fc ); | 1211 | GNUNET_free (fc); |
1199 | } | 1212 | } |
1200 | 1213 | ||
1214 | |||
1201 | /** | 1215 | /** |
1202 | * Functions with this signature are called whenever we need | 1216 | * Functions with this signature are called whenever we need |
1203 | * to close a session due to a disconnect or failure to | 1217 | * to close a session due to a disconnect or failure to |
1204 | * establish a connection. | 1218 | * establish a connection. |
1205 | * | 1219 | * |
1220 | * @param cls closure with the `struct Plugin` | ||
1206 | * @param s session to close down | 1221 | * @param s session to close down |
1222 | * @return #GNUNET_OK on success | ||
1207 | */ | 1223 | */ |
1208 | static void | 1224 | static int |
1209 | disconnect_session (struct Session *s) | 1225 | udp_disconnect_session (void *cls, |
1226 | struct Session *s) | ||
1210 | { | 1227 | { |
1228 | struct Plugin *plugin = cls; | ||
1211 | struct UDP_MessageWrapper *udpw; | 1229 | struct UDP_MessageWrapper *udpw; |
1212 | struct UDP_MessageWrapper *next; | 1230 | struct UDP_MessageWrapper *next; |
1213 | 1231 | ||
1214 | GNUNET_assert (GNUNET_YES != s->in_destroy); | 1232 | GNUNET_assert (GNUNET_YES != s->in_destroy); |
1215 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1233 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1216 | "Session %p to peer `%s' address ended \n", | 1234 | "Session %p to peer `%s' address ended\n", |
1217 | s, | 1235 | s, |
1218 | GNUNET_i2s (&s->target), | 1236 | GNUNET_i2s (&s->target), |
1219 | GNUNET_a2s (s->sock_addr, s->addrlen)); | 1237 | GNUNET_a2s (s->sock_addr, s->addrlen)); |
1220 | stop_session_timeout (s); | 1238 | stop_session_timeout (s); |
1221 | 1239 | ||
1222 | if (NULL != s->frag_ctx) | 1240 | if (NULL != s->frag_ctx) |
@@ -1232,7 +1250,7 @@ disconnect_session (struct Session *s) | |||
1232 | if (udpw->session == s) | 1250 | if (udpw->session == s) |
1233 | { | 1251 | { |
1234 | dequeue (plugin, udpw); | 1252 | dequeue (plugin, udpw); |
1235 | call_continuation(udpw, GNUNET_SYSERR); | 1253 | call_continuation (udpw, GNUNET_SYSERR); |
1236 | GNUNET_free (udpw); | 1254 | GNUNET_free (udpw); |
1237 | } | 1255 | } |
1238 | } | 1256 | } |
@@ -1243,7 +1261,7 @@ disconnect_session (struct Session *s) | |||
1243 | if (udpw->session == s) | 1261 | if (udpw->session == s) |
1244 | { | 1262 | { |
1245 | dequeue (plugin, udpw); | 1263 | dequeue (plugin, udpw); |
1246 | call_continuation(udpw, GNUNET_SYSERR); | 1264 | call_continuation (udpw, GNUNET_SYSERR); |
1247 | GNUNET_free (udpw); | 1265 | GNUNET_free (udpw); |
1248 | } | 1266 | } |
1249 | } | 1267 | } |
@@ -1265,48 +1283,55 @@ disconnect_session (struct Session *s) | |||
1265 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, | 1283 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, |
1266 | &s->target, | 1284 | &s->target, |
1267 | s)); | 1285 | s)); |
1268 | GNUNET_STATISTICS_set(plugin->env->stats, | 1286 | GNUNET_STATISTICS_set (plugin->env->stats, |
1269 | "# UDP, sessions active", | 1287 | "# UDP, sessions active", |
1270 | GNUNET_CONTAINER_multipeermap_size(plugin->sessions), | 1288 | GNUNET_CONTAINER_multipeermap_size(plugin->sessions), |
1271 | GNUNET_NO); | 1289 | GNUNET_NO); |
1272 | if (s->rc > 0) | 1290 | if (s->rc > 0) |
1273 | s->in_destroy = GNUNET_YES; | 1291 | s->in_destroy = GNUNET_YES; |
1274 | else | 1292 | else |
1275 | free_session (s); | 1293 | free_session (s); |
1294 | return GNUNET_OK; | ||
1276 | } | 1295 | } |
1277 | 1296 | ||
1297 | |||
1278 | /** | 1298 | /** |
1279 | * Destroy a session, plugin is being unloaded. | 1299 | * Destroy a session, plugin is being unloaded. |
1280 | * | 1300 | * |
1281 | * @param cls unused | 1301 | * @param cls the `struct Plugin` |
1282 | * @param key hash of public key of target peer | 1302 | * @param key hash of public key of target peer |
1283 | * @param value a 'struct PeerSession*' to clean up | 1303 | * @param value a `struct PeerSession *` to clean up |
1284 | * @return GNUNET_OK (continue to iterate) | 1304 | * @return #GNUNET_OK (continue to iterate) |
1285 | */ | 1305 | */ |
1286 | static int | 1306 | static int |
1287 | disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity * key, void *value) | 1307 | disconnect_and_free_it (void *cls, |
1308 | const struct GNUNET_PeerIdentity *key, | ||
1309 | void *value) | ||
1288 | { | 1310 | { |
1289 | disconnect_session(value); | 1311 | struct Plugin *plugin = cls; |
1312 | |||
1313 | udp_disconnect_session (plugin, value); | ||
1290 | return GNUNET_OK; | 1314 | return GNUNET_OK; |
1291 | } | 1315 | } |
1292 | 1316 | ||
1293 | 1317 | ||
1294 | /** | 1318 | /** |
1295 | * Disconnect from a remote node. Clean up session if we have one for this peer | 1319 | * Disconnect from a remote node. Clean up session if we have one for |
1320 | * this peer. | ||
1296 | * | 1321 | * |
1297 | * @param cls closure for this call (should be handle to Plugin) | 1322 | * @param cls closure for this call (should be handle to Plugin) |
1298 | * @param target the peeridentity of the peer to disconnect | 1323 | * @param target the peeridentity of the peer to disconnect |
1299 | * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed | 1324 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1300 | */ | 1325 | */ |
1301 | static void | 1326 | static void |
1302 | udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 1327 | udp_disconnect (void *cls, |
1328 | const struct GNUNET_PeerIdentity *target) | ||
1303 | { | 1329 | { |
1304 | struct Plugin *plugin = cls; | 1330 | struct Plugin *plugin = cls; |
1305 | GNUNET_assert (plugin != NULL); | ||
1306 | 1331 | ||
1307 | GNUNET_assert (target != NULL); | ||
1308 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1332 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1309 | "Disconnecting from peer `%s'\n", GNUNET_i2s (target)); | 1333 | "Disconnecting from peer `%s'\n", |
1334 | GNUNET_i2s (target)); | ||
1310 | /* Clean up sessions */ | 1335 | /* Clean up sessions */ |
1311 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, | 1336 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, target, |
1312 | &disconnect_and_free_it, plugin); | 1337 | &disconnect_and_free_it, plugin); |
@@ -1317,9 +1342,9 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
1317 | * Session was idle, so disconnect it | 1342 | * Session was idle, so disconnect it |
1318 | */ | 1343 | */ |
1319 | static void | 1344 | static void |
1320 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1345 | session_timeout (void *cls, |
1346 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1321 | { | 1347 | { |
1322 | GNUNET_assert (NULL != cls); | ||
1323 | struct Session *s = cls; | 1348 | struct Session *s = cls; |
1324 | 1349 | ||
1325 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1350 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -1329,7 +1354,8 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1329 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, | 1354 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, |
1330 | GNUNET_YES)); | 1355 | GNUNET_YES)); |
1331 | /* call session destroy function */ | 1356 | /* call session destroy function */ |
1332 | disconnect_session (s); | 1357 | udp_disconnect_session (s->plugin, |
1358 | s); | ||
1333 | } | 1359 | } |
1334 | 1360 | ||
1335 | 1361 | ||
@@ -1374,7 +1400,8 @@ reschedule_session_timeout (struct Session *s) | |||
1374 | 1400 | ||
1375 | 1401 | ||
1376 | static struct Session * | 1402 | static struct Session * |
1377 | create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | 1403 | create_session (struct Plugin *plugin, |
1404 | const struct GNUNET_PeerIdentity *target, | ||
1378 | const void *addr, size_t addrlen, | 1405 | const void *addr, size_t addrlen, |
1379 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 1406 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
1380 | { | 1407 | { |
@@ -1387,8 +1414,8 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
1387 | 1414 | ||
1388 | if (NULL == addr) | 1415 | if (NULL == addr) |
1389 | { | 1416 | { |
1390 | GNUNET_break (0); | 1417 | GNUNET_break (0); |
1391 | return NULL; | 1418 | return NULL; |
1392 | } | 1419 | } |
1393 | 1420 | ||
1394 | switch (addrlen) | 1421 | switch (addrlen) |
@@ -1399,11 +1426,12 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
1399 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1426 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1400 | "Could not create session for peer `%s' address `%s': IPv4 is not enabled\n", | 1427 | "Could not create session for peer `%s' address `%s': IPv4 is not enabled\n", |
1401 | GNUNET_i2s(target), | 1428 | GNUNET_i2s(target), |
1402 | udp_address_to_string(NULL, addr, addrlen)); | 1429 | udp_address_to_string (NULL, addr, addrlen)); |
1403 | return NULL; | 1430 | return NULL; |
1404 | } | 1431 | } |
1405 | t4 = addr; | 1432 | t4 = addr; |
1406 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); | 1433 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in)); |
1434 | s->plugin = plugin; | ||
1407 | len = sizeof (struct sockaddr_in); | 1435 | len = sizeof (struct sockaddr_in); |
1408 | v4 = (struct sockaddr_in *) &s[1]; | 1436 | v4 = (struct sockaddr_in *) &s[1]; |
1409 | v4->sin_family = AF_INET; | 1437 | v4->sin_family = AF_INET; |
@@ -1425,6 +1453,7 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target, | |||
1425 | } | 1453 | } |
1426 | t6 = addr; | 1454 | t6 = addr; |
1427 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); | 1455 | s = GNUNET_malloc (sizeof (struct Session) + sizeof (struct sockaddr_in6)); |
1456 | s->plugin = plugin; | ||
1428 | len = sizeof (struct sockaddr_in6); | 1457 | len = sizeof (struct sockaddr_in6); |
1429 | v6 = (struct sockaddr_in6 *) &s[1]; | 1458 | v6 = (struct sockaddr_in6 *) &s[1]; |
1430 | v6->sin6_family = AF_INET6; | 1459 | v6->sin6_family = AF_INET6; |
@@ -1512,7 +1541,7 @@ session_cmp_it (void *cls, | |||
1512 | * | 1541 | * |
1513 | * @param cls closure ('struct Plugin*') | 1542 | * @param cls closure ('struct Plugin*') |
1514 | * @param session the session | 1543 | * @param session the session |
1515 | * @return the network type in HBO or GNUNET_SYSERR | 1544 | * @return the network type in HBO or #GNUNET_SYSERR |
1516 | */ | 1545 | */ |
1517 | static enum GNUNET_ATS_Network_Type | 1546 | static enum GNUNET_ATS_Network_Type |
1518 | udp_get_network (void *cls, | 1547 | udp_get_network (void *cls, |
@@ -2991,7 +3020,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2991 | { | 3020 | { |
2992 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 3021 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
2993 | initialze the plugin or the API */ | 3022 | initialze the plugin or the API */ |
2994 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3023 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2995 | api->cls = NULL; | 3024 | api->cls = NULL; |
2996 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; | 3025 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; |
2997 | api->address_to_string = &udp_address_to_string; | 3026 | api->address_to_string = &udp_address_to_string; |
@@ -3002,8 +3031,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3002 | GNUNET_assert (NULL != env->stats); | 3031 | GNUNET_assert (NULL != env->stats); |
3003 | 3032 | ||
3004 | /* Get port number: port == 0 : autodetect a port, | 3033 | /* Get port number: port == 0 : autodetect a port, |
3005 | * > 0 : use this port, | 3034 | * > 0 : use this port, not given : 2086 default */ |
3006 | * not given : 2086 default */ | ||
3007 | if (GNUNET_OK != | 3035 | if (GNUNET_OK != |
3008 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", | 3036 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", "PORT", |
3009 | &port)) | 3037 | &port)) |
@@ -3097,7 +3125,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3097 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | 3125 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
3098 | } | 3126 | } |
3099 | 3127 | ||
3100 | p = GNUNET_malloc (sizeof (struct Plugin)); | 3128 | p = GNUNET_new (struct Plugin); |
3101 | p->port = port; | 3129 | p->port = port; |
3102 | p->aport = aport; | 3130 | p->aport = aport; |
3103 | p->broadcast_interval = interval; | 3131 | p->broadcast_interval = interval; |
@@ -3130,10 +3158,11 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3130 | setup_broadcast (p, &server_addrv6, &server_addrv4); | 3158 | setup_broadcast (p, &server_addrv6, &server_addrv4); |
3131 | } | 3159 | } |
3132 | 3160 | ||
3133 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3161 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3134 | api->cls = p; | 3162 | api->cls = p; |
3135 | api->send = NULL; | 3163 | api->send = NULL; |
3136 | api->disconnect = &udp_disconnect; | 3164 | api->disconnect_session = &udp_disconnect_session; |
3165 | api->disconnect_peer = &udp_disconnect; | ||
3137 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; | 3166 | api->address_pretty_printer = &udp_plugin_address_pretty_printer; |
3138 | api->address_to_string = &udp_address_to_string; | 3167 | api->address_to_string = &udp_address_to_string; |
3139 | api->string_to_address = &udp_string_to_address; | 3168 | api->string_to_address = &udp_string_to_address; |
@@ -3148,10 +3177,9 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3148 | 3177 | ||
3149 | static int | 3178 | static int |
3150 | heap_cleanup_iterator (void *cls, | 3179 | heap_cleanup_iterator (void *cls, |
3151 | struct GNUNET_CONTAINER_HeapNode * | 3180 | struct GNUNET_CONTAINER_HeapNode *node, |
3152 | node, void *element, | 3181 | void *element, |
3153 | GNUNET_CONTAINER_HeapCostType | 3182 | GNUNET_CONTAINER_HeapCostType cost) |
3154 | cost) | ||
3155 | { | 3183 | { |
3156 | struct DefragContext * d_ctx = element; | 3184 | struct DefragContext * d_ctx = element; |
3157 | 3185 | ||
@@ -3197,35 +3225,37 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3197 | } | 3225 | } |
3198 | 3226 | ||
3199 | /* Closing sockets */ | 3227 | /* Closing sockets */ |
3200 | if (GNUNET_YES ==plugin->enable_ipv4) | 3228 | if (GNUNET_YES == plugin->enable_ipv4) |
3201 | { | 3229 | { |
3202 | if (plugin->sockv4 != NULL) | 3230 | if (NULL != plugin->sockv4) |
3203 | { | 3231 | { |
3204 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); | 3232 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); |
3205 | plugin->sockv4 = NULL; | 3233 | plugin->sockv4 = NULL; |
3206 | } | 3234 | } |
3207 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); | 3235 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v4); |
3208 | GNUNET_NETWORK_fdset_destroy (plugin->ws_v4); | 3236 | GNUNET_NETWORK_fdset_destroy (plugin->ws_v4); |
3209 | } | 3237 | } |
3210 | if (GNUNET_YES ==plugin->enable_ipv6) | 3238 | if (GNUNET_YES == plugin->enable_ipv6) |
3211 | { | 3239 | { |
3212 | if (plugin->sockv6 != NULL) | 3240 | if (NULL != plugin->sockv6) |
3213 | { | 3241 | { |
3214 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); | 3242 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); |
3215 | plugin->sockv6 = NULL; | 3243 | plugin->sockv6 = NULL; |
3216 | 3244 | ||
3217 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); | 3245 | GNUNET_NETWORK_fdset_destroy (plugin->rs_v6); |
3218 | GNUNET_NETWORK_fdset_destroy (plugin->ws_v6); | 3246 | GNUNET_NETWORK_fdset_destroy (plugin->ws_v6); |
3219 | } | 3247 | } |
3220 | } | 3248 | } |
3221 | if (NULL != plugin->nat) | 3249 | if (NULL != plugin->nat) |
3222 | GNUNET_NAT_unregister (plugin->nat); | ||
3223 | |||
3224 | if (plugin->defrag_ctxs != NULL) | ||
3225 | { | 3250 | { |
3226 | GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs, | 3251 | GNUNET_NAT_unregister (plugin->nat); |
3227 | heap_cleanup_iterator, NULL); | 3252 | plugin->nat = NULL; |
3228 | GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs); | 3253 | } |
3254 | if (NULL != plugin->defrag_ctxs) | ||
3255 | { | ||
3256 | GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, | ||
3257 | heap_cleanup_iterator, NULL); | ||
3258 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); | ||
3229 | plugin->defrag_ctxs = NULL; | 3259 | plugin->defrag_ctxs = NULL; |
3230 | } | 3260 | } |
3231 | if (plugin->mst != NULL) | 3261 | if (plugin->mst != NULL) |
@@ -3266,12 +3296,12 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3266 | next = ppc_dll_head; | 3296 | next = ppc_dll_head; |
3267 | for (cur = next; NULL != cur; cur = next) | 3297 | for (cur = next; NULL != cur; cur = next) |
3268 | { | 3298 | { |
3269 | next = cur->next; | 3299 | next = cur->next; |
3270 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); | 3300 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); |
3271 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | 3301 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
3272 | GNUNET_SCHEDULER_cancel (cur->timeout_task); | 3302 | GNUNET_SCHEDULER_cancel (cur->timeout_task); |
3273 | GNUNET_free (cur); | 3303 | GNUNET_free (cur); |
3274 | GNUNET_break (0); | 3304 | GNUNET_break (0); |
3275 | } | 3305 | } |
3276 | 3306 | ||
3277 | plugin->nat = NULL; | 3307 | plugin->nat = NULL; |
@@ -3281,16 +3311,16 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
3281 | struct Allocation *allocation; | 3311 | struct Allocation *allocation; |
3282 | while (NULL != ahead) | 3312 | while (NULL != ahead) |
3283 | { | 3313 | { |
3284 | allocation = ahead; | 3314 | allocation = ahead; |
3285 | GNUNET_CONTAINER_DLL_remove (ahead, atail, allocation); | 3315 | GNUNET_CONTAINER_DLL_remove (ahead, atail, allocation); |
3286 | GNUNET_free (allocation); | 3316 | GNUNET_free (allocation); |
3287 | } | 3317 | } |
3288 | struct Allocator *allocator; | 3318 | struct Allocator *allocator; |
3289 | while (NULL != aehead) | 3319 | while (NULL != aehead) |
3290 | { | 3320 | { |
3291 | allocator = aehead; | 3321 | allocator = aehead; |
3292 | GNUNET_CONTAINER_DLL_remove (aehead, aetail, allocator); | 3322 | GNUNET_CONTAINER_DLL_remove (aehead, aetail, allocator); |
3293 | GNUNET_free (allocator); | 3323 | GNUNET_free (allocator); |
3294 | } | 3324 | } |
3295 | #endif | 3325 | #endif |
3296 | return NULL; | 3326 | return NULL; |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index e78445a0a..3d6ac4d23 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -530,9 +530,6 @@ lookup_session (struct Plugin *plugin, | |||
530 | { | 530 | { |
531 | struct LookupCtx lctx; | 531 | struct LookupCtx lctx; |
532 | 532 | ||
533 | GNUNET_assert (NULL != plugin); | ||
534 | GNUNET_assert (NULL != sender); | ||
535 | GNUNET_assert (NULL != ua); | ||
536 | lctx.s = NULL; | 533 | lctx.s = NULL; |
537 | lctx.ua = ua; | 534 | lctx.ua = ua; |
538 | lctx.ua_len = ua_len; | 535 | lctx.ua_len = ua_len; |
@@ -548,12 +545,15 @@ lookup_session (struct Plugin *plugin, | |||
548 | * to close a session due to a disconnect or failure to | 545 | * to close a session due to a disconnect or failure to |
549 | * establish a connection. | 546 | * establish a connection. |
550 | * | 547 | * |
548 | * @param cls closure with the `struct Plugin` | ||
551 | * @param s session to close down | 549 | * @param s session to close down |
550 | * @return #GNUNET_OK on success | ||
552 | */ | 551 | */ |
553 | static void | 552 | static int |
554 | disconnect_session (struct Session *s) | 553 | unix_session_disconnect (void *cls, |
554 | struct Session *s) | ||
555 | { | 555 | { |
556 | struct Plugin *plugin = s->plugin; | 556 | struct Plugin *plugin = cls; |
557 | struct UNIXMessageWrapper *msgw; | 557 | struct UNIXMessageWrapper *msgw; |
558 | struct UNIXMessageWrapper *next; | 558 | struct UNIXMessageWrapper *next; |
559 | int removed; | 559 | int removed; |
@@ -595,6 +595,7 @@ disconnect_session (struct Session *s) | |||
595 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 595 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
596 | } | 596 | } |
597 | GNUNET_free (s); | 597 | GNUNET_free (s); |
598 | return GNUNET_OK; | ||
598 | } | 599 | } |
599 | 600 | ||
600 | 601 | ||
@@ -610,13 +611,13 @@ disconnect_session (struct Session *s) | |||
610 | * @param priority how important is the message (ignored by UNIX) | 611 | * @param priority how important is the message (ignored by UNIX) |
611 | * @param timeout when should we time out (give up) if we can not transmit? | 612 | * @param timeout when should we time out (give up) if we can not transmit? |
612 | * @param addr the addr to send the message to, needs to be a sockaddr for us | 613 | * @param addr the addr to send the message to, needs to be a sockaddr for us |
613 | * @param addrlen the len of addr | 614 | * @param addrlen the len of @a addr |
614 | * @param payload bytes payload to send | 615 | * @param payload bytes payload to send |
615 | * @param cont continuation to call once the message has | 616 | * @param cont continuation to call once the message has |
616 | * been transmitted (or if the transport is ready | 617 | * been transmitted (or if the transport is ready |
617 | * for the next transmission call; or if the | 618 | * for the next transmission call; or if the |
618 | * peer disconnected...) | 619 | * peer disconnected...) |
619 | * @param cont_cls closure for cont | 620 | * @param cont_cls closure for @a cont |
620 | * @return on success the number of bytes written, RETRY for retry, -1 on errors | 621 | * @return on success the number of bytes written, RETRY for retry, -1 on errors |
621 | */ | 622 | */ |
622 | static ssize_t | 623 | static ssize_t |
@@ -637,7 +638,6 @@ unix_real_send (void *cls, | |||
637 | socklen_t un_len; | 638 | socklen_t un_len; |
638 | const char *unixpath; | 639 | const char *unixpath; |
639 | 640 | ||
640 | |||
641 | GNUNET_assert (NULL != plugin); | 641 | GNUNET_assert (NULL != plugin); |
642 | if (NULL == send_handle) | 642 | if (NULL == send_handle) |
643 | { | 643 | { |
@@ -734,7 +734,7 @@ struct GetSessionIteratorContext | |||
734 | const char *address; | 734 | const char *address; |
735 | 735 | ||
736 | /** | 736 | /** |
737 | * Number of bytes in 'address' | 737 | * Number of bytes in @e address |
738 | */ | 738 | */ |
739 | size_t addrlen; | 739 | size_t addrlen; |
740 | }; | 740 | }; |
@@ -784,7 +784,7 @@ session_timeout (void *cls, | |||
784 | s, | 784 | s, |
785 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 785 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
786 | GNUNET_YES)); | 786 | GNUNET_YES)); |
787 | disconnect_session (s); | 787 | unix_session_disconnect (s->plugin, s); |
788 | } | 788 | } |
789 | 789 | ||
790 | 790 | ||
@@ -903,7 +903,7 @@ unix_plugin_get_session (void *cls, | |||
903 | * @param cls closure | 903 | * @param cls closure |
904 | * @param session which session must be used | 904 | * @param session which session must be used |
905 | * @param msgbuf the message to transmit | 905 | * @param msgbuf the message to transmit |
906 | * @param msgbuf_size number of bytes in 'msgbuf' | 906 | * @param msgbuf_size number of bytes in @a msgbuf |
907 | * @param priority how important is the message (most plugins will | 907 | * @param priority how important is the message (most plugins will |
908 | * ignore message priority and just FIFO) | 908 | * ignore message priority and just FIFO) |
909 | * @param to how long to wait at most for the transmission (does not | 909 | * @param to how long to wait at most for the transmission (does not |
@@ -914,7 +914,7 @@ unix_plugin_get_session (void *cls, | |||
914 | * been transmitted (or if the transport is ready | 914 | * been transmitted (or if the transport is ready |
915 | * for the next transmission call; or if the | 915 | * for the next transmission call; or if the |
916 | * peer disconnected...); can be NULL | 916 | * peer disconnected...); can be NULL |
917 | * @param cont_cls closure for cont | 917 | * @param cont_cls closure for @a cont |
918 | * @return number of bytes used (on the physical network, with overheads); | 918 | * @return number of bytes used (on the physical network, with overheads); |
919 | * -1 on hard errors (i.e. address invalid); 0 is a legal value | 919 | * -1 on hard errors (i.e. address invalid); 0 is a legal value |
920 | * and does NOT mean that the message was not transmitted (DV) | 920 | * and does NOT mean that the message was not transmitted (DV) |
@@ -932,9 +932,6 @@ unix_plugin_send (void *cls, | |||
932 | struct UNIXMessage *message; | 932 | struct UNIXMessage *message; |
933 | int ssize; | 933 | int ssize; |
934 | 934 | ||
935 | GNUNET_assert (NULL != plugin); | ||
936 | GNUNET_assert (NULL != session); | ||
937 | |||
938 | if (GNUNET_OK != | 935 | if (GNUNET_OK != |
939 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, | 936 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, |
940 | &session->target, | 937 | &session->target, |
@@ -960,7 +957,7 @@ unix_plugin_send (void *cls, | |||
960 | sizeof (struct GNUNET_PeerIdentity)); | 957 | sizeof (struct GNUNET_PeerIdentity)); |
961 | memcpy (&message[1], msgbuf, msgbuf_size); | 958 | memcpy (&message[1], msgbuf, msgbuf_size); |
962 | reschedule_session_timeout (session); | 959 | reschedule_session_timeout (session); |
963 | wrapper = GNUNET_malloc (sizeof (struct UNIXMessageWrapper)); | 960 | wrapper = GNUNET_new (struct UNIXMessageWrapper); |
964 | wrapper->msg = message; | 961 | wrapper->msg = message; |
965 | wrapper->msgsize = ssize; | 962 | wrapper->msgsize = ssize; |
966 | wrapper->payload = msgbuf_size; | 963 | wrapper->payload = msgbuf_size; |
@@ -1001,9 +998,7 @@ unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | |||
1001 | struct GNUNET_HELLO_Address * addr; | 998 | struct GNUNET_HELLO_Address * addr; |
1002 | 999 | ||
1003 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); | 1000 | GNUNET_break (ntohl(plugin->ats_network.value) != GNUNET_ATS_NET_UNSPECIFIED); |
1004 | |||
1005 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); | 1001 | GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); |
1006 | |||
1007 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1002 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1008 | "Received message from %s\n", | 1003 | "Received message from %s\n", |
1009 | unix_address_to_string(NULL, ua, ua_len)); | 1004 | unix_address_to_string(NULL, ua, ua_len)); |
@@ -1329,10 +1324,10 @@ unix_transport_server_start (void *cls) | |||
1329 | static int | 1324 | static int |
1330 | unix_check_address (void *cls, const void *addr, size_t addrlen) | 1325 | unix_check_address (void *cls, const void *addr, size_t addrlen) |
1331 | { | 1326 | { |
1332 | struct Plugin* plugin = cls; | 1327 | struct Plugin* plugin = cls; |
1333 | struct UnixAddress *ua = (struct UnixAddress *) addr; | 1328 | struct UnixAddress *ua = (struct UnixAddress *) addr; |
1334 | char *addrstr; | 1329 | char *addrstr; |
1335 | size_t addr_str_len; | 1330 | size_t addr_str_len; |
1336 | 1331 | ||
1337 | if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) | 1332 | if ((NULL == addr) || (0 == addrlen) || (sizeof (struct UnixAddress) > addrlen)) |
1338 | { | 1333 | { |
@@ -1366,11 +1361,11 @@ unix_check_address (void *cls, const void *addr, size_t addrlen) | |||
1366 | * @param type name of the transport that generated the address | 1361 | * @param type name of the transport that generated the address |
1367 | * @param addr one of the addresses of the host, NULL for the last address | 1362 | * @param addr one of the addresses of the host, NULL for the last address |
1368 | * the specific address format depends on the transport | 1363 | * the specific address format depends on the transport |
1369 | * @param addrlen length of the address | 1364 | * @param addrlen length of the @a addr |
1370 | * @param numeric should (IP) addresses be displayed in numeric form? | 1365 | * @param numeric should (IP) addresses be displayed in numeric form? |
1371 | * @param timeout after how long should we give up? | 1366 | * @param timeout after how long should we give up? |
1372 | * @param asc function to call on each string | 1367 | * @param asc function to call on each string |
1373 | * @param asc_cls closure for asc | 1368 | * @param asc_cls closure for @a asc |
1374 | */ | 1369 | */ |
1375 | static void | 1370 | static void |
1376 | unix_plugin_address_pretty_printer (void *cls, const char *type, | 1371 | unix_plugin_address_pretty_printer (void *cls, const char *type, |
@@ -1403,15 +1398,16 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1403 | * | 1398 | * |
1404 | * @param cls closure ('struct Plugin*') | 1399 | * @param cls closure ('struct Plugin*') |
1405 | * @param addr string address | 1400 | * @param addr string address |
1406 | * @param addrlen length of the address (strlen(addr) + '\0') | 1401 | * @param addrlen length of the @a addr (strlen(addr) + '\0') |
1407 | * @param buf location to store the buffer | 1402 | * @param buf location to store the buffer |
1408 | * If the function returns GNUNET_SYSERR, its contents are undefined. | 1403 | * If the function returns #GNUNET_SYSERR, its contents are undefined. |
1409 | * @param added length of created address | 1404 | * @param added length of created address |
1410 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | 1405 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1411 | */ | 1406 | */ |
1412 | static int | 1407 | static int |
1413 | unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 1408 | unix_string_to_address (void *cls, |
1414 | void **buf, size_t *added) | 1409 | const char *addr, uint16_t addrlen, |
1410 | void **buf, size_t *added) | ||
1415 | { | 1411 | { |
1416 | struct UnixAddress *ua; | 1412 | struct UnixAddress *ua; |
1417 | char *address; | 1413 | char *address; |
@@ -1532,19 +1528,20 @@ reschedule_session_timeout (struct Session *s) | |||
1532 | /** | 1528 | /** |
1533 | * Function called on sessions to disconnect | 1529 | * Function called on sessions to disconnect |
1534 | * | 1530 | * |
1535 | * @param cls the plugin (unused) | 1531 | * @param cls the plugin |
1536 | * @param key peer identity (unused) | 1532 | * @param key peer identity (unused) |
1537 | * @param value the 'struct Session' to disconnect | 1533 | * @param value the 'struct Session' to disconnect |
1538 | * @return GNUNET_YES (always, continue to iterate) | 1534 | * @return #GNUNET_YES (always, continue to iterate) |
1539 | */ | 1535 | */ |
1540 | static int | 1536 | static int |
1541 | get_session_delete_it (void *cls, | 1537 | get_session_delete_it (void *cls, |
1542 | const struct GNUNET_PeerIdentity *key, | 1538 | const struct GNUNET_PeerIdentity *key, |
1543 | void *value) | 1539 | void *value) |
1544 | { | 1540 | { |
1541 | struct Plugin *plugin = cls; | ||
1545 | struct Session *s = value; | 1542 | struct Session *s = value; |
1546 | 1543 | ||
1547 | disconnect_session (s); | 1544 | unix_session_disconnect (plugin, s); |
1548 | return GNUNET_YES; | 1545 | return GNUNET_YES; |
1549 | } | 1546 | } |
1550 | 1547 | ||
@@ -1557,8 +1554,8 @@ get_session_delete_it (void *cls, | |||
1557 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 1554 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
1558 | */ | 1555 | */ |
1559 | static void | 1556 | static void |
1560 | unix_disconnect (void *cls, | 1557 | unix_peer_disconnect (void *cls, |
1561 | const struct GNUNET_PeerIdentity *target) | 1558 | const struct GNUNET_PeerIdentity *target) |
1562 | { | 1559 | { |
1563 | struct Plugin *plugin = cls; | 1560 | struct Plugin *plugin = cls; |
1564 | 1561 | ||
@@ -1589,7 +1586,7 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1589 | { | 1586 | { |
1590 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 1587 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
1591 | initialze the plugin or the API */ | 1588 | initialze the plugin or the API */ |
1592 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1589 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1593 | api->cls = NULL; | 1590 | api->cls = NULL; |
1594 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; | 1591 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; |
1595 | api->address_to_string = &unix_address_to_string; | 1592 | api->address_to_string = &unix_address_to_string; |
@@ -1600,7 +1597,7 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1600 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT", | 1597 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-unix", "PORT", |
1601 | &port)) | 1598 | &port)) |
1602 | port = UNIX_NAT_DEFAULT_PORT; | 1599 | port = UNIX_NAT_DEFAULT_PORT; |
1603 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 1600 | plugin = GNUNET_new (struct Plugin); |
1604 | plugin->port = port; | 1601 | plugin->port = port; |
1605 | plugin->env = env; | 1602 | plugin->env = env; |
1606 | GNUNET_asprintf (&plugin->unix_socket_path, | 1603 | GNUNET_asprintf (&plugin->unix_socket_path, |
@@ -1610,12 +1607,13 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1610 | /* Initialize my flags */ | 1607 | /* Initialize my flags */ |
1611 | myoptions = 0; | 1608 | myoptions = 0; |
1612 | 1609 | ||
1613 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 1610 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1614 | api->cls = plugin; | 1611 | api->cls = plugin; |
1615 | 1612 | ||
1616 | api->get_session = &unix_plugin_get_session; | 1613 | api->get_session = &unix_plugin_get_session; |
1617 | api->send = &unix_plugin_send; | 1614 | api->send = &unix_plugin_send; |
1618 | api->disconnect = &unix_disconnect; | 1615 | api->disconnect_peer = &unix_peer_disconnect; |
1616 | api->disconnect_session = &unix_session_disconnect; | ||
1619 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; | 1617 | api->address_pretty_printer = &unix_plugin_address_pretty_printer; |
1620 | api->address_to_string = &unix_address_to_string; | 1618 | api->address_to_string = &unix_address_to_string; |
1621 | api->check_address = &unix_check_address; | 1619 | api->check_address = &unix_check_address; |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 0957676f2..3e1a6396c 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -597,8 +597,8 @@ send_ack (void *cls, uint32_t msg_id, | |||
597 | 597 | ||
598 | if (NULL == endpoint) | 598 | if (NULL == endpoint) |
599 | { | 599 | { |
600 | GNUNET_break (0); | 600 | GNUNET_break (0); |
601 | return; | 601 | return; |
602 | } | 602 | } |
603 | 603 | ||
604 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 604 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
@@ -654,10 +654,12 @@ wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr) | |||
654 | /** | 654 | /** |
655 | * Free a session | 655 | * Free a session |
656 | * | 656 | * |
657 | * @param cls our `struct Plugin`. | ||
657 | * @param session the session free | 658 | * @param session the session free |
658 | */ | 659 | */ |
659 | static void | 660 | static int |
660 | free_session (struct Session *session) | 661 | wlan_plugin_disconnect_session (void *cls, |
662 | struct Session *session) | ||
661 | { | 663 | { |
662 | struct MacEndpoint *endpoint = session->mac; | 664 | struct MacEndpoint *endpoint = session->mac; |
663 | struct PendingMessage *pm; | 665 | struct PendingMessage *pm; |
@@ -685,9 +687,11 @@ free_session (struct Session *session) | |||
685 | GNUNET_SCHEDULER_cancel (session->timeout_task); | 687 | GNUNET_SCHEDULER_cancel (session->timeout_task); |
686 | session->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 688 | session->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
687 | } | 689 | } |
688 | GNUNET_STATISTICS_update (endpoint->plugin->env->stats, _("# WLAN sessions allocated"), -1, | 690 | GNUNET_STATISTICS_update (endpoint->plugin->env->stats, |
691 | _("# WLAN sessions allocated"), -1, | ||
689 | GNUNET_NO); | 692 | GNUNET_NO); |
690 | GNUNET_free (session); | 693 | GNUNET_free (session); |
694 | return GNUNET_OK; | ||
691 | } | 695 | } |
692 | 696 | ||
693 | 697 | ||
@@ -700,14 +704,15 @@ free_session (struct Session *session) | |||
700 | static void | 704 | static void |
701 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 705 | session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
702 | { | 706 | { |
703 | struct Session * session = cls; | 707 | struct Session *session = cls; |
704 | struct GNUNET_TIME_Relative timeout; | 708 | struct GNUNET_TIME_Relative timeout; |
705 | 709 | ||
706 | session->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 710 | session->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
707 | timeout = GNUNET_TIME_absolute_get_remaining (session->timeout); | 711 | timeout = GNUNET_TIME_absolute_get_remaining (session->timeout); |
708 | if (0 == timeout.rel_value_us) | 712 | if (0 == timeout.rel_value_us) |
709 | { | 713 | { |
710 | free_session (session); | 714 | wlan_plugin_disconnect_session (session->mac->plugin, |
715 | session); | ||
711 | return; | 716 | return; |
712 | } | 717 | } |
713 | session->timeout_task = | 718 | session->timeout_task = |
@@ -804,7 +809,7 @@ get_session (struct MacEndpoint *endpoint, | |||
804 | * the next fragment. | 809 | * the next fragment. |
805 | * | 810 | * |
806 | * @param cls the 'struct FragmentMessage' | 811 | * @param cls the 'struct FragmentMessage' |
807 | * @param result result of the operation (GNUNET_OK on success, GNUNET_NO if the helper died, GNUNET_SYSERR | 812 | * @param result result of the operation (#GNUNET_OK on success, #GNUNET_NO if the helper died, #GNUNET_SYSERR |
808 | * if the helper was stopped) | 813 | * if the helper was stopped) |
809 | */ | 814 | */ |
810 | static void | 815 | static void |
@@ -894,8 +899,8 @@ free_fragment_message (struct FragmentMessage *fm) | |||
894 | fm->sh = NULL; | 899 | fm->sh = NULL; |
895 | } | 900 | } |
896 | GNUNET_FRAGMENT_context_destroy (fm->fragcontext, | 901 | GNUNET_FRAGMENT_context_destroy (fm->fragcontext, |
897 | &endpoint->msg_delay, | 902 | &endpoint->msg_delay, |
898 | &endpoint->ack_delay); | 903 | &endpoint->ack_delay); |
899 | if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK) | 904 | if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK) |
900 | { | 905 | { |
901 | GNUNET_SCHEDULER_cancel (fm->timeout_task); | 906 | GNUNET_SCHEDULER_cancel (fm->timeout_task); |
@@ -944,7 +949,7 @@ fragmentmessage_timeout (void *cls, | |||
944 | static void | 949 | static void |
945 | send_with_fragmentation (struct MacEndpoint *endpoint, | 950 | send_with_fragmentation (struct MacEndpoint *endpoint, |
946 | struct GNUNET_TIME_Relative timeout, | 951 | struct GNUNET_TIME_Relative timeout, |
947 | const struct GNUNET_PeerIdentity *target, | 952 | const struct GNUNET_PeerIdentity *target, |
948 | const struct GNUNET_MessageHeader *msg, | 953 | const struct GNUNET_MessageHeader *msg, |
949 | size_t payload_size, | 954 | size_t payload_size, |
950 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 955 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
@@ -994,7 +999,8 @@ free_macendpoint (struct MacEndpoint *endpoint) | |||
994 | GNUNET_STATISTICS_update (plugin->env->stats, | 999 | GNUNET_STATISTICS_update (plugin->env->stats, |
995 | _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO); | 1000 | _("# WLAN MAC endpoints allocated"), -1, GNUNET_NO); |
996 | while (NULL != (session = endpoint->sessions_head)) | 1001 | while (NULL != (session = endpoint->sessions_head)) |
997 | free_session (session); | 1002 | wlan_plugin_disconnect_session (plugin, |
1003 | session); | ||
998 | while (NULL != (fm = endpoint->sending_messages_head)) | 1004 | while (NULL != (fm = endpoint->sending_messages_head)) |
999 | free_fragment_message (fm); | 1005 | free_fragment_message (fm); |
1000 | GNUNET_CONTAINER_DLL_remove (plugin->mac_head, | 1006 | GNUNET_CONTAINER_DLL_remove (plugin->mac_head, |
@@ -1142,7 +1148,8 @@ wlan_plugin_get_session (void *cls, | |||
1142 | * @param target peer from which to disconnect | 1148 | * @param target peer from which to disconnect |
1143 | */ | 1149 | */ |
1144 | static void | 1150 | static void |
1145 | wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | 1151 | wlan_plugin_disconnect_peer (void *cls, |
1152 | const struct GNUNET_PeerIdentity *target) | ||
1146 | { | 1153 | { |
1147 | struct Plugin *plugin = cls; | 1154 | struct Plugin *plugin = cls; |
1148 | struct Session *session; | 1155 | struct Session *session; |
@@ -1153,7 +1160,7 @@ wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
1153 | if (0 == memcmp (target, &session->target, | 1160 | if (0 == memcmp (target, &session->target, |
1154 | sizeof (struct GNUNET_PeerIdentity))) | 1161 | sizeof (struct GNUNET_PeerIdentity))) |
1155 | { | 1162 | { |
1156 | free_session (session); | 1163 | wlan_plugin_disconnect_session (plugin, session); |
1157 | break; /* inner-loop only (in case peer has another MAC as well!) */ | 1164 | break; /* inner-loop only (in case peer has another MAC as well!) */ |
1158 | } | 1165 | } |
1159 | } | 1166 | } |
@@ -1959,7 +1966,8 @@ libgnunet_plugin_transport_wlan_init (void *cls) | |||
1959 | api->cls = plugin; | 1966 | api->cls = plugin; |
1960 | api->send = &wlan_plugin_send; | 1967 | api->send = &wlan_plugin_send; |
1961 | api->get_session = &wlan_plugin_get_session; | 1968 | api->get_session = &wlan_plugin_get_session; |
1962 | api->disconnect = &wlan_plugin_disconnect; | 1969 | api->disconnect_peer = &wlan_plugin_disconnect_peer; |
1970 | api->disconnect_session = &wlan_plugin_disconnect_session; | ||
1963 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; | 1971 | api->address_pretty_printer = &wlan_plugin_address_pretty_printer; |
1964 | api->check_address = &wlan_plugin_address_suggested; | 1972 | api->check_address = &wlan_plugin_address_suggested; |
1965 | api->address_to_string = &wlan_plugin_address_to_string; | 1973 | api->address_to_string = &wlan_plugin_address_to_string; |
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 98806fbb8..6c81acb49 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c | |||
@@ -695,8 +695,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
695 | end_badly_now (); | 695 | end_badly_now (); |
696 | return; | 696 | return; |
697 | } | 697 | } |
698 | GNUNET_assert (NULL != api->disconnect); | 698 | GNUNET_assert (NULL != api->disconnect_peer); |
699 | if (NULL == api->disconnect) | 699 | if (NULL == api->disconnect_peer) |
700 | { | 700 | { |
701 | GNUNET_break (0); | 701 | GNUNET_break (0); |
702 | end_badly_now (); | 702 | end_badly_now (); |