diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-09-07 13:18:41 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-09-07 13:18:41 +0000 |
commit | 087c350b59a24467dfc9d922270b288bb17eb241 (patch) | |
tree | 97cd8b61b5c6fc42e3106f3b5c7ce713e2706d95 /src/transport/plugin_transport_http.c | |
parent | c0ad7d994c1c7cb96a68a784f3b677f3de981f57 (diff) | |
download | gnunet-087c350b59a24467dfc9d922270b288bb17eb241.tar.gz gnunet-087c350b59a24467dfc9d922270b288bb17eb241.zip |
Improved documentation
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r-- | src/transport/plugin_transport_http.c | 183 |
1 files changed, 131 insertions, 52 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index d05f4e012..1fb318b85 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -321,6 +321,9 @@ struct Plugin | |||
321 | */ | 321 | */ |
322 | struct GNUNET_STATISTICS_Handle *stats; | 322 | struct GNUNET_STATISTICS_Handle *stats; |
323 | 323 | ||
324 | /** | ||
325 | * Plugin Port | ||
326 | */ | ||
324 | unsigned int port_inbound; | 327 | unsigned int port_inbound; |
325 | 328 | ||
326 | struct GNUNET_CONTAINER_MultiHashMap *peers; | 329 | struct GNUNET_CONTAINER_MultiHashMap *peers; |
@@ -361,11 +364,34 @@ struct Plugin | |||
361 | */ | 364 | */ |
362 | struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident; | 365 | struct GNUNET_CRYPTO_HashAsciiEncoded my_ascii_hash_ident; |
363 | 366 | ||
367 | /** | ||
368 | * IPv4 Address the plugin binds to | ||
369 | */ | ||
364 | struct sockaddr_in * bind4_address; | 370 | struct sockaddr_in * bind4_address; |
371 | |||
372 | /** | ||
373 | * IPv6 Address the plugins binds to | ||
374 | */ | ||
365 | struct sockaddr_in6 * bind6_address; | 375 | struct sockaddr_in6 * bind6_address; |
376 | |||
377 | /** | ||
378 | * Hostname to bind to | ||
379 | */ | ||
366 | char * bind_hostname; | 380 | char * bind_hostname; |
381 | |||
382 | /** | ||
383 | * Is IPv4 enabled? | ||
384 | */ | ||
367 | int use_ipv6; | 385 | int use_ipv6; |
386 | |||
387 | /** | ||
388 | * Is IPv6 enabled? | ||
389 | */ | ||
368 | int use_ipv4; | 390 | int use_ipv4; |
391 | |||
392 | /** | ||
393 | * Closure passed by MHD to the mhd_logger function | ||
394 | */ | ||
369 | void * mhd_log; | 395 | void * mhd_log; |
370 | }; | 396 | }; |
371 | 397 | ||
@@ -416,7 +442,14 @@ static ssize_t send_check_connections (void *cls, struct Session *ps); | |||
416 | static int curl_schedule(void *cls ); | 442 | static int curl_schedule(void *cls ); |
417 | 443 | ||
418 | 444 | ||
419 | 445 | /** | |
446 | * Creates a valid url from passed address and id | ||
447 | * @param cls plugin as closure | ||
448 | * @param addr address to create url from | ||
449 | * @param addrlen address lenth | ||
450 | * @param id session id | ||
451 | * @return the created url | ||
452 | */ | ||
420 | static char * create_url(void * cls, const void * addr, size_t addrlen, size_t id) | 453 | static char * create_url(void * cls, const void * addr, size_t addrlen, size_t id) |
421 | { | 454 | { |
422 | struct Plugin *plugin = cls; | 455 | struct Plugin *plugin = cls; |
@@ -444,7 +477,61 @@ static int remove_http_message (struct Session * ps, struct HTTP_Message * msg) | |||
444 | return GNUNET_OK; | 477 | return GNUNET_OK; |
445 | } | 478 | } |
446 | 479 | ||
447 | int remove_peer_context_Iterator (void *cls, const GNUNET_HashCode *key, void *value); | 480 | /** |
481 | * Iterator to remove peer context | ||
482 | * @param cls the plugin | ||
483 | * @key the peers public key hashcode | ||
484 | * @value the peer context | ||
485 | * @return GNUNET_YES on success | ||
486 | */ | ||
487 | int remove_peer_context_Iterator (void *cls, const GNUNET_HashCode *key, void *value) | ||
488 | { | ||
489 | struct Plugin *plugin = cls; | ||
490 | struct HTTP_PeerContext * pc = value; | ||
491 | struct Session * ps = pc->head; | ||
492 | struct Session * tmp = NULL; | ||
493 | struct HTTP_Message * msg = NULL; | ||
494 | struct HTTP_Message * msg_tmp = NULL; | ||
495 | #if DEBUG_HTTP | ||
496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing context for peer `%s'\n",GNUNET_i2s(&pc->identity)); | ||
497 | #endif | ||
498 | GNUNET_CONTAINER_multihashmap_remove (plugin->peers, &pc->identity.hashPubKey, pc); | ||
499 | while (ps!=NULL) | ||
500 | { | ||
501 | plugin->env->session_end(plugin, &pc->identity, ps); | ||
502 | tmp = ps->next; | ||
503 | |||
504 | GNUNET_free_non_null (ps->addr); | ||
505 | GNUNET_free(ps->url); | ||
506 | if (ps->msgtok != NULL) | ||
507 | GNUNET_SERVER_mst_destroy (ps->msgtok); | ||
508 | |||
509 | msg = ps->pending_msgs_head; | ||
510 | while (msg!=NULL) | ||
511 | { | ||
512 | msg_tmp = msg->next; | ||
513 | GNUNET_free(msg); | ||
514 | msg = msg_tmp; | ||
515 | } | ||
516 | if (ps->direction==OUTBOUND) | ||
517 | { | ||
518 | if (ps->send_endpoint!=NULL) | ||
519 | curl_easy_cleanup(ps->send_endpoint); | ||
520 | if (ps->recv_endpoint!=NULL) | ||
521 | curl_easy_cleanup(ps->recv_endpoint); | ||
522 | } | ||
523 | |||
524 | GNUNET_free(ps); | ||
525 | ps=tmp; | ||
526 | } | ||
527 | GNUNET_free(pc); | ||
528 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
529 | gettext_noop ("# HTTP peers active"), | ||
530 | -1, | ||
531 | GNUNET_NO); | ||
532 | return GNUNET_YES; | ||
533 | } | ||
534 | |||
448 | 535 | ||
449 | /** | 536 | /** |
450 | * Removes a session from the linked list of sessions | 537 | * Removes a session from the linked list of sessions |
@@ -510,53 +597,6 @@ static int remove_session (struct HTTP_PeerContext * pc, struct Session * ps, i | |||
510 | return GNUNET_OK; | 597 | return GNUNET_OK; |
511 | } | 598 | } |
512 | 599 | ||
513 | int remove_peer_context_Iterator (void *cls, const GNUNET_HashCode *key, void *value) | ||
514 | { | ||
515 | struct Plugin *plugin = cls; | ||
516 | struct HTTP_PeerContext * pc = value; | ||
517 | struct Session * ps = pc->head; | ||
518 | struct Session * tmp = NULL; | ||
519 | struct HTTP_Message * msg = NULL; | ||
520 | struct HTTP_Message * msg_tmp = NULL; | ||
521 | #if DEBUG_HTTP | ||
522 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Freeing context for peer `%s'\n",GNUNET_i2s(&pc->identity)); | ||
523 | #endif | ||
524 | GNUNET_CONTAINER_multihashmap_remove (plugin->peers, &pc->identity.hashPubKey, pc); | ||
525 | while (ps!=NULL) | ||
526 | { | ||
527 | plugin->env->session_end(plugin, &pc->identity, ps); | ||
528 | tmp = ps->next; | ||
529 | |||
530 | GNUNET_free_non_null (ps->addr); | ||
531 | GNUNET_free(ps->url); | ||
532 | if (ps->msgtok != NULL) | ||
533 | GNUNET_SERVER_mst_destroy (ps->msgtok); | ||
534 | |||
535 | msg = ps->pending_msgs_head; | ||
536 | while (msg!=NULL) | ||
537 | { | ||
538 | msg_tmp = msg->next; | ||
539 | GNUNET_free(msg); | ||
540 | msg = msg_tmp; | ||
541 | } | ||
542 | if (ps->direction==OUTBOUND) | ||
543 | { | ||
544 | if (ps->send_endpoint!=NULL) | ||
545 | curl_easy_cleanup(ps->send_endpoint); | ||
546 | if (ps->recv_endpoint!=NULL) | ||
547 | curl_easy_cleanup(ps->recv_endpoint); | ||
548 | } | ||
549 | |||
550 | GNUNET_free(ps); | ||
551 | ps=tmp; | ||
552 | } | ||
553 | GNUNET_free(pc); | ||
554 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
555 | gettext_noop ("# HTTP peers active"), | ||
556 | -1, | ||
557 | GNUNET_NO); | ||
558 | return GNUNET_YES; | ||
559 | } | ||
560 | 600 | ||
561 | /** | 601 | /** |
562 | * Add the IP of our network interface to the list of | 602 | * Add the IP of our network interface to the list of |
@@ -642,6 +682,13 @@ process_interfaces (void *cls, | |||
642 | return GNUNET_OK; | 682 | return GNUNET_OK; |
643 | } | 683 | } |
644 | 684 | ||
685 | |||
686 | /** | ||
687 | * External logging function for MHD | ||
688 | * @param arg arguments | ||
689 | * @param fmt format string | ||
690 | * @param ap list of arguments | ||
691 | */ | ||
645 | void mhd_logger (void * arg, const char * fmt, va_list ap) | 692 | void mhd_logger (void * arg, const char * fmt, va_list ap) |
646 | { | 693 | { |
647 | char text[1024]; | 694 | char text[1024]; |
@@ -652,6 +699,9 @@ void mhd_logger (void * arg, const char * fmt, va_list ap) | |||
652 | 699 | ||
653 | /** | 700 | /** |
654 | * Callback called by MHD when a connection is terminated | 701 | * Callback called by MHD when a connection is terminated |
702 | * @param cls closure | ||
703 | * @param connection the terminated connection | ||
704 | * @httpSessionCache the mhd session reference | ||
655 | */ | 705 | */ |
656 | static void mhd_termination_cb (void *cls, struct MHD_Connection * connection, void **httpSessionCache) | 706 | static void mhd_termination_cb (void *cls, struct MHD_Connection * connection, void **httpSessionCache) |
657 | { | 707 | { |
@@ -691,6 +741,13 @@ static void mhd_termination_cb (void *cls, struct MHD_Connection * connection, v | |||
691 | } | 741 | } |
692 | } | 742 | } |
693 | 743 | ||
744 | /** | ||
745 | * Callback called by MessageStreamTokenizer when a message has arrived | ||
746 | * @param cls current session as closure | ||
747 | * @param client clien | ||
748 | * @param message the message to be forwarded to transport service | ||
749 | */ | ||
750 | |||
694 | static void mhd_write_mst_cb (void *cls, | 751 | static void mhd_write_mst_cb (void *cls, |
695 | void *client, | 752 | void *client, |
696 | const struct GNUNET_MessageHeader *message) | 753 | const struct GNUNET_MessageHeader *message) |
@@ -717,7 +774,13 @@ static void mhd_write_mst_cb (void *cls, | |||
717 | } | 774 | } |
718 | 775 | ||
719 | /** | 776 | /** |
720 | * Check if ip is allowed to connect. | 777 | * Check if incoming connection is accepted. |
778 | * NOTE: Here every connection is accepted | ||
779 | * @param cls plugin as closure | ||
780 | * @param addr address of incoming connection | ||
781 | * @param addr_len address length of incoming connection | ||
782 | * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected | ||
783 | * | ||
721 | */ | 784 | */ |
722 | static int | 785 | static int |
723 | mhd_accept_cb (void *cls, | 786 | mhd_accept_cb (void *cls, |
@@ -730,6 +793,15 @@ mhd_accept_cb (void *cls, | |||
730 | return MHD_YES; | 793 | return MHD_YES; |
731 | } | 794 | } |
732 | 795 | ||
796 | |||
797 | /** | ||
798 | * Callback called by MHD when it needs data to send | ||
799 | * @param cls current session | ||
800 | * @param pos position in buffer | ||
801 | * @param buf the buffer to write data to | ||
802 | * @param max max number of bytes available in buffer | ||
803 | * @return bytes written to buffer | ||
804 | */ | ||
733 | int mhd_send_callback (void *cls, uint64_t pos, char *buf, int max) | 805 | int mhd_send_callback (void *cls, uint64_t pos, char *buf, int max) |
734 | { | 806 | { |
735 | int bytes_read = 0; | 807 | int bytes_read = 0; |
@@ -1019,6 +1091,9 @@ mdh_access_cb (void *cls, | |||
1019 | /** | 1091 | /** |
1020 | * Function that queries MHD's select sets and | 1092 | * Function that queries MHD's select sets and |
1021 | * starts the task waiting for them. | 1093 | * starts the task waiting for them. |
1094 | * @param cls plugin as closure | ||
1095 | * @param daemon_handle the MHD daemon handle | ||
1096 | * @return gnunet task identifier | ||
1022 | */ | 1097 | */ |
1023 | static GNUNET_SCHEDULER_TaskIdentifier | 1098 | static GNUNET_SCHEDULER_TaskIdentifier |
1024 | http_server_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | 1099 | http_server_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) |
@@ -1100,8 +1175,10 @@ http_server_daemon_prepare (void * cls, struct MHD_Daemon *daemon_handle) | |||
1100 | } | 1175 | } |
1101 | 1176 | ||
1102 | /** | 1177 | /** |
1103 | * Call MHD to process pending requests and then go back | 1178 | * Call MHD IPv4 to process pending requests and then go back |
1104 | * and schedule the next run. | 1179 | * and schedule the next run. |
1180 | * @param cls plugin as closure | ||
1181 | * @param tc task context | ||
1105 | */ | 1182 | */ |
1106 | static void http_server_daemon_v4_run (void *cls, | 1183 | static void http_server_daemon_v4_run (void *cls, |
1107 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1184 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
@@ -1121,8 +1198,10 @@ static void http_server_daemon_v4_run (void *cls, | |||
1121 | 1198 | ||
1122 | 1199 | ||
1123 | /** | 1200 | /** |
1124 | * Call MHD to process pending requests and then go back | 1201 | * Call MHD IPv6 to process pending requests and then go back |
1125 | * and schedule the next run. | 1202 | * and schedule the next run. |
1203 | * @param cls plugin as closure | ||
1204 | * @param tc task context | ||
1126 | */ | 1205 | */ |
1127 | static void http_server_daemon_v6_run (void *cls, | 1206 | static void http_server_daemon_v6_run (void *cls, |
1128 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1207 | const struct GNUNET_SCHEDULER_TaskContext *tc) |