aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c3934
1 files changed, 1980 insertions, 1954 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index e63549784..0c856e4ab 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -114,14 +114,14 @@ struct IPv4HttpAddressWrapper
114 /** 114 /**
115 * Linked list next 115 * Linked list next
116 */ 116 */
117 struct IPv4HttpAddressWrapper * next; 117 struct IPv4HttpAddressWrapper *next;
118 118
119 /** 119 /**
120 * Linked list previous 120 * Linked list previous
121 */ 121 */
122 struct IPv4HttpAddressWrapper * prev; 122 struct IPv4HttpAddressWrapper *prev;
123 123
124 struct IPv4HttpAddress * addr; 124 struct IPv4HttpAddress *addr;
125}; 125};
126 126
127/** 127/**
@@ -149,14 +149,14 @@ struct IPv6HttpAddressWrapper
149 /** 149 /**
150 * Linked list next 150 * Linked list next
151 */ 151 */
152 struct IPv6HttpAddressWrapper * next; 152 struct IPv6HttpAddressWrapper *next;
153 153
154 /** 154 /**
155 * Linked list previous 155 * Linked list previous
156 */ 156 */
157 struct IPv6HttpAddressWrapper * prev; 157 struct IPv6HttpAddressWrapper *prev;
158 158
159 struct IPv6HttpAddress * addr; 159 struct IPv6HttpAddress *addr;
160}; 160};
161 161
162/** 162/**
@@ -167,12 +167,12 @@ struct HTTP_Message
167 /** 167 /**
168 * next pointer for double linked list 168 * next pointer for double linked list
169 */ 169 */
170 struct HTTP_Message * next; 170 struct HTTP_Message *next;
171 171
172 /** 172 /**
173 * previous pointer for double linked list 173 * previous pointer for double linked list
174 */ 174 */
175 struct HTTP_Message * prev; 175 struct HTTP_Message *prev;
176 176
177 /** 177 /**
178 * buffer containing data to send 178 * buffer containing data to send
@@ -219,13 +219,13 @@ struct HTTP_PeerContext
219 * Linked list of connections with this peer 219 * Linked list of connections with this peer
220 * head 220 * head
221 */ 221 */
222 struct Session * head; 222 struct Session *head;
223 223
224 /** 224 /**
225 * Linked list of connections with this peer 225 * Linked list of connections with this peer
226 * tail 226 * tail
227 */ 227 */
228 struct Session * tail; 228 struct Session *tail;
229 229
230 /** 230 /**
231 * id for next session 231 * id for next session
@@ -235,7 +235,7 @@ struct HTTP_PeerContext
235 /** 235 /**
236 * Last session used to send data 236 * Last session used to send data
237 */ 237 */
238 struct Session * last_session; 238 struct Session *last_session;
239 239
240 /** 240 /**
241 * The task resetting inbound quota delay 241 * The task resetting inbound quota delay
@@ -259,17 +259,17 @@ struct Session
259 /** 259 /**
260 * next session in linked list 260 * next session in linked list
261 */ 261 */
262 struct Session * next; 262 struct Session *next;
263 263
264 /** 264 /**
265 * previous session in linked list 265 * previous session in linked list
266 */ 266 */
267 struct Session * prev; 267 struct Session *prev;
268 268
269 /** 269 /**
270 * address of this session 270 * address of this session
271 */ 271 */
272 void * addr; 272 void *addr;
273 273
274 /** 274 /**
275 * address length 275 * address length
@@ -279,24 +279,24 @@ struct Session
279 /** 279 /**
280 * target url 280 * target url
281 */ 281 */
282 char * url; 282 char *url;
283 283
284 /** 284 /**
285 * Message queue for outbound messages 285 * Message queue for outbound messages
286 * head of queue 286 * head of queue
287 */ 287 */
288 struct HTTP_Message * pending_msgs_head; 288 struct HTTP_Message *pending_msgs_head;
289 289
290 /** 290 /**
291 * Message queue for outbound messages 291 * Message queue for outbound messages
292 * tail of queue 292 * tail of queue
293 */ 293 */
294 struct HTTP_Message * pending_msgs_tail; 294 struct HTTP_Message *pending_msgs_tail;
295 295
296 /** 296 /**
297 * partner peer this connection belongs to 297 * partner peer this connection belongs to
298 */ 298 */
299 struct HTTP_PeerContext * peercontext; 299 struct HTTP_PeerContext *peercontext;
300 300
301 /** 301 /**
302 * message stream tokenizer for incoming data 302 * message stream tokenizer for incoming data
@@ -352,14 +352,14 @@ struct Session
352 * outbound session: CURL * 352 * outbound session: CURL *
353 * inbound session: mhd_connection * 353 * inbound session: mhd_connection *
354 */ 354 */
355 void * send_endpoint; 355 void *send_endpoint;
356 356
357 /** 357 /**
358 * entity managing recieving data 358 * entity managing recieving data
359 * outbound session: CURL * 359 * outbound session: CURL *
360 * inbound session: mhd_connection * 360 * inbound session: mhd_connection *
361 */ 361 */
362 void * recv_endpoint; 362 void *recv_endpoint;
363 363
364 /** 364 /**
365 * Current queue size 365 * Current queue size
@@ -423,7 +423,7 @@ struct Plugin
423 /** 423 /**
424 * cURL Multihandle 424 * cURL Multihandle
425 */ 425 */
426 CURLM * multi_handle; 426 CURLM *multi_handle;
427 427
428 /** 428 /**
429 * Our handle to the NAT module. 429 * Our handle to the NAT module.
@@ -433,22 +433,22 @@ struct Plugin
433 /** 433 /**
434 * ipv4 DLL head 434 * ipv4 DLL head
435 */ 435 */
436 struct IPv4HttpAddressWrapper * ipv4_addr_head; 436 struct IPv4HttpAddressWrapper *ipv4_addr_head;
437 437
438 /** 438 /**
439 * ipv4 DLL tail 439 * ipv4 DLL tail
440 */ 440 */
441 struct IPv4HttpAddressWrapper * ipv4_addr_tail; 441 struct IPv4HttpAddressWrapper *ipv4_addr_tail;
442 442
443 /** 443 /**
444 * ipv6 DLL head 444 * ipv6 DLL head
445 */ 445 */
446 struct IPv6HttpAddressWrapper * ipv6_addr_head; 446 struct IPv6HttpAddressWrapper *ipv6_addr_head;
447 447
448 /** 448 /**
449 * ipv6 DLL tail 449 * ipv6 DLL tail
450 */ 450 */
451 struct IPv6HttpAddressWrapper * ipv6_addr_tail; 451 struct IPv6HttpAddressWrapper *ipv6_addr_tail;
452 452
453 /** 453 /**
454 * Our ASCII encoded, hashed peer identity 454 * Our ASCII encoded, hashed peer identity
@@ -459,17 +459,17 @@ struct Plugin
459 /** 459 /**
460 * IPv4 Address the plugin binds to 460 * IPv4 Address the plugin binds to
461 */ 461 */
462 struct sockaddr_in * bind4_address; 462 struct sockaddr_in *bind4_address;
463 463
464 /** 464 /**
465 * IPv6 Address the plugins binds to 465 * IPv6 Address the plugins binds to
466 */ 466 */
467 struct sockaddr_in6 * bind6_address; 467 struct sockaddr_in6 *bind6_address;
468 468
469 /** 469 /**
470 * Hostname to bind to 470 * Hostname to bind to
471 */ 471 */
472 char * bind_hostname; 472 char *bind_hostname;
473 473
474 /** 474 /**
475 * Is IPv4 enabled? 475 * Is IPv4 enabled?
@@ -499,18 +499,18 @@ struct Plugin
499 /** 499 /**
500 * Closure passed by MHD to the mhd_logger function 500 * Closure passed by MHD to the mhd_logger function
501 */ 501 */
502 void * mhd_log; 502 void *mhd_log;
503 503
504 /* only needed for HTTPS plugin */ 504 /* only needed for HTTPS plugin */
505#if BUILD_HTTPS 505#if BUILD_HTTPS
506 /* The certificate MHD uses as an \0 terminated string */ 506 /* The certificate MHD uses as an \0 terminated string */
507 char * cert; 507 char *cert;
508 508
509 /* The private key MHD uses as an \0 terminated string */ 509 /* The private key MHD uses as an \0 terminated string */
510 char * key; 510 char *key;
511 511
512 /* crypto init string */ 512 /* crypto init string */
513 char * crypto_init; 513 char *crypto_init;
514#endif 514#endif
515}; 515};
516 516
@@ -547,22 +547,25 @@ struct PrettyPrinterContext
547 * @param addrlen length of the address 547 * @param addrlen length of the address
548 * @return string representing the same address 548 * @return string representing the same address
549 */ 549 */
550static const char* 550static const char *http_plugin_address_to_string (void *cls,
551http_plugin_address_to_string (void *cls, 551 const void *addr,
552 const void *addr, 552 size_t addrlen);
553 size_t addrlen);
554 553
555 554
556/** 555/**
557 * Call MHD to process pending ipv4 requests and then go back 556 * Call MHD to process pending ipv4 requests and then go back
558 * and schedule the next run. 557 * and schedule the next run.
559 */ 558 */
560static void http_server_daemon_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 559static void http_server_daemon_v4_run (void *cls,
560 const struct GNUNET_SCHEDULER_TaskContext
561 *tc);
561/** 562/**
562 * Call MHD to process pending ipv6 requests and then go back 563 * Call MHD to process pending ipv6 requests and then go back
563 * and schedule the next run. 564 * and schedule the next run.
564 */ 565 */
565static void http_server_daemon_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 566static void http_server_daemon_v6_run (void *cls,
567 const struct GNUNET_SCHEDULER_TaskContext
568 *tc);
566 569
567/** 570/**
568 * Function setting up curl handle and selecting message to send 571 * Function setting up curl handle and selecting message to send
@@ -586,12 +589,13 @@ static int curl_schedule (struct Plugin *plugin);
586 * @param cls plugin as closure 589 * @param cls plugin as closure
587 * @param tc task context 590 * @param tc task context
588 */ 591 */
589static void reset_inbound_quota_delay (void *cls, 592static void
590 const struct GNUNET_SCHEDULER_TaskContext *tc) 593reset_inbound_quota_delay (void *cls,
594 const struct GNUNET_SCHEDULER_TaskContext *tc)
591{ 595{
592 struct HTTP_PeerContext * pc = cls; 596 struct HTTP_PeerContext *pc = cls;
593 597
594 GNUNET_assert(cls != NULL); 598 GNUNET_assert (cls != NULL);
595 pc->reset_task = GNUNET_SCHEDULER_NO_TASK; 599 pc->reset_task = GNUNET_SCHEDULER_NO_TASK;
596 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 600 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
597 return; 601 return;
@@ -607,18 +611,16 @@ static void reset_inbound_quota_delay (void *cls,
607 * @param id session id 611 * @param id session id
608 * @return the created url 612 * @return the created url
609 */ 613 */
610static char * 614static char *
611create_url(struct Plugin *plugin, 615create_url (struct Plugin *plugin, const void *addr, size_t addrlen, size_t id)
612 const void * addr, size_t addrlen,
613 size_t id)
614{ 616{
615 char *url = NULL; 617 char *url = NULL;
616 char *addr_str = (char *) http_plugin_address_to_string(NULL, addr, addrlen); 618 char *addr_str = (char *) http_plugin_address_to_string (NULL, addr, addrlen);
617 619
618 GNUNET_assert ((addr!=NULL) && (addrlen != 0)); 620 GNUNET_assert ((addr != NULL) && (addrlen != 0));
619 GNUNET_asprintf(&url, 621 GNUNET_asprintf (&url,
620 "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str, 622 "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str,
621 (char *) (&plugin->my_ascii_hash_ident),id); 623 (char *) (&plugin->my_ascii_hash_ident), id);
622 return url; 624 return url;
623} 625}
624 626
@@ -629,14 +631,12 @@ create_url(struct Plugin *plugin,
629 * @param msg message 631 * @param msg message
630 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success 632 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
631 */ 633 */
632static int 634static int
633remove_http_message (struct Session * ps, 635remove_http_message (struct Session *ps, struct HTTP_Message *msg)
634 struct HTTP_Message * msg)
635{ 636{
636 GNUNET_CONTAINER_DLL_remove(ps->pending_msgs_head, 637 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head,
637 ps->pending_msgs_tail, 638 ps->pending_msgs_tail, msg);
638 msg); 639 GNUNET_free (msg);
639 GNUNET_free(msg);
640 return GNUNET_OK; 640 return GNUNET_OK;
641} 641}
642 642
@@ -647,59 +647,56 @@ remove_http_message (struct Session * ps,
647 * @param value the peer context 647 * @param value the peer context
648 * @return GNUNET_YES on success 648 * @return GNUNET_YES on success
649 */ 649 */
650static int 650static int
651remove_peer_context_Iterator (void *cls, 651remove_peer_context_Iterator (void *cls,
652 const GNUNET_HashCode *key, 652 const GNUNET_HashCode * key, void *value)
653 void *value)
654{ 653{
655 struct Plugin *plugin = cls; 654 struct Plugin *plugin = cls;
656 struct HTTP_PeerContext * pc = value; 655 struct HTTP_PeerContext *pc = value;
657 struct Session * ps = pc->head; 656 struct Session *ps = pc->head;
658 struct Session * tmp = NULL; 657 struct Session *tmp = NULL;
659 struct HTTP_Message * msg = NULL; 658 struct HTTP_Message *msg = NULL;
660 struct HTTP_Message * msg_tmp = NULL; 659 struct HTTP_Message *msg_tmp = NULL;
661 660
662#if DEBUG_HTTP 661#if DEBUG_HTTP
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
664 "Freeing context for peer `%s'\n", 663 "Freeing context for peer `%s'\n", GNUNET_i2s (&pc->identity));
665 GNUNET_i2s(&pc->identity));
666#endif 664#endif
667 GNUNET_assert (GNUNET_YES == 665 GNUNET_assert (GNUNET_YES ==
668 GNUNET_CONTAINER_multihashmap_remove (plugin->peers, 666 GNUNET_CONTAINER_multihashmap_remove (plugin->peers,
669 &pc->identity.hashPubKey, 667 &pc->identity.hashPubKey,
670 pc)); 668 pc));
671 while (ps!=NULL) 669 while (ps != NULL)
670 {
671 plugin->env->session_end (plugin, &pc->identity, ps);
672 tmp = ps->next;
673
674 GNUNET_free_non_null (ps->addr);
675 GNUNET_free (ps->url);
676 if (ps->msgtok != NULL)
677 GNUNET_SERVER_mst_destroy (ps->msgtok);
678
679 msg = ps->pending_msgs_head;
680 while (msg != NULL)
672 { 681 {
673 plugin->env->session_end(plugin, &pc->identity, ps); 682 msg_tmp = msg->next;
674 tmp = ps->next; 683 GNUNET_free (msg);
675 684 msg = msg_tmp;
676 GNUNET_free_non_null (ps->addr); 685 }
677 GNUNET_free(ps->url); 686 if (ps->direction == OUTBOUND)
678 if (ps->msgtok != NULL) 687 {
679 GNUNET_SERVER_mst_destroy (ps->msgtok); 688 if (ps->send_endpoint != NULL)
680 689 curl_easy_cleanup (ps->send_endpoint);
681 msg = ps->pending_msgs_head; 690 if (ps->recv_endpoint != NULL)
682 while (msg!=NULL) 691 curl_easy_cleanup (ps->recv_endpoint);
683 {
684 msg_tmp = msg->next;
685 GNUNET_free(msg);
686 msg = msg_tmp;
687 }
688 if (ps->direction==OUTBOUND)
689 {
690 if (ps->send_endpoint!=NULL)
691 curl_easy_cleanup(ps->send_endpoint);
692 if (ps->recv_endpoint!=NULL)
693 curl_easy_cleanup(ps->recv_endpoint);
694 }
695 GNUNET_free(ps);
696 ps=tmp;
697 } 692 }
698 GNUNET_free(pc); 693 GNUNET_free (ps);
694 ps = tmp;
695 }
696 GNUNET_free (pc);
699 GNUNET_STATISTICS_update (plugin->env->stats, 697 GNUNET_STATISTICS_update (plugin->env->stats,
700 gettext_noop ("# HTTP peers active"), 698 gettext_noop ("# HTTP peers active"),
701 -1, 699 -1, GNUNET_NO);
702 GNUNET_NO);
703 return GNUNET_YES; 700 return GNUNET_YES;
704} 701}
705 702
@@ -712,115 +709,114 @@ remove_peer_context_Iterator (void *cls,
712 * @param call_msg_cont_result result to call message continuations with 709 * @param call_msg_cont_result result to call message continuations with
713 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success 710 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
714 */ 711 */
715static int 712static int
716remove_session (struct HTTP_PeerContext * pc, 713remove_session (struct HTTP_PeerContext *pc,
717 struct Session * ps, 714 struct Session *ps, int call_msg_cont, int call_msg_cont_result)
718 int call_msg_cont,
719 int call_msg_cont_result)
720{ 715{
721 struct HTTP_Message * msg; 716 struct HTTP_Message *msg;
722 struct Plugin * plugin = ps->peercontext->plugin; 717 struct Plugin *plugin = ps->peercontext->plugin;
723 718
724#if DEBUG_CONNECTIONS 719#if DEBUG_CONNECTIONS
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Connection %X: removing %s session %X with id %u\n", 721 "Connection %X: removing %s session %X with id %u\n",
727 ps, 722 ps,
728 (ps->direction == INBOUND) 723 (ps->direction == INBOUND)
729 ? "inbound" 724 ? "inbound" : "outbound", ps, ps->session_id);
730 : "outbound", 725#endif
731 ps, ps->session_id); 726 plugin->env->session_end (plugin, &pc->identity, ps);
732#endif
733 plugin->env->session_end(plugin, &pc->identity, ps);
734 GNUNET_free_non_null (ps->addr); 727 GNUNET_free_non_null (ps->addr);
735 GNUNET_SERVER_mst_destroy (ps->msgtok); 728 GNUNET_SERVER_mst_destroy (ps->msgtok);
736 GNUNET_free(ps->url); 729 GNUNET_free (ps->url);
737 if (ps->direction==INBOUND) 730 if (ps->direction == INBOUND)
731 {
732 if (ps->recv_endpoint != NULL)
738 { 733 {
739 if (ps->recv_endpoint != NULL) 734 curl_easy_cleanup (ps->recv_endpoint);
740 { 735 ps->recv_endpoint = NULL;
741 curl_easy_cleanup(ps->recv_endpoint); 736 }
742 ps->recv_endpoint = NULL; 737 if (ps->send_endpoint != NULL)
743 } 738 {
744 if (ps->send_endpoint != NULL) 739 curl_easy_cleanup (ps->send_endpoint);
745 { 740 ps->send_endpoint = NULL;
746 curl_easy_cleanup(ps->send_endpoint);
747 ps->send_endpoint = NULL;
748 }
749 } 741 }
750 742 }
743
751 msg = ps->pending_msgs_head; 744 msg = ps->pending_msgs_head;
752 while (msg!=NULL) 745 while (msg != NULL)
746 {
747 if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont != NULL))
753 { 748 {
754 if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont!=NULL)) 749 msg->transmit_cont (msg->transmit_cont_cls,
755 { 750 &pc->identity, call_msg_cont_result);
756 msg->transmit_cont (msg->transmit_cont_cls,
757 &pc->identity,
758 call_msg_cont_result);
759 }
760 GNUNET_CONTAINER_DLL_remove(ps->pending_msgs_head,
761 ps->pending_msgs_head,
762 msg);
763 GNUNET_free(msg);
764 msg = ps->pending_msgs_head;
765 } 751 }
766 752 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head,
767 GNUNET_CONTAINER_DLL_remove(pc->head,pc->tail,ps); 753 ps->pending_msgs_head, msg);
768 GNUNET_free(ps); 754 GNUNET_free (msg);
755 msg = ps->pending_msgs_head;
756 }
757
758 GNUNET_CONTAINER_DLL_remove (pc->head, pc->tail, ps);
759 GNUNET_free (ps);
769 ps = NULL; 760 ps = NULL;
770 761
771 /* no sessions left remove peer */ 762 /* no sessions left remove peer */
772 if (pc->head==NULL) 763 if (pc->head == NULL)
773 { 764 {
774#if DEBUG_HTTP 765#if DEBUG_HTTP
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
776 "No sessions left for peer `%s', removing context\n", 767 "No sessions left for peer `%s', removing context\n",
777 GNUNET_i2s(&pc->identity)); 768 GNUNET_i2s (&pc->identity));
778#endif 769#endif
779 remove_peer_context_Iterator(plugin, &pc->identity.hashPubKey, pc); 770 remove_peer_context_Iterator (plugin, &pc->identity.hashPubKey, pc);
780 } 771 }
781 772
782 return GNUNET_OK; 773 return GNUNET_OK;
783} 774}
784 775
785 776
786#if 0 777#if 0
787static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) 778static int
779check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
788{ 780{
789 uint32_t res = 0; 781 uint32_t res = 0;
790 int local = GNUNET_NO; 782 int local = GNUNET_NO;
791 int af = addr->sa_family; 783 int af = addr->sa_family;
792 switch (af) 784
793 { 785 switch (af)
794 case AF_INET: 786 {
795 { 787 case AF_INET:
796 uint32_t netmask = 0x7F000000; 788 {
797 uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr); 789 uint32_t netmask = 0x7F000000;
798 res = (address >> 24) ^ (netmask >> 24); 790 uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
799 if (res != 0) 791
800 local = GNUNET_NO; 792 res = (address >> 24) ^ (netmask >> 24);
801 else 793 if (res != 0)
802 local = GNUNET_YES; 794 local = GNUNET_NO;
795 else
796 local = GNUNET_YES;
803#if DEBUG_HTTP 797#if DEBUG_HTTP
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
805 "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); 799 "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen),
800 (local == GNUNET_YES) ? "local" : "global");
806#endif 801#endif
807 break; 802 break;
808 } 803 }
809 case AF_INET6: 804 case AF_INET6:
810 { 805 {
811 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) || 806 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
812 IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) 807 IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
813 local = GNUNET_YES; 808 local = GNUNET_YES;
814 else 809 else
815 local = GNUNET_NO; 810 local = GNUNET_NO;
816#if DEBUG_HTTP 811#if DEBUG_HTTP
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
818 "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); 813 "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen),
814 (local == GNUNET_YES) ? "local" : "global");
819#endif 815#endif
820 break; 816 break;
821 } 817 }
822 } 818 }
823 return local; 819 return local;
824} 820}
825 821
826 822
@@ -842,99 +838,103 @@ process_interfaces (void *cls,
842 const struct sockaddr *addr, socklen_t addrlen) 838 const struct sockaddr *addr, socklen_t addrlen)
843{ 839{
844 struct Plugin *plugin = cls; 840 struct Plugin *plugin = cls;
845 struct IPv4HttpAddress * t4; 841 struct IPv4HttpAddress *t4;
846 struct IPv6HttpAddress * t6; 842 struct IPv6HttpAddress *t6;
847 int af; 843 int af;
848 844
849 if (plugin->use_localaddresses == GNUNET_NO) 845 if (plugin->use_localaddresses == GNUNET_NO)
850 { 846 {
851 if (GNUNET_YES == check_localaddress (addr, addrlen)) 847 if (GNUNET_YES == check_localaddress (addr, addrlen))
852 { 848 {
853#if DEBUG_HTTP 849#if DEBUG_HTTP
854 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 850 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
855 PROTOCOL_PREFIX, 851 PROTOCOL_PREFIX,
856 "Not notifying transport of address `%s' (local address)\n", 852 "Not notifying transport of address `%s' (local address)\n",
857 GNUNET_a2s (addr, addrlen)); 853 GNUNET_a2s (addr, addrlen));
858#endif 854#endif
859 return GNUNET_OK; 855 return GNUNET_OK;
860 } 856 }
861 } 857 }
862 858
863 859
864 GNUNET_assert(cls !=NULL); 860 GNUNET_assert (cls != NULL);
865 af = addr->sa_family; 861 af = addr->sa_family;
866 if ((af == AF_INET) && 862 if ((af == AF_INET) &&
867 (plugin->use_ipv4 == GNUNET_YES) && 863 (plugin->use_ipv4 == GNUNET_YES) && (plugin->bind6_address == NULL))
868 (plugin->bind6_address == NULL) ) { 864 {
869 865
870 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr; 866 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
871 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
872 // Not skipping loopback addresses
873 867
868 t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
869 // Not skipping loopback addresses
874 870
875 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 871
876 t4->port = htons (plugin->port_inbound); 872 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
877 if (plugin->bind4_address != NULL) { 873 t4->port = htons (plugin->port_inbound);
878 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) 874 if (plugin->bind4_address != NULL)
879 { 875 {
880 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, 876 if (0 ==
881 plugin->ipv4_addr_tail,t4); 877 memcmp (&plugin->bind4_address->sin_addr, &bnd_cmp,
882 plugin->env->notify_address(plugin->env->cls, 878 sizeof (struct in_addr)))
883 GNUNET_YES, 879 {
884 t4, sizeof (struct IPv4HttpAddress)); 880 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
885 return GNUNET_OK; 881 plugin->ipv4_addr_tail, t4);
886 } 882 plugin->env->notify_address (plugin->env->cls,
887 GNUNET_free (t4); 883 GNUNET_YES,
888 return GNUNET_OK; 884 t4, sizeof (struct IPv4HttpAddress));
885 return GNUNET_OK;
889 } 886 }
890 else 887 GNUNET_free (t4);
891 { 888 return GNUNET_OK;
892 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 889 }
893 plugin->ipv4_addr_tail, 890 else
894 t4); 891 {
895 plugin->env->notify_address(plugin->env->cls, 892 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
896 GNUNET_YES, 893 plugin->ipv4_addr_tail, t4);
897 t4, sizeof (struct IPv4HttpAddress)); 894 plugin->env->notify_address (plugin->env->cls,
898 return GNUNET_OK; 895 GNUNET_YES,
899 } 896 t4, sizeof (struct IPv4HttpAddress));
900 } 897 return GNUNET_OK;
901 if ((af == AF_INET6) && 898 }
902 (plugin->use_ipv6 == GNUNET_YES) && 899 }
903 (plugin->bind4_address == NULL) ) { 900 if ((af == AF_INET6) &&
904 901 (plugin->use_ipv6 == GNUNET_YES) && (plugin->bind4_address == NULL))
905 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr; 902 {
906
907 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
908 GNUNET_assert(t6 != NULL);
909
910 if (plugin->bind6_address != NULL) {
911 if (0 == memcmp(&plugin->bind6_address->sin6_addr,
912 &bnd_cmp6,
913 sizeof (struct in6_addr))) {
914 memcpy (&t6->ipv6_addr,
915 &((struct sockaddr_in6 *) addr)->sin6_addr,
916 sizeof (struct in6_addr));
917 t6->port = htons (plugin->port_inbound);
918 plugin->env->notify_address(plugin->env->cls,
919 GNUNET_YES,
920 t6, sizeof (struct IPv6HttpAddress));
921 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,
922 plugin->ipv6_addr_tail,
923 t6);
924 return GNUNET_OK;
925 }
926 GNUNET_free (t6);
927 return GNUNET_OK;
928 }
929 memcpy (&t6->ipv6_addr,
930 &((struct sockaddr_in6 *) addr)->sin6_addr,
931 sizeof (struct in6_addr));
932 t6->port = htons (plugin->port_inbound);
933 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
934 903
935 plugin->env->notify_address(plugin->env->cls, 904 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
936 GNUNET_YES, 905
937 t6, sizeof (struct IPv6HttpAddress)); 906 t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
907 GNUNET_assert (t6 != NULL);
908
909 if (plugin->bind6_address != NULL)
910 {
911 if (0 == memcmp (&plugin->bind6_address->sin6_addr,
912 &bnd_cmp6, sizeof (struct in6_addr)))
913 {
914 memcpy (&t6->ipv6_addr,
915 &((struct sockaddr_in6 *) addr)->sin6_addr,
916 sizeof (struct in6_addr));
917 t6->port = htons (plugin->port_inbound);
918 plugin->env->notify_address (plugin->env->cls,
919 GNUNET_YES,
920 t6, sizeof (struct IPv6HttpAddress));
921 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
922 plugin->ipv6_addr_tail, t6);
923 return GNUNET_OK;
924 }
925 GNUNET_free (t6);
926 return GNUNET_OK;
927 }
928 memcpy (&t6->ipv6_addr,
929 &((struct sockaddr_in6 *) addr)->sin6_addr,
930 sizeof (struct in6_addr));
931 t6->port = htons (plugin->port_inbound);
932 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
933 t6);
934
935 plugin->env->notify_address (plugin->env->cls,
936 GNUNET_YES,
937 t6, sizeof (struct IPv6HttpAddress));
938 } 938 }
939 return GNUNET_OK; 939 return GNUNET_OK;
940} 940}
@@ -946,69 +946,62 @@ process_interfaces (void *cls,
946 * @param fmt format string 946 * @param fmt format string
947 * @param ap list of arguments 947 * @param ap list of arguments
948 */ 948 */
949static void 949static void
950mhd_logger (void * arg, 950mhd_logger (void *arg, const char *fmt, va_list ap)
951 const char * fmt,
952 va_list ap)
953{ 951{
954 char text[1024]; 952 char text[1024];
955 953
956 vsnprintf(text, sizeof(text), fmt, ap); 954 vsnprintf (text, sizeof (text), fmt, ap);
957 va_end(ap); 955 va_end (ap);
958 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MHD: %s\n", text);
959 "MHD: %s\n",
960 text);
961} 957}
962 958
963 959
964static void 960static void
965mhd_termination_cb (void *cls, 961mhd_termination_cb (void *cls,
966 struct MHD_Connection * connection, 962 struct MHD_Connection *connection, void **httpSessionCache)
967 void **httpSessionCache)
968{ 963{
969 struct Session * ps = *httpSessionCache; 964 struct Session *ps = *httpSessionCache;
965
970 if (ps == NULL) 966 if (ps == NULL)
971 return; 967 return;
972 struct HTTP_PeerContext * pc = ps->peercontext; 968 struct HTTP_PeerContext *pc = ps->peercontext;
973 struct Plugin *plugin = cls; 969 struct Plugin *plugin = cls;
974 970
975 GNUNET_assert (cls != NULL); 971 GNUNET_assert (cls != NULL);
976 plugin->current_connections--; 972 plugin->current_connections--;
977 973
978 if (connection==ps->recv_endpoint) 974 if (connection == ps->recv_endpoint)
979 { 975 {
980#if DEBUG_CONNECTIONS 976#if DEBUG_CONNECTIONS
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "Connection %X: inbound connection from peer `%s' was terminated\n", 978 "Connection %X: inbound connection from peer `%s' was terminated\n",
983 ps, 979 ps, GNUNET_i2s (&pc->identity));
984 GNUNET_i2s(&pc->identity));
985#endif 980#endif
986 ps->recv_active = GNUNET_NO; 981 ps->recv_active = GNUNET_NO;
987 ps->recv_connected = GNUNET_NO; 982 ps->recv_connected = GNUNET_NO;
988 ps->recv_endpoint = NULL; 983 ps->recv_endpoint = NULL;
989 } 984 }
990 if (connection==ps->send_endpoint) 985 if (connection == ps->send_endpoint)
991 { 986 {
992 ps->send_active = GNUNET_NO; 987 ps->send_active = GNUNET_NO;
993 ps->send_connected = GNUNET_NO; 988 ps->send_connected = GNUNET_NO;
994 ps->send_endpoint = NULL; 989 ps->send_endpoint = NULL;
995#if DEBUG_CONNECTIONS 990#if DEBUG_CONNECTIONS
996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
997 "Connection %X: outbound connection from peer `%s' was terminated\n", 992 "Connection %X: outbound connection from peer `%s' was terminated\n",
998 ps, 993 ps, GNUNET_i2s (&pc->identity));
999 GNUNET_i2s(&pc->identity));
1000#endif 994#endif
1001 } 995 }
1002 996
1003 /* if both connections disconnected, remove session */ 997 /* if both connections disconnected, remove session */
1004 if ( (ps->send_connected == GNUNET_NO) && 998 if ((ps->send_connected == GNUNET_NO) && (ps->recv_connected == GNUNET_NO))
1005 (ps->recv_connected == GNUNET_NO) )
1006 { 999 {
1007 GNUNET_STATISTICS_update (pc->plugin->env->stats, 1000 GNUNET_STATISTICS_update (pc->plugin->env->stats,
1008 gettext_noop ("# HTTP inbound sessions for peers active"), 1001 gettext_noop
1009 -1, 1002 ("# HTTP inbound sessions for peers active"), -1,
1010 GNUNET_NO); 1003 GNUNET_NO);
1011 remove_session(pc,ps,GNUNET_YES,GNUNET_SYSERR); 1004 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
1012 } 1005 }
1013} 1006}
1014 1007
@@ -1019,54 +1012,52 @@ mhd_termination_cb (void *cls,
1019 * @param client clien 1012 * @param client clien
1020 * @param message the message to be forwarded to transport service 1013 * @param message the message to be forwarded to transport service
1021 */ 1014 */
1022static void 1015static void
1023mhd_write_mst_cb (void *cls, 1016mhd_write_mst_cb (void *cls,
1024 void *client, 1017 void *client, const struct GNUNET_MessageHeader *message)
1025 const struct GNUNET_MessageHeader *message)
1026{ 1018{
1027 struct Session *ps = cls; 1019 struct Session *ps = cls;
1028 struct HTTP_PeerContext *pc; 1020 struct HTTP_PeerContext *pc;
1029 struct GNUNET_TIME_Relative delay; 1021 struct GNUNET_TIME_Relative delay;
1030 1022
1031 GNUNET_assert(ps != NULL); 1023 GNUNET_assert (ps != NULL);
1032 pc = ps->peercontext; 1024 pc = ps->peercontext;
1033 GNUNET_assert(pc != NULL); 1025 GNUNET_assert (pc != NULL);
1034#if DEBUG_HTTP 1026#if DEBUG_HTTP
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1028 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1037 ps, 1029 ps,
1038 ntohs(message->type), 1030 ntohs (message->type),
1039 ntohs(message->size), 1031 ntohs (message->size),
1040 GNUNET_i2s(&(ps->peercontext)->identity), 1032 GNUNET_i2s (&(ps->peercontext)->identity),
1041 http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); 1033 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1042#endif 1034#endif
1043 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1035 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1036
1044 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 1037 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1045 distance[0].value = htonl (1); 1038 distance[0].value = htonl (1);
1046 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1039 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1047 distance[1].value = htonl (0); 1040 distance[1].value = htonl (0);
1048 delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls, 1041 delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls,
1049 &pc->identity, 1042 &pc->identity,
1050 message, 1043 message,
1051 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 1044 (const struct
1052 2, 1045 GNUNET_TRANSPORT_ATS_Information *)
1053 ps, 1046 &distance, 2, ps, NULL, 0);
1054 NULL,
1055 0);
1056 pc->delay = delay; 1047 pc->delay = delay;
1057 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) 1048 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
1058 GNUNET_SCHEDULER_cancel (pc->reset_task); 1049 GNUNET_SCHEDULER_cancel (pc->reset_task);
1059 1050
1060 if (delay.rel_value > 0) 1051 if (delay.rel_value > 0)
1061 { 1052 {
1062#if DEBUG_HTTP 1053#if DEBUG_HTTP
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1064 "Connection %X: Inbound quota management: delay next read for %llu ms \n", 1055 "Connection %X: Inbound quota management: delay next read for %llu ms \n",
1065 ps, 1056 ps, delay.rel_value);
1066 delay.rel_value);
1067#endif 1057#endif
1068 pc->reset_task = GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc); 1058 pc->reset_task =
1069 } 1059 GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc);
1060 }
1070} 1061}
1071 1062
1072 1063
@@ -1080,19 +1071,19 @@ mhd_write_mst_cb (void *cls,
1080 * 1071 *
1081 */ 1072 */
1082static int 1073static int
1083mhd_accept_cb (void *cls, 1074mhd_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
1084 const struct sockaddr *addr,
1085 socklen_t addr_len)
1086{ 1075{
1087 struct Plugin *plugin = cls; 1076 struct Plugin *plugin = cls;
1077
1088 GNUNET_assert (cls != NULL); 1078 GNUNET_assert (cls != NULL);
1089 1079
1090 if (plugin->max_connect_per_transport > plugin->current_connections) 1080 if (plugin->max_connect_per_transport > plugin->current_connections)
1091 { 1081 {
1092 plugin->current_connections ++; 1082 plugin->current_connections++;
1093 return MHD_YES; 1083 return MHD_YES;
1094 } 1084 }
1095 else return MHD_NO; 1085 else
1086 return MHD_NO;
1096} 1087}
1097 1088
1098 1089
@@ -1107,55 +1098,52 @@ mhd_accept_cb (void *cls,
1107static ssize_t 1098static ssize_t
1108mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max) 1099mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1109{ 1100{
1110 struct Session * ps = cls; 1101 struct Session *ps = cls;
1111 struct HTTP_PeerContext * pc; 1102 struct HTTP_PeerContext *pc;
1112 struct HTTP_Message * msg; 1103 struct HTTP_Message *msg;
1113 int bytes_read = 0; 1104 int bytes_read = 0;
1114 1105
1115 GNUNET_assert (ps!=NULL); 1106 GNUNET_assert (ps != NULL);
1116 1107
1117 pc = ps->peercontext; 1108 pc = ps->peercontext;
1118 msg = ps->pending_msgs_tail; 1109 msg = ps->pending_msgs_tail;
1119 if (ps->send_force_disconnect==GNUNET_YES) 1110 if (ps->send_force_disconnect == GNUNET_YES)
1120 { 1111 {
1121#if DEBUG_CONNECTIONS 1112#if DEBUG_CONNECTIONS
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "Connection %X: outbound forced to disconnect\n", 1114 "Connection %X: outbound forced to disconnect\n", ps);
1124 ps);
1125#endif 1115#endif
1126 return -1; 1116 return -1;
1117 }
1118
1119 if (msg != NULL)
1120 {
1121 /* sending */
1122 if ((msg->size - msg->pos) <= max)
1123 {
1124 memcpy (buf, &msg->buf[msg->pos], (msg->size - msg->pos));
1125 bytes_read = msg->size - msg->pos;
1126 msg->pos += (msg->size - msg->pos);
1127 } 1127 }
1128 1128 else
1129 if (msg!=NULL)
1130 { 1129 {
1131 /* sending */ 1130 memcpy (buf, &msg->buf[msg->pos], max);
1132 if ((msg->size-msg->pos) <= max) 1131 msg->pos += max;
1133 { 1132 bytes_read = max;
1134 memcpy(buf,&msg->buf[msg->pos],(msg->size-msg->pos));
1135 bytes_read = msg->size-msg->pos;
1136 msg->pos+=(msg->size-msg->pos);
1137 }
1138 else
1139 {
1140 memcpy(buf,&msg->buf[msg->pos],max);
1141 msg->pos+=max;
1142 bytes_read = max;
1143 }
1144
1145 /* removing message */
1146 if (msg->pos==msg->size)
1147 {
1148 if (NULL!=msg->transmit_cont)
1149 msg->transmit_cont (msg->transmit_cont_cls,&pc->identity,GNUNET_OK);
1150 ps->queue_length_cur -= msg->size;
1151 remove_http_message(ps,msg);
1152 }
1153 } 1133 }
1134
1135 /* removing message */
1136 if (msg->pos == msg->size)
1137 {
1138 if (NULL != msg->transmit_cont)
1139 msg->transmit_cont (msg->transmit_cont_cls, &pc->identity, GNUNET_OK);
1140 ps->queue_length_cur -= msg->size;
1141 remove_http_message (ps, msg);
1142 }
1143 }
1154#if DEBUG_CONNECTIONS 1144#if DEBUG_CONNECTIONS
1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1156 "Connection %X: MHD has sent %u bytes\n", 1146 "Connection %X: MHD has sent %u bytes\n", ps, bytes_read);
1157 ps,
1158 bytes_read);
1159#endif 1147#endif
1160 return bytes_read; 1148 return bytes_read;
1161} 1149}
@@ -1170,21 +1158,20 @@ mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1170 */ 1158 */
1171static int 1159static int
1172mhd_access_cb (void *cls, 1160mhd_access_cb (void *cls,
1173 struct MHD_Connection *mhd_connection, 1161 struct MHD_Connection *mhd_connection,
1174 const char *url, 1162 const char *url,
1175 const char *method, 1163 const char *method,
1176 const char *version, 1164 const char *version,
1177 const char *upload_data, 1165 const char *upload_data,
1178 size_t * upload_data_size, 1166 size_t * upload_data_size, void **httpSessionCache)
1179 void **httpSessionCache)
1180{ 1167{
1181 struct Plugin *plugin = cls; 1168 struct Plugin *plugin = cls;
1182 struct MHD_Response *response; 1169 struct MHD_Response *response;
1183 const union MHD_ConnectionInfo * conn_info; 1170 const union MHD_ConnectionInfo *conn_info;
1184 const struct sockaddr *client_addr; 1171 const struct sockaddr *client_addr;
1185 const struct sockaddr_in *addrin; 1172 const struct sockaddr_in *addrin;
1186 const struct sockaddr_in6 *addrin6; 1173 const struct sockaddr_in6 *addrin6;
1187 char address[INET6_ADDRSTRLEN+14]; 1174 char address[INET6_ADDRSTRLEN + 14];
1188 struct GNUNET_PeerIdentity pi_in; 1175 struct GNUNET_PeerIdentity pi_in;
1189 size_t id_num = 0; 1176 size_t id_num = 0;
1190 struct IPv4HttpAddress ipv4addr; 1177 struct IPv4HttpAddress ipv4addr;
@@ -1193,251 +1180,259 @@ mhd_access_cb (void *cls,
1193 struct Session *ps = NULL; 1180 struct Session *ps = NULL;
1194 struct Session *ps_tmp = NULL; 1181 struct Session *ps_tmp = NULL;
1195 int res = GNUNET_NO; 1182 int res = GNUNET_NO;
1196 void * addr = NULL; 1183 void *addr = NULL;
1197 size_t addr_len = 0 ; 1184 size_t addr_len = 0;
1198 1185
1199 GNUNET_assert(cls !=NULL); 1186 GNUNET_assert (cls != NULL);
1200 1187
1201 if (NULL == *httpSessionCache) 1188 if (NULL == *httpSessionCache)
1189 {
1190 /* check url for peer identity , if invalid send HTTP 404 */
1191 size_t len = strlen (&url[1]);
1192 char *peer = GNUNET_malloc (104 + 1);
1193
1194 if ((len > 104) && (url[104] == ';'))
1202 { 1195 {
1203 /* check url for peer identity , if invalid send HTTP 404*/ 1196 char *id = GNUNET_malloc ((len - 104) + 1);
1204 size_t len = strlen(&url[1]); 1197
1205 char * peer = GNUNET_malloc(104+1); 1198 strcpy (id, &url[105]);
1206 1199 memcpy (peer, &url[1], 103);
1207 if ( (len>104) && (url[104]==';')) 1200 peer[103] = '\0';
1208 { 1201 id_num = strtoul (id, NULL, 10);
1209 char * id = GNUNET_malloc((len-104)+1); 1202 GNUNET_free (id);
1210 strcpy(id,&url[105]);
1211 memcpy(peer,&url[1],103);
1212 peer[103] = '\0';
1213 id_num = strtoul ( id, NULL , 10);
1214 GNUNET_free(id);
1215 } 1203 }
1216 res = GNUNET_CRYPTO_hash_from_string (peer, &(pi_in.hashPubKey)); 1204 res = GNUNET_CRYPTO_hash_from_string (peer, &(pi_in.hashPubKey));
1217 GNUNET_free(peer); 1205 GNUNET_free (peer);
1218 if ( GNUNET_SYSERR == res ) 1206 if (GNUNET_SYSERR == res)
1219 { 1207 {
1220 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), 1208 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),
1221 HTTP_ERROR_RESPONSE, 1209 HTTP_ERROR_RESPONSE,
1222 MHD_NO, MHD_NO); 1210 MHD_NO, MHD_NO);
1223 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); 1211 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
1224 MHD_destroy_response (response); 1212 MHD_destroy_response (response);
1225#if DEBUG_CONNECTIONS 1213#if DEBUG_CONNECTIONS
1226 if (res == MHD_YES) 1214 if (res == MHD_YES)
1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1228 "Peer has no valid ident, sent HTTP 1.1/404\n"); 1216 "Peer has no valid ident, sent HTTP 1.1/404\n");
1229 else 1217 else
1230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1231 "Peer has no valid ident, could not send error\n"); 1219 "Peer has no valid ident, could not send error\n");
1232#endif 1220#endif
1233 return res; 1221 return res;
1234 }
1235 } 1222 }
1223 }
1236 else 1224 else
1225 {
1226 ps = *httpSessionCache;
1227 pc = ps->peercontext;
1228 }
1229
1230 if (NULL == *httpSessionCache)
1231 {
1232 /* get peer context */
1233 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &pi_in.hashPubKey);
1234 /* Peer unknown */
1235 if (pc == NULL)
1237 { 1236 {
1238 ps = *httpSessionCache; 1237 pc = GNUNET_malloc (sizeof (struct HTTP_PeerContext));
1239 pc = ps->peercontext; 1238 pc->plugin = plugin;
1239 pc->session_id_counter = 1;
1240 pc->last_session = NULL;
1241 memcpy (&pc->identity, &pi_in, sizeof (struct GNUNET_PeerIdentity));
1242 GNUNET_CONTAINER_multihashmap_put (plugin->peers,
1243 &pc->identity.hashPubKey,
1244 pc,
1245 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1246 GNUNET_STATISTICS_update (plugin->env->stats,
1247 gettext_noop ("# HTTP peers active"),
1248 1, GNUNET_NO);
1249 }
1250
1251 conn_info =
1252 MHD_get_connection_info (mhd_connection,
1253 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
1254 /* Incoming IPv4 connection */
1255 /* cast required for legacy MHD API < 0.9.6 */
1256 client_addr = (const struct sockaddr *) conn_info->client_addr;
1257 if (AF_INET == client_addr->sa_family)
1258 {
1259 addrin = (const struct sockaddr_in *) client_addr;
1260 inet_ntop (addrin->sin_family, &(addrin->sin_addr), address,
1261 INET_ADDRSTRLEN);
1262 memcpy (&ipv4addr.ipv4_addr, &(addrin->sin_addr),
1263 sizeof (struct in_addr));
1264 ipv4addr.port = addrin->sin_port;
1265 addr = &ipv4addr;
1266 addr_len = sizeof (struct IPv4HttpAddress);
1267 }
1268 /* Incoming IPv6 connection */
1269 if (AF_INET6 == client_addr->sa_family)
1270 {
1271 addrin6 = (const struct sockaddr_in6 *) client_addr;
1272 inet_ntop (addrin6->sin6_family, &(addrin6->sin6_addr), address,
1273 INET6_ADDRSTRLEN);
1274 memcpy (&ipv6addr.ipv6_addr, &(addrin6->sin6_addr),
1275 sizeof (struct in6_addr));
1276 ipv6addr.port = addrin6->sin6_port;
1277 addr = &ipv6addr;
1278 addr_len = sizeof (struct IPv6HttpAddress);
1240 } 1279 }
1241 1280
1242 if (NULL == *httpSessionCache) 1281 GNUNET_assert (addr != NULL);
1282 GNUNET_assert (addr_len != 0);
1283
1284 ps = NULL;
1285 /* only inbound sessions here */
1286
1287 ps_tmp = pc->head;
1288 while (ps_tmp != NULL)
1243 { 1289 {
1244 /* get peer context */ 1290 if ((ps_tmp->direction == INBOUND) && (ps_tmp->session_id == id_num) &&
1245 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &pi_in.hashPubKey); 1291 (id_num != 0))
1246 /* Peer unknown */ 1292 {
1247 if (pc==NULL) 1293 if ((ps_tmp->recv_force_disconnect != GNUNET_YES) &&
1248 { 1294 (ps_tmp->send_force_disconnect != GNUNET_YES))
1249 pc = GNUNET_malloc(sizeof (struct HTTP_PeerContext)); 1295 ps = ps_tmp;
1250 pc->plugin = plugin; 1296 break;
1251 pc->session_id_counter=1; 1297 }
1252 pc->last_session = NULL; 1298 ps_tmp = ps_tmp->next;
1253 memcpy(&pc->identity, &pi_in, sizeof(struct GNUNET_PeerIdentity)); 1299 }
1254 GNUNET_CONTAINER_multihashmap_put(plugin->peers, 1300
1255 &pc->identity.hashPubKey, 1301 if (ps == NULL)
1256 pc, 1302 {
1257 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1303 ps = GNUNET_malloc (sizeof (struct Session));
1258 GNUNET_STATISTICS_update (plugin->env->stats, 1304 ps->addr = GNUNET_malloc (addr_len);
1259 gettext_noop ("# HTTP peers active"), 1305 memcpy (ps->addr, addr, addr_len);
1260 1, 1306 ps->addrlen = addr_len;
1261 GNUNET_NO); 1307 ps->direction = INBOUND;
1262 } 1308 ps->pending_msgs_head = NULL;
1263 1309 ps->pending_msgs_tail = NULL;
1264 conn_info = MHD_get_connection_info(mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS ); 1310 ps->send_connected = GNUNET_NO;
1265 /* Incoming IPv4 connection */ 1311 ps->send_active = GNUNET_NO;
1266 /* cast required for legacy MHD API < 0.9.6 */ 1312 ps->recv_connected = GNUNET_NO;
1267 client_addr = (const struct sockaddr *) conn_info->client_addr; 1313 ps->recv_active = GNUNET_NO;
1268 if ( AF_INET == client_addr->sa_family) 1314 ps->peercontext = pc;
1269 { 1315 ps->session_id = id_num;
1270 addrin = (const struct sockaddr_in*) client_addr; 1316 ps->queue_length_cur = 0;
1271 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN); 1317 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
1272 memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr)); 1318 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
1273 ipv4addr.port = addrin->sin_port; 1319 GNUNET_CONTAINER_DLL_insert (pc->head, pc->tail, ps);
1274 addr = &ipv4addr; 1320 GNUNET_STATISTICS_update (plugin->env->stats,
1275 addr_len = sizeof(struct IPv4HttpAddress); 1321 gettext_noop
1276 } 1322 ("# HTTP inbound sessions for peers active"), 1,
1277 /* Incoming IPv6 connection */ 1323 GNUNET_NO);
1278 if ( AF_INET6 == client_addr->sa_family) 1324 }
1279 { 1325
1280 addrin6 = (const struct sockaddr_in6 *) client_addr; 1326 *httpSessionCache = ps;
1281 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN); 1327 if (ps->msgtok == NULL)
1282 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in6_addr)); 1328 ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
1283 ipv6addr.port = addrin6->sin6_port;
1284 addr = &ipv6addr;
1285 addr_len = sizeof(struct IPv6HttpAddress);
1286 }
1287
1288 GNUNET_assert (addr != NULL);
1289 GNUNET_assert (addr_len != 0);
1290
1291 ps = NULL;
1292 /* only inbound sessions here */
1293
1294 ps_tmp = pc->head;
1295 while (ps_tmp!=NULL)
1296 {
1297 if ((ps_tmp->direction==INBOUND) && (ps_tmp->session_id == id_num) && (id_num!=0))
1298 {
1299 if ((ps_tmp->recv_force_disconnect!=GNUNET_YES) && (ps_tmp->send_force_disconnect!=GNUNET_YES))
1300 ps=ps_tmp;
1301 break;
1302 }
1303 ps_tmp=ps_tmp->next;
1304 }
1305
1306 if (ps==NULL)
1307 {
1308 ps = GNUNET_malloc(sizeof (struct Session));
1309 ps->addr = GNUNET_malloc(addr_len);
1310 memcpy(ps->addr,addr,addr_len);
1311 ps->addrlen = addr_len;
1312 ps->direction=INBOUND;
1313 ps->pending_msgs_head = NULL;
1314 ps->pending_msgs_tail = NULL;
1315 ps->send_connected=GNUNET_NO;
1316 ps->send_active=GNUNET_NO;
1317 ps->recv_connected=GNUNET_NO;
1318 ps->recv_active=GNUNET_NO;
1319 ps->peercontext=pc;
1320 ps->session_id =id_num;
1321 ps->queue_length_cur = 0;
1322 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
1323 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
1324 GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
1325 GNUNET_STATISTICS_update (plugin->env->stats,
1326 gettext_noop ("# HTTP inbound sessions for peers active"),
1327 1,
1328 GNUNET_NO);
1329 }
1330
1331 *httpSessionCache = ps;
1332 if (ps->msgtok==NULL)
1333 ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
1334#if DEBUG_HTTP 1329#if DEBUG_HTTP
1335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1336 "Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", 1331 "Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",
1337 ps, 1332 ps,
1338 method, 1333 method,
1339 GNUNET_i2s(&pc->identity), 1334 GNUNET_i2s (&pc->identity),
1340 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen)); 1335 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1341#endif 1336#endif
1342 } 1337 }
1343 1338
1344 /* Is it a PUT or a GET request */ 1339 /* Is it a PUT or a GET request */
1345 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) 1340 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
1341 {
1342 if (ps->recv_force_disconnect == GNUNET_YES)
1346 { 1343 {
1347 if (ps->recv_force_disconnect == GNUNET_YES)
1348 {
1349#if DEBUG_CONNECTIONS
1350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1351 "Connection %X: inbound connection was forced to disconnect\n",ps);
1352#endif
1353 ps->recv_active = GNUNET_NO;
1354 return MHD_NO;
1355 }
1356 if ((*upload_data_size == 0) && (ps->recv_active==GNUNET_NO))
1357 {
1358 ps->recv_endpoint = mhd_connection;
1359 ps->recv_connected = GNUNET_YES;
1360 ps->recv_active = GNUNET_YES;
1361 ps->recv_force_disconnect = GNUNET_NO;
1362#if DEBUG_CONNECTIONS
1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1364 "Connection %X: inbound PUT connection connected\n",ps);
1365#endif
1366 return MHD_YES;
1367 }
1368
1369 /* Transmission of all data complete */
1370 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
1371 {
1372 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
1373 HTTP_PUT_RESPONSE,
1374 MHD_NO, MHD_NO);
1375 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1376#if DEBUG_CONNECTIONS 1344#if DEBUG_CONNECTIONS
1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1378 "Connection %X: Sent HTTP/1.1: 200 OK as PUT Response\n", 1346 "Connection %X: inbound connection was forced to disconnect\n",
1379 ps); 1347 ps);
1380#endif 1348#endif
1381 MHD_destroy_response (response); 1349 ps->recv_active = GNUNET_NO;
1382 ps->recv_active=GNUNET_NO; 1350 return MHD_NO;
1383 return MHD_YES;
1384 }
1385
1386 /* Recieving data */
1387 if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES))
1388 {
1389 if (pc->delay.rel_value == 0)
1390 {
1391#if DEBUG_HTTP
1392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1393 "Connection %X: PUT with %u bytes forwarded to MST\n",
1394 ps, *upload_data_size);
1395#endif
1396 res = GNUNET_SERVER_mst_receive(ps->msgtok, ps,
1397 upload_data, *upload_data_size,
1398 GNUNET_NO, GNUNET_NO);
1399 (*upload_data_size) = 0;
1400 }
1401 else
1402 {
1403#if DEBUG_HTTP
1404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1405 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n",
1406 ps,
1407 ps->peercontext->delay.rel_value);
1408#endif
1409 }
1410 return MHD_YES;
1411 }
1412 else
1413 return MHD_NO;
1414 } 1351 }
1415 if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) 1352 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_NO))
1416 { 1353 {
1417 if (ps->send_force_disconnect == GNUNET_YES) 1354 ps->recv_endpoint = mhd_connection;
1418 { 1355 ps->recv_connected = GNUNET_YES;
1356 ps->recv_active = GNUNET_YES;
1357 ps->recv_force_disconnect = GNUNET_NO;
1419#if DEBUG_CONNECTIONS 1358#if DEBUG_CONNECTIONS
1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1421 "Connection %X: outbound connection was forced to disconnect\n", 1360 "Connection %X: inbound PUT connection connected\n", ps);
1422 ps);
1423#endif 1361#endif
1424 ps->send_active = GNUNET_NO; 1362 return MHD_YES;
1425 return MHD_NO; 1363 }
1426 } 1364
1427 ps->send_connected = GNUNET_YES; 1365 /* Transmission of all data complete */
1428 ps->send_active = GNUNET_YES; 1366 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
1429 ps->send_endpoint = mhd_connection; 1367 {
1430 ps->send_force_disconnect = GNUNET_NO; 1368 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
1369 HTTP_PUT_RESPONSE,
1370 MHD_NO, MHD_NO);
1371 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1431#if DEBUG_CONNECTIONS 1372#if DEBUG_CONNECTIONS
1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1433 "Connection %X: inbound GET connection connected\n", 1374 "Connection %X: Sent HTTP/1.1: 200 OK as PUT Response\n", ps);
1434 ps);
1435#endif 1375#endif
1436 response = MHD_create_response_from_callback(-1,32 * 1024, &mhd_send_callback, ps, NULL);
1437 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1438 MHD_destroy_response (response); 1376 MHD_destroy_response (response);
1377 ps->recv_active = GNUNET_NO;
1439 return MHD_YES; 1378 return MHD_YES;
1440 } 1379 }
1380
1381 /* Recieving data */
1382 if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES))
1383 {
1384 if (pc->delay.rel_value == 0)
1385 {
1386#if DEBUG_HTTP
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Connection %X: PUT with %u bytes forwarded to MST\n",
1389 ps, *upload_data_size);
1390#endif
1391 res = GNUNET_SERVER_mst_receive (ps->msgtok, ps,
1392 upload_data, *upload_data_size,
1393 GNUNET_NO, GNUNET_NO);
1394 (*upload_data_size) = 0;
1395 }
1396 else
1397 {
1398#if DEBUG_HTTP
1399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1400 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n",
1401 ps, ps->peercontext->delay.rel_value);
1402#endif
1403 }
1404 return MHD_YES;
1405 }
1406 else
1407 return MHD_NO;
1408 }
1409 if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
1410 {
1411 if (ps->send_force_disconnect == GNUNET_YES)
1412 {
1413#if DEBUG_CONNECTIONS
1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1415 "Connection %X: outbound connection was forced to disconnect\n",
1416 ps);
1417#endif
1418 ps->send_active = GNUNET_NO;
1419 return MHD_NO;
1420 }
1421 ps->send_connected = GNUNET_YES;
1422 ps->send_active = GNUNET_YES;
1423 ps->send_endpoint = mhd_connection;
1424 ps->send_force_disconnect = GNUNET_NO;
1425#if DEBUG_CONNECTIONS
1426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "Connection %X: inbound GET connection connected\n", ps);
1428#endif
1429 response =
1430 MHD_create_response_from_callback (-1, 32 * 1024, &mhd_send_callback,
1431 ps, NULL);
1432 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1433 MHD_destroy_response (response);
1434 return MHD_YES;
1435 }
1441 return MHD_NO; 1436 return MHD_NO;
1442} 1437}
1443 1438
@@ -1451,7 +1446,7 @@ mhd_access_cb (void *cls,
1451 */ 1446 */
1452static GNUNET_SCHEDULER_TaskIdentifier 1447static GNUNET_SCHEDULER_TaskIdentifier
1453http_server_daemon_prepare (struct Plugin *plugin, 1448http_server_daemon_prepare (struct Plugin *plugin,
1454 struct MHD_Daemon *daemon_handle) 1449 struct MHD_Daemon *daemon_handle)
1455{ 1450{
1456 GNUNET_SCHEDULER_TaskIdentifier ret; 1451 GNUNET_SCHEDULER_TaskIdentifier ret;
1457 fd_set rs; 1452 fd_set rs;
@@ -1466,19 +1461,14 @@ http_server_daemon_prepare (struct Plugin *plugin,
1466 struct GNUNET_TIME_Relative tv; 1461 struct GNUNET_TIME_Relative tv;
1467 1462
1468 ret = GNUNET_SCHEDULER_NO_TASK; 1463 ret = GNUNET_SCHEDULER_NO_TASK;
1469 FD_ZERO(&rs); 1464 FD_ZERO (&rs);
1470 FD_ZERO(&ws); 1465 FD_ZERO (&ws);
1471 FD_ZERO(&es); 1466 FD_ZERO (&es);
1472 wrs = GNUNET_NETWORK_fdset_create (); 1467 wrs = GNUNET_NETWORK_fdset_create ();
1473 wes = GNUNET_NETWORK_fdset_create (); 1468 wes = GNUNET_NETWORK_fdset_create ();
1474 wws = GNUNET_NETWORK_fdset_create (); 1469 wws = GNUNET_NETWORK_fdset_create ();
1475 max = -1; 1470 max = -1;
1476 GNUNET_assert (MHD_YES == 1471 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
1477 MHD_get_fdset (daemon_handle,
1478 &rs,
1479 &ws,
1480 &es,
1481 &max));
1482 haveto = MHD_get_timeout (daemon_handle, &timeout); 1472 haveto = MHD_get_timeout (daemon_handle, &timeout);
1483 if (haveto == MHD_YES) 1473 if (haveto == MHD_YES)
1484 tv.rel_value = (uint64_t) timeout; 1474 tv.rel_value = (uint64_t) timeout;
@@ -1488,37 +1478,33 @@ http_server_daemon_prepare (struct Plugin *plugin,
1488 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 1478 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
1489 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); 1479 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
1490 if (daemon_handle == plugin->http_server_daemon_v4) 1480 if (daemon_handle == plugin->http_server_daemon_v4)
1481 {
1482 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1491 { 1483 {
1492 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 1484 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v4);
1493 { 1485 plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
1494 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v4);
1495 plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
1496 }
1497
1498 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1499 GNUNET_SCHEDULER_NO_TASK,
1500 tv,
1501 wrs,
1502 wws,
1503 &http_server_daemon_v4_run,
1504 plugin);
1505 } 1486 }
1487
1488 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1489 GNUNET_SCHEDULER_NO_TASK,
1490 tv,
1491 wrs,
1492 wws, &http_server_daemon_v4_run, plugin);
1493 }
1506 if (daemon_handle == plugin->http_server_daemon_v6) 1494 if (daemon_handle == plugin->http_server_daemon_v6)
1495 {
1496 if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1507 { 1497 {
1508 if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) 1498 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v6);
1509 { 1499 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1510 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v6);
1511 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1512 }
1513
1514 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1515 GNUNET_SCHEDULER_NO_TASK,
1516 tv,
1517 wrs,
1518 wws,
1519 &http_server_daemon_v6_run,
1520 plugin);
1521 } 1500 }
1501
1502 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1503 GNUNET_SCHEDULER_NO_TASK,
1504 tv,
1505 wrs,
1506 wws, &http_server_daemon_v6_run, plugin);
1507 }
1522 GNUNET_NETWORK_fdset_destroy (wrs); 1508 GNUNET_NETWORK_fdset_destroy (wrs);
1523 GNUNET_NETWORK_fdset_destroy (wws); 1509 GNUNET_NETWORK_fdset_destroy (wws);
1524 GNUNET_NETWORK_fdset_destroy (wes); 1510 GNUNET_NETWORK_fdset_destroy (wes);
@@ -1532,39 +1518,40 @@ http_server_daemon_prepare (struct Plugin *plugin,
1532 * @param cls plugin as closure 1518 * @param cls plugin as closure
1533 * @param tc task context 1519 * @param tc task context
1534 */ 1520 */
1535static void 1521static void
1536http_server_daemon_v4_run (void *cls, 1522http_server_daemon_v4_run (void *cls,
1537 const struct GNUNET_SCHEDULER_TaskContext *tc) 1523 const struct GNUNET_SCHEDULER_TaskContext *tc)
1538{ 1524{
1539 struct Plugin *plugin = cls; 1525 struct Plugin *plugin = cls;
1540 1526
1541#if DEBUG_SCHEDULING 1527#if DEBUG_SCHEDULING
1542 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1528 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1544 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_READ_READY\n"); 1530 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_READ_READY\n");
1545 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1531 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n"); 1533 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n");
1548 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1534 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1550 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n"); 1536 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n");
1551 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP)) 1537 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
1552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1553 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_STARTUP\n"); 1539 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_STARTUP\n");
1554 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1540 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1556 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n"); 1542 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
1557#endif 1543#endif
1558 1544
1559 GNUNET_assert(cls !=NULL); 1545 GNUNET_assert (cls != NULL);
1560 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK; 1546 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
1561 1547
1562 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1548 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1563 return; 1549 return;
1564 1550
1565 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v4)); 1551 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v4));
1566 plugin->http_server_task_v4 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4); 1552 plugin->http_server_task_v4 =
1567 } 1553 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4);
1554}
1568 1555
1569 1556
1570/** 1557/**
@@ -1573,92 +1560,95 @@ http_server_daemon_v4_run (void *cls,
1573 * @param cls plugin as closure 1560 * @param cls plugin as closure
1574 * @param tc task context 1561 * @param tc task context
1575 */ 1562 */
1576static void 1563static void
1577http_server_daemon_v6_run (void *cls, 1564http_server_daemon_v6_run (void *cls,
1578 const struct GNUNET_SCHEDULER_TaskContext *tc) 1565 const struct GNUNET_SCHEDULER_TaskContext *tc)
1579{ 1566{
1580 struct Plugin *plugin = cls; 1567 struct Plugin *plugin = cls;
1581 1568
1582#if DEBUG_SCHEDULING 1569#if DEBUG_SCHEDULING
1583 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1570 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1585 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_READ_READY\n"); 1572 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_READ_READY\n");
1586 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1573 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1588 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n"); 1575 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n");
1589 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1576 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1591 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n"); 1578 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n");
1592 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP)) 1579 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
1593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1594 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_STARTUP\n"); 1581 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_STARTUP\n");
1595 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1582 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1597 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n"); 1584 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
1598#endif 1585#endif
1599 1586
1600 GNUNET_assert(cls !=NULL); 1587 GNUNET_assert (cls != NULL);
1601 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; 1588 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1602 1589
1603 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1590 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1604 return; 1591 return;
1605 1592
1606 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v6)); 1593 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v6));
1607 plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); 1594 plugin->http_server_task_v6 =
1595 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
1608} 1596}
1609 1597
1610 1598
1611static size_t 1599static size_t
1612curl_get_header_cb( void *ptr, 1600curl_get_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
1613 size_t size, size_t nmemb,
1614 void *stream)
1615{ 1601{
1616 struct Session * ps = stream; 1602 struct Session *ps = stream;
1617 1603
1618 long http_result = 0; 1604 long http_result = 0;
1619 int res; 1605 int res;
1606
1620 /* Getting last http result code */ 1607 /* Getting last http result code */
1621 GNUNET_assert(NULL!=ps); 1608 GNUNET_assert (NULL != ps);
1622 if (ps->recv_connected==GNUNET_NO) 1609 if (ps->recv_connected == GNUNET_NO)
1610 {
1611 res =
1612 curl_easy_getinfo (ps->recv_endpoint, CURLINFO_RESPONSE_CODE,
1613 &http_result);
1614 if (CURLE_OK == res)
1623 { 1615 {
1624 res = curl_easy_getinfo(ps->recv_endpoint, CURLINFO_RESPONSE_CODE, &http_result); 1616 if (http_result == 200)
1625 if (CURLE_OK == res) 1617 {
1626 { 1618 ps->recv_connected = GNUNET_YES;
1627 if (http_result == 200) 1619 ps->recv_active = GNUNET_YES;
1628 {
1629 ps->recv_connected = GNUNET_YES;
1630 ps->recv_active = GNUNET_YES;
1631#if DEBUG_CONNECTIONS 1620#if DEBUG_CONNECTIONS
1632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: connected to recieve data\n",ps); 1621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1622 "Connection %X: connected to recieve data\n", ps);
1633#endif 1623#endif
1634 // Calling send_check_connections again since receive is established 1624 // Calling send_check_connections again since receive is established
1635 send_check_connections (ps->peercontext->plugin, ps); 1625 send_check_connections (ps->peercontext->plugin, ps);
1636 } 1626 }
1637 }
1638 } 1627 }
1639 1628 }
1629
1640#if DEBUG_CURL 1630#if DEBUG_CURL
1641 char * tmp; 1631 char *tmp;
1642 size_t len = size * nmemb; 1632 size_t len = size * nmemb;
1633
1643 tmp = NULL; 1634 tmp = NULL;
1644 if ((size * nmemb) < SIZE_MAX) 1635 if ((size * nmemb) < SIZE_MAX)
1645 tmp = GNUNET_malloc (len+1); 1636 tmp = GNUNET_malloc (len + 1);
1646 1637
1647 if ((tmp != NULL) && (len > 0)) 1638 if ((tmp != NULL) && (len > 0))
1639 {
1640 memcpy (tmp, ptr, len);
1641 if (len >= 2)
1648 { 1642 {
1649 memcpy(tmp,ptr,len); 1643 if (tmp[len - 2] == 13)
1650 if (len>=2) 1644 tmp[len - 2] = '\0';
1651 {
1652 if (tmp[len-2] == 13)
1653 tmp[len-2]= '\0';
1654 }
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "Connection %X: Header: %s\n",
1657 ps, tmp);
1658 } 1645 }
1646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1647 "Connection %X: Header: %s\n", ps, tmp);
1648 }
1659 GNUNET_free_non_null (tmp); 1649 GNUNET_free_non_null (tmp);
1660#endif 1650#endif
1661 1651
1662 return size * nmemb; 1652 return size * nmemb;
1663} 1653}
1664 1654
@@ -1672,59 +1662,56 @@ curl_get_header_cb( void *ptr,
1672 * @param stream closure set by user 1662 * @param stream closure set by user
1673 * @return bytes read by function 1663 * @return bytes read by function
1674 */ 1664 */
1675static size_t 1665static size_t
1676curl_put_header_cb(void *ptr, 1666curl_put_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
1677 size_t size,
1678 size_t nmemb,
1679 void *stream)
1680{ 1667{
1681 struct Session * ps = stream; 1668 struct Session *ps = stream;
1682 1669
1683 char * tmp; 1670 char *tmp;
1684 size_t len = size * nmemb; 1671 size_t len = size * nmemb;
1685 long http_result = 0; 1672 long http_result = 0;
1686 int res; 1673 int res;
1687 1674
1688 /* Getting last http result code */ 1675 /* Getting last http result code */
1689 GNUNET_assert(NULL!=ps); 1676 GNUNET_assert (NULL != ps);
1690 res = curl_easy_getinfo (ps->send_endpoint, CURLINFO_RESPONSE_CODE, &http_result); 1677 res =
1678 curl_easy_getinfo (ps->send_endpoint, CURLINFO_RESPONSE_CODE,
1679 &http_result);
1691 if (CURLE_OK == res) 1680 if (CURLE_OK == res)
1681 {
1682 if ((http_result == 100) && (ps->send_connected == GNUNET_NO))
1692 { 1683 {
1693 if ((http_result == 100) && (ps->send_connected==GNUNET_NO)) 1684 ps->send_connected = GNUNET_YES;
1694 { 1685 ps->send_active = GNUNET_YES;
1695 ps->send_connected = GNUNET_YES;
1696 ps->send_active = GNUNET_YES;
1697#if DEBUG_CONNECTIONS 1686#if DEBUG_CONNECTIONS
1698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1699 "Connection %X: connected to send data\n", 1688 "Connection %X: connected to send data\n", ps);
1700 ps); 1689#endif
1701#endif 1690 }
1702 } 1691 if ((http_result == 200) && (ps->send_connected == GNUNET_YES))
1703 if ((http_result == 200) && (ps->send_connected==GNUNET_YES)) 1692 {
1704 { 1693 ps->send_connected = GNUNET_NO;
1705 ps->send_connected = GNUNET_NO; 1694 ps->send_active = GNUNET_NO;
1706 ps->send_active = GNUNET_NO;
1707#if DEBUG_CONNECTIONS 1695#if DEBUG_CONNECTIONS
1708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1709 "Connection %X: sending disconnected\n", 1697 "Connection %X: sending disconnected\n", ps);
1710 ps);
1711#endif 1698#endif
1712 }
1713 } 1699 }
1714 1700 }
1701
1715 tmp = NULL; 1702 tmp = NULL;
1716 if ((size * nmemb) < SIZE_MAX) 1703 if ((size * nmemb) < SIZE_MAX)
1717 tmp = GNUNET_malloc (len+1); 1704 tmp = GNUNET_malloc (len + 1);
1718 1705
1719 if ((tmp != NULL) && (len > 0)) 1706 if ((tmp != NULL) && (len > 0))
1707 {
1708 memcpy (tmp, ptr, len);
1709 if (len >= 2)
1720 { 1710 {
1721 memcpy(tmp,ptr,len); 1711 if (tmp[len - 2] == 13)
1722 if (len>=2) 1712 tmp[len - 2] = '\0';
1723 {
1724 if (tmp[len-2] == 13)
1725 tmp[len-2]= '\0';
1726 }
1727 } 1713 }
1714 }
1728 GNUNET_free_non_null (tmp); 1715 GNUNET_free_non_null (tmp);
1729 return size * nmemb; 1716 return size * nmemb;
1730} 1717}
@@ -1738,123 +1725,119 @@ curl_put_header_cb(void *ptr,
1738 * @param ptr source pointer, passed to the libcurl handle 1725 * @param ptr source pointer, passed to the libcurl handle
1739 * @return bytes written to stream 1726 * @return bytes written to stream
1740 */ 1727 */
1741static size_t 1728static size_t
1742curl_send_cb(void *stream, 1729curl_send_cb (void *stream, size_t size, size_t nmemb, void *ptr)
1743 size_t size, size_t nmemb,
1744 void *ptr)
1745{ 1730{
1746 struct Session * ps = ptr; 1731 struct Session *ps = ptr;
1747 struct HTTP_Message * msg = ps->pending_msgs_tail; 1732 struct HTTP_Message *msg = ps->pending_msgs_tail;
1748 size_t bytes_sent; 1733 size_t bytes_sent;
1749 size_t len; 1734 size_t len;
1750 1735
1751 if (ps->send_active == GNUNET_NO) 1736 if (ps->send_active == GNUNET_NO)
1752 return CURL_READFUNC_PAUSE; 1737 return CURL_READFUNC_PAUSE;
1753 if ( (ps->pending_msgs_tail == NULL) && 1738 if ((ps->pending_msgs_tail == NULL) && (ps->send_active == GNUNET_YES))
1754 (ps->send_active == GNUNET_YES) ) 1739 {
1755 {
1756#if DEBUG_CONNECTIONS 1740#if DEBUG_CONNECTIONS
1757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1758 "Connection %X: No Message to send, pausing connection\n", 1742 "Connection %X: No Message to send, pausing connection\n", ps);
1759 ps);
1760#endif 1743#endif
1761 ps->send_active = GNUNET_NO; 1744 ps->send_active = GNUNET_NO;
1762 return CURL_READFUNC_PAUSE; 1745 return CURL_READFUNC_PAUSE;
1763 } 1746 }
1764 1747
1765 GNUNET_assert (msg!=NULL); 1748 GNUNET_assert (msg != NULL);
1766 1749
1767 /* data to send */ 1750 /* data to send */
1768 if (msg->pos < msg->size) 1751 if (msg->pos < msg->size)
1752 {
1753 /* data fit in buffer */
1754 if ((msg->size - msg->pos) <= (size * nmemb))
1769 { 1755 {
1770 /* data fit in buffer */ 1756 len = (msg->size - msg->pos);
1771 if ((msg->size - msg->pos) <= (size * nmemb)) 1757 memcpy (stream, &msg->buf[msg->pos], len);
1772 { 1758 msg->pos += len;
1773 len = (msg->size - msg->pos); 1759 bytes_sent = len;
1774 memcpy(stream, &msg->buf[msg->pos], len);
1775 msg->pos += len;
1776 bytes_sent = len;
1777 }
1778 else
1779 {
1780 len = size*nmemb;
1781 memcpy(stream, &msg->buf[msg->pos], len);
1782 msg->pos += len;
1783 bytes_sent = len;
1784 }
1785 } 1760 }
1786 /* no data to send */ 1761 else
1787 else
1788 { 1762 {
1789 bytes_sent = 0; 1763 len = size * nmemb;
1764 memcpy (stream, &msg->buf[msg->pos], len);
1765 msg->pos += len;
1766 bytes_sent = len;
1790 } 1767 }
1791 1768 }
1792 if ( msg->pos == msg->size) 1769 /* no data to send */
1793 { 1770 else
1771 {
1772 bytes_sent = 0;
1773 }
1774
1775 if (msg->pos == msg->size)
1776 {
1794#if DEBUG_CONNECTIONS 1777#if DEBUG_CONNECTIONS
1795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1796 "Connection %X: Message with %u bytes sent, removing message from queue\n", 1779 "Connection %X: Message with %u bytes sent, removing message from queue\n",
1797 ps, 1780 ps, msg->pos);
1798 msg->pos); 1781#endif
1799#endif 1782 /* Calling transmit continuation */
1800 /* Calling transmit continuation */ 1783 if (NULL != ps->pending_msgs_tail->transmit_cont)
1801 if (NULL != ps->pending_msgs_tail->transmit_cont) 1784 msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls,
1802 msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls, 1785 &(ps->peercontext)->identity, GNUNET_OK);
1803 &(ps->peercontext)->identity, 1786 ps->queue_length_cur -= msg->size;
1804 GNUNET_OK); 1787 remove_http_message (ps, msg);
1805 ps->queue_length_cur -= msg->size; 1788 }
1806 remove_http_message(ps, msg);
1807 }
1808 return bytes_sent; 1789 return bytes_sent;
1809} 1790}
1810 1791
1811 1792
1812static void 1793static void
1813curl_receive_mst_cb (void *cls, 1794curl_receive_mst_cb (void *cls,
1814 void *client, 1795 void *client, const struct GNUNET_MessageHeader *message)
1815 const struct GNUNET_MessageHeader *message)
1816{ 1796{
1817 struct Session *ps = cls; 1797 struct Session *ps = cls;
1818 struct GNUNET_TIME_Relative delay; 1798 struct GNUNET_TIME_Relative delay;
1819 GNUNET_assert(ps != NULL); 1799
1800 GNUNET_assert (ps != NULL);
1820 1801
1821 struct HTTP_PeerContext *pc = ps->peercontext; 1802 struct HTTP_PeerContext *pc = ps->peercontext;
1822 GNUNET_assert(pc != NULL); 1803
1804 GNUNET_assert (pc != NULL);
1823#if DEBUG_HTTP 1805#if DEBUG_HTTP
1824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1825 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1807 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1826 ps, 1808 ps,
1827 ntohs(message->type), 1809 ntohs (message->type),
1828 ntohs(message->size), 1810 ntohs (message->size),
1829 GNUNET_i2s(&(pc->identity)), 1811 GNUNET_i2s (&(pc->identity)),
1830 http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); 1812 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1831#endif 1813#endif
1832 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1814 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1815
1833 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 1816 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1834 distance[0].value = htonl (1); 1817 distance[0].value = htonl (1);
1835 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1818 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1836 distance[1].value = htonl (0); 1819 distance[1].value = htonl (0);
1837 1820
1838 delay = pc->plugin->env->receive (pc->plugin->env->cls, 1821 delay = pc->plugin->env->receive (pc->plugin->env->cls,
1839 &pc->identity, 1822 &pc->identity,
1840 message, 1823 message,
1841 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, 1824 (const struct
1842 ps, 1825 GNUNET_TRANSPORT_ATS_Information *)
1843 ps->addr, 1826 &distance, 2, ps, ps->addr, ps->addrlen);
1844 ps->addrlen);
1845 pc->delay = delay; 1827 pc->delay = delay;
1846 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) 1828 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
1847 GNUNET_SCHEDULER_cancel (pc->reset_task); 1829 GNUNET_SCHEDULER_cancel (pc->reset_task);
1848 1830
1849 if (delay.rel_value > 0) 1831 if (delay.rel_value > 0)
1850 { 1832 {
1851#if DEBUG_HTTP 1833#if DEBUG_HTTP
1852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1853 "Connection %X: Inbound quota management: delay next read for %llu ms\n", 1835 "Connection %X: Inbound quota management: delay next read for %llu ms\n",
1854 ps, delay.rel_value); 1836 ps, delay.rel_value);
1855#endif 1837#endif
1856 pc->reset_task = GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc); 1838 pc->reset_task =
1857 } 1839 GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc);
1840 }
1858} 1841}
1859 1842
1860 1843
@@ -1867,163 +1850,171 @@ curl_receive_mst_cb (void *cls,
1867* @param ptr destination pointer, passed to the libcurl handle 1850* @param ptr destination pointer, passed to the libcurl handle
1868* @return bytes read from stream 1851* @return bytes read from stream
1869*/ 1852*/
1870static size_t 1853static size_t
1871curl_receive_cb( void *stream, size_t size, size_t nmemb, void *ptr) 1854curl_receive_cb (void *stream, size_t size, size_t nmemb, void *ptr)
1872{ 1855{
1873 struct Session * ps = ptr; 1856 struct Session *ps = ptr;
1874 1857
1875 if (ps->peercontext->delay.rel_value > 0) 1858 if (ps->peercontext->delay.rel_value > 0)
1876 { 1859 {
1877#if DEBUG_HTTP 1860#if DEBUG_HTTP
1878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1879 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", 1862 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n",
1880 ps, ps->peercontext->delay.rel_value); 1863 ps, ps->peercontext->delay.rel_value);
1881#endif 1864#endif
1882 return 0; 1865 return 0;
1883 } 1866 }
1884#if DEBUG_CONNECTIONS 1867#if DEBUG_CONNECTIONS
1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1886 "Connection %X: %u bytes received\n", 1869 "Connection %X: %u bytes received\n", ps, size * nmemb);
1887 ps, size*nmemb);
1888#endif 1870#endif
1889 GNUNET_SERVER_mst_receive(ps->msgtok, ps, 1871 GNUNET_SERVER_mst_receive (ps->msgtok, ps,
1890 stream, size*nmemb, 1872 stream, size * nmemb, GNUNET_NO, GNUNET_NO);
1891 GNUNET_NO, GNUNET_NO);
1892 return (size * nmemb); 1873 return (size * nmemb);
1893} 1874}
1894 1875
1895 1876
1896static void 1877static void
1897curl_handle_finished (struct Plugin *plugin) 1878curl_handle_finished (struct Plugin *plugin)
1898{ 1879{
1899 struct Session *ps = NULL; 1880 struct Session *ps = NULL;
1900 struct HTTP_PeerContext *pc = NULL; 1881 struct HTTP_PeerContext *pc = NULL;
1901 struct CURLMsg *msg; 1882 struct CURLMsg *msg;
1902 struct HTTP_Message * cur_msg = NULL; 1883 struct HTTP_Message *cur_msg = NULL;
1903 int msgs_in_queue; 1884 int msgs_in_queue;
1904 char * tmp; 1885 char *tmp;
1905 long http_result; 1886 long http_result;
1906 1887
1907 do 1888 do
1908 { 1889 {
1909 msg = curl_multi_info_read (plugin->multi_handle, &msgs_in_queue); 1890 msg = curl_multi_info_read (plugin->multi_handle, &msgs_in_queue);
1910 if ((msgs_in_queue == 0) || (msg == NULL)) 1891 if ((msgs_in_queue == 0) || (msg == NULL))
1911 break; 1892 break;
1912 /* get session for affected curl handle */ 1893 /* get session for affected curl handle */
1913 GNUNET_assert ( msg->easy_handle != NULL ); 1894 GNUNET_assert (msg->easy_handle != NULL);
1914 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &tmp); 1895 curl_easy_getinfo (msg->easy_handle, CURLINFO_PRIVATE, &tmp);
1915 ps = (struct Session *) tmp; 1896 ps = (struct Session *) tmp;
1916 GNUNET_assert ( ps != NULL ); 1897 GNUNET_assert (ps != NULL);
1917 pc = ps->peercontext; 1898 pc = ps->peercontext;
1918 GNUNET_assert ( pc != NULL ); 1899 GNUNET_assert (pc != NULL);
1919 switch (msg->msg) 1900 switch (msg->msg)
1920 { 1901 {
1921 case CURLMSG_DONE: 1902 case CURLMSG_DONE:
1922 if ( (msg->data.result != CURLE_OK) && 1903 if ((msg->data.result != CURLE_OK) &&
1923 (msg->data.result != CURLE_GOT_NOTHING) ) 1904 (msg->data.result != CURLE_GOT_NOTHING))
1924 { 1905 {
1925 /* sending msg failed*/ 1906 /* sending msg failed */
1926 if (msg->easy_handle == ps->send_endpoint) 1907 if (msg->easy_handle == ps->send_endpoint)
1927 { 1908 {
1928#if DEBUG_CONNECTIONS 1909#if DEBUG_CONNECTIONS
1929 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1910 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1930 _("Connection %X: HTTP PUT to peer `%s' (`%s') failed: `%s' `%s'\n"), 1911 _
1931 ps, 1912 ("Connection %X: HTTP PUT to peer `%s' (`%s') failed: `%s' `%s'\n"),
1932 GNUNET_i2s(&pc->identity), 1913 ps, GNUNET_i2s (&pc->identity),
1933 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 1914 http_plugin_address_to_string (NULL, ps->addr,
1934 "curl_multi_perform", 1915 ps->addrlen),
1935 curl_easy_strerror (msg->data.result)); 1916 "curl_multi_perform",
1936#endif 1917 curl_easy_strerror (msg->data.result));
1937 ps->send_connected = GNUNET_NO; 1918#endif
1938 ps->send_active = GNUNET_NO; 1919 ps->send_connected = GNUNET_NO;
1939 curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint); 1920 ps->send_active = GNUNET_NO;
1940 while (ps->pending_msgs_tail != NULL) 1921 curl_multi_remove_handle (plugin->multi_handle, ps->send_endpoint);
1941 { 1922 while (ps->pending_msgs_tail != NULL)
1942 cur_msg = ps->pending_msgs_tail; 1923 {
1943 if ( NULL != cur_msg->transmit_cont) 1924 cur_msg = ps->pending_msgs_tail;
1944 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_SYSERR); 1925 if (NULL != cur_msg->transmit_cont)
1945 ps->queue_length_cur -= cur_msg->size; 1926 cur_msg->transmit_cont (cur_msg->transmit_cont_cls, &pc->identity,
1946 remove_http_message(ps,cur_msg); 1927 GNUNET_SYSERR);
1947 } 1928 ps->queue_length_cur -= cur_msg->size;
1948 } 1929 remove_http_message (ps, cur_msg);
1949 /* GET connection failed */ 1930 }
1950 if (msg->easy_handle == ps->recv_endpoint) 1931 }
1951 { 1932 /* GET connection failed */
1933 if (msg->easy_handle == ps->recv_endpoint)
1934 {
1952#if DEBUG_CONNECTIONS 1935#if DEBUG_CONNECTIONS
1953 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1936 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1954 _("Connection %X: HTTP GET to peer `%s' (`%s') failed: `%s' `%s'\n"), 1937 _
1955 ps, 1938 ("Connection %X: HTTP GET to peer `%s' (`%s') failed: `%s' `%s'\n"),
1956 GNUNET_i2s(&pc->identity), 1939 ps, GNUNET_i2s (&pc->identity),
1957 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 1940 http_plugin_address_to_string (NULL, ps->addr,
1958 "curl_multi_perform", 1941 ps->addrlen),
1959 curl_easy_strerror (msg->data.result)); 1942 "curl_multi_perform",
1960#endif 1943 curl_easy_strerror (msg->data.result));
1961 ps->recv_connected = GNUNET_NO; 1944#endif
1962 ps->recv_active = GNUNET_NO; 1945 ps->recv_connected = GNUNET_NO;
1963 curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint); 1946 ps->recv_active = GNUNET_NO;
1964 } 1947 curl_multi_remove_handle (plugin->multi_handle, ps->recv_endpoint);
1965 } 1948 }
1966 else 1949 }
1967 { 1950 else
1968 if (msg->easy_handle == ps->send_endpoint) 1951 {
1969 { 1952 if (msg->easy_handle == ps->send_endpoint)
1970 GNUNET_assert (CURLE_OK == curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_result)); 1953 {
1954 GNUNET_assert (CURLE_OK ==
1955 curl_easy_getinfo (msg->easy_handle,
1956 CURLINFO_RESPONSE_CODE,
1957 &http_result));
1971#if DEBUG_CONNECTIONS 1958#if DEBUG_CONNECTIONS
1972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1973 "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n", 1960 "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n",
1974 ps, 1961 ps,
1975 GNUNET_i2s(&pc->identity), 1962 GNUNET_i2s (&pc->identity),
1976 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 1963 http_plugin_address_to_string (NULL, ps->addr,
1977 http_result); 1964 ps->addrlen), http_result);
1978#endif 1965#endif
1979 /* Calling transmit continuation */ 1966 /* Calling transmit continuation */
1980 while (ps->pending_msgs_tail != NULL) 1967 while (ps->pending_msgs_tail != NULL)
1981 { 1968 {
1982 cur_msg = ps->pending_msgs_tail; 1969 cur_msg = ps->pending_msgs_tail;
1983 if ( NULL != cur_msg->transmit_cont) 1970 if (NULL != cur_msg->transmit_cont)
1984 { 1971 {
1985 /* HTTP 1xx : Last message before here was informational */ 1972 /* HTTP 1xx : Last message before here was informational */
1986 if ((http_result >=100) && (http_result < 200)) 1973 if ((http_result >= 100) && (http_result < 200))
1987 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_OK); 1974 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
1988 /* HTTP 2xx: successful operations */ 1975 &pc->identity, GNUNET_OK);
1989 if ((http_result >=200) && (http_result < 300)) 1976 /* HTTP 2xx: successful operations */
1990 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_OK); 1977 if ((http_result >= 200) && (http_result < 300))
1991 /* HTTP 3xx..5xx: error */ 1978 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
1992 if ((http_result >=300) && (http_result < 600)) 1979 &pc->identity, GNUNET_OK);
1993 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_SYSERR); 1980 /* HTTP 3xx..5xx: error */
1994 } 1981 if ((http_result >= 300) && (http_result < 600))
1995 ps->queue_length_cur -= cur_msg->size; 1982 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
1996 remove_http_message(ps,cur_msg); 1983 &pc->identity, GNUNET_SYSERR);
1997 } 1984 }
1998 1985 ps->queue_length_cur -= cur_msg->size;
1999 ps->send_connected = GNUNET_NO; 1986 remove_http_message (ps, cur_msg);
2000 ps->send_active = GNUNET_NO; 1987 }
2001 curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint); 1988
2002 } 1989 ps->send_connected = GNUNET_NO;
2003 if (msg->easy_handle == ps->recv_endpoint) 1990 ps->send_active = GNUNET_NO;
2004 { 1991 curl_multi_remove_handle (plugin->multi_handle, ps->send_endpoint);
1992 }
1993 if (msg->easy_handle == ps->recv_endpoint)
1994 {
2005#if DEBUG_CONNECTIONS 1995#if DEBUG_CONNECTIONS
2006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2007 "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n", 1997 "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n",
2008 ps, 1998 ps,
2009 GNUNET_i2s(&pc->identity), 1999 GNUNET_i2s (&pc->identity),
2010 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 2000 http_plugin_address_to_string (NULL, ps->addr,
2011 http_result); 2001 ps->addrlen), http_result);
2012#endif 2002#endif
2013 ps->recv_connected = GNUNET_NO; 2003 ps->recv_connected = GNUNET_NO;
2014 ps->recv_active = GNUNET_NO; 2004 ps->recv_active = GNUNET_NO;
2015 curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint); 2005 curl_multi_remove_handle (plugin->multi_handle, ps->recv_endpoint);
2016 } 2006 }
2017 plugin->current_connections--; 2007 plugin->current_connections--;
2018 } 2008 }
2019 if ((ps->recv_connected == GNUNET_NO) && (ps->send_connected == GNUNET_NO)) 2009 if ((ps->recv_connected == GNUNET_NO) &&
2020 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR); 2010 (ps->send_connected == GNUNET_NO))
2021 break; 2011 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
2022 default: 2012 break;
2023 break; 2013 default:
2024 } 2014 break;
2025 } 2015 }
2026 while ( (msgs_in_queue > 0) ); 2016 }
2017 while ((msgs_in_queue > 0));
2027} 2018}
2028 2019
2029 2020
@@ -2032,29 +2023,29 @@ curl_handle_finished (struct Plugin *plugin)
2032 * @param cls plugin as closure 2023 * @param cls plugin as closure
2033 * @param tc gnunet scheduler task context 2024 * @param tc gnunet scheduler task context
2034 */ 2025 */
2035static void curl_perform (void *cls, 2026static void
2036 const struct GNUNET_SCHEDULER_TaskContext *tc) 2027curl_perform (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2037{ 2028{
2038 struct Plugin *plugin = cls; 2029 struct Plugin *plugin = cls;
2039 static unsigned int handles_last_run; 2030 static unsigned int handles_last_run;
2040 int running; 2031 int running;
2041 CURLMcode mret; 2032 CURLMcode mret;
2042 2033
2043 GNUNET_assert(cls !=NULL); 2034 GNUNET_assert (cls != NULL);
2044 2035
2045 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2036 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2046 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 2037 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2047 return; 2038 return;
2048 do 2039 do
2049 { 2040 {
2050 running = 0; 2041 running = 0;
2051 mret = curl_multi_perform (plugin->multi_handle, &running); 2042 mret = curl_multi_perform (plugin->multi_handle, &running);
2052 if ((running < handles_last_run) && (running>0)) 2043 if ((running < handles_last_run) && (running > 0))
2053 curl_handle_finished(plugin); 2044 curl_handle_finished (plugin);
2054 handles_last_run = running; 2045 handles_last_run = running;
2055 } 2046 }
2056 while (mret == CURLM_CALL_MULTI_PERFORM); 2047 while (mret == CURLM_CALL_MULTI_PERFORM);
2057 curl_schedule(plugin); 2048 curl_schedule (plugin);
2058} 2049}
2059 2050
2060 2051
@@ -2064,8 +2055,8 @@ static void curl_perform (void *cls,
2064 * @param plugin plugin as closure 2055 * @param plugin plugin as closure
2065 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok 2056 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
2066 */ 2057 */
2067static int 2058static int
2068curl_schedule(struct Plugin *plugin) 2059curl_schedule (struct Plugin *plugin)
2069{ 2060{
2070 fd_set rs; 2061 fd_set rs;
2071 fd_set ws; 2062 fd_set ws;
@@ -2077,48 +2068,50 @@ curl_schedule(struct Plugin *plugin)
2077 CURLMcode mret; 2068 CURLMcode mret;
2078 2069
2079 /* Cancel previous scheduled task */ 2070 /* Cancel previous scheduled task */
2080 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 2071 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2081 { 2072 {
2082 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 2073 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2083 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2074 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2084 } 2075 }
2085 2076
2086 max = -1; 2077 max = -1;
2087 FD_ZERO (&rs); 2078 FD_ZERO (&rs);
2088 FD_ZERO (&ws); 2079 FD_ZERO (&ws);
2089 FD_ZERO (&es); 2080 FD_ZERO (&es);
2090 mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max); 2081 mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max);
2091 if (mret != CURLM_OK) 2082 if (mret != CURLM_OK)
2092 { 2083 {
2093 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2084 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2094 _("%s failed at %s:%d: `%s'\n"), 2085 _("%s failed at %s:%d: `%s'\n"),
2095 "curl_multi_fdset", __FILE__, __LINE__, 2086 "curl_multi_fdset", __FILE__, __LINE__,
2096 curl_multi_strerror (mret)); 2087 curl_multi_strerror (mret));
2097 return GNUNET_SYSERR; 2088 return GNUNET_SYSERR;
2098 } 2089 }
2099 mret = curl_multi_timeout (plugin->multi_handle, &to); 2090 mret = curl_multi_timeout (plugin->multi_handle, &to);
2100 if (mret != CURLM_OK) 2091 if (mret != CURLM_OK)
2101 { 2092 {
2102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2093 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2103 _("%s failed at %s:%d: `%s'\n"), 2094 _("%s failed at %s:%d: `%s'\n"),
2104 "curl_multi_timeout", __FILE__, __LINE__, 2095 "curl_multi_timeout", __FILE__, __LINE__,
2105 curl_multi_strerror (mret)); 2096 curl_multi_strerror (mret));
2106 return GNUNET_SYSERR; 2097 return GNUNET_SYSERR;
2107 } 2098 }
2108 2099
2109 grs = GNUNET_NETWORK_fdset_create (); 2100 grs = GNUNET_NETWORK_fdset_create ();
2110 gws = GNUNET_NETWORK_fdset_create (); 2101 gws = GNUNET_NETWORK_fdset_create ();
2111 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 2102 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
2112 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 2103 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
2113 plugin->http_curl_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 2104 plugin->http_curl_task =
2114 GNUNET_SCHEDULER_NO_TASK, 2105 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
2115 (to == -1) 2106 GNUNET_SCHEDULER_NO_TASK,
2116 ? GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 2107 (to ==
2117 : GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to), 2108 -1) ?
2118 grs, 2109 GNUNET_TIME_relative_multiply
2119 gws, 2110 (GNUNET_TIME_UNIT_SECONDS,
2120 &curl_perform, 2111 5) :
2121 plugin); 2112 GNUNET_TIME_relative_multiply
2113 (GNUNET_TIME_UNIT_MILLISECONDS, to), grs,
2114 gws, &curl_perform, plugin);
2122 GNUNET_NETWORK_fdset_destroy (gws); 2115 GNUNET_NETWORK_fdset_destroy (gws);
2123 GNUNET_NETWORK_fdset_destroy (grs); 2116 GNUNET_NETWORK_fdset_destroy (grs);
2124 return GNUNET_OK; 2117 return GNUNET_OK;
@@ -2135,28 +2128,24 @@ curl_schedule(struct Plugin *plugin)
2135 * @param cls closure 2128 * @param cls closure
2136 * @return 0 2129 * @return 0
2137 */ 2130 */
2138static int 2131static int
2139curl_logger (CURL * curl, 2132curl_logger (CURL * curl,
2140 curl_infotype type, 2133 curl_infotype type, char *data, size_t size, void *cls)
2141 char * data, size_t size,
2142 void * cls)
2143{ 2134{
2144 if (type == CURLINFO_TEXT) 2135 if (type == CURLINFO_TEXT)
2136 {
2137 char text[size + 2];
2138
2139 memcpy (text, data, size);
2140 if (text[size - 1] == '\n')
2141 text[size] = '\0';
2142 else
2145 { 2143 {
2146 char text[size+2]; 2144 text[size] = '\n';
2147 memcpy(text,data,size); 2145 text[size + 1] = '\0';
2148 if (text[size-1] == '\n')
2149 text[size] = '\0';
2150 else
2151 {
2152 text[size] = '\n';
2153 text[size+1] = '\0';
2154 }
2155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2156 "CURL: Connection %X - %s",
2157 cls,
2158 text);
2159 } 2146 }
2147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CURL: Connection %X - %s", cls, text);
2148 }
2160 return 0; 2149 return 0;
2161} 2150}
2162#endif 2151#endif
@@ -2169,184 +2158,203 @@ curl_logger (CURL * curl,
2169 * @param ps session 2158 * @param ps session
2170 * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok 2159 * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok
2171 */ 2160 */
2172static int 2161static int
2173send_check_connections (struct Plugin *plugin, 2162send_check_connections (struct Plugin *plugin, struct Session *ps)
2174 struct Session *ps)
2175{ 2163{
2176 CURLMcode mret; 2164 CURLMcode mret;
2177 struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; 2165 struct GNUNET_TIME_Relative timeout =
2166 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
2178 2167
2179 if ((ps->direction == OUTBOUND) && (plugin->current_connections < plugin->max_connect_per_transport)) 2168 if ((ps->direction == OUTBOUND) &&
2169 (plugin->current_connections < plugin->max_connect_per_transport))
2170 {
2171 /* RECV DIRECTION */
2172 /* Check if session is connected to receive data, otherwise connect to peer */
2173
2174 if (ps->recv_connected == GNUNET_NO)
2180 { 2175 {
2181 /* RECV DIRECTION */ 2176 int fresh = GNUNET_NO;
2182 /* Check if session is connected to receive data, otherwise connect to peer */ 2177
2183 2178 if (ps->recv_endpoint == NULL)
2184 if (ps->recv_connected == GNUNET_NO) 2179 {
2185 { 2180 fresh = GNUNET_YES;
2186 int fresh = GNUNET_NO; 2181 ps->recv_endpoint = curl_easy_init ();
2187 if (ps->recv_endpoint == NULL) 2182 }
2188 {
2189 fresh = GNUNET_YES;
2190 ps->recv_endpoint = curl_easy_init();
2191 }
2192#if DEBUG_CURL 2183#if DEBUG_CURL
2193 curl_easy_setopt(ps->recv_endpoint, CURLOPT_VERBOSE, 1L); 2184 curl_easy_setopt (ps->recv_endpoint, CURLOPT_VERBOSE, 1L);
2194 curl_easy_setopt(ps->recv_endpoint, CURLOPT_DEBUGFUNCTION , &curl_logger); 2185 curl_easy_setopt (ps->recv_endpoint, CURLOPT_DEBUGFUNCTION, &curl_logger);
2195 curl_easy_setopt(ps->recv_endpoint, CURLOPT_DEBUGDATA , ps->recv_endpoint); 2186 curl_easy_setopt (ps->recv_endpoint, CURLOPT_DEBUGDATA,
2187 ps->recv_endpoint);
2196#endif 2188#endif
2197#if BUILD_HTTPS 2189#if BUILD_HTTPS
2198 curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 2190 curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSLVERSION,
2199 curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSL_VERIFYPEER, 0); 2191 CURL_SSLVERSION_TLSv1);
2200 curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSL_VERIFYHOST, 0); 2192 curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
2201#endif 2193 curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
2202 curl_easy_setopt(ps->recv_endpoint, CURLOPT_URL, ps->url); 2194#endif
2203 curl_easy_setopt(ps->recv_endpoint, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); 2195 curl_easy_setopt (ps->recv_endpoint, CURLOPT_URL, ps->url);
2204 curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEHEADER, ps); 2196 curl_easy_setopt (ps->recv_endpoint, CURLOPT_HEADERFUNCTION,
2205 curl_easy_setopt(ps->recv_endpoint, CURLOPT_READFUNCTION, curl_send_cb); 2197 &curl_get_header_cb);
2206 curl_easy_setopt(ps->recv_endpoint, CURLOPT_READDATA, ps); 2198 curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEHEADER, ps);
2207 curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb); 2199 curl_easy_setopt (ps->recv_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
2208 curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEDATA, ps); 2200 curl_easy_setopt (ps->recv_endpoint, CURLOPT_READDATA, ps);
2209 curl_easy_setopt(ps->recv_endpoint, CURLOPT_TIMEOUT, (long) timeout.rel_value); 2201 curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEFUNCTION,
2210 curl_easy_setopt(ps->recv_endpoint, CURLOPT_PRIVATE, ps); 2202 curl_receive_cb);
2211 curl_easy_setopt(ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); 2203 curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEDATA, ps);
2212 curl_easy_setopt(ps->recv_endpoint, CURLOPT_BUFFERSIZE, 2*GNUNET_SERVER_MAX_MESSAGE_SIZE); 2204 curl_easy_setopt (ps->recv_endpoint, CURLOPT_TIMEOUT,
2205 (long) timeout.rel_value);
2206 curl_easy_setopt (ps->recv_endpoint, CURLOPT_PRIVATE, ps);
2207 curl_easy_setopt (ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT,
2208 HTTP_CONNECT_TIMEOUT);
2209 curl_easy_setopt (ps->recv_endpoint, CURLOPT_BUFFERSIZE,
2210 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
2213#if CURL_TCP_NODELAY 2211#if CURL_TCP_NODELAY
2214 curl_easy_setopt(ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1); 2212 curl_easy_setopt (ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
2215#endif 2213#endif
2216 if (fresh==GNUNET_YES) 2214 if (fresh == GNUNET_YES)
2217 { 2215 {
2218 mret = curl_multi_add_handle(plugin->multi_handle, ps->recv_endpoint); 2216 mret = curl_multi_add_handle (plugin->multi_handle, ps->recv_endpoint);
2219 if (mret != CURLM_OK) 2217 if (mret != CURLM_OK)
2220 { 2218 {
2221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2222 _("Connection: %X: %s failed at %s:%d: `%s'\n"), 2220 _("Connection: %X: %s failed at %s:%d: `%s'\n"),
2223 ps, 2221 ps,
2224 "curl_multi_add_handle", __FILE__, __LINE__, 2222 "curl_multi_add_handle", __FILE__, __LINE__,
2225 curl_multi_strerror (mret)); 2223 curl_multi_strerror (mret));
2226 return GNUNET_SYSERR; 2224 return GNUNET_SYSERR;
2227 } 2225 }
2228 } 2226 }
2229 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 2227 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2230 { 2228 {
2231 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 2229 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2232 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2230 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2233 } 2231 }
2234 plugin->current_connections ++; 2232 plugin->current_connections++;
2235 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin); 2233 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2236 } 2234 }
2237 2235
2238 /* waiting for receive direction */ 2236 /* waiting for receive direction */
2239 if (ps->recv_connected==GNUNET_NO) 2237 if (ps->recv_connected == GNUNET_NO)
2240 return GNUNET_NO; 2238 return GNUNET_NO;
2241 2239
2242 /* SEND DIRECTION */ 2240 /* SEND DIRECTION */
2243 /* Check if session is connected to send data, otherwise connect to peer */ 2241 /* Check if session is connected to send data, otherwise connect to peer */
2244 if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint!= NULL)) 2242 if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint != NULL))
2245 { 2243 {
2246 if (ps->send_active == GNUNET_YES) 2244 if (ps->send_active == GNUNET_YES)
2247 { 2245 {
2248#if DEBUG_CONNECTIONS 2246#if DEBUG_CONNECTIONS
2249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2250 "Connection %X: outbound active, enqueueing message\n", 2248 "Connection %X: outbound active, enqueueing message\n", ps);
2251 ps); 2249#endif
2252#endif 2250 return GNUNET_YES;
2253 return GNUNET_YES; 2251 }
2254 } 2252 if (ps->send_active == GNUNET_NO)
2255 if (ps->send_active == GNUNET_NO) 2253 {
2256 {
2257#if DEBUG_CONNECTIONS 2254#if DEBUG_CONNECTIONS
2258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2259 "Connection %X: outbound paused, unpausing existing connection and enqueueing message\n", 2256 "Connection %X: outbound paused, unpausing existing connection and enqueueing message\n",
2260 ps); 2257 ps);
2261#endif 2258#endif
2262 if (CURLE_OK == curl_easy_pause(ps->send_endpoint,CURLPAUSE_CONT)) 2259 if (CURLE_OK == curl_easy_pause (ps->send_endpoint, CURLPAUSE_CONT))
2263 { 2260 {
2264 ps->send_active=GNUNET_YES; 2261 ps->send_active = GNUNET_YES;
2265 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 2262 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2266 { 2263 {
2267 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 2264 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2268 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2265 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2269 } 2266 }
2270 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin); 2267 plugin->http_curl_task =
2271 return GNUNET_YES; 2268 GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2272 } 2269 return GNUNET_YES;
2273 else 2270 }
2274 return GNUNET_SYSERR; 2271 else
2275 } 2272 return GNUNET_SYSERR;
2276 } 2273 }
2277 /* not connected, initiate connection */ 2274 }
2278 if ((ps->send_connected==GNUNET_NO) && (plugin->current_connections < plugin->max_connect_per_transport)) 2275 /* not connected, initiate connection */
2279 { 2276 if ((ps->send_connected == GNUNET_NO) &&
2280 int fresh = GNUNET_NO; 2277 (plugin->current_connections < plugin->max_connect_per_transport))
2281 if (NULL == ps->send_endpoint) 2278 {
2282 { 2279 int fresh = GNUNET_NO;
2283 ps->send_endpoint = curl_easy_init(); 2280
2284 fresh = GNUNET_YES; 2281 if (NULL == ps->send_endpoint)
2285 } 2282 {
2286 GNUNET_assert (ps->send_endpoint != NULL); 2283 ps->send_endpoint = curl_easy_init ();
2287 GNUNET_assert (NULL != ps->pending_msgs_tail); 2284 fresh = GNUNET_YES;
2285 }
2286 GNUNET_assert (ps->send_endpoint != NULL);
2287 GNUNET_assert (NULL != ps->pending_msgs_tail);
2288#if DEBUG_CONNECTIONS 2288#if DEBUG_CONNECTIONS
2289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2290 "Connection %X: outbound not connected, initiating connection\n", 2290 "Connection %X: outbound not connected, initiating connection\n",
2291 ps); 2291 ps);
2292#endif 2292#endif
2293 ps->send_active = GNUNET_NO; 2293 ps->send_active = GNUNET_NO;
2294 2294
2295#if DEBUG_CURL 2295#if DEBUG_CURL
2296 curl_easy_setopt(ps->send_endpoint, CURLOPT_VERBOSE, 1L); 2296 curl_easy_setopt (ps->send_endpoint, CURLOPT_VERBOSE, 1L);
2297 curl_easy_setopt(ps->send_endpoint, CURLOPT_DEBUGFUNCTION , &curl_logger); 2297 curl_easy_setopt (ps->send_endpoint, CURLOPT_DEBUGFUNCTION, &curl_logger);
2298 curl_easy_setopt(ps->send_endpoint, CURLOPT_DEBUGDATA , ps->send_endpoint); 2298 curl_easy_setopt (ps->send_endpoint, CURLOPT_DEBUGDATA,
2299 ps->send_endpoint);
2299#endif 2300#endif
2300#if BUILD_HTTPS 2301#if BUILD_HTTPS
2301 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 2302 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSLVERSION,
2302 curl_easy_setopt(ps->send_endpoint, CURLOPT_SSL_VERIFYPEER, 0); 2303 CURL_SSLVERSION_TLSv1);
2303 curl_easy_setopt(ps->send_endpoint, CURLOPT_SSL_VERIFYHOST, 0); 2304 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
2304#endif 2305 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
2305 curl_easy_setopt(ps->send_endpoint, CURLOPT_URL, ps->url); 2306#endif
2306 curl_easy_setopt(ps->send_endpoint, CURLOPT_PUT, 1L); 2307 curl_easy_setopt (ps->send_endpoint, CURLOPT_URL, ps->url);
2307 curl_easy_setopt(ps->send_endpoint, CURLOPT_HEADERFUNCTION, &curl_put_header_cb); 2308 curl_easy_setopt (ps->send_endpoint, CURLOPT_PUT, 1L);
2308 curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEHEADER, ps); 2309 curl_easy_setopt (ps->send_endpoint, CURLOPT_HEADERFUNCTION,
2309 curl_easy_setopt(ps->send_endpoint, CURLOPT_READFUNCTION, curl_send_cb); 2310 &curl_put_header_cb);
2310 curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps); 2311 curl_easy_setopt (ps->send_endpoint, CURLOPT_WRITEHEADER, ps);
2311 curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb); 2312 curl_easy_setopt (ps->send_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
2312 curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps); 2313 curl_easy_setopt (ps->send_endpoint, CURLOPT_READDATA, ps);
2313 curl_easy_setopt(ps->send_endpoint, CURLOPT_TIMEOUT, (long) timeout.rel_value); 2314 curl_easy_setopt (ps->send_endpoint, CURLOPT_WRITEFUNCTION,
2314 curl_easy_setopt(ps->send_endpoint, CURLOPT_PRIVATE, ps); 2315 curl_receive_cb);
2315 curl_easy_setopt(ps->send_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); 2316 curl_easy_setopt (ps->send_endpoint, CURLOPT_READDATA, ps);
2316 curl_easy_setopt(ps->send_endpoint, CURLOPT_BUFFERSIZE, 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); 2317 curl_easy_setopt (ps->send_endpoint, CURLOPT_TIMEOUT,
2318 (long) timeout.rel_value);
2319 curl_easy_setopt (ps->send_endpoint, CURLOPT_PRIVATE, ps);
2320 curl_easy_setopt (ps->send_endpoint, CURLOPT_CONNECTTIMEOUT,
2321 HTTP_CONNECT_TIMEOUT);
2322 curl_easy_setopt (ps->send_endpoint, CURLOPT_BUFFERSIZE,
2323 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
2317#if CURL_TCP_NODELAY 2324#if CURL_TCP_NODELAY
2318 curl_easy_setopt(ps->send_endpoint, CURLOPT_TCP_NODELAY, 1); 2325 curl_easy_setopt (ps->send_endpoint, CURLOPT_TCP_NODELAY, 1);
2319#endif 2326#endif
2320 if (fresh==GNUNET_YES) 2327 if (fresh == GNUNET_YES)
2321 { 2328 {
2322 mret = curl_multi_add_handle(plugin->multi_handle, ps->send_endpoint); 2329 mret = curl_multi_add_handle (plugin->multi_handle, ps->send_endpoint);
2323 if (mret != CURLM_OK) 2330 if (mret != CURLM_OK)
2324 { 2331 {
2325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2332 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2326 _("Connection: %X: %s failed at %s:%d: `%s'\n"), 2333 _("Connection: %X: %s failed at %s:%d: `%s'\n"),
2327 ps, 2334 ps,
2328 "curl_multi_add_handle", __FILE__, __LINE__, 2335 "curl_multi_add_handle", __FILE__, __LINE__,
2329 curl_multi_strerror (mret)); 2336 curl_multi_strerror (mret));
2330 return GNUNET_SYSERR; 2337 return GNUNET_SYSERR;
2331 } 2338 }
2332 } 2339 }
2333 }
2334 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2335 {
2336 GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
2337 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2338 }
2339 plugin->current_connections++;
2340 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2341 return GNUNET_YES;
2342 } 2340 }
2343 if (ps->direction == INBOUND) 2341 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2344 { 2342 {
2345 GNUNET_assert (NULL != ps->pending_msgs_tail); 2343 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2346 if ((ps->recv_connected==GNUNET_YES) && (ps->send_connected==GNUNET_YES) && 2344 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2347 (ps->recv_force_disconnect==GNUNET_NO) && (ps->recv_force_disconnect==GNUNET_NO))
2348 return GNUNET_YES;
2349 } 2345 }
2346 plugin->current_connections++;
2347 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2348 return GNUNET_YES;
2349 }
2350 if (ps->direction == INBOUND)
2351 {
2352 GNUNET_assert (NULL != ps->pending_msgs_tail);
2353 if ((ps->recv_connected == GNUNET_YES) && (ps->send_connected == GNUNET_YES)
2354 && (ps->recv_force_disconnect == GNUNET_NO) &&
2355 (ps->recv_force_disconnect == GNUNET_NO))
2356 return GNUNET_YES;
2357 }
2350 return GNUNET_SYSERR; 2358 return GNUNET_SYSERR;
2351} 2359}
2352 2360
@@ -2362,130 +2370,129 @@ send_check_connections (struct Plugin *plugin,
2362 * @return selected session 2370 * @return selected session
2363 * 2371 *
2364 */ 2372 */
2365static struct Session * 2373static struct Session *
2366send_select_session (struct HTTP_PeerContext *pc, 2374send_select_session (struct HTTP_PeerContext *pc,
2367 const void * addr, size_t addrlen, 2375 const void *addr, size_t addrlen,
2368 int force_address, 2376 int force_address, struct Session *session)
2369 struct Session * session)
2370{ 2377{
2371 struct Session * tmp = NULL; 2378 struct Session *tmp = NULL;
2372 int addr_given = GNUNET_NO; 2379 int addr_given = GNUNET_NO;
2373 2380
2374 if ((addr!=NULL) && (addrlen>0)) 2381 if ((addr != NULL) && (addrlen > 0))
2375 addr_given = GNUNET_YES; 2382 addr_given = GNUNET_YES;
2376 2383
2377 if (force_address == GNUNET_YES) 2384 if (force_address == GNUNET_YES)
2385 {
2386 /* check session given as argument */
2387 if ((session != NULL) && (addr_given == GNUNET_YES))
2378 { 2388 {
2379 /* check session given as argument */ 2389 if (0 == memcmp (session->addr, addr, addrlen))
2380 if ((session != NULL) && (addr_given == GNUNET_YES)) 2390 {
2381 { 2391 /* connection can not be used, since it is disconnected */
2382 if (0 == memcmp(session->addr, addr, addrlen)) 2392 if ((session->recv_force_disconnect == GNUNET_NO) &&
2383 { 2393 (session->send_force_disconnect == GNUNET_NO))
2384 /* connection can not be used, since it is disconnected */ 2394 {
2385 if ( (session->recv_force_disconnect==GNUNET_NO) &&
2386 (session->send_force_disconnect==GNUNET_NO) )
2387 {
2388#if DEBUG_SESSION_SELECTION 2395#if DEBUG_SESSION_SELECTION
2389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2390 "Session %X selected: Using session passed by transport to send to forced address \n", 2397 "Session %X selected: Using session passed by transport to send to forced address \n",
2391 session); 2398 session);
2392#endif 2399#endif
2393 return session; 2400 return session;
2394 } 2401 }
2395 } 2402 }
2396 } 2403 }
2397 /* check last session used */ 2404 /* check last session used */
2398 if ((pc->last_session != NULL)&& (addr_given == GNUNET_YES)) 2405 if ((pc->last_session != NULL) && (addr_given == GNUNET_YES))
2399 { 2406 {
2400 if (0 == memcmp(pc->last_session->addr, addr, addrlen)) 2407 if (0 == memcmp (pc->last_session->addr, addr, addrlen))
2401 { 2408 {
2402 /* connection can not be used, since it is disconnected */ 2409 /* connection can not be used, since it is disconnected */
2403 if ( (pc->last_session->recv_force_disconnect==GNUNET_NO) && 2410 if ((pc->last_session->recv_force_disconnect == GNUNET_NO) &&
2404 (pc->last_session->send_force_disconnect==GNUNET_NO) ) 2411 (pc->last_session->send_force_disconnect == GNUNET_NO))
2405 { 2412 {
2406#if DEBUG_SESSION_SELECTION 2413#if DEBUG_SESSION_SELECTION
2407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2408 "Session %X selected: Using last session used to send to forced address \n", 2415 "Session %X selected: Using last session used to send to forced address \n",
2409 pc->last_session); 2416 pc->last_session);
2410#endif 2417#endif
2411 return pc->last_session; 2418 return pc->last_session;
2412 } 2419 }
2413 } 2420 }
2414 } 2421 }
2415 /* find session in existing sessions */ 2422 /* find session in existing sessions */
2416 tmp = pc->head; 2423 tmp = pc->head;
2417 while ((tmp!=NULL) && (addr_given == GNUNET_YES)) 2424 while ((tmp != NULL) && (addr_given == GNUNET_YES))
2418 { 2425 {
2419 if (0 == memcmp(tmp->addr, addr, addrlen)) 2426 if (0 == memcmp (tmp->addr, addr, addrlen))
2420 { 2427 {
2421 /* connection can not be used, since it is disconnected */ 2428 /* connection can not be used, since it is disconnected */
2422 if ( (tmp->recv_force_disconnect==GNUNET_NO) && 2429 if ((tmp->recv_force_disconnect == GNUNET_NO) &&
2423 (tmp->send_force_disconnect==GNUNET_NO) ) 2430 (tmp->send_force_disconnect == GNUNET_NO))
2424 { 2431 {
2425#if DEBUG_SESSION_SELECTION 2432#if DEBUG_SESSION_SELECTION
2426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2427 "Session %X selected: Using existing session to send to forced address \n", 2434 "Session %X selected: Using existing session to send to forced address \n",
2428 session); 2435 session);
2429#endif 2436#endif
2430 return session; 2437 return session;
2431 } 2438 }
2432 } 2439 }
2433 tmp=tmp->next; 2440 tmp = tmp->next;
2434 }
2435 /* no session to use */
2436 return NULL;
2437 } 2441 }
2442 /* no session to use */
2443 return NULL;
2444 }
2438 if ((force_address == GNUNET_NO) || (force_address == GNUNET_SYSERR)) 2445 if ((force_address == GNUNET_NO) || (force_address == GNUNET_SYSERR))
2446 {
2447 /* check session given as argument */
2448 if (session != NULL)
2439 { 2449 {
2440 /* check session given as argument */ 2450 /* connection can not be used, since it is disconnected */
2441 if (session != NULL) 2451 if ((session->recv_force_disconnect == GNUNET_NO) &&
2442 { 2452 (session->send_force_disconnect == GNUNET_NO))
2443 /* connection can not be used, since it is disconnected */ 2453 {
2444 if ( (session->recv_force_disconnect==GNUNET_NO) &&
2445 (session->send_force_disconnect==GNUNET_NO) )
2446 {
2447#if DEBUG_SESSION_SELECTION 2454#if DEBUG_SESSION_SELECTION
2448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2449 "Session %X selected: Using session passed by transport to send not-forced address\n", 2456 "Session %X selected: Using session passed by transport to send not-forced address\n",
2450 session); 2457 session);
2451#endif 2458#endif
2452 return session; 2459 return session;
2453 } 2460 }
2454 } 2461 }
2455 /* check last session used */ 2462 /* check last session used */
2456 if (pc->last_session != NULL) 2463 if (pc->last_session != NULL)
2457 { 2464 {
2458 /* connection can not be used, since it is disconnected */ 2465 /* connection can not be used, since it is disconnected */
2459 if ( (pc->last_session->recv_force_disconnect==GNUNET_NO) && 2466 if ((pc->last_session->recv_force_disconnect == GNUNET_NO) &&
2460 (pc->last_session->send_force_disconnect==GNUNET_NO) ) 2467 (pc->last_session->send_force_disconnect == GNUNET_NO))
2461 { 2468 {
2462#if DEBUG_SESSION_SELECTION 2469#if DEBUG_SESSION_SELECTION
2463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2464 "Session %X selected: Using last session to send to not-forced address\n", 2471 "Session %X selected: Using last session to send to not-forced address\n",
2465 pc->last_session); 2472 pc->last_session);
2466#endif 2473#endif
2467 return pc->last_session; 2474 return pc->last_session;
2468 } 2475 }
2469 } 2476 }
2470 /* find session in existing sessions */ 2477 /* find session in existing sessions */
2471 tmp = pc->head; 2478 tmp = pc->head;
2472 while (tmp!=NULL) 2479 while (tmp != NULL)
2473 { 2480 {
2474 /* connection can not be used, since it is disconnected */ 2481 /* connection can not be used, since it is disconnected */
2475 if ( (tmp->recv_force_disconnect==GNUNET_NO) && 2482 if ((tmp->recv_force_disconnect == GNUNET_NO) &&
2476 (tmp->send_force_disconnect==GNUNET_NO) ) 2483 (tmp->send_force_disconnect == GNUNET_NO))
2477 { 2484 {
2478#if DEBUG_SESSION_SELECTION 2485#if DEBUG_SESSION_SELECTION
2479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2480 "Session %X selected: Using existing session to send to not-forced address\n", 2487 "Session %X selected: Using existing session to send to not-forced address\n",
2481 tmp); 2488 tmp);
2482#endif 2489#endif
2483 return tmp; 2490 return tmp;
2484 } 2491 }
2485 tmp=tmp->next; 2492 tmp = tmp->next;
2486 }
2487 return NULL;
2488 } 2493 }
2494 return NULL;
2495 }
2489 return NULL; 2496 return NULL;
2490} 2497}
2491 2498
@@ -2537,117 +2544,112 @@ http_plugin_send (void *cls,
2537 const void *addr, 2544 const void *addr,
2538 size_t addrlen, 2545 size_t addrlen,
2539 int force_address, 2546 int force_address,
2540 GNUNET_TRANSPORT_TransmitContinuation cont, 2547 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2541 void *cont_cls)
2542{ 2548{
2543 struct Plugin *plugin = cls; 2549 struct Plugin *plugin = cls;
2544 struct HTTP_Message *msg; 2550 struct HTTP_Message *msg;
2545 struct HTTP_PeerContext * pc; 2551 struct HTTP_PeerContext *pc;
2546 struct Session * ps = NULL; 2552 struct Session *ps = NULL;
2547 2553
2548 GNUNET_assert(cls !=NULL); 2554 GNUNET_assert (cls != NULL);
2549 2555
2550#if DEBUG_HTTP 2556#if DEBUG_HTTP
2551 char * force; 2557 char *force;
2552 2558
2553 if (force_address == GNUNET_YES) 2559 if (force_address == GNUNET_YES)
2554 GNUNET_asprintf(&force, "forced addr."); 2560 GNUNET_asprintf (&force, "forced addr.");
2555 else if (force_address == GNUNET_NO) 2561 else if (force_address == GNUNET_NO)
2556 GNUNET_asprintf(&force, "any addr."); 2562 GNUNET_asprintf (&force, "any addr.");
2557 else if (force_address == GNUNET_SYSERR) 2563 else if (force_address == GNUNET_SYSERR)
2558 GNUNET_asprintf(&force,"reliable bi-direc. address addr."); 2564 GNUNET_asprintf (&force, "reliable bi-direc. address addr.");
2559 else 2565 else
2560 GNUNET_assert (0); 2566 GNUNET_assert (0);
2561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2562 "Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n", 2568 "Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n",
2563 msgbuf_size, 2569 msgbuf_size,
2564 GNUNET_i2s(target), 2570 GNUNET_i2s (target),
2565 force, 2571 force,
2566 http_plugin_address_to_string(NULL, addr, addrlen), 2572 http_plugin_address_to_string (NULL, addr, addrlen), session);
2567 session); 2573 GNUNET_free (force);
2568 GNUNET_free(force);
2569#endif 2574#endif
2570 2575
2571 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey); 2576 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
2572 /* Peer unknown */ 2577 /* Peer unknown */
2573 if (pc==NULL) 2578 if (pc == NULL)
2574 { 2579 {
2575 pc = GNUNET_malloc(sizeof (struct HTTP_PeerContext)); 2580 pc = GNUNET_malloc (sizeof (struct HTTP_PeerContext));
2576 pc->plugin = plugin; 2581 pc->plugin = plugin;
2577 pc->session_id_counter=1; 2582 pc->session_id_counter = 1;
2578 pc->last_session = NULL; 2583 pc->last_session = NULL;
2579 memcpy(&pc->identity, target, sizeof(struct GNUNET_PeerIdentity)); 2584 memcpy (&pc->identity, target, sizeof (struct GNUNET_PeerIdentity));
2580 GNUNET_CONTAINER_multihashmap_put (plugin->peers, 2585 GNUNET_CONTAINER_multihashmap_put (plugin->peers,
2581 &pc->identity.hashPubKey, 2586 &pc->identity.hashPubKey,
2582 pc, 2587 pc,
2583 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2588 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2584 GNUNET_STATISTICS_update (plugin->env->stats, 2589 GNUNET_STATISTICS_update (plugin->env->stats,
2585 gettext_noop ("# HTTP peers active"), 2590 gettext_noop ("# HTTP peers active"),
2586 1, 2591 1, GNUNET_NO);
2587 GNUNET_NO); 2592 }
2588 }
2589 ps = send_select_session (pc, addr, addrlen, force_address, session); 2593 ps = send_select_session (pc, addr, addrlen, force_address, session);
2590 /* session not existing, but address forced -> creating new session */ 2594 /* session not existing, but address forced -> creating new session */
2591 if (ps==NULL) 2595 if (ps == NULL)
2596 {
2597 if ((addr != NULL) && (addrlen != 0))
2592 { 2598 {
2593 if ((addr!=NULL) && (addrlen!=0)) 2599 ps = GNUNET_malloc (sizeof (struct Session));
2594 {
2595 ps = GNUNET_malloc(sizeof (struct Session));
2596#if DEBUG_SESSION_SELECTION 2600#if DEBUG_SESSION_SELECTION
2597 if (force_address == GNUNET_YES) 2601 if (force_address == GNUNET_YES)
2598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2599 "No existing connection & forced address: creating new session %X to peer %s\n", 2603 "No existing connection & forced address: creating new session %X to peer %s\n",
2600 ps, GNUNET_i2s(target)); 2604 ps, GNUNET_i2s (target));
2601 if (force_address != GNUNET_YES) 2605 if (force_address != GNUNET_YES)
2602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2603 "No existing connection: creating new session %X to peer %s\n", 2607 "No existing connection: creating new session %X to peer %s\n",
2604 ps, GNUNET_i2s(target)); 2608 ps, GNUNET_i2s (target));
2605#endif
2606 ps->addr = GNUNET_malloc(addrlen);
2607 memcpy(ps->addr,addr,addrlen);
2608 ps->addrlen = addrlen;
2609 ps->direction=OUTBOUND;
2610 ps->recv_connected = GNUNET_NO;
2611 ps->recv_force_disconnect = GNUNET_NO;
2612 ps->send_connected = GNUNET_NO;
2613 ps->send_force_disconnect = GNUNET_NO;
2614 ps->pending_msgs_head = NULL;
2615 ps->pending_msgs_tail = NULL;
2616 ps->peercontext = pc;
2617 ps->session_id = pc->session_id_counter;
2618 ps->queue_length_cur = 0;
2619 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
2620 pc->session_id_counter++;
2621 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
2622 if (ps->msgtok == NULL)
2623 ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
2624 GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
2625 GNUNET_STATISTICS_update (plugin->env->stats,
2626 gettext_noop ("# HTTP outbound sessions for peers active"),
2627 1,
2628 GNUNET_NO);
2629 }
2630 else
2631 {
2632#if DEBUG_HTTP
2633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2634 "No existing session found & and no address given: no way to send this message to peer `%s'!\n",
2635 GNUNET_i2s(target));
2636#endif 2609#endif
2637 return GNUNET_SYSERR; 2610 ps->addr = GNUNET_malloc (addrlen);
2638 } 2611 memcpy (ps->addr, addr, addrlen);
2612 ps->addrlen = addrlen;
2613 ps->direction = OUTBOUND;
2614 ps->recv_connected = GNUNET_NO;
2615 ps->recv_force_disconnect = GNUNET_NO;
2616 ps->send_connected = GNUNET_NO;
2617 ps->send_force_disconnect = GNUNET_NO;
2618 ps->pending_msgs_head = NULL;
2619 ps->pending_msgs_tail = NULL;
2620 ps->peercontext = pc;
2621 ps->session_id = pc->session_id_counter;
2622 ps->queue_length_cur = 0;
2623 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
2624 pc->session_id_counter++;
2625 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
2626 if (ps->msgtok == NULL)
2627 ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
2628 GNUNET_CONTAINER_DLL_insert (pc->head, pc->tail, ps);
2629 GNUNET_STATISTICS_update (plugin->env->stats,
2630 gettext_noop
2631 ("# HTTP outbound sessions for peers active"),
2632 1, GNUNET_NO);
2639 } 2633 }
2640 2634 else
2641 if (msgbuf_size >= (ps->queue_length_max - ps->queue_length_cur))
2642 { 2635 {
2636#if DEBUG_HTTP
2643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2644 "Queue %X full: %u bytes in queue available, message with %u is too big\n", 2638 "No existing session found & and no address given: no way to send this message to peer `%s'!\n",
2645 ps, 2639 GNUNET_i2s (target));
2646 (ps->queue_length_max - ps->queue_length_cur), 2640#endif
2647 msgbuf_size); 2641 return GNUNET_SYSERR;
2648 //return GNUNET_SYSERR;
2649 } 2642 }
2650 2643 }
2644
2645 if (msgbuf_size >= (ps->queue_length_max - ps->queue_length_cur))
2646 {
2647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2648 "Queue %X full: %u bytes in queue available, message with %u is too big\n",
2649 ps, (ps->queue_length_max - ps->queue_length_cur), msgbuf_size);
2650 //return GNUNET_SYSERR;
2651 }
2652
2651 /* create msg */ 2653 /* create msg */
2652 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); 2654 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
2653 msg->next = NULL; 2655 msg->next = NULL;
@@ -2656,16 +2658,15 @@ http_plugin_send (void *cls,
2656 msg->buf = (char *) &msg[1]; 2658 msg->buf = (char *) &msg[1];
2657 msg->transmit_cont = cont; 2659 msg->transmit_cont = cont;
2658 msg->transmit_cont_cls = cont_cls; 2660 msg->transmit_cont_cls = cont_cls;
2659 memcpy (msg->buf,msgbuf, msgbuf_size); 2661 memcpy (msg->buf, msgbuf, msgbuf_size);
2660 GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head, 2662 GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head,
2661 ps->pending_msgs_tail, 2663 ps->pending_msgs_tail, msg);
2662 msg);
2663 ps->queue_length_cur += msgbuf_size; 2664 ps->queue_length_cur += msgbuf_size;
2664 if (send_check_connections (plugin, ps) == GNUNET_SYSERR) 2665 if (send_check_connections (plugin, ps) == GNUNET_SYSERR)
2665 return GNUNET_SYSERR; 2666 return GNUNET_SYSERR;
2666 if (force_address != GNUNET_YES) 2667 if (force_address != GNUNET_YES)
2667 pc->last_session = ps; 2668 pc->last_session = ps;
2668 if (pc->last_session==NULL) 2669 if (pc->last_session == NULL)
2669 pc->last_session = ps; 2670 pc->last_session = ps;
2670 return msg->size; 2671 return msg->size;
2671} 2672}
@@ -2680,49 +2681,48 @@ http_plugin_send (void *cls,
2680 * @param target peer from which to disconnect 2681 * @param target peer from which to disconnect
2681 */ 2682 */
2682static void 2683static void
2683http_plugin_disconnect (void *cls, 2684http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2684 const struct GNUNET_PeerIdentity *target)
2685{ 2685{
2686 struct Plugin *plugin = cls; 2686 struct Plugin *plugin = cls;
2687 struct HTTP_PeerContext *pc = NULL; 2687 struct HTTP_PeerContext *pc = NULL;
2688 struct Session *ps = NULL; 2688 struct Session *ps = NULL;
2689 2689
2690 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey); 2690 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
2691 if (pc==NULL) 2691 if (pc == NULL)
2692 return; 2692 return;
2693 ps = pc->head; 2693 ps = pc->head;
2694 while (ps!=NULL) 2694 while (ps != NULL)
2695 {
2696 /* Telling transport that session is getting disconnected */
2697 plugin->env->session_end (plugin, target, ps);
2698 if (ps->direction == OUTBOUND)
2695 { 2699 {
2696 /* Telling transport that session is getting disconnected */ 2700 if (ps->send_endpoint != NULL)
2697 plugin->env->session_end(plugin, target, ps); 2701 {
2698 if (ps->direction==OUTBOUND) 2702 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint));
2699 { 2703 //curl_easy_cleanup(ps->send_endpoint);
2700 if (ps->send_endpoint!=NULL) 2704 //ps->send_endpoint=NULL;
2701 { 2705 ps->send_force_disconnect = GNUNET_YES;
2702 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint)); 2706 }
2703 //curl_easy_cleanup(ps->send_endpoint); 2707 if (ps->recv_endpoint != NULL)
2704 //ps->send_endpoint=NULL; 2708 {
2705 ps->send_force_disconnect = GNUNET_YES; 2709 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint));
2706 } 2710 //curl_easy_cleanup(ps->recv_endpoint);
2707 if (ps->recv_endpoint!=NULL) 2711 //ps->recv_endpoint=NULL;
2708 { 2712 ps->recv_force_disconnect = GNUNET_YES;
2709 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint)); 2713 }
2710 //curl_easy_cleanup(ps->recv_endpoint);
2711 //ps->recv_endpoint=NULL;
2712 ps->recv_force_disconnect = GNUNET_YES;
2713 }
2714 }
2715 if (ps->direction==INBOUND)
2716 {
2717 ps->recv_force_disconnect = GNUNET_YES;
2718 ps->send_force_disconnect = GNUNET_YES;
2719 }
2720 while (ps->pending_msgs_head!=NULL)
2721 remove_http_message(ps, ps->pending_msgs_head);
2722 ps->recv_active = GNUNET_NO;
2723 ps->send_active = GNUNET_NO;
2724 ps=ps->next;
2725 } 2714 }
2715 if (ps->direction == INBOUND)
2716 {
2717 ps->recv_force_disconnect = GNUNET_YES;
2718 ps->send_force_disconnect = GNUNET_YES;
2719 }
2720 while (ps->pending_msgs_head != NULL)
2721 remove_http_message (ps, ps->pending_msgs_head);
2722 ps->recv_active = GNUNET_NO;
2723 ps->send_active = GNUNET_NO;
2724 ps = ps->next;
2725 }
2726} 2726}
2727 2727
2728 2728
@@ -2739,11 +2739,11 @@ append_port (void *cls, const char *hostname)
2739 char *ret; 2739 char *ret;
2740 2740
2741 if (hostname == NULL) 2741 if (hostname == NULL)
2742 { 2742 {
2743 ppc->asc (ppc->asc_cls, NULL); 2743 ppc->asc (ppc->asc_cls, NULL);
2744 GNUNET_free (ppc); 2744 GNUNET_free (ppc);
2745 return; 2745 return;
2746 } 2746 }
2747 GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port); 2747 GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port);
2748 2748
2749 ppc->asc (ppc->asc_cls, ret); 2749 ppc->asc (ppc->asc_cls, ret);
@@ -2768,61 +2768,57 @@ append_port (void *cls, const char *hostname)
2768 */ 2768 */
2769static void 2769static void
2770http_plugin_address_pretty_printer (void *cls, 2770http_plugin_address_pretty_printer (void *cls,
2771 const char *type, 2771 const char *type,
2772 const void *addr, 2772 const void *addr,
2773 size_t addrlen, 2773 size_t addrlen,
2774 int numeric, 2774 int numeric,
2775 struct GNUNET_TIME_Relative timeout, 2775 struct GNUNET_TIME_Relative timeout,
2776 GNUNET_TRANSPORT_AddressStringCallback 2776 GNUNET_TRANSPORT_AddressStringCallback
2777 asc, void *asc_cls) 2777 asc, void *asc_cls)
2778{ 2778{
2779 struct PrettyPrinterContext *ppc; 2779 struct PrettyPrinterContext *ppc;
2780 const void *sb; 2780 const void *sb;
2781 size_t sbs; 2781 size_t sbs;
2782 struct sockaddr_in a4; 2782 struct sockaddr_in a4;
2783 struct sockaddr_in6 a6; 2783 struct sockaddr_in6 a6;
2784 const struct IPv4HttpAddress *t4; 2784 const struct IPv4HttpAddress *t4;
2785 const struct IPv6HttpAddress *t6; 2785 const struct IPv6HttpAddress *t6;
2786 uint16_t port; 2786 uint16_t port;
2787 2787
2788 if (addrlen == sizeof (struct IPv6HttpAddress)) 2788 if (addrlen == sizeof (struct IPv6HttpAddress))
2789 { 2789 {
2790 t6 = addr; 2790 t6 = addr;
2791 memset (&a6, 0, sizeof (a6)); 2791 memset (&a6, 0, sizeof (a6));
2792 a6.sin6_family = AF_INET6; 2792 a6.sin6_family = AF_INET6;
2793 a6.sin6_port = t6->port; 2793 a6.sin6_port = t6->port;
2794 memcpy (&a6.sin6_addr, 2794 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
2795 &t6->ipv6_addr, 2795 port = ntohs (t6->port);
2796 sizeof (struct in6_addr)); 2796 sb = &a6;
2797 port = ntohs (t6->port); 2797 sbs = sizeof (a6);
2798 sb = &a6; 2798 }
2799 sbs = sizeof (a6);
2800 }
2801 else if (addrlen == sizeof (struct IPv4HttpAddress)) 2799 else if (addrlen == sizeof (struct IPv4HttpAddress))
2802 { 2800 {
2803 t4 = addr; 2801 t4 = addr;
2804 memset (&a4, 0, sizeof (a4)); 2802 memset (&a4, 0, sizeof (a4));
2805 a4.sin_family = AF_INET; 2803 a4.sin_family = AF_INET;
2806 a4.sin_port = t4->port; 2804 a4.sin_port = t4->port;
2807 a4.sin_addr.s_addr = t4->ipv4_addr; 2805 a4.sin_addr.s_addr = t4->ipv4_addr;
2808 port = ntohs (t4->ipv4_addr); 2806 port = ntohs (t4->ipv4_addr);
2809 sb = &a4; 2807 sb = &a4;
2810 sbs = sizeof (a4); 2808 sbs = sizeof (a4);
2811 } 2809 }
2812 else 2810 else
2813 { 2811 {
2814 /* invalid address */ 2812 /* invalid address */
2815 GNUNET_break_op (0); 2813 GNUNET_break_op (0);
2816 asc (asc_cls, NULL); 2814 asc (asc_cls, NULL);
2817 return; 2815 return;
2818 } 2816 }
2819 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 2817 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
2820 ppc->asc = asc; 2818 ppc->asc = asc;
2821 ppc->asc_cls = asc_cls; 2819 ppc->asc_cls = asc_cls;
2822 ppc->port = port; 2820 ppc->port = port;
2823 GNUNET_RESOLVER_hostname_get (sb, 2821 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
2824 sbs,
2825 !numeric, timeout, &append_port, ppc);
2826} 2822}
2827 2823
2828 2824
@@ -2840,8 +2836,7 @@ http_plugin_address_pretty_printer (void *cls,
2840 * and transport 2836 * and transport
2841 */ 2837 */
2842static int 2838static int
2843http_plugin_address_suggested (void *cls, 2839http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2844 const void *addr, size_t addrlen)
2845{ 2840{
2846 struct Plugin *plugin = cls; 2841 struct Plugin *plugin = cls;
2847 struct IPv4HttpAddress *v4; 2842 struct IPv4HttpAddress *v4;
@@ -2849,52 +2844,59 @@ http_plugin_address_suggested (void *cls,
2849 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head; 2844 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
2850 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head; 2845 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
2851 2846
2852 GNUNET_assert(cls !=NULL); 2847 GNUNET_assert (cls != NULL);
2853 if ((addrlen != sizeof (struct IPv4HttpAddress)) && 2848 if ((addrlen != sizeof (struct IPv4HttpAddress)) &&
2854 (addrlen != sizeof (struct IPv6HttpAddress))) 2849 (addrlen != sizeof (struct IPv6HttpAddress)))
2855 return GNUNET_SYSERR; 2850 return GNUNET_SYSERR;
2856 if (addrlen == sizeof (struct IPv4HttpAddress)) 2851 if (addrlen == sizeof (struct IPv4HttpAddress))
2852 {
2853 v4 = (struct IPv4HttpAddress *) addr;
2854 if (plugin->bind4_address != NULL)
2857 { 2855 {
2858 v4 = (struct IPv4HttpAddress *) addr; 2856 if (0 ==
2859 if (plugin->bind4_address!=NULL) 2857 memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr,
2860 { 2858 sizeof (uint32_t)))
2861 if (0 == memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr, sizeof(uint32_t)))
2862 return GNUNET_OK;
2863 else
2864 return GNUNET_SYSERR;
2865 }
2866 while (w_tv4!=NULL)
2867 {
2868 if (0==memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr, sizeof(uint32_t)))
2869 break;
2870 w_tv4 = w_tv4->next;
2871 }
2872 if (w_tv4 != NULL)
2873 return GNUNET_OK; 2859 return GNUNET_OK;
2874 else 2860 else
2875 return GNUNET_SYSERR; 2861 return GNUNET_SYSERR;
2862 }
2863 while (w_tv4 != NULL)
2864 {
2865 if (0 ==
2866 memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr, sizeof (uint32_t)))
2867 break;
2868 w_tv4 = w_tv4->next;
2876 } 2869 }
2870 if (w_tv4 != NULL)
2871 return GNUNET_OK;
2872 else
2873 return GNUNET_SYSERR;
2874 }
2877 if (addrlen == sizeof (struct IPv6HttpAddress)) 2875 if (addrlen == sizeof (struct IPv6HttpAddress))
2876 {
2877 v6 = (struct IPv6HttpAddress *) addr;
2878 if (plugin->bind6_address != NULL)
2878 { 2879 {
2879 v6 = (struct IPv6HttpAddress *) addr; 2880 if (0 ==
2880 if (plugin->bind6_address!=NULL) 2881 memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr,
2881 { 2882 sizeof (struct in6_addr)))
2882 if (0 == memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr, sizeof(struct in6_addr)))
2883 return GNUNET_OK;
2884 else
2885 return GNUNET_SYSERR;
2886 }
2887 while (w_tv6!=NULL)
2888 {
2889 if (0 == memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr, sizeof(struct in6_addr)))
2890 break;
2891 w_tv6 = w_tv6->next;
2892 }
2893 if (w_tv6 !=NULL)
2894 return GNUNET_OK; 2883 return GNUNET_OK;
2895 else 2884 else
2896 return GNUNET_SYSERR; 2885 return GNUNET_SYSERR;
2886 }
2887 while (w_tv6 != NULL)
2888 {
2889 if (0 ==
2890 memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr,
2891 sizeof (struct in6_addr)))
2892 break;
2893 w_tv6 = w_tv6->next;
2897 } 2894 }
2895 if (w_tv6 != NULL)
2896 return GNUNET_OK;
2897 else
2898 return GNUNET_SYSERR;
2899 }
2898 return GNUNET_SYSERR; 2900 return GNUNET_SYSERR;
2899} 2901}
2900 2902
@@ -2910,50 +2912,44 @@ http_plugin_address_suggested (void *cls,
2910 * @param addrlen length of the address 2912 * @param addrlen length of the address
2911 * @return string representing the same address 2913 * @return string representing the same address
2912 */ 2914 */
2913static const char* 2915static const char *
2914http_plugin_address_to_string (void *cls, 2916http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
2915 const void *addr,
2916 size_t addrlen)
2917{ 2917{
2918 const struct IPv4HttpAddress *t4; 2918 const struct IPv4HttpAddress *t4;
2919 const struct IPv6HttpAddress *t6; 2919 const struct IPv6HttpAddress *t6;
2920 struct sockaddr_in a4; 2920 struct sockaddr_in a4;
2921 struct sockaddr_in6 a6; 2921 struct sockaddr_in6 a6;
2922 char * address; 2922 char *address;
2923 static char rbuf[INET6_ADDRSTRLEN + 13]; 2923 static char rbuf[INET6_ADDRSTRLEN + 13];
2924 uint16_t port; 2924 uint16_t port;
2925 int res; 2925 int res;
2926 2926
2927 if (addrlen == sizeof (struct IPv6HttpAddress)) 2927 if (addrlen == sizeof (struct IPv6HttpAddress))
2928 { 2928 {
2929 address = GNUNET_malloc (INET6_ADDRSTRLEN); 2929 address = GNUNET_malloc (INET6_ADDRSTRLEN);
2930 t6 = addr; 2930 t6 = addr;
2931 a6.sin6_addr = t6->ipv6_addr; 2931 a6.sin6_addr = t6->ipv6_addr;
2932 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN); 2932 inet_ntop (AF_INET6, &(a6.sin6_addr), address, INET6_ADDRSTRLEN);
2933 port = ntohs(t6->port); 2933 port = ntohs (t6->port);
2934 } 2934 }
2935 else if (addrlen == sizeof (struct IPv4HttpAddress)) 2935 else if (addrlen == sizeof (struct IPv4HttpAddress))
2936 { 2936 {
2937 address = GNUNET_malloc (INET_ADDRSTRLEN); 2937 address = GNUNET_malloc (INET_ADDRSTRLEN);
2938 t4 = addr; 2938 t4 = addr;
2939 a4.sin_addr.s_addr = t4->ipv4_addr; 2939 a4.sin_addr.s_addr = t4->ipv4_addr;
2940 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN); 2940 inet_ntop (AF_INET, &(a4.sin_addr), address, INET_ADDRSTRLEN);
2941 port = ntohs(t4->port); 2941 port = ntohs (t4->port);
2942 } 2942 }
2943 else 2943 else
2944 { 2944 {
2945 /* invalid address */ 2945 /* invalid address */
2946 return NULL; 2946 return NULL;
2947 } 2947 }
2948 2948
2949 res = GNUNET_snprintf (rbuf, 2949 res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", address, port);
2950 sizeof (rbuf),
2951 "%s:%u",
2952 address,
2953 port);
2954 2950
2955 GNUNET_free (address); 2951 GNUNET_free (address);
2956 GNUNET_assert(res != 0); 2952 GNUNET_assert (res != 0);
2957 return rbuf; 2953 return rbuf;
2958} 2954}
2959 2955
@@ -2968,23 +2964,21 @@ http_plugin_address_to_string (void *cls,
2968 */ 2964 */
2969static void 2965static void
2970try_connection_reversal (void *cls, 2966try_connection_reversal (void *cls,
2971 const struct sockaddr *addr, 2967 const struct sockaddr *addr, socklen_t addrlen)
2972 socklen_t addrlen)
2973{ 2968{
2974 2969
2975} 2970}
2976 2971
2977static void 2972static void
2978tcp_nat_cb_add_addr (void *cls, 2973tcp_nat_cb_add_addr (void *cls,
2979 int add_remove, 2974 int add_remove,
2980 const struct sockaddr *addr, 2975 const struct sockaddr *addr, socklen_t addrlen)
2981 socklen_t addrlen)
2982{ 2976{
2983 struct Plugin *plugin = cls; 2977 struct Plugin *plugin = cls;
2984 struct IPv4HttpAddress * t4 = NULL; 2978 struct IPv4HttpAddress *t4 = NULL;
2985 struct IPv4HttpAddressWrapper * w_t4 = NULL; 2979 struct IPv4HttpAddressWrapper *w_t4 = NULL;
2986 struct IPv6HttpAddress * t6 = NULL; 2980 struct IPv6HttpAddress *t6 = NULL;
2987 struct IPv6HttpAddressWrapper * w_t6 = NULL; 2981 struct IPv6HttpAddressWrapper *w_t6 = NULL;
2988 int af; 2982 int af;
2989 2983
2990 af = addr->sa_family; 2984 af = addr->sa_family;
@@ -2994,61 +2988,63 @@ tcp_nat_cb_add_addr (void *cls,
2994 w_t4 = plugin->ipv4_addr_head; 2988 w_t4 = plugin->ipv4_addr_head;
2995 while (w_t4 != NULL) 2989 while (w_t4 != NULL)
2996 { 2990 {
2997 int res = memcmp(&w_t4->addr->ipv4_addr, 2991 int res = memcmp (&w_t4->addr->ipv4_addr,
2998 &((struct sockaddr_in *) addr)->sin_addr, 2992 &((struct sockaddr_in *) addr)->sin_addr,
2999 sizeof (struct in_addr)); 2993 sizeof (struct in_addr));
2994
3000 if (0 == res) 2995 if (0 == res)
3001 break; 2996 break;
3002 w_t4 = w_t4->next; 2997 w_t4 = w_t4->next;
3003 } 2998 }
3004 if (w_t4 == NULL) 2999 if (w_t4 == NULL)
3005 { 3000 {
3006 w_t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddressWrapper)); 3001 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
3007 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); 3002 t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
3008 memcpy (&t4->ipv4_addr, 3003 memcpy (&t4->ipv4_addr,
3009 &((struct sockaddr_in *) addr)->sin_addr, 3004 &((struct sockaddr_in *) addr)->sin_addr,
3010 sizeof (struct in_addr)); 3005 sizeof (struct in_addr));
3011 t4->port = htons (plugin->port_inbound); 3006 t4->port = htons (plugin->port_inbound);
3012 3007
3013 w_t4->addr = t4; 3008 w_t4->addr = t4;
3014 3009
3015 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, 3010 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
3016 plugin->ipv4_addr_tail,w_t4); 3011 plugin->ipv4_addr_tail, w_t4);
3017 } 3012 }
3018 plugin->env->notify_address(plugin->env->cls, 3013 plugin->env->notify_address (plugin->env->cls,
3019 add_remove, 3014 add_remove,
3020 w_t4->addr, sizeof (struct IPv4HttpAddress)); 3015 w_t4->addr, sizeof (struct IPv4HttpAddress));
3021 3016
3022 break; 3017 break;
3023 case AF_INET6: 3018 case AF_INET6:
3024 w_t6 = plugin->ipv6_addr_head; 3019 w_t6 = plugin->ipv6_addr_head;
3025 while (w_t6) 3020 while (w_t6)
3026 { 3021 {
3027 int res = memcmp(&w_t6->addr->ipv6_addr, 3022 int res = memcmp (&w_t6->addr->ipv6_addr,
3028 &((struct sockaddr_in6 *) addr)->sin6_addr, 3023 &((struct sockaddr_in6 *) addr)->sin6_addr,
3029 sizeof (struct in6_addr)); 3024 sizeof (struct in6_addr));
3025
3030 if (0 == res) 3026 if (0 == res)
3031 break; 3027 break;
3032 w_t6 = w_t6->next; 3028 w_t6 = w_t6->next;
3033 } 3029 }
3034 if (w_t6 == NULL) 3030 if (w_t6 == NULL)
3035 { 3031 {
3036 w_t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddressWrapper)); 3032 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
3037 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); 3033 t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
3038 3034
3039 memcpy (&t6->ipv6_addr, 3035 memcpy (&t6->ipv6_addr,
3040 &((struct sockaddr_in6 *) addr)->sin6_addr, 3036 &((struct sockaddr_in6 *) addr)->sin6_addr,
3041 sizeof (struct in6_addr)); 3037 sizeof (struct in6_addr));
3042 t6->port = htons (plugin->port_inbound); 3038 t6->port = htons (plugin->port_inbound);
3043 3039
3044 w_t6->addr = t6; 3040 w_t6->addr = t6;
3045 3041
3046 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, 3042 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
3047 plugin->ipv6_addr_tail,w_t6); 3043 plugin->ipv6_addr_tail, w_t6);
3048 } 3044 }
3049 plugin->env->notify_address(plugin->env->cls, 3045 plugin->env->notify_address (plugin->env->cls,
3050 add_remove, 3046 add_remove,
3051 w_t6->addr, sizeof (struct IPv6HttpAddress)); 3047 w_t6->addr, sizeof (struct IPv6HttpAddress));
3052 break; 3048 break;
3053 default: 3049 default:
3054 return; 3050 return;
@@ -3058,13 +3054,12 @@ tcp_nat_cb_add_addr (void *cls,
3058 3054
3059static void 3055static void
3060tcp_nat_cb_remove_addr (void *cls, 3056tcp_nat_cb_remove_addr (void *cls,
3061 int add_remove, 3057 int add_remove,
3062 const struct sockaddr *addr, 3058 const struct sockaddr *addr, socklen_t addrlen)
3063 socklen_t addrlen)
3064{ 3059{
3065 struct Plugin *plugin = cls; 3060 struct Plugin *plugin = cls;
3066 struct IPv4HttpAddressWrapper * w_t4 = NULL; 3061 struct IPv4HttpAddressWrapper *w_t4 = NULL;
3067 struct IPv6HttpAddressWrapper * w_t6 = NULL; 3062 struct IPv6HttpAddressWrapper *w_t6 = NULL;
3068 int af; 3063 int af;
3069 3064
3070 af = addr->sa_family; 3065 af = addr->sa_family;
@@ -3072,45 +3067,47 @@ tcp_nat_cb_remove_addr (void *cls,
3072 { 3067 {
3073 case AF_INET: 3068 case AF_INET:
3074 w_t4 = plugin->ipv4_addr_head; 3069 w_t4 = plugin->ipv4_addr_head;
3075 while (w_t4 != NULL) 3070 while (w_t4 != NULL)
3076 { 3071 {
3077 int res = memcmp(&w_t4->addr->ipv4_addr, 3072 int res = memcmp (&w_t4->addr->ipv4_addr,
3078 &((struct sockaddr_in *) addr)->sin_addr, 3073 &((struct sockaddr_in *) addr)->sin_addr,
3079 sizeof (struct in_addr)); 3074 sizeof (struct in_addr));
3080 if (0 == res) 3075
3081 break; 3076 if (0 == res)
3082 w_t4 = w_t4->next; 3077 break;
3083 } 3078 w_t4 = w_t4->next;
3084 if (w_t4 == NULL) 3079 }
3085 return; 3080 if (w_t4 == NULL)
3086 plugin->env->notify_address(plugin->env->cls, 3081 return;
3087 add_remove, 3082 plugin->env->notify_address (plugin->env->cls,
3088 w_t4->addr, sizeof (struct IPv4HttpAddress)); 3083 add_remove,
3089 3084 w_t4->addr, sizeof (struct IPv4HttpAddress));
3090 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head, 3085
3091 plugin->ipv4_addr_tail,w_t4); 3086 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head,
3092 GNUNET_free (w_t4->addr); 3087 plugin->ipv4_addr_tail, w_t4);
3093 GNUNET_free (w_t4); 3088 GNUNET_free (w_t4->addr);
3089 GNUNET_free (w_t4);
3094 break; 3090 break;
3095 case AF_INET6: 3091 case AF_INET6:
3096 w_t6 = plugin->ipv6_addr_head; 3092 w_t6 = plugin->ipv6_addr_head;
3097 while (w_t6 != NULL) 3093 while (w_t6 != NULL)
3098 { 3094 {
3099 int res = memcmp(&w_t6->addr->ipv6_addr, 3095 int res = memcmp (&w_t6->addr->ipv6_addr,
3100 &((struct sockaddr_in6 *) addr)->sin6_addr, 3096 &((struct sockaddr_in6 *) addr)->sin6_addr,
3101 sizeof (struct in6_addr)); 3097 sizeof (struct in6_addr));
3098
3102 if (0 == res) 3099 if (0 == res)
3103 break; 3100 break;
3104 w_t6 = w_t6->next; 3101 w_t6 = w_t6->next;
3105 } 3102 }
3106 if (w_t6 == NULL) 3103 if (w_t6 == NULL)
3107 return; 3104 return;
3108 plugin->env->notify_address(plugin->env->cls, 3105 plugin->env->notify_address (plugin->env->cls,
3109 add_remove, 3106 add_remove,
3110 w_t6->addr, sizeof (struct IPv6HttpAddress)); 3107 w_t6->addr, sizeof (struct IPv6HttpAddress));
3111 3108
3112 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head, 3109 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head,
3113 plugin->ipv6_addr_tail,w_t6); 3110 plugin->ipv6_addr_tail, w_t6);
3114 GNUNET_free (w_t6->addr); 3111 GNUNET_free (w_t6->addr);
3115 GNUNET_free (w_t6); 3112 GNUNET_free (w_t6);
3116 break; 3113 break;
@@ -3132,10 +3129,9 @@ tcp_nat_cb_remove_addr (void *cls,
3132static void 3129static void
3133tcp_nat_port_map_callback (void *cls, 3130tcp_nat_port_map_callback (void *cls,
3134 int add_remove, 3131 int add_remove,
3135 const struct sockaddr *addr, 3132 const struct sockaddr *addr, socklen_t addrlen)
3136 socklen_t addrlen)
3137{ 3133{
3138 GNUNET_assert(cls !=NULL ); 3134 GNUNET_assert (cls != NULL);
3139#if DEBUG_HTTP 3135#if DEBUG_HTTP
3140 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 3136 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
3141 "NPMC called to %s address `%s'\n", 3137 "NPMC called to %s address `%s'\n",
@@ -3163,74 +3159,77 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3163 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3159 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3164 struct Plugin *plugin = api->cls; 3160 struct Plugin *plugin = api->cls;
3165 CURLMcode mret; 3161 CURLMcode mret;
3166 struct IPv4HttpAddressWrapper * w_t4; 3162 struct IPv4HttpAddressWrapper *w_t4;
3167 struct IPv6HttpAddressWrapper * w_t6; 3163 struct IPv6HttpAddressWrapper *w_t6;
3168 GNUNET_assert(cls !=NULL); 3164
3165 GNUNET_assert (cls != NULL);
3169 3166
3170 if (plugin->nat != NULL) 3167 if (plugin->nat != NULL)
3171 GNUNET_NAT_unregister (plugin->nat); 3168 GNUNET_NAT_unregister (plugin->nat);
3172 3169
3173 if (plugin->http_server_daemon_v4 != NULL) 3170 if (plugin->http_server_daemon_v4 != NULL)
3174 { 3171 {
3175 MHD_stop_daemon (plugin->http_server_daemon_v4); 3172 MHD_stop_daemon (plugin->http_server_daemon_v4);
3176 plugin->http_server_daemon_v4 = NULL; 3173 plugin->http_server_daemon_v4 = NULL;
3177 } 3174 }
3178 if (plugin->http_server_daemon_v6 != NULL) 3175 if (plugin->http_server_daemon_v6 != NULL)
3179 { 3176 {
3180 MHD_stop_daemon (plugin->http_server_daemon_v6); 3177 MHD_stop_daemon (plugin->http_server_daemon_v6);
3181 plugin->http_server_daemon_v6 = NULL; 3178 plugin->http_server_daemon_v6 = NULL;
3182 } 3179 }
3183 if ( plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 3180 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
3184 { 3181 {
3185 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v4); 3182 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v4);
3186 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK; 3183 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
3187 } 3184 }
3188 if ( plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) 3185 if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
3189 { 3186 {
3190 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v6); 3187 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v6);
3191 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; 3188 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
3192 } 3189 }
3190
3191 while (plugin->ipv4_addr_head != NULL)
3192 {
3193 w_t4 = plugin->ipv4_addr_head;
3194 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
3195 w_t4);
3196 GNUNET_free (w_t4->addr);
3197 GNUNET_free (w_t4);
3198 }
3199
3200 while (plugin->ipv6_addr_head != NULL)
3201 {
3202 w_t6 = plugin->ipv6_addr_head;
3203 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
3204 w_t6);
3205 GNUNET_free (w_t6->addr);
3206 GNUNET_free (w_t6);
3207 }
3193 3208
3194 while (plugin->ipv4_addr_head!=NULL)
3195 {
3196 w_t4 = plugin->ipv4_addr_head;
3197 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,w_t4);
3198 GNUNET_free(w_t4->addr);
3199 GNUNET_free(w_t4);
3200 }
3201
3202 while (plugin->ipv6_addr_head!=NULL)
3203 {
3204 w_t6 = plugin->ipv6_addr_head;
3205 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,w_t6);
3206 GNUNET_free(w_t6->addr);
3207 GNUNET_free(w_t6);
3208 }
3209
3210 /* free all peer information */ 3209 /* free all peer information */
3211 if (plugin->peers!=NULL) 3210 if (plugin->peers != NULL)
3212 { 3211 {
3213 GNUNET_CONTAINER_multihashmap_iterate (plugin->peers, 3212 GNUNET_CONTAINER_multihashmap_iterate (plugin->peers,
3214 &remove_peer_context_Iterator, 3213 &remove_peer_context_Iterator,
3215 plugin); 3214 plugin);
3216 GNUNET_CONTAINER_multihashmap_destroy (plugin->peers); 3215 GNUNET_CONTAINER_multihashmap_destroy (plugin->peers);
3217 } 3216 }
3218 if (plugin->multi_handle!=NULL) 3217 if (plugin->multi_handle != NULL)
3219 { 3218 {
3220 mret = curl_multi_cleanup(plugin->multi_handle); 3219 mret = curl_multi_cleanup (plugin->multi_handle);
3221 if (CURLM_OK != mret) 3220 if (CURLM_OK != mret)
3222 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3223 "curl multihandle clean up failed\n"); 3222 "curl multihandle clean up failed\n");
3224 plugin->multi_handle = NULL; 3223 plugin->multi_handle = NULL;
3225 } 3224 }
3226 curl_global_cleanup(); 3225 curl_global_cleanup ();
3227 3226
3228 if ( plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 3227 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
3229 { 3228 {
3230 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 3229 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
3231 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 3230 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
3232 } 3231 }
3233 3232
3234 3233
3235 GNUNET_free_non_null (plugin->bind4_address); 3234 GNUNET_free_non_null (plugin->bind4_address);
3236 GNUNET_free_non_null (plugin->bind6_address); 3235 GNUNET_free_non_null (plugin->bind6_address);
@@ -3244,35 +3243,36 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3244 GNUNET_free (api); 3243 GNUNET_free (api);
3245#if DEBUG_HTTP 3244#if DEBUG_HTTP
3246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3247 "Unload %s plugin complete...\n", 3246 "Unload %s plugin complete...\n", PROTOCOL_PREFIX);
3248 PROTOCOL_PREFIX);
3249#endif 3247#endif
3250 return NULL; 3248 return NULL;
3251} 3249}
3252 3250
3253#if BUILD_HTTPS 3251#if BUILD_HTTPS
3254static char * 3252static char *
3255load_certificate( const char * file ) 3253load_certificate (const char *file)
3256{ 3254{
3257 struct GNUNET_DISK_FileHandle * gn_file; 3255 struct GNUNET_DISK_FileHandle *gn_file;
3258 struct stat fstat; 3256 struct stat fstat;
3259 char * text = NULL; 3257 char *text = NULL;
3260 3258
3261 if (0 != STAT(file, &fstat)) 3259 if (0 != STAT (file, &fstat))
3262 return NULL; 3260 return NULL;
3263 text = GNUNET_malloc (fstat.st_size+1); 3261 text = GNUNET_malloc (fstat.st_size + 1);
3264 gn_file = GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ); 3262 gn_file =
3265 if (gn_file==NULL) 3263 GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
3266 { 3264 GNUNET_DISK_PERM_USER_READ);
3267 GNUNET_free(text); 3265 if (gn_file == NULL)
3268 return NULL; 3266 {
3269 } 3267 GNUNET_free (text);
3268 return NULL;
3269 }
3270 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size)) 3270 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size))
3271 { 3271 {
3272 GNUNET_free (text); 3272 GNUNET_free (text);
3273 GNUNET_DISK_file_close (gn_file); 3273 GNUNET_DISK_file_close (gn_file);
3274 return NULL; 3274 return NULL;
3275 } 3275 }
3276 text[fstat.st_size] = '\0'; 3276 text[fstat.st_size] = '\0';
3277 GNUNET_DISK_file_close (gn_file); 3277 GNUNET_DISK_file_close (gn_file);
3278 return text; 3278 return text;
@@ -3295,21 +3295,19 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3295 struct sockaddr **addrs; 3295 struct sockaddr **addrs;
3296 socklen_t *addrlens; 3296 socklen_t *addrlens;
3297 int ret; 3297 int ret;
3298 char * component_name; 3298 char *component_name;
3299
3299#if BUILD_HTTPS 3300#if BUILD_HTTPS
3300 char * key_file = NULL; 3301 char *key_file = NULL;
3301 char * cert_file = NULL; 3302 char *cert_file = NULL;
3302#endif 3303#endif
3303 3304
3304 GNUNET_assert(cls !=NULL); 3305 GNUNET_assert (cls != NULL);
3305#if DEBUG_HTTP 3306#if DEBUG_HTTP
3306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3307 "Starting %s plugin...\n", 3308 "Starting %s plugin...\n", PROTOCOL_PREFIX);
3308 PROTOCOL_PREFIX);
3309#endif 3309#endif
3310 GNUNET_asprintf(&component_name, 3310 GNUNET_asprintf (&component_name, "transport-%s", PROTOCOL_PREFIX);
3311 "transport-%s",
3312 PROTOCOL_PREFIX);
3313 3311
3314 plugin = GNUNET_malloc (sizeof (struct Plugin)); 3312 plugin = GNUNET_malloc (sizeof (struct Plugin));
3315 plugin->stats = env->stats; 3313 plugin->stats = env->stats;
@@ -3317,8 +3315,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3317 plugin->peers = NULL; 3315 plugin->peers = NULL;
3318 plugin->bind4_address = NULL; 3316 plugin->bind4_address = NULL;
3319 plugin->bind6_address = NULL; 3317 plugin->bind6_address = NULL;
3320 plugin->use_ipv6 = GNUNET_YES; 3318 plugin->use_ipv6 = GNUNET_YES;
3321 plugin->use_ipv4 = GNUNET_YES; 3319 plugin->use_ipv4 = GNUNET_YES;
3322 plugin->use_localaddresses = GNUNET_NO; 3320 plugin->use_localaddresses = GNUNET_NO;
3323 3321
3324 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 3322 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
@@ -3330,207 +3328,207 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3330 api->address_to_string = &http_plugin_address_to_string; 3328 api->address_to_string = &http_plugin_address_to_string;
3331 3329
3332 /* Hashing our identity to use it in URLs */ 3330 /* Hashing our identity to use it in URLs */
3333 GNUNET_CRYPTO_hash_to_enc (&(plugin->env->my_identity->hashPubKey), 3331 GNUNET_CRYPTO_hash_to_enc (&(plugin->env->my_identity->hashPubKey),
3334 &plugin->my_ascii_hash_ident); 3332 &plugin->my_ascii_hash_ident);
3335 3333
3336 3334
3337 if (GNUNET_OK != 3335 if (GNUNET_OK !=
3338 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3336 GNUNET_CONFIGURATION_get_value_number (env->cfg,
3339 component_name, 3337 component_name,
3340 "MAX_CONNECTIONS", 3338 "MAX_CONNECTIONS", &tneigh))
3341 &tneigh))
3342 tneigh = 128; 3339 tneigh = 128;
3343 plugin->max_connect_per_transport = tneigh; 3340 plugin->max_connect_per_transport = tneigh;
3344 3341
3345 3342
3346 /* Use IPv6? */ 3343 /* Use IPv6? */
3347 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3344 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv6"))
3348 component_name, "USE_IPv6")) 3345 {
3349 { 3346 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3350 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3347 component_name,
3351 component_name, 3348 "USE_IPv6");
3352 "USE_IPv6"); 3349 }
3353 }
3354 /* Use IPv4? */ 3350 /* Use IPv4? */
3355 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3351 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv4"))
3356 component_name, "USE_IPv4")) 3352 {
3357 { 3353 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3358 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3354 component_name,
3359 component_name,"USE_IPv4"); 3355 "USE_IPv4");
3360 } 3356 }
3361 /* use local addresses? */ 3357 /* use local addresses? */
3362 3358
3363 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3359 if (GNUNET_CONFIGURATION_have_value (env->cfg,
3364 component_name, "USE_LOCALADDR")) 3360 component_name, "USE_LOCALADDR"))
3365 { 3361 {
3366 plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3362 plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3367 component_name, 3363 component_name,
3368 "USE_LOCALADDR"); 3364 "USE_LOCALADDR");
3369 } 3365 }
3370 /* Reading port number from config file */ 3366 /* Reading port number from config file */
3371 if ((GNUNET_OK != 3367 if ((GNUNET_OK !=
3372 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3368 GNUNET_CONFIGURATION_get_value_number (env->cfg,
3373 component_name, 3369 component_name,
3374 "PORT", 3370 "PORT", &port)) || (port > 65535))
3375 &port)) || 3371 {
3376 (port > 65535) ) 3372 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3377 { 3373 component_name,
3378 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3374 _
3379 component_name, 3375 ("Require valid port number for transport plugin `%s' in configuration!\n"),
3380 _("Require valid port number for transport plugin `%s' in configuration!\n"), 3376 PROTOCOL_PREFIX);
3381 PROTOCOL_PREFIX); 3377 GNUNET_free (component_name);
3382 GNUNET_free(component_name); 3378 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3383 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3379 return NULL;
3384 return NULL; 3380 }
3385 }
3386 3381
3387 /* Reading ipv4 addresse to bind to from config file */ 3382 /* Reading ipv4 addresse to bind to from config file */
3388 if ( (plugin->use_ipv4==GNUNET_YES) && 3383 if ((plugin->use_ipv4 == GNUNET_YES) &&
3389 (GNUNET_CONFIGURATION_have_value (env->cfg, 3384 (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO4")))
3390 component_name, "BINDTO4"))) 3385 {
3391 { 3386 GNUNET_break (GNUNET_OK ==
3392 GNUNET_break (GNUNET_OK == 3387 GNUNET_CONFIGURATION_get_value_string (env->cfg,
3393 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3388 component_name,
3394 component_name, 3389 "BINDTO4",
3395 "BINDTO4", 3390 &plugin->bind_hostname));
3396 &plugin->bind_hostname)); 3391 plugin->bind4_address = GNUNET_malloc (sizeof (struct sockaddr_in));
3397 plugin->bind4_address = GNUNET_malloc(sizeof(struct sockaddr_in)); 3392 plugin->bind4_address->sin_family = AF_INET;
3398 plugin->bind4_address->sin_family = AF_INET; 3393 plugin->bind4_address->sin_port = htons (port);
3399 plugin->bind4_address->sin_port = htons (port); 3394
3400 3395 if (plugin->bind_hostname != NULL)
3401 if (plugin->bind_hostname!=NULL) 3396 {
3402 { 3397 if (inet_pton
3403 if (inet_pton(AF_INET,plugin->bind_hostname, &plugin->bind4_address->sin_addr)<=0) 3398 (AF_INET, plugin->bind_hostname,
3404 { 3399 &plugin->bind4_address->sin_addr) <= 0)
3405 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3400 {
3406 component_name, 3401 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3407 _("Misconfigured address to bind to in configuration!\n")); 3402 component_name,
3408 GNUNET_free(plugin->bind4_address); 3403 _
3409 GNUNET_free(plugin->bind_hostname); 3404 ("Misconfigured address to bind to in configuration!\n"));
3410 plugin->bind_hostname = NULL; 3405 GNUNET_free (plugin->bind4_address);
3411 plugin->bind4_address = NULL; 3406 GNUNET_free (plugin->bind_hostname);
3412 } 3407 plugin->bind_hostname = NULL;
3413 } 3408 plugin->bind4_address = NULL;
3409 }
3414 } 3410 }
3415 3411 }
3412
3416 /* Reading ipv4 addresse to bind to from config file */ 3413 /* Reading ipv4 addresse to bind to from config file */
3417 if ( (plugin->use_ipv6==GNUNET_YES) && 3414 if ((plugin->use_ipv6 == GNUNET_YES) &&
3418 (GNUNET_CONFIGURATION_have_value (env->cfg, 3415 (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO6")))
3419 component_name, "BINDTO6"))) 3416 {
3420 { 3417 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg,
3421 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3418 component_name,
3422 component_name, 3419 "BINDTO6",
3423 "BINDTO6", 3420 &plugin->bind_hostname))
3424 &plugin->bind_hostname)) 3421 {
3425 { 3422 plugin->bind6_address = GNUNET_malloc (sizeof (struct sockaddr_in6));
3426 plugin->bind6_address = GNUNET_malloc(sizeof(struct sockaddr_in6)); 3423 plugin->bind6_address->sin6_family = AF_INET6;
3427 plugin->bind6_address->sin6_family = AF_INET6; 3424 plugin->bind6_address->sin6_port = htons (port);
3428 plugin->bind6_address->sin6_port = htons (port); 3425 if (plugin->bind_hostname != NULL)
3429 if (plugin->bind_hostname!=NULL) 3426 {
3430 { 3427 if (inet_pton
3431 if (inet_pton(AF_INET6,plugin->bind_hostname, &plugin->bind6_address->sin6_addr)<=0) 3428 (AF_INET6, plugin->bind_hostname,
3432 { 3429 &plugin->bind6_address->sin6_addr) <= 0)
3433 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3430 {
3434 component_name, 3431 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3435 _("Misconfigured address to bind to in configuration!\n")); 3432 component_name,
3436 GNUNET_free(plugin->bind6_address); 3433 _
3437 GNUNET_free(plugin->bind_hostname); 3434 ("Misconfigured address to bind to in configuration!\n"));
3438 plugin->bind_hostname = NULL; 3435 GNUNET_free (plugin->bind6_address);
3439 plugin->bind6_address = NULL; 3436 GNUNET_free (plugin->bind_hostname);
3440 } 3437 plugin->bind_hostname = NULL;
3441 } 3438 plugin->bind6_address = NULL;
3442 } 3439 }
3440 }
3443 } 3441 }
3444 3442 }
3443
3445#if BUILD_HTTPS 3444#if BUILD_HTTPS
3446 /* Reading HTTPS crypto related configuration */ 3445 /* Reading HTTPS crypto related configuration */
3447 /* Get crypto init string from config */ 3446 /* Get crypto init string from config */
3448 if ( (GNUNET_OK != 3447 if ((GNUNET_OK !=
3449 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3448 GNUNET_CONFIGURATION_get_value_string (env->cfg,
3450 "transport-https", 3449 "transport-https",
3451 "CRYPTO_INIT", 3450 "CRYPTO_INIT",
3452 &plugin->crypto_init)) || 3451 &plugin->crypto_init)) ||
3453 (GNUNET_OK != 3452 (GNUNET_OK !=
3454 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 3453 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
3455 "transport-https", 3454 "transport-https",
3456 "KEY_FILE", 3455 "KEY_FILE",
3457 &key_file)) || 3456 &key_file)) ||
3458 (GNUNET_OK != 3457 (GNUNET_OK !=
3459 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 3458 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
3460 "transport-https", 3459 "transport-https",
3461 "CERT_FILE", 3460 "CERT_FILE", &cert_file)))
3462 &cert_file)) ) 3461 {
3463 { 3462 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3464 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3463 "https",
3465 "https", 3464 _
3466 _("Required configuration options missing in section `%s'\n"), 3465 ("Required configuration options missing in section `%s'\n"),
3467 "transport-https"); 3466 "transport-https");
3468 GNUNET_free (component_name); 3467 GNUNET_free (component_name);
3469 GNUNET_free_non_null (key_file); 3468 GNUNET_free_non_null (key_file);
3470 GNUNET_free_non_null (cert_file); 3469 GNUNET_free_non_null (cert_file);
3471 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3470 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3472 return NULL; 3471 return NULL;
3473 } 3472 }
3474 3473
3475 /* read key & certificates from file */ 3474 /* read key & certificates from file */
3476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3477 "Loading TLS certificate `%s' `%s'\n", 3476 "Loading TLS certificate `%s' `%s'\n", key_file, cert_file);
3478 key_file, cert_file);
3479 3477
3480 plugin->key = load_certificate (key_file); 3478 plugin->key = load_certificate (key_file);
3481 plugin->cert = load_certificate (cert_file); 3479 plugin->cert = load_certificate (cert_file);
3482 3480
3483 if ( (plugin->key==NULL) || (plugin->cert==NULL) ) 3481 if ((plugin->key == NULL) || (plugin->cert == NULL))
3484 { 3482 {
3485 struct GNUNET_OS_Process *certcreation; 3483 struct GNUNET_OS_Process *certcreation;
3486 3484
3487 GNUNET_free_non_null (plugin->key); 3485 GNUNET_free_non_null (plugin->key);
3488 plugin->key = NULL; 3486 plugin->key = NULL;
3489 GNUNET_free_non_null (plugin->cert); 3487 GNUNET_free_non_null (plugin->cert);
3490 plugin->cert = NULL; 3488 plugin->cert = NULL;
3491#if DEBUG_HTTP 3489#if DEBUG_HTTP
3492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3493 "No usable TLS certificate found, creating certificate\n"); 3491 "No usable TLS certificate found, creating certificate\n");
3494#endif 3492#endif
3495 errno = 0; 3493 errno = 0;
3496 certcreation = GNUNET_OS_start_process (NULL, NULL, 3494 certcreation = GNUNET_OS_start_process (NULL, NULL,
3497 "gnunet-transport-certificate-creation", 3495 "gnunet-transport-certificate-creation",
3498 "gnunet-transport-certificate-creation", 3496 "gnunet-transport-certificate-creation",
3499 key_file, cert_file, 3497 key_file, cert_file, NULL);
3500 NULL); 3498 if (certcreation == NULL)
3501 if (certcreation == NULL)
3502 {
3503 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3504 "https",
3505 _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
3506 GNUNET_free (key_file);
3507 GNUNET_free (cert_file);
3508 GNUNET_free (component_name);
3509 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3510 return NULL;
3511 }
3512 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
3513 GNUNET_OS_process_close (certcreation);
3514 plugin->key = load_certificate (key_file);
3515 plugin->cert = load_certificate (cert_file);
3516 }
3517 if ( (plugin->key==NULL) || (plugin->cert==NULL) )
3518 { 3499 {
3519 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3500 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3520 "https", 3501 "https",
3521 _("No usable TLS certificate found and creating one failed!\n"), 3502 _
3522 "transport-https"); 3503 ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
3523 GNUNET_free (key_file); 3504 GNUNET_free (key_file);
3524 GNUNET_free (cert_file); 3505 GNUNET_free (cert_file);
3525 GNUNET_free (component_name); 3506 GNUNET_free (component_name);
3526 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3507 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3527 return NULL; 3508 return NULL;
3528 } 3509 }
3510 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
3511 GNUNET_OS_process_close (certcreation);
3512 plugin->key = load_certificate (key_file);
3513 plugin->cert = load_certificate (cert_file);
3514 }
3515 if ((plugin->key == NULL) || (plugin->cert == NULL))
3516 {
3517 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3518 "https",
3519 _
3520 ("No usable TLS certificate found and creating one failed!\n"),
3521 "transport-https");
3522 GNUNET_free (key_file);
3523 GNUNET_free (cert_file);
3524 GNUNET_free (component_name);
3525 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3526 return NULL;
3527 }
3529 GNUNET_free (key_file); 3528 GNUNET_free (key_file);
3530 GNUNET_free (cert_file); 3529 GNUNET_free (cert_file);
3531#if DEBUG_HTTP 3530#if DEBUG_HTTP
3532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
3533 "TLS certificate loaded\n");
3534#endif 3532#endif
3535#endif 3533#endif
3536 3534
@@ -3538,171 +3536,199 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3538 plugin->port_inbound = port; 3536 plugin->port_inbound = port;
3539 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; 3537 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
3540 unsigned int timeout = (gn_timeout.rel_value) / 1000; 3538 unsigned int timeout = (gn_timeout.rel_value) / 1000;
3541 if ( (plugin->http_server_daemon_v6 == NULL) && 3539
3542 (plugin->use_ipv6 == GNUNET_YES) && 3540 if ((plugin->http_server_daemon_v6 == NULL) &&
3543 (port != 0) ) 3541 (plugin->use_ipv6 == GNUNET_YES) && (port != 0))
3544 { 3542 {
3545 struct sockaddr * tmp = (struct sockaddr *) plugin->bind6_address; 3543 struct sockaddr *tmp = (struct sockaddr *) plugin->bind6_address;
3546 plugin->http_server_daemon_v6 = MHD_start_daemon ( 3544
3545 plugin->http_server_daemon_v6 = MHD_start_daemon (
3547#if DEBUG_MHD 3546#if DEBUG_MHD
3548 MHD_USE_DEBUG | 3547 MHD_USE_DEBUG |
3549#endif 3548#endif
3550#if BUILD_HTTPS 3549#if BUILD_HTTPS
3551 MHD_USE_SSL | 3550 MHD_USE_SSL |
3552#endif 3551#endif
3553 MHD_USE_IPv6, 3552 MHD_USE_IPv6,
3554 port, 3553 port,
3555 &mhd_accept_cb, plugin, 3554 &mhd_accept_cb, plugin,
3556 &mhd_access_cb, plugin, 3555 &mhd_access_cb, plugin,
3557 MHD_OPTION_SOCK_ADDR, tmp, 3556 MHD_OPTION_SOCK_ADDR,
3558 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport, 3557 tmp,
3558 MHD_OPTION_CONNECTION_LIMIT,
3559 (unsigned int)
3560 plugin->max_connect_per_transport,
3559#if BUILD_HTTPS 3561#if BUILD_HTTPS
3560 MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, 3562 MHD_OPTION_HTTPS_PRIORITIES,
3561 MHD_OPTION_HTTPS_MEM_KEY, plugin->key, 3563 plugin->crypto_init,
3562 MHD_OPTION_HTTPS_MEM_CERT, plugin->cert, 3564 MHD_OPTION_HTTPS_MEM_KEY,
3563#endif 3565 plugin->key,
3564 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) timeout, 3566 MHD_OPTION_HTTPS_MEM_CERT,
3565 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 * GNUNET_SERVER_MAX_MESSAGE_SIZE), 3567 plugin->cert,
3566 MHD_OPTION_NOTIFY_COMPLETED, &mhd_termination_cb, plugin, 3568#endif
3567 MHD_OPTION_EXTERNAL_LOGGER, mhd_logger, plugin->mhd_log, 3569 MHD_OPTION_CONNECTION_TIMEOUT,
3568 MHD_OPTION_END); 3570 (unsigned int) timeout,
3569 } 3571 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
3570 if ( (plugin->http_server_daemon_v4 == NULL) && 3572 (size_t) (2 *
3571 (plugin->use_ipv4 == GNUNET_YES) && 3573 GNUNET_SERVER_MAX_MESSAGE_SIZE),
3572 (port != 0) ) 3574 MHD_OPTION_NOTIFY_COMPLETED,
3573 { 3575 &mhd_termination_cb,
3574 plugin->http_server_daemon_v4 = MHD_start_daemon ( 3576 plugin,
3577 MHD_OPTION_EXTERNAL_LOGGER,
3578 mhd_logger,
3579 plugin->mhd_log,
3580 MHD_OPTION_END);
3581 }
3582 if ((plugin->http_server_daemon_v4 == NULL) &&
3583 (plugin->use_ipv4 == GNUNET_YES) && (port != 0))
3584 {
3585 plugin->http_server_daemon_v4 = MHD_start_daemon (
3575#if DEBUG_MHD 3586#if DEBUG_MHD
3576 MHD_USE_DEBUG | 3587 MHD_USE_DEBUG |
3577#endif 3588#endif
3578#if BUILD_HTTPS 3589#if BUILD_HTTPS
3579 MHD_USE_SSL | 3590 MHD_USE_SSL |
3580#endif 3591#endif
3581 MHD_NO_FLAG, 3592 MHD_NO_FLAG,
3582 port, 3593 port,
3583 &mhd_accept_cb, plugin , 3594 &mhd_accept_cb, plugin,
3584 &mhd_access_cb, plugin, 3595 &mhd_access_cb, plugin,
3585 MHD_OPTION_SOCK_ADDR, (struct sockaddr_in *) plugin->bind4_address, 3596 MHD_OPTION_SOCK_ADDR,
3586 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport, 3597 (struct sockaddr_in *)
3598 plugin->bind4_address,
3599 MHD_OPTION_CONNECTION_LIMIT,
3600 (unsigned int)
3601 plugin->max_connect_per_transport,
3587#if BUILD_HTTPS 3602#if BUILD_HTTPS
3588 MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, 3603 MHD_OPTION_HTTPS_PRIORITIES,
3589 3604 plugin->crypto_init,
3590 MHD_OPTION_HTTPS_MEM_KEY, plugin->key, 3605 MHD_OPTION_HTTPS_MEM_KEY,
3591 MHD_OPTION_HTTPS_MEM_CERT, plugin->cert, 3606 plugin->key,
3592#endif 3607 MHD_OPTION_HTTPS_MEM_CERT,
3593 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) timeout, 3608 plugin->cert,
3594 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 * GNUNET_SERVER_MAX_MESSAGE_SIZE), 3609#endif
3595 MHD_OPTION_NOTIFY_COMPLETED, &mhd_termination_cb, plugin, 3610 MHD_OPTION_CONNECTION_TIMEOUT,
3596 MHD_OPTION_EXTERNAL_LOGGER, mhd_logger, plugin->mhd_log, 3611 (unsigned int) timeout,
3597 MHD_OPTION_END); 3612 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
3598 } 3613 (size_t) (2 *
3614 GNUNET_SERVER_MAX_MESSAGE_SIZE),
3615 MHD_OPTION_NOTIFY_COMPLETED,
3616 &mhd_termination_cb,
3617 plugin,
3618 MHD_OPTION_EXTERNAL_LOGGER,
3619 mhd_logger,
3620 plugin->mhd_log,
3621 MHD_OPTION_END);
3622 }
3599 if (plugin->http_server_daemon_v4 != NULL) 3623 if (plugin->http_server_daemon_v4 != NULL)
3600 plugin->http_server_task_v4 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4); 3624 plugin->http_server_task_v4 =
3625 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4);
3601 if (plugin->http_server_daemon_v6 != NULL) 3626 if (plugin->http_server_daemon_v6 != NULL)
3602 plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); 3627 plugin->http_server_task_v6 =
3603 3628 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
3604 3629
3630
3605 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 3631 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
3606 { 3632 {
3607#if DEBUG_HTTP 3633#if DEBUG_HTTP
3608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3609 "Starting MHD with IPv4 bound to %s with port %u\n", 3635 "Starting MHD with IPv4 bound to %s with port %u\n",
3610 (plugin->bind_hostname!=NULL) ? plugin->bind_hostname : "every address",port); 3636 (plugin->bind_hostname !=
3637 NULL) ? plugin->bind_hostname : "every address", port);
3611#endif 3638#endif
3612 } 3639 }
3613 else if ( (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) && 3640 else if ((plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
3614 (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) ) 3641 (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK))
3615 { 3642 {
3616#if DEBUG_HTTP 3643#if DEBUG_HTTP
3617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3618 "Starting MHD with IPv6 bound to %s with port %u\n", 3645 "Starting MHD with IPv6 bound to %s with port %u\n",
3619 (plugin->bind_hostname!=NULL) ? plugin->bind_hostname : "every address", port); 3646 (plugin->bind_hostname !=
3647 NULL) ? plugin->bind_hostname : "every address", port);
3620#endif 3648#endif
3621 } 3649 }
3622 else if ( (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) && 3650 else if ((plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
3623 (plugin->http_server_task_v4 == GNUNET_SCHEDULER_NO_TASK) ) 3651 (plugin->http_server_task_v4 == GNUNET_SCHEDULER_NO_TASK))
3624 { 3652 {
3625#if DEBUG_HTTP 3653#if DEBUG_HTTP
3626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3627 "Starting MHD with IPv4 and IPv6 bound to %s with port %u\n", 3655 "Starting MHD with IPv4 and IPv6 bound to %s with port %u\n",
3628 (plugin->bind_hostname!=NULL) ? plugin->bind_hostname : "every address", 3656 (plugin->bind_hostname !=
3629 port); 3657 NULL) ? plugin->bind_hostname : "every address", port);
3630#endif 3658#endif
3631 } 3659 }
3632 else 3660 else
3633 { 3661 {
3634 char * tmp = NULL; 3662 char *tmp = NULL;
3635 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_YES)) 3663
3636 GNUNET_asprintf(&tmp,"with IPv4 and IPv6 enabled"); 3664 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_YES))
3637 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_YES)) 3665 GNUNET_asprintf (&tmp, "with IPv4 and IPv6 enabled");
3638 GNUNET_asprintf(&tmp,"with IPv4 enabled"); 3666 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_YES))
3639 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_NO)) 3667 GNUNET_asprintf (&tmp, "with IPv4 enabled");
3640 GNUNET_asprintf(&tmp,"with IPv6 enabled"); 3668 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_NO))
3641 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_NO)) 3669 GNUNET_asprintf (&tmp, "with IPv6 enabled");
3642 GNUNET_asprintf(&tmp,"with NO IP PROTOCOL enabled"); 3670 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_NO))
3643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3671 GNUNET_asprintf (&tmp, "with NO IP PROTOCOL enabled");
3644 _("HTTP Server with %s could not be started on port %u! %s plugin failed!\n"), 3672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3645 tmp, port, PROTOCOL_PREFIX); 3673 _
3646 GNUNET_free (tmp); 3674 ("HTTP Server with %s could not be started on port %u! %s plugin failed!\n"),
3647 GNUNET_free (component_name); 3675 tmp, port, PROTOCOL_PREFIX);
3648 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3676 GNUNET_free (tmp);
3649 return NULL; 3677 GNUNET_free (component_name);
3650 } 3678 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3651 3679 return NULL;
3680 }
3681
3652 /* Initializing cURL */ 3682 /* Initializing cURL */
3653 curl_global_init(CURL_GLOBAL_ALL); 3683 curl_global_init (CURL_GLOBAL_ALL);
3654 plugin->multi_handle = curl_multi_init(); 3684 plugin->multi_handle = curl_multi_init ();
3655 3685
3656 if ( NULL == plugin->multi_handle ) 3686 if (NULL == plugin->multi_handle)
3657 { 3687 {
3658 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3688 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3659 component_name, 3689 component_name,
3660 _("Could not initialize curl multi handle, failed to start %s plugin!\n"), 3690 _
3661 PROTOCOL_PREFIX); 3691 ("Could not initialize curl multi handle, failed to start %s plugin!\n"),
3662 GNUNET_free(component_name); 3692 PROTOCOL_PREFIX);
3663 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3693 GNUNET_free (component_name);
3664 return NULL; 3694 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3665 } 3695 return NULL;
3666 3696 }
3697
3667 ret = GNUNET_SERVICE_get_server_addresses (component_name, 3698 ret = GNUNET_SERVICE_get_server_addresses (component_name,
3668 env->cfg, 3699 env->cfg, &addrs, &addrlens);
3669 &addrs,
3670 &addrlens);
3671 3700
3672 if (ret != GNUNET_SYSERR) 3701 if (ret != GNUNET_SYSERR)
3673 { 3702 {
3674 plugin->nat = GNUNET_NAT_register (env->cfg, 3703 plugin->nat = GNUNET_NAT_register (env->cfg,
3675 GNUNET_YES, 3704 GNUNET_YES,
3676 port, 3705 port,
3677 (unsigned int) ret, 3706 (unsigned int) ret,
3678 (const struct sockaddr **) addrs, 3707 (const struct sockaddr **) addrs,
3679 addrlens, 3708 addrlens,
3680 &tcp_nat_port_map_callback, 3709 &tcp_nat_port_map_callback,
3681 &try_connection_reversal, 3710 &try_connection_reversal, plugin);
3682 plugin); 3711 while (ret > 0)
3683 while (ret > 0) 3712 {
3684 { 3713 ret--;
3685 ret--; 3714 GNUNET_assert (addrs[ret] != NULL);
3686 GNUNET_assert (addrs[ret] != NULL); 3715 GNUNET_free (addrs[ret]);
3687 GNUNET_free (addrs[ret]); 3716 }
3688 } 3717 GNUNET_free_non_null (addrs);
3689 GNUNET_free_non_null (addrs); 3718 GNUNET_free_non_null (addrlens);
3690 GNUNET_free_non_null (addrlens);
3691 } 3719 }
3692 else 3720 else
3693 { 3721 {
3694 plugin->nat = GNUNET_NAT_register (env->cfg, 3722 plugin->nat = GNUNET_NAT_register (env->cfg,
3695 GNUNET_YES, 3723 GNUNET_YES,
3696 0, 3724 0,
3697 0, NULL, NULL, 3725 0, NULL, NULL,
3698 NULL, 3726 NULL, &try_connection_reversal, plugin);
3699 &try_connection_reversal,
3700 plugin);
3701 } 3727 }
3702 3728
3703 plugin->peers = GNUNET_CONTAINER_multihashmap_create (10); 3729 plugin->peers = GNUNET_CONTAINER_multihashmap_create (10);
3704 3730
3705 GNUNET_free(component_name); 3731 GNUNET_free (component_name);
3706 //GNUNET_SCHEDULER_add_now(address_notification, plugin); 3732 //GNUNET_SCHEDULER_add_now(address_notification, plugin);
3707 return api; 3733 return api;
3708} 3734}