2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/plugin_transport_http.c
23 * @brief http transport service plugin
24 * @author Matthias Wachs
27 #include "plugin_transport_http.h"
30 * After how long do we expire an address that we
31 * learned from another peer if it is not reconfirmed
34 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
37 * Wrapper to manage IPv4 addresses
39 struct IPv4HttpAddressWrapper
44 struct IPv4HttpAddressWrapper *next;
47 * Linked list previous
49 struct IPv4HttpAddressWrapper *prev;
51 struct IPv4HttpAddress addr;
55 * Wrapper for IPv4 addresses.
57 struct IPv6HttpAddressWrapper
62 struct IPv6HttpAddressWrapper *next;
65 * Linked list previous
67 struct IPv6HttpAddressWrapper *prev;
69 struct IPv6HttpAddress addr6;
74 * Context for address to string conversion.
76 struct PrettyPrinterContext
79 * Function to call with the result.
81 GNUNET_TRANSPORT_AddressStringCallback asc;
86 struct Plugin *plugin;
94 * Port to add after the IP address.
105 * Encapsulation of all of the state of the plugin.
112 * Append our port and forward the result.
114 * @param cls the 'struct PrettyPrinterContext*'
115 * @param hostname hostname part of the address
118 append_port (void *cls, const char *hostname)
120 struct PrettyPrinterContext *ppc = cls;
121 static char rbuf[INET6_ADDRSTRLEN + 13];
123 if (hostname == NULL)
125 ppc->asc (ppc->asc_cls, NULL);
131 const char *protocol = "http";
133 const char *protocol = "https";
135 GNUNET_assert ((strlen (hostname) + 7) < (INET6_ADDRSTRLEN + 13));
136 if (ppc->addrlen == sizeof (struct IPv6HttpAddress))
138 if (ppc->numeric == GNUNET_YES)
139 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port);
142 if (strchr(hostname, ':') != NULL)
143 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port);
145 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port);
148 else if (ppc->addrlen == sizeof (struct IPv4HttpAddress))
149 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port);
150 ppc->asc (ppc->asc_cls, rbuf);
155 * Convert the transports address to a nice, human-readable
159 * @param type name of the transport that generated the address
160 * @param addr one of the addresses of the host, NULL for the last address
161 * the specific address format depends on the transport
162 * @param addrlen length of the address
163 * @param numeric should (IP) addresses be displayed in numeric form?
164 * @param timeout after how long should we give up?
165 * @param asc function to call on each string
166 * @param asc_cls closure for asc
169 http_plugin_address_pretty_printer (void *cls, const char *type,
170 const void *addr, size_t addrlen,
172 struct GNUNET_TIME_Relative timeout,
173 GNUNET_TRANSPORT_AddressStringCallback asc,
176 GNUNET_assert (cls != NULL);
177 struct PrettyPrinterContext *ppc;
179 struct sockaddr_in s4;
180 struct sockaddr_in6 s6;
184 if ((addrlen == sizeof (struct IPv6HttpAddress)) && (addr != NULL))
186 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
187 s6.sin6_family = AF_INET6;
188 s6.sin6_addr = a6->ipv6_addr;
189 s6.sin6_port = a6->u6_port;
190 #if HAVE_SOCKADDR_IN_SIN_LEN
191 s6.sin6_len = sizeof (struct sockaddr_in6);
194 sbs = sizeof (struct sockaddr_in6);
195 port = ntohs (a6->u6_port);
198 else if ((addrlen == sizeof (struct IPv4HttpAddress)) && (addr != NULL))
200 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
202 s4.sin_family = AF_INET;
203 s4.sin_addr.s_addr = a4->ipv4_addr;
204 s4.sin_port = a4->u4_port;
205 #if HAVE_SOCKADDR_IN_SIN_LEN
206 s4.sin_len = sizeof (struct sockaddr_in);
209 sbs = sizeof (struct sockaddr_in);
210 port = ntohs (a4->u4_port);
214 /* invalid address */
219 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
221 ppc->asc_cls = asc_cls;
224 ppc->addrlen = addrlen;
225 ppc->numeric = numeric;
226 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
232 * Another peer has suggested an address for this
233 * peer and transport plugin. Check that this could be a valid
234 * address. If so, consider adding it to the list
238 * @param addr pointer to the address
239 * @param addrlen length of addr
240 * @return GNUNET_OK if this is a plausible address for this peer
244 http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
247 struct Plugin *plugin = cls;
248 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
249 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
253 GNUNET_assert (cls != NULL);
254 if ((addrlen != sizeof (struct sockaddr_in)) ||
255 (addrlen != sizeof (struct sockaddr_in6)))
256 return GNUNET_SYSERR;
258 if (addrlen == sizeof (struct IPv4HttpAddress))
260 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
262 while (w_tv4 != NULL)
265 memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr,
266 sizeof (struct in_addr))) &&
267 (w_tv4->addr.u4_port == a4->u4_port))
274 return GNUNET_SYSERR;
276 if (addrlen == sizeof (struct sockaddr_in6))
278 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
280 while (w_tv6 != NULL)
283 memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr,
284 sizeof (struct in6_addr))) &&
285 (w_tv6->addr6.u6_port == a6->u6_port))
292 return GNUNET_SYSERR;
297 struct GNUNET_TIME_Relative
298 http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
299 const struct GNUNET_MessageHeader *message,
300 struct Session *session, const char *sender_address,
301 uint16_t sender_address_len)
303 struct Session *s = cls;
304 struct Plugin *plugin = s->plugin;
305 struct GNUNET_TIME_Relative delay;
306 struct GNUNET_ATS_Information atsi[2];
308 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
309 atsi[0].value = htonl (1);
310 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
311 atsi[1].value = session->ats_address_network_type;
312 GNUNET_break (session->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
315 plugin->env->receive (plugin->env->cls, &s->target, message,
316 (const struct GNUNET_ATS_Information *) &atsi,
317 2, s, s->addr, s->addrlen);
322 * Function called for a quick conversion of the binary address to
323 * a numeric address. Note that the caller must not free the
324 * address and that the next call to this function is allowed
325 * to override the address again.
328 * @param addr binary address
329 * @param addrlen length of the address
330 * @return string representing the same address
333 http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
336 struct IPv4HttpAddress *a4;
337 struct IPv6HttpAddress *a6;
339 static char rbuf[INET6_ADDRSTRLEN + 13];
343 if (addrlen == sizeof (struct IPv6HttpAddress))
345 a6 = (struct IPv6HttpAddress *) addr;
346 address = GNUNET_malloc (INET6_ADDRSTRLEN);
347 GNUNET_assert (NULL !=
348 inet_ntop (AF_INET6, &a6->ipv6_addr, address,
350 port = ntohs (a6->u6_port);
352 else if (addrlen == sizeof (struct IPv4HttpAddress))
354 a4 = (struct IPv4HttpAddress *) addr;
355 address = GNUNET_malloc (INET_ADDRSTRLEN);
356 GNUNET_assert (NULL !=
357 inet_ntop (AF_INET, &(a4->ipv4_addr), address,
359 port = ntohs (a4->u4_port);
363 /* invalid address */
368 char *protocol = "http";
370 char *protocol = "https";
373 GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13));
374 if (addrlen == sizeof (struct IPv6HttpAddress))
376 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
378 else if (addrlen == sizeof (struct IPv4HttpAddress))
380 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address,
383 GNUNET_free (address);
384 GNUNET_assert (res != 0);
389 lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
390 struct Session *session, const void *addr, size_t addrlen,
393 struct Session *s = NULL;
394 struct Session *t = NULL;
404 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
405 "Comparing peer `%s' address `%s' len %i session %X to \n",
406 GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
408 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
409 "peer `%s' address `%s' len %i session %X \n\n",
410 GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
412 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
413 memcmp (addr, t->addr, addrlen));
418 if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity)))
421 if (addrlen == t->addrlen)
423 if (0 == memcmp (addr, t->addr, addrlen))
430 if (t->addrlen == session->addrlen)
432 if (0 == memcmp (session->addr, t->addr, t->addrlen))
440 if ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO))
445 if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) &&
446 (e_addr == GNUNET_YES))
451 if ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR))
466 lookup_session (struct Plugin *plugin,
467 const struct GNUNET_HELLO_Address *address)
469 struct Session *tmp = NULL;
476 if (0 != memcmp (&address->peer, &tmp->target, sizeof (struct GNUNET_PeerIdentity)))
478 if ((address->address_length != tmp->addrlen) &&
479 (0 != memcmp (address->address, tmp->addr, tmp->addrlen)))
489 delete_session (struct Session *s)
491 if (s->msg_tk != NULL)
493 GNUNET_SERVER_mst_destroy (s->msg_tk);
496 GNUNET_free (s->addr);
497 GNUNET_free_non_null (s->server_recv);
498 GNUNET_free_non_null (s->server_send);
503 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
504 const void *addr, size_t addrlen,
505 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
507 struct Session *s = NULL;
509 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
510 (addrlen == sizeof (struct IPv4HttpAddress)));
511 s = GNUNET_malloc (sizeof (struct Session));
512 memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
514 s->addr = GNUNET_malloc (addrlen);
515 memcpy (s->addr, addr, addrlen);
516 s->addrlen = addrlen;
518 s->next_receive = GNUNET_TIME_absolute_get_zero ();
519 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
524 notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
527 struct Plugin *plugin = cls;
529 plugin->env->session_end (plugin->env->cls, peer, s);
530 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
535 * Creates a new session the transport service will use to send data to the
538 * @param cls the plugin
539 * @param address the address
540 * @return the session or NULL of max connections exceeded
543 static struct Session *
544 http_get_session (void *cls,
545 const struct GNUNET_HELLO_Address *address)
547 struct Plugin *plugin = cls;
548 struct Session * s = NULL;
549 struct GNUNET_ATS_Information ats;
552 GNUNET_assert (plugin != NULL);
553 GNUNET_assert (address != NULL);
555 /* find existing session */
556 s = lookup_session (plugin, address);
560 if (plugin->max_connections <= plugin->cur_connections)
562 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
563 "Maximum number of connections reached, "
564 "cannot connect to peer `%s'\n", GNUNET_i2s (&address->peer));
568 /* create new session */
569 addrlen = address->address_length;
571 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
572 (addrlen == sizeof (struct IPv4HttpAddress)));
574 s = GNUNET_malloc (sizeof (struct Session));
575 memcpy (&s->target, &address->peer, sizeof (struct GNUNET_PeerIdentity));
577 s->addr = GNUNET_malloc (address->address_length);
578 memcpy (s->addr, address->address, address->address_length);
579 s->addrlen = addrlen;
581 s->next_receive = GNUNET_TIME_absolute_get_zero ();
583 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
586 if ((addrlen == sizeof (struct IPv4HttpAddress)) && (address->address != NULL))
588 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) address->address;
589 struct sockaddr_in s4;
591 s4.sin_family = AF_INET;
592 s4.sin_addr.s_addr = a4->ipv4_addr;
593 s4.sin_port = a4->u4_port;
594 #if HAVE_SOCKADDR_IN_SIN_LEN
595 s4.sin_len = sizeof (struct sockaddr_in);
597 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
599 if ((addrlen == sizeof (struct IPv6HttpAddress)) && (address->address != NULL))
601 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) address->address;
602 struct sockaddr_in6 s6;
604 s6.sin6_family = AF_INET6;
605 s6.sin6_addr = a6->ipv6_addr;
606 s6.sin6_port = a6->u6_port;
607 #if HAVE_SOCKADDR_IN_SIN_LEN
608 s6.sin6_len = sizeof (struct sockaddr_in6);
610 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
612 s->ats_address_network_type = ats.value;
614 /* add new session */
615 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
616 /* initiate new connection */
617 if (GNUNET_SYSERR == client_connect (s))
621 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
631 * Function that can be used by the transport service to transmit
632 * a message using the plugin. Note that in the case of a
633 * peer disconnecting, the continuation MUST be called
634 * prior to the disconnect notification itself. This function
635 * will be called with this peer's HELLO message to initiate
636 * a fresh connection to another peer.
639 * @param session which session must be used
640 * @param msgbuf the message to transmit
641 * @param msgbuf_size number of bytes in 'msgbuf'
642 * @param priority how important is the message (most plugins will
643 * ignore message priority and just FIFO)
644 * @param to how long to wait at most for the transmission (does not
645 * require plugins to discard the message after the timeout,
646 * just advisory for the desired delay; most plugins will ignore
648 * @param cont continuation to call once the message has
649 * been transmitted (or if the transport is ready
650 * for the next transmission call; or if the
651 * peer disconnected...); can be NULL
652 * @param cont_cls closure for cont
653 * @return number of bytes used (on the physical network, with overheads);
654 * -1 on hard errors (i.e. address invalid); 0 is a legal value
655 * and does NOT mean that the message was not transmitted (DV)
658 http_plugin_send (void *cls,
659 struct Session *session,
660 const char *msgbuf, size_t msgbuf_size,
661 unsigned int priority,
662 struct GNUNET_TIME_Relative to,
663 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
665 struct Plugin *plugin = cls;
666 struct HTTP_Message *msg;
670 GNUNET_assert (plugin != NULL);
671 GNUNET_assert (session != NULL);
673 /* lookup if session is really existing */
677 if ((tmp == session) &&
678 (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) &&
679 (session->addrlen != tmp->addrlen) &&
680 (0 != memcmp (session->addr, tmp->addr, tmp->addrlen)))
690 /* create new message and schedule */
692 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
694 msg->size = msgbuf_size;
696 msg->buf = (char *) &msg[1];
697 msg->transmit_cont = cont;
698 msg->transmit_cont_cls = cont_cls;
699 memcpy (msg->buf, msgbuf, msgbuf_size);
701 if (session->inbound == GNUNET_NO)
704 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
705 "Using outbound client session %p to send to `%session'\n", session,
706 GNUNET_i2s (&session->target));
709 client_send (session, msg);
712 if (session->inbound == GNUNET_YES)
715 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
716 "Using inbound server %p session to send to `%session'\n", session,
717 GNUNET_i2s (&session->target));
720 server_send (session, msg);
728 * Function that can be used by the transport service to transmit
729 * a message using the plugin. Note that in the case of a
730 * peer disconnecting, the continuation MUST be called
731 * prior to the disconnect notification itself. This function
732 * will be called with this peer's HELLO message to initiate
733 * a fresh connection to another peer.
736 * @param target who should receive this message
737 * @param msgbuf the message to transmit
738 * @param msgbuf_size number of bytes in 'msgbuf'
739 * @param priority how important is the message (most plugins will
740 * ignore message priority and just FIFO)
741 * @param to how long to wait at most for the transmission (does not
742 * require plugins to discard the message after the timeout,
743 * just advisory for the desired delay; most plugins will ignore
745 * @param session which session must be used (or NULL for "any")
746 * @param addr the address to use (can be NULL if the plugin
747 * is "on its own" (i.e. re-use existing TCP connection))
748 * @param addrlen length of the address in bytes
749 * @param force_address GNUNET_YES if the plugin MUST use the given address,
750 * GNUNET_NO means the plugin may use any other address and
751 * GNUNET_SYSERR means that only reliable existing
752 * bi-directional connections should be used (regardless
754 * @param cont continuation to call once the message has
755 * been transmitted (or if the transport is ready
756 * for the next transmission call; or if the
757 * peer disconnected...); can be NULL
758 * @param cont_cls closure for cont
759 * @return number of bytes used (on the physical network, with overheads);
760 * -1 on hard errors (i.e. address invalid); 0 is a legal value
761 * and does NOT mean that the message was not transmitted (DV)
764 http_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
765 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
766 struct GNUNET_TIME_Relative to, struct Session *session,
767 const void *addr, size_t addrlen, int force_address,
768 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
770 struct Plugin *plugin = cls;
771 struct HTTP_Message *msg;
774 GNUNET_assert (plugin != NULL);
776 int res = GNUNET_SYSERR;
779 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
780 "Sending %u bytes to peer `%s' on address `%s' %X %i\n",
781 msgbuf_size, GNUNET_i2s (target), ((addr != NULL) &&
784 http_plugin_address_to_string (plugin, addr,
785 addrlen) : "<inbound>",
786 session, force_address);
792 GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
793 (addrlen == sizeof (struct IPv6HttpAddress)));
794 /* look for existing connection */
795 s = lookup_session_old (plugin, target, session, addr, addrlen, 1);
797 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
798 "%s existing session: %s\n",
799 (s != NULL) ? "Found" : "NOT Found", ((s != NULL) &&
802 "inbound" : "outbound");
804 /* create new outbound connection */
807 if (plugin->max_connections <= plugin->cur_connections)
809 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
810 "Maximum number of connections reached, "
811 "cannot connect to peer `%s'\n", GNUNET_i2s (target));
816 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
817 "Initiiating new connection to peer `%s'\n",
818 GNUNET_i2s (target));
820 /* AAAAAAAAAAAAAAAAAAA */
822 struct GNUNET_ATS_Information ats;
823 if ((addrlen == sizeof (struct IPv4HttpAddress)) && (addr != NULL))
825 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
826 struct sockaddr_in s4;
828 s4.sin_family = AF_INET;
829 s4.sin_addr.s_addr = a4->ipv4_addr;
830 s4.sin_port = a4->u4_port;
831 #if HAVE_SOCKADDR_IN_SIN_LEN
832 s4.sin_len = sizeof (struct sockaddr_in);
834 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
836 if ((ntohs (a4->u4_port) == 0) || (plugin->ipv4 == GNUNET_NO))
839 if ((addrlen == sizeof (struct IPv6HttpAddress)) && (addr != NULL))
841 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
842 struct sockaddr_in6 s6;
844 s6.sin6_family = AF_INET6;
845 s6.sin6_addr = a6->ipv6_addr;
846 s6.sin6_port = a6->u6_port;
847 #if HAVE_SOCKADDR_IN_SIN_LEN
848 s6.sin6_len = sizeof (struct sockaddr_in6);
850 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
852 if ((ntohs (a6->u6_port) == 0) || (plugin->ipv6 == GNUNET_NO))
855 if (res == GNUNET_OK)
857 s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
858 s->ats_address_network_type = ats.value;
859 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
860 // initiate new connection
861 res = client_connect (s);
863 if (res == GNUNET_SYSERR)
867 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
870 return GNUNET_SYSERR;
876 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
878 msg->size = msgbuf_size;
880 msg->buf = (char *) &msg[1];
881 msg->transmit_cont = cont;
882 msg->transmit_cont_cls = cont_cls;
883 memcpy (msg->buf, msgbuf, msgbuf_size);
885 if (s->inbound == GNUNET_NO)
888 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
889 "Using outbound client session %p to send to `%s'\n", s,
890 GNUNET_i2s (target));
893 client_send (s, msg);
896 if (s->inbound == GNUNET_YES)
899 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
900 "Using inbound server %p session to send to `%s'\n", s,
901 GNUNET_i2s (target));
904 server_send (s, msg);
912 * Function that can be used to force the plugin to disconnect
913 * from the given peer and cancel all previous transmissions
914 * (and their continuationc).
917 * @param target peer from which to disconnect
920 http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
922 struct Plugin *plugin = cls;
923 struct Session *next = NULL;
924 struct Session *s = plugin->head;
926 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
927 "Transport tells me to disconnect `%s'\n",
928 GNUNET_i2s (target));
932 if (0 == memcmp (target, &s->target, sizeof (struct GNUNET_PeerIdentity)))
934 if (s->inbound == GNUNET_NO)
935 GNUNET_assert (GNUNET_OK == client_disconnect (s));
937 GNUNET_assert (GNUNET_OK == server_disconnect (s));
938 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
940 struct HTTP_Message *msg = s->msg_head;
941 struct HTTP_Message *tmp = NULL;
947 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
948 if (msg->transmit_cont != NULL)
950 msg->transmit_cont (msg->transmit_cont_cls, target, GNUNET_SYSERR);
963 nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
966 struct Plugin *plugin = cls;
967 struct IPv4HttpAddressWrapper *w_t4 = NULL;
968 struct IPv6HttpAddressWrapper *w_t6 = NULL;
971 af = addr->sa_family;
975 w_t4 = plugin->ipv4_addr_head;
976 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
980 int res = memcmp (&w_t4->addr.ipv4_addr,
982 sizeof (struct in_addr));
986 if (a4->sin_port != w_t4->addr.u4_port)
996 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
997 memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
998 w_t4->addr.u4_port = a4->sin_port;
1000 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
1001 plugin->ipv4_addr_tail, w_t4);
1004 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1005 "Notifying transport to add IPv4 address `%s'\n",
1006 http_plugin_address_to_string (NULL, &w_t4->addr,
1010 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
1011 sizeof (struct IPv4HttpAddress));
1015 w_t6 = plugin->ipv6_addr_head;
1016 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
1020 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
1021 sizeof (struct in6_addr));
1025 if (a6->sin6_port != w_t6->addr6.u6_port)
1034 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
1036 memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
1037 w_t6->addr6.u6_port = a6->sin6_port;
1039 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
1040 plugin->ipv6_addr_tail, w_t6);
1043 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1044 "Notifying transport to add IPv6 address `%s'\n",
1045 http_plugin_address_to_string (NULL, &w_t6->addr6,
1049 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
1050 sizeof (struct IPv6HttpAddress));
1059 nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
1062 struct Plugin *plugin = cls;
1063 struct IPv4HttpAddressWrapper *w_t4 = NULL;
1064 struct IPv6HttpAddressWrapper *w_t6 = NULL;
1067 af = addr->sa_family;
1071 w_t4 = plugin->ipv4_addr_head;
1072 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
1074 while (w_t4 != NULL)
1076 int res = memcmp (&w_t4->addr.ipv4_addr,
1078 sizeof (struct in_addr));
1082 if (a4->sin_port != w_t4->addr.u4_port)
1094 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1095 "Notifying transport to remove IPv4 address `%s'\n",
1096 http_plugin_address_to_string (NULL, &w_t4->addr,
1100 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
1101 sizeof (struct IPv4HttpAddress));
1103 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1108 w_t6 = plugin->ipv6_addr_head;
1109 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
1113 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
1114 sizeof (struct in6_addr));
1118 if (a6->sin6_port != w_t6->addr6.u6_port)
1128 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1129 "Notifying transport to remove IPv6 address `%s'\n",
1130 http_plugin_address_to_string (NULL, &w_t6->addr6,
1134 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
1135 sizeof (struct IPv6HttpAddress));
1137 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1148 * Our external IP address/port mapping has changed.
1150 * @param cls closure, the 'struct LocalAddrList'
1151 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
1152 * the previous (now invalid) one
1153 * @param addr either the previous or the new public IP address
1154 * @param addrlen actual lenght of the address
1157 nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
1160 GNUNET_assert (cls != NULL);
1162 struct Plugin *plugin = cls;
1165 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1166 "NPMC called %s to address `%s'\n",
1167 (add_remove == GNUNET_NO) ? "remove" : "add",
1168 GNUNET_a2s (addr, addrlen));
1173 nat_add_address (cls, add_remove, addr, addrlen);
1176 nat_remove_address (cls, add_remove, addr, addrlen);
1182 http_check_ipv6 (struct Plugin *plugin)
1184 struct GNUNET_NETWORK_Handle *desc = NULL;
1186 if (plugin->ipv6 == GNUNET_YES)
1188 /* probe IPv6 support */
1189 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1192 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
1195 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1197 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
1199 ("Disabling IPv6 since it is not supported on this system!\n"));
1200 plugin->ipv6 = GNUNET_NO;
1204 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
1208 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1209 "Testing IPv6 on this system: %s\n",
1210 (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed");
1215 http_get_addresses (struct Plugin *plugin, const char *serviceName,
1216 const struct GNUNET_CONFIGURATION_Handle *cfg,
1217 struct sockaddr ***addrs, socklen_t ** addr_lens)
1220 unsigned long long port;
1221 struct addrinfo hints;
1222 struct addrinfo *res;
1223 struct addrinfo *pos;
1224 struct addrinfo *next;
1228 struct sockaddr **saddrs;
1229 socklen_t *saddrlens;
1235 disablev6 = !plugin->ipv6;
1238 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
1240 GNUNET_break (GNUNET_OK ==
1241 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
1245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1247 ("Require valid port number for service in configuration!\n"));
1248 return GNUNET_SYSERR;
1252 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
1254 GNUNET_break (GNUNET_OK ==
1255 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
1256 "BINDTO", &hostname));
1261 if (hostname != NULL)
1263 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1264 "Resolving `%s' since that is where `%s' will bind to.\n",
1265 hostname, serviceName);
1266 memset (&hints, 0, sizeof (struct addrinfo));
1268 hints.ai_family = AF_INET;
1269 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1272 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
1273 hostname, gai_strerror (ret));
1274 GNUNET_free (hostname);
1275 return GNUNET_SYSERR;
1279 while (NULL != (pos = next))
1281 next = pos->ai_next;
1282 if ((disablev6) && (pos->ai_family == AF_INET6))
1288 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1289 _("Failed to find %saddress for `%s'.\n"),
1290 disablev6 ? "IPv4 " : "", hostname);
1292 GNUNET_free (hostname);
1293 return GNUNET_SYSERR;
1296 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1297 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1300 while (NULL != (pos = next))
1302 next = pos->ai_next;
1303 if ((disablev6) && (pos->ai_family == AF_INET6))
1305 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
1306 continue; /* not TCP */
1307 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
1308 continue; /* huh? */
1309 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1310 "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
1312 if (pos->ai_family == AF_INET)
1314 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
1315 saddrlens[i] = pos->ai_addrlen;
1316 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1317 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1318 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1322 GNUNET_assert (pos->ai_family == AF_INET6);
1323 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
1324 saddrlens[i] = pos->ai_addrlen;
1325 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1326 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1327 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1331 GNUNET_free (hostname);
1337 /* will bind against everything, just set port */
1343 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1344 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1346 saddrlens[i] = sizeof (struct sockaddr_in);
1347 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1348 #if HAVE_SOCKADDR_IN_SIN_LEN
1349 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1351 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1352 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1358 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1359 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1361 saddrlens[i] = sizeof (struct sockaddr_in6);
1362 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1363 #if HAVE_SOCKADDR_IN_SIN_LEN
1364 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1366 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1367 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1369 saddrlens[i] = sizeof (struct sockaddr_in);
1370 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1371 #if HAVE_SOCKADDR_IN_SIN_LEN
1372 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1374 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1375 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1379 *addr_lens = saddrlens;
1384 start_report_addresses (struct Plugin *plugin)
1386 int res = GNUNET_OK;
1387 struct sockaddr **addrs;
1388 socklen_t *addrlens;
1391 http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs,
1393 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1394 _("Found %u addresses to report to NAT service\n"), res);
1396 if (res != GNUNET_SYSERR)
1399 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
1401 (const struct sockaddr **) addrs, addrlens,
1402 &nat_port_map_callback, NULL, plugin);
1407 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"),
1408 GNUNET_a2s (addrs[res], addrlens[res]));
1410 GNUNET_assert (addrs[res] != NULL);
1411 GNUNET_free (addrs[res]);
1413 GNUNET_free_non_null (addrs);
1414 GNUNET_free_non_null (addrlens);
1419 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, 0, 0, NULL, NULL,
1420 NULL, NULL, plugin);
1425 stop_report_addresses (struct Plugin *plugin)
1427 /* Stop NAT handle */
1428 GNUNET_NAT_unregister (plugin->nat);
1430 /* Clean up addresses */
1431 struct IPv4HttpAddressWrapper *w_t4;
1432 struct IPv6HttpAddressWrapper *w_t6;
1434 while (plugin->ipv4_addr_head != NULL)
1436 w_t4 = plugin->ipv4_addr_head;
1437 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1442 while (plugin->ipv6_addr_head != NULL)
1444 w_t6 = plugin->ipv6_addr_head;
1445 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1452 configure_plugin (struct Plugin *plugin)
1454 int res = GNUNET_OK;
1457 if (GNUNET_CONFIGURATION_have_value
1458 (plugin->env->cfg, plugin->name, "USE_IPv4"))
1461 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1465 plugin->ipv4 = GNUNET_YES;
1468 if (GNUNET_CONFIGURATION_have_value
1469 (plugin->env->cfg, plugin->name, "USE_IPv6"))
1472 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1476 plugin->ipv6 = GNUNET_YES;
1478 if ((plugin->ipv4 == GNUNET_NO) && (plugin->ipv6 == GNUNET_NO))
1480 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1482 ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"),
1484 res = GNUNET_SYSERR;
1487 /* Reading port number from config file */
1488 unsigned long long port;
1491 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1492 "PORT", &port)) || (port > 65535))
1494 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1495 _("Port is required! Fix in configuration\n"),
1497 res = GNUNET_SYSERR;
1500 plugin->port = port;
1502 plugin->client_only = GNUNET_NO;
1503 if (plugin->port == 0)
1505 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1506 _("Port 0, client only mode\n"));
1507 plugin->client_only = GNUNET_YES;
1510 char *bind4_address = NULL;
1512 if ((plugin->ipv4 == GNUNET_YES) &&
1514 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1515 "BINDTO", &bind4_address)))
1517 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1518 "Binding %s plugin to specific IPv4 address: `%s'\n",
1519 plugin->protocol, bind4_address);
1520 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
1522 inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
1524 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1526 ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1527 bind4_address, plugin->protocol);
1528 GNUNET_free (plugin->server_addr_v4);
1529 plugin->server_addr_v4 = NULL;
1533 plugin->server_addr_v4->sin_family = AF_INET;
1534 plugin->server_addr_v4->sin_port = htons (plugin->port);
1536 GNUNET_free (bind4_address);
1540 char *bind6_address = NULL;
1542 if ((plugin->ipv6 == GNUNET_YES) &&
1544 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1545 "BINDTO6", &bind6_address)))
1547 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1548 "Binding %s plugin to specific IPv6 address: `%s'\n",
1549 plugin->protocol, bind6_address);
1550 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
1552 inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
1554 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1556 ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1557 bind6_address, plugin->protocol);
1558 GNUNET_free (plugin->server_addr_v6);
1559 plugin->server_addr_v6 = NULL;
1563 plugin->server_addr_v6->sin6_family = AF_INET6;
1564 plugin->server_addr_v6->sin6_port = htons (plugin->port);
1566 GNUNET_free (bind6_address);
1570 /* Optional parameters */
1571 unsigned long long maxneigh;
1574 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1575 "MAX_CONNECTIONS", &maxneigh))
1577 plugin->max_connections = maxneigh;
1584 * Entry point for the plugin.
1587 LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1589 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1590 struct GNUNET_TRANSPORT_PluginFunctions *api;
1591 struct Plugin *plugin;
1594 plugin = GNUNET_malloc (sizeof (struct Plugin));
1596 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1598 api->send = &http_plugin_send_old;
1599 api->disconnect = &http_plugin_disconnect;
1600 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1601 api->check_address = &http_plugin_address_suggested;
1602 api->address_to_string = &http_plugin_address_to_string;
1603 api->get_session = &http_get_session;
1604 api->send_with_session = &http_plugin_send;
1607 plugin->name = "transport-https";
1608 plugin->protocol = "https";
1610 plugin->name = "transport-http";
1611 plugin->protocol = "http";
1613 /* Configure plugin from configuration */
1614 res = configure_plugin (plugin);
1615 if (res == GNUNET_SYSERR)
1617 GNUNET_free_non_null (plugin->server_addr_v4);
1618 GNUNET_free_non_null (plugin->server_addr_v6);
1619 GNUNET_free (plugin);
1624 /* checking IPv6 support */
1625 http_check_ipv6 (plugin);
1628 res = client_start (plugin);
1629 if (res == GNUNET_SYSERR)
1631 GNUNET_free_non_null (plugin->server_addr_v4);
1632 GNUNET_free_non_null (plugin->server_addr_v6);
1633 GNUNET_free (plugin);
1639 if (plugin->client_only == GNUNET_NO)
1641 res = server_start (plugin);
1642 if (res == GNUNET_SYSERR)
1644 server_stop (plugin);
1645 client_stop (plugin);
1647 GNUNET_free_non_null (plugin->server_addr_v4);
1648 GNUNET_free_non_null (plugin->server_addr_v6);
1649 GNUNET_free (plugin);
1654 /* Report addresses to transport service */
1655 start_report_addresses (plugin);
1658 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1659 "Plugin `%s' loaded\n", plugin->name);
1667 * Exit point from the plugin.
1670 LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1672 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1673 struct Plugin *plugin = api->cls;
1674 struct Session *s = NULL;
1676 /* Stop reporting addresses to transport service */
1677 stop_report_addresses (plugin);
1679 /* cleaning up sessions */
1684 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1685 "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
1687 if (s->inbound == GNUNET_NO)
1688 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1690 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1695 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
1698 server_stop (plugin);
1701 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n");
1704 client_stop (plugin);
1706 /* deleting up sessions */
1710 struct Session *t = s->next;
1712 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
1714 struct HTTP_Message *msg = s->msg_head;
1715 struct HTTP_Message *tmp = NULL;
1721 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
1722 if (msg->transmit_cont != NULL)
1724 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
1736 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1737 "Plugin `%s' unloaded\n", plugin->name);
1740 GNUNET_free_non_null (plugin->server_addr_v4);
1741 GNUNET_free_non_null (plugin->server_addr_v6);
1742 GNUNET_free (plugin);
1748 /* end of plugin_transport_http.c */