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.
110 * Start session timeout
113 start_session_timeout (struct Session *s);
116 * Increment session timeout due to activity
119 reschedule_session_timeout (struct Session *s);
125 stop_session_timeout (struct Session *s);
128 * Append our port and forward the result.
130 * @param cls the 'struct PrettyPrinterContext*'
131 * @param hostname hostname part of the address
134 append_port (void *cls, const char *hostname)
136 struct PrettyPrinterContext *ppc = cls;
137 static char rbuf[INET6_ADDRSTRLEN + 13];
139 if (hostname == NULL)
141 ppc->asc (ppc->asc_cls, NULL);
147 const char *protocol = "http";
149 const char *protocol = "https";
151 GNUNET_assert ((strlen (hostname) + 7) < (INET6_ADDRSTRLEN + 13));
152 if (ppc->addrlen == sizeof (struct IPv6HttpAddress))
154 if (ppc->numeric == GNUNET_YES)
155 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port);
158 if (strchr(hostname, ':') != NULL)
159 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port);
161 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port);
164 else if (ppc->addrlen == sizeof (struct IPv4HttpAddress))
165 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port);
166 ppc->asc (ppc->asc_cls, rbuf);
174 * Convert the transports address to a nice, human-readable
178 * @param type name of the transport that generated the address
179 * @param addr one of the addresses of the host, NULL for the last address
180 * the specific address format depends on the transport
181 * @param addrlen length of the address
182 * @param numeric should (IP) addresses be displayed in numeric form?
183 * @param timeout after how long should we give up?
184 * @param asc function to call on each string
185 * @param asc_cls closure for asc
188 http_plugin_address_pretty_printer (void *cls, const char *type,
189 const void *addr, size_t addrlen,
191 struct GNUNET_TIME_Relative timeout,
192 GNUNET_TRANSPORT_AddressStringCallback asc,
195 GNUNET_assert (cls != NULL);
196 struct PrettyPrinterContext *ppc;
198 struct sockaddr_in s4;
199 struct sockaddr_in6 s6;
203 if ((addrlen == sizeof (struct IPv6HttpAddress)) && (addr != NULL))
205 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
206 s6.sin6_family = AF_INET6;
207 s6.sin6_addr = a6->ipv6_addr;
208 s6.sin6_port = a6->u6_port;
209 #if HAVE_SOCKADDR_IN_SIN_LEN
210 s6.sin6_len = sizeof (struct sockaddr_in6);
213 sbs = sizeof (struct sockaddr_in6);
214 port = ntohs (a6->u6_port);
217 else if ((addrlen == sizeof (struct IPv4HttpAddress)) && (addr != NULL))
219 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
221 s4.sin_family = AF_INET;
222 s4.sin_addr.s_addr = a4->ipv4_addr;
223 s4.sin_port = a4->u4_port;
224 #if HAVE_SOCKADDR_IN_SIN_LEN
225 s4.sin_len = sizeof (struct sockaddr_in);
228 sbs = sizeof (struct sockaddr_in);
229 port = ntohs (a4->u4_port);
231 else if (0 == addrlen)
233 asc (asc_cls, "<inbound connection>");
239 /* invalid address */
244 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
246 ppc->asc_cls = asc_cls;
249 ppc->addrlen = addrlen;
250 ppc->numeric = numeric;
251 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
257 * Another peer has suggested an address for this
258 * peer and transport plugin. Check that this could be a valid
259 * address. If so, consider adding it to the list
263 * @param addr pointer to the address
264 * @param addrlen length of addr
265 * @return GNUNET_OK if this is a plausible address for this peer
269 http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
271 struct Plugin *plugin = cls;
272 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
273 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
275 GNUNET_assert (cls != NULL);
276 if ((addrlen != sizeof (struct sockaddr_in)) ||
277 (addrlen != sizeof (struct sockaddr_in6)))
278 return GNUNET_SYSERR;
280 if (addrlen == sizeof (struct IPv4HttpAddress))
282 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
284 while (w_tv4 != NULL)
287 memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr,
288 sizeof (struct in_addr))) &&
289 (w_tv4->addr.u4_port == a4->u4_port))
296 return GNUNET_SYSERR;
298 if (addrlen == sizeof (struct sockaddr_in6))
300 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
302 while (w_tv6 != NULL)
305 memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr,
306 sizeof (struct in6_addr))) &&
307 (w_tv6->addr6.u6_port == a6->u6_port))
314 return GNUNET_SYSERR;
319 struct GNUNET_TIME_Relative
320 http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
321 const struct GNUNET_MessageHeader *message,
322 struct Session *session, const char *sender_address,
323 uint16_t sender_address_len)
325 struct Session *s = cls;
326 struct Plugin *plugin = s->plugin;
327 struct GNUNET_TIME_Relative delay;
328 struct GNUNET_ATS_Information atsi[2];
330 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
331 atsi[0].value = htonl (1);
332 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
333 atsi[1].value = session->ats_address_network_type;
334 GNUNET_break (session->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
336 reschedule_session_timeout (session);
339 plugin->env->receive (plugin->env->cls, &s->target, message,
340 (const struct GNUNET_ATS_Information *) &atsi,
341 2, s, s->addr, s->addrlen);
347 * Function called to convert a string address to
350 * @param cls closure ('struct Plugin*')
351 * @param addr string address
352 * @param addrlen length of the address
353 * @param buf location to store the buffer
354 * If the function returns GNUNET_SYSERR, its contents are undefined.
355 * @param added length of created address
356 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
359 http_string_to_address (void *cls,
366 char *protocol = "http";
368 char *protocol = "https";
370 char *addr_str = NULL;
371 struct sockaddr_in addr_4;
372 struct sockaddr_in6 addr_6;
373 struct IPv4HttpAddress * http_4addr;
374 struct IPv6HttpAddress * http_6addr;
376 if ((NULL == addr) || (addrlen == 0))
379 return GNUNET_SYSERR;
382 if ('\0' != addr[addrlen - 1])
385 return GNUNET_SYSERR;
388 if (strlen (addr) != addrlen - 1)
391 return GNUNET_SYSERR;
394 /* protocoll + "://" + ":" */
395 if (addrlen <= (strlen (protocol) + 4))
397 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
398 "Invalid address string `%s' to convert to address\n",
401 return GNUNET_SYSERR;
404 if (NULL == (addr_str = strstr(addr, "://")))
406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
407 "Invalid address string `%s' to convert to address\n",
410 return GNUNET_SYSERR;
412 addr_str = &addr_str[3];
414 if (addr_str[strlen(addr_str)-1] == '/')
415 addr_str[strlen(addr_str)-1] = '\0';
417 if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr_str, strlen(addr_str), &addr_4))
419 http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
420 http_4addr->u4_port = addr_4.sin_port;
421 http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr;
423 (*added) = sizeof (struct IPv4HttpAddress);
426 if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
428 http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
429 http_6addr->u6_port = addr_6.sin6_port;
430 http_6addr->ipv6_addr = addr_6.sin6_addr;
432 (*added) = sizeof (struct IPv6HttpAddress);
435 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
436 "Invalid address string `%s' to convert to address\n",
439 return GNUNET_SYSERR;
444 * Function called for a quick conversion of the binary address to
445 * a numeric address. Note that the caller must not free the
446 * address and that the next call to this function is allowed
447 * to override the address again.
450 * @param addr binary address
451 * @param addrlen length of the address
452 * @return string representing the same address
455 http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
458 struct IPv4HttpAddress *a4;
459 struct IPv6HttpAddress *a6;
461 static char rbuf[INET6_ADDRSTRLEN + 13];
465 if (addrlen == sizeof (struct IPv6HttpAddress))
467 a6 = (struct IPv6HttpAddress *) addr;
468 address = GNUNET_malloc (INET6_ADDRSTRLEN);
469 GNUNET_assert (NULL !=
470 inet_ntop (AF_INET6, &a6->ipv6_addr, address,
472 port = ntohs (a6->u6_port);
474 else if (addrlen == sizeof (struct IPv4HttpAddress))
476 a4 = (struct IPv4HttpAddress *) addr;
477 address = GNUNET_malloc (INET_ADDRSTRLEN);
478 GNUNET_assert (NULL !=
479 inet_ntop (AF_INET, &(a4->ipv4_addr), address,
481 port = ntohs (a4->u4_port);
485 /* invalid address */
490 char *protocol = "http";
492 char *protocol = "https";
495 GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13));
496 if (addrlen == sizeof (struct IPv6HttpAddress))
498 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
500 else if (addrlen == sizeof (struct IPv4HttpAddress))
502 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address,
505 GNUNET_free (address);
506 GNUNET_assert (res != 0);
512 lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
513 struct Session *session, const void *addr, size_t addrlen,
520 for (t = plugin->head; NULL != t; t = t->next)
523 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
524 "Comparing peer `%s' address `%s' len %i session %p to \n",
525 GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
527 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
528 "peer `%s' address `%s' len %i session %p \n\n",
529 GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
531 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
532 memcmp (addr, t->addr, addrlen));
536 if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity)))
539 if ( (addrlen == t->addrlen) &&
540 (0 == memcmp (addr, t->addr, addrlen)) )
542 if ( (t == session) &&
543 (t->addrlen == session->addrlen) &&
544 (0 == memcmp (session->addr, t->addr, t->addrlen)) )
548 if ( ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO)) ||
549 ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES)) ||
550 ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR)) )
558 lookup_session (struct Plugin *plugin,
559 const struct GNUNET_HELLO_Address *address)
563 for (pos = plugin->head; NULL != pos; pos = pos->next)
564 if ( (0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) &&
565 (address->address_length == pos->addrlen) &&
566 (0 == memcmp (address->address, pos->addr, pos->addrlen)) )
573 exist_session (struct Plugin *plugin, struct Session *s)
575 struct Session * head;
577 GNUNET_assert (NULL != plugin);
578 GNUNET_assert (NULL != s);
580 for (head = plugin->head; head != NULL; head = head->next)
590 delete_session (struct Session *s)
592 stop_session_timeout(s);
594 if (s->msg_tk != NULL)
596 GNUNET_SERVER_mst_destroy (s->msg_tk);
599 GNUNET_free (s->addr);
600 GNUNET_free_non_null (s->server_recv);
601 GNUNET_free_non_null (s->server_send);
607 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
608 const void *addr, size_t addrlen)
610 struct Session *s = NULL;
612 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
613 (addrlen == sizeof (struct IPv4HttpAddress)));
614 s = GNUNET_malloc (sizeof (struct Session));
615 memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
617 s->addr = GNUNET_malloc (addrlen);
618 memcpy (s->addr, addr, addrlen);
619 s->addrlen = addrlen;
620 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
621 start_session_timeout(s);
627 notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
630 struct Plugin *plugin = cls;
632 plugin->env->session_end (plugin->env->cls, peer, s);
633 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
639 * Creates a new outbound session the transport service will use to send data to the
642 * @param cls the plugin
643 * @param address the address
644 * @return the session or NULL of max connections exceeded
646 static struct Session *
647 http_get_session (void *cls,
648 const struct GNUNET_HELLO_Address *address)
650 struct Plugin *plugin = cls;
651 struct Session * s = NULL;
652 struct GNUNET_ATS_Information ats;
655 GNUNET_assert (plugin != NULL);
656 GNUNET_assert (address != NULL);
657 GNUNET_assert (address->address != NULL);
659 ats.type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
660 ats.value = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
662 /* find existing session */
663 s = lookup_session (plugin, address);
667 if (plugin->max_connections <= plugin->cur_connections)
669 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
670 "Maximum number of connections reached, "
671 "cannot connect to peer `%s'\n", GNUNET_i2s (&address->peer));
675 /* create new session */
676 addrlen = address->address_length;
678 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
679 (addrlen == sizeof (struct IPv4HttpAddress)));
681 s = create_session (plugin, &address->peer, address->address, address->address_length);
684 if (addrlen == sizeof (struct IPv4HttpAddress))
686 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) address->address;
687 struct sockaddr_in s4;
689 s4.sin_family = AF_INET;
690 s4.sin_addr.s_addr = a4->ipv4_addr;
691 s4.sin_port = a4->u4_port;
692 #if HAVE_SOCKADDR_IN_SIN_LEN
693 s4.sin_len = sizeof (struct sockaddr_in);
695 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
697 if (addrlen == sizeof (struct IPv6HttpAddress))
699 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) address->address;
700 struct sockaddr_in6 s6;
702 s6.sin6_family = AF_INET6;
703 s6.sin6_addr = a6->ipv6_addr;
704 s6.sin6_port = a6->u6_port;
705 #if HAVE_SOCKADDR_IN_SIN_LEN
706 s6.sin6_len = sizeof (struct sockaddr_in6);
708 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
710 s->ats_address_network_type = ats.value;
712 /* add new session */
713 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
714 /* initiate new connection */
715 if (GNUNET_SYSERR == client_connect (s))
717 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
718 "Cannot connect to peer `%s' address `%s''\n",
719 http_plugin_address_to_string(NULL, s->addr, s->addrlen),
720 GNUNET_i2s (&s->target));
721 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
731 * Function that can be used by the transport service to transmit
732 * a message using the plugin. Note that in the case of a
733 * peer disconnecting, the continuation MUST be called
734 * prior to the disconnect notification itself. This function
735 * will be called with this peer's HELLO message to initiate
736 * a fresh connection to another peer.
739 * @param session which session must be used
740 * @param msgbuf the message to transmit
741 * @param msgbuf_size number of bytes in 'msgbuf'
742 * @param priority how important is the message (most plugins will
743 * ignore message priority and just FIFO)
744 * @param to how long to wait at most for the transmission (does not
745 * require plugins to discard the message after the timeout,
746 * just advisory for the desired delay; most plugins will ignore
748 * @param cont continuation to call once the message has
749 * been transmitted (or if the transport is ready
750 * for the next transmission call; or if the
751 * peer disconnected...); can be NULL
752 * @param cont_cls closure for cont
753 * @return number of bytes used (on the physical network, with overheads);
754 * -1 on hard errors (i.e. address invalid); 0 is a legal value
755 * and does NOT mean that the message was not transmitted (DV)
758 http_plugin_send (void *cls,
759 struct Session *session,
760 const char *msgbuf, size_t msgbuf_size,
761 unsigned int priority,
762 struct GNUNET_TIME_Relative to,
763 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
765 struct Plugin *plugin = cls;
766 struct HTTP_Message *msg;
770 GNUNET_assert (plugin != NULL);
771 GNUNET_assert (session != NULL);
773 /* lookup if session is really existing */
777 if ((tmp == session) &&
778 (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) &&
779 (session->addrlen == tmp->addrlen) &&
780 (0 == memcmp (session->addr, tmp->addr, tmp->addrlen)))
790 /* create new message and schedule */
791 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
793 msg->size = msgbuf_size;
795 msg->buf = (char *) &msg[1];
796 msg->transmit_cont = cont;
797 msg->transmit_cont_cls = cont_cls;
798 memcpy (msg->buf, msgbuf, msgbuf_size);
800 reschedule_session_timeout (session);
802 if (session->inbound == GNUNET_NO)
804 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
805 "Using outbound client session %p to send to `%s'\n", session,
806 GNUNET_i2s (&session->target));
807 client_send (session, msg);
810 if (session->inbound == GNUNET_YES)
812 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
813 "Using inbound server %p session to send to `%s'\n", session,
814 GNUNET_i2s (&session->target));
815 server_send (session, msg);
824 * Function that can be used to force the plugin to disconnect
825 * from the given peer and cancel all previous transmissions
826 * (and their continuationc).
829 * @param target peer from which to disconnect
832 http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
834 struct Plugin *plugin = cls;
835 struct Session *next = NULL;
836 struct Session *s = plugin->head;
838 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
839 "Transport tells me to disconnect `%s'\n",
840 GNUNET_i2s (target));
844 if (0 == memcmp (target, &s->target, sizeof (struct GNUNET_PeerIdentity)))
846 if (s->inbound == GNUNET_NO)
847 GNUNET_assert (GNUNET_OK == client_disconnect (s));
849 GNUNET_assert (GNUNET_OK == server_disconnect (s));
850 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
852 struct HTTP_Message *msg = s->msg_head;
853 struct HTTP_Message *tmp = NULL;
859 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
860 if (msg->transmit_cont != NULL)
862 msg->transmit_cont (msg->transmit_cont_cls, target, GNUNET_SYSERR);
876 find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
879 struct IPv4HttpAddressWrapper *w_t4 = NULL;
880 struct IPv6HttpAddressWrapper *w_t6 = NULL;
882 af = addr->sa_family;
886 w_t4 = plugin->ipv4_addr_head;
887 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
891 int res = memcmp (&w_t4->addr.ipv4_addr,
893 sizeof (struct in_addr));
897 if (a4->sin_port != w_t4->addr.u4_port)
908 w_t6 = plugin->ipv6_addr_head;
909 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
913 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
914 sizeof (struct in6_addr));
918 if (a6->sin6_port != w_t6->addr6.u6_port)
935 nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
938 struct Plugin *plugin = cls;
939 struct IPv4HttpAddressWrapper *w_t4 = NULL;
940 struct IPv6HttpAddressWrapper *w_t6 = NULL;
943 af = addr->sa_family;
947 w_t4 = find_address (plugin, addr, addrlen);
950 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
951 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
952 memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
953 w_t4->addr.u4_port = a4->sin_port;
955 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
956 plugin->ipv4_addr_tail, w_t4);
958 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
959 "Notifying transport to add IPv4 address `%s'\n",
960 http_plugin_address_to_string (NULL, &w_t4->addr,
963 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
964 sizeof (struct IPv4HttpAddress));
968 w_t6 = find_address (plugin, addr, addrlen);
971 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
972 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
973 memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
974 w_t6->addr6.u6_port = a6->sin6_port;
976 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
977 plugin->ipv6_addr_tail, w_t6);
979 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
980 "Notifying transport to add IPv6 address `%s'\n",
981 http_plugin_address_to_string (NULL, &w_t6->addr6,
984 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
985 sizeof (struct IPv6HttpAddress));
996 nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
999 struct Plugin *plugin = cls;
1000 struct IPv4HttpAddressWrapper *w_t4 = NULL;
1001 struct IPv6HttpAddressWrapper *w_t6 = NULL;
1004 af = addr->sa_family;
1008 w_t4 = find_address (plugin, addr, addrlen);
1013 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1014 "Notifying transport to remove IPv4 address `%s'\n",
1015 http_plugin_address_to_string (NULL, &w_t4->addr,
1018 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
1019 sizeof (struct IPv4HttpAddress));
1021 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1026 w_t6 = find_address (plugin, addr, addrlen);
1030 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1031 "Notifying transport to remove IPv6 address `%s'\n",
1032 http_plugin_address_to_string (NULL, &w_t6->addr6,
1036 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
1037 sizeof (struct IPv6HttpAddress));
1039 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1050 * Our external IP address/port mapping has changed.
1052 * @param cls closure, the 'struct LocalAddrList'
1053 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
1054 * the previous (now invalid) one
1055 * @param addr either the previous or the new public IP address
1056 * @param addrlen actual lenght of the address
1059 nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
1062 GNUNET_assert (cls != NULL);
1063 struct Plugin *plugin = cls;
1065 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1066 "NPMC called %s to address `%s'\n",
1067 (add_remove == GNUNET_NO) ? "remove" : "add",
1068 GNUNET_a2s (addr, addrlen));
1073 nat_add_address (cls, add_remove, addr, addrlen);
1076 nat_remove_address (cls, add_remove, addr, addrlen);
1083 http_check_ipv6 (struct Plugin *plugin)
1085 struct GNUNET_NETWORK_Handle *desc = NULL;
1087 if (plugin->ipv6 == GNUNET_YES)
1089 /* probe IPv6 support */
1090 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1093 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
1096 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1098 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
1100 ("Disabling IPv6 since it is not supported on this system!\n"));
1101 plugin->ipv6 = GNUNET_NO;
1105 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
1109 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1110 "Testing IPv6 on this system: %s\n",
1111 (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed");
1117 http_get_addresses (struct Plugin *plugin, const char *serviceName,
1118 const struct GNUNET_CONFIGURATION_Handle *cfg,
1119 struct sockaddr ***addrs, socklen_t ** addr_lens)
1122 unsigned long long port;
1123 struct addrinfo hints;
1124 struct addrinfo *res;
1125 struct addrinfo *pos;
1126 struct addrinfo *next;
1130 struct sockaddr **saddrs;
1131 socklen_t *saddrlens;
1137 disablev6 = !plugin->ipv6;
1140 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
1142 GNUNET_break (GNUNET_OK ==
1143 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
1147 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1149 ("Require valid port number for service in configuration!\n"));
1150 return GNUNET_SYSERR;
1154 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
1156 GNUNET_break (GNUNET_OK ==
1157 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
1158 "BINDTO", &hostname));
1163 if (hostname != NULL)
1165 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1166 "Resolving `%s' since that is where `%s' will bind to.\n",
1167 hostname, serviceName);
1168 memset (&hints, 0, sizeof (struct addrinfo));
1170 hints.ai_family = AF_INET;
1171 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
1175 hostname, gai_strerror (ret));
1176 GNUNET_free (hostname);
1177 return GNUNET_SYSERR;
1181 while (NULL != (pos = next))
1183 next = pos->ai_next;
1184 if ((disablev6) && (pos->ai_family == AF_INET6))
1190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1191 _("Failed to find %saddress for `%s'.\n"),
1192 disablev6 ? "IPv4 " : "", hostname);
1194 GNUNET_free (hostname);
1195 return GNUNET_SYSERR;
1198 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1199 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1202 while (NULL != (pos = next))
1204 next = pos->ai_next;
1205 if ((disablev6) && (pos->ai_family == AF_INET6))
1207 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
1208 continue; /* not TCP */
1209 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
1210 continue; /* huh? */
1211 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1212 "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
1214 if (pos->ai_family == AF_INET)
1216 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
1217 saddrlens[i] = pos->ai_addrlen;
1218 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1219 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1220 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1224 GNUNET_assert (pos->ai_family == AF_INET6);
1225 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
1226 saddrlens[i] = pos->ai_addrlen;
1227 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1228 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1229 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1233 GNUNET_free (hostname);
1239 /* will bind against everything, just set port */
1245 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1246 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1248 saddrlens[i] = sizeof (struct sockaddr_in);
1249 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1250 #if HAVE_SOCKADDR_IN_SIN_LEN
1251 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1253 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1254 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1260 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1261 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1263 saddrlens[i] = sizeof (struct sockaddr_in6);
1264 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1265 #if HAVE_SOCKADDR_IN_SIN_LEN
1266 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1268 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1269 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1271 saddrlens[i] = sizeof (struct sockaddr_in);
1272 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1273 #if HAVE_SOCKADDR_IN_SIN_LEN
1274 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1276 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1277 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1281 *addr_lens = saddrlens;
1286 start_report_addresses (struct Plugin *plugin)
1288 int res = GNUNET_OK;
1289 struct sockaddr **addrs;
1290 socklen_t *addrlens;
1293 http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs,
1295 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1296 _("Found %u addresses to report to NAT service\n"), res);
1298 if (res != GNUNET_SYSERR)
1301 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
1303 (const struct sockaddr **) addrs, addrlens,
1304 &nat_port_map_callback, NULL, plugin);
1309 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"),
1310 GNUNET_a2s (addrs[res], addrlens[res]));
1312 GNUNET_assert (addrs[res] != NULL);
1313 GNUNET_free (addrs[res]);
1315 GNUNET_free_non_null (addrs);
1316 GNUNET_free_non_null (addrlens);
1321 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, 0, 0, NULL, NULL,
1322 NULL, NULL, plugin);
1328 stop_report_addresses (struct Plugin *plugin)
1330 /* Stop NAT handle */
1331 GNUNET_NAT_unregister (plugin->nat);
1333 /* Clean up addresses */
1334 struct IPv4HttpAddressWrapper *w_t4;
1335 struct IPv6HttpAddressWrapper *w_t6;
1337 while (plugin->ipv4_addr_head != NULL)
1339 w_t4 = plugin->ipv4_addr_head;
1340 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1345 while (plugin->ipv6_addr_head != NULL)
1347 w_t6 = plugin->ipv6_addr_head;
1348 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1356 configure_plugin (struct Plugin *plugin)
1358 int res = GNUNET_OK;
1361 if (GNUNET_CONFIGURATION_have_value
1362 (plugin->env->cfg, plugin->name, "USE_IPv4"))
1365 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1369 plugin->ipv4 = GNUNET_YES;
1372 if (GNUNET_CONFIGURATION_have_value
1373 (plugin->env->cfg, plugin->name, "USE_IPv6"))
1376 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1380 plugin->ipv6 = GNUNET_YES;
1382 if ((plugin->ipv4 == GNUNET_NO) && (plugin->ipv6 == GNUNET_NO))
1384 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1386 ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"),
1388 res = GNUNET_SYSERR;
1391 /* Reading port number from config file */
1392 unsigned long long port;
1395 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1396 "PORT", &port)) || (port > 65535))
1398 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1399 _("Port is required! Fix in configuration\n"),
1401 res = GNUNET_SYSERR;
1404 plugin->port = port;
1406 plugin->client_only = GNUNET_NO;
1407 if (plugin->port == 0)
1409 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1410 _("Port 0, client only mode\n"));
1411 plugin->client_only = GNUNET_YES;
1414 char *bind4_address = NULL;
1416 if ((plugin->ipv4 == GNUNET_YES) &&
1418 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1419 "BINDTO", &bind4_address)))
1421 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1422 "Binding %s plugin to specific IPv4 address: `%s'\n",
1423 plugin->protocol, bind4_address);
1424 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
1426 inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
1428 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1430 ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1431 bind4_address, plugin->protocol);
1432 GNUNET_free (plugin->server_addr_v4);
1433 plugin->server_addr_v4 = NULL;
1437 plugin->server_addr_v4->sin_family = AF_INET;
1438 plugin->server_addr_v4->sin_port = htons (plugin->port);
1440 GNUNET_free (bind4_address);
1444 char *bind6_address = NULL;
1446 if ((plugin->ipv6 == GNUNET_YES) &&
1448 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1449 "BINDTO6", &bind6_address)))
1451 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1452 "Binding %s plugin to specific IPv6 address: `%s'\n",
1453 plugin->protocol, bind6_address);
1454 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
1456 inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
1458 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1460 ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1461 bind6_address, plugin->protocol);
1462 GNUNET_free (plugin->server_addr_v6);
1463 plugin->server_addr_v6 = NULL;
1467 plugin->server_addr_v6->sin6_family = AF_INET6;
1468 plugin->server_addr_v6->sin6_port = htons (plugin->port);
1470 GNUNET_free (bind6_address);
1474 /* Optional parameters */
1475 unsigned long long maxneigh;
1478 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1479 "MAX_CONNECTIONS", &maxneigh))
1481 plugin->max_connections = maxneigh;
1489 * Session was idle, so disconnect it
1492 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1494 GNUNET_assert (NULL != cls);
1495 struct Session *s = cls;
1497 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1499 "Session %p was idle for %llu ms, disconnecting\n",
1500 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1502 /* call session destroy function */
1503 if (s->inbound == GNUNET_NO)
1504 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1506 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1511 * Start session timeout
1514 start_session_timeout (struct Session *s)
1516 GNUNET_assert (NULL != s);
1517 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
1518 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 "Timeout for session %p set to %llu ms\n",
1523 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1528 * Increment session timeout due to activity
1531 reschedule_session_timeout (struct Session *s)
1533 GNUNET_assert (NULL != s);
1534 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
1536 GNUNET_SCHEDULER_cancel (s->timeout_task);
1537 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1541 "Timeout rescheduled for session %p set to %llu ms\n",
1542 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1550 stop_session_timeout (struct Session *s)
1552 GNUNET_assert (NULL != s);
1554 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
1556 GNUNET_SCHEDULER_cancel (s->timeout_task);
1557 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1559 "Timeout stopped for session %p canceled\n",
1560 s, (unsigned long long) GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1565 * Entry point for the plugin.
1568 LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1570 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1571 struct GNUNET_TRANSPORT_PluginFunctions *api;
1572 struct Plugin *plugin;
1575 if (NULL == env->receive)
1577 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1578 initialze the plugin or the API */
1579 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1581 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1582 api->address_to_string = &http_plugin_address_to_string;
1583 api->string_to_address = &http_string_to_address;
1587 plugin = GNUNET_malloc (sizeof (struct Plugin));
1589 plugin->outbound_sessions = 0;
1590 plugin->inbound_sessions = 0;
1591 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1593 api->disconnect = &http_plugin_disconnect;
1594 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1595 api->check_address = &http_plugin_address_suggested;
1596 api->address_to_string = &http_plugin_address_to_string;
1597 api->string_to_address = &http_string_to_address;
1598 api->get_session = &http_get_session;
1599 api->send = &http_plugin_send;
1602 plugin->name = "transport-https";
1603 plugin->protocol = "https";
1605 plugin->name = "transport-http";
1606 plugin->protocol = "http";
1608 /* Configure plugin from configuration */
1609 res = configure_plugin (plugin);
1610 if (res == GNUNET_SYSERR)
1612 GNUNET_free_non_null (plugin->server_addr_v4);
1613 GNUNET_free_non_null (plugin->server_addr_v6);
1614 GNUNET_free (plugin);
1619 /* checking IPv6 support */
1620 http_check_ipv6 (plugin);
1623 res = client_start (plugin);
1624 if (res == GNUNET_SYSERR)
1626 GNUNET_free_non_null (plugin->server_addr_v4);
1627 GNUNET_free_non_null (plugin->server_addr_v6);
1628 GNUNET_free (plugin);
1634 if (plugin->client_only == GNUNET_NO)
1636 res = server_start (plugin);
1637 if (res == GNUNET_SYSERR)
1639 server_stop (plugin);
1640 client_stop (plugin);
1642 GNUNET_free_non_null (plugin->server_addr_v4);
1643 GNUNET_free_non_null (plugin->server_addr_v6);
1644 GNUNET_free (plugin);
1649 /* Report addresses to transport service */
1650 start_report_addresses (plugin);
1652 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1653 "Plugin `%s' loaded\n", plugin->name);
1659 * Exit point from the plugin.
1662 LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1664 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1665 struct Plugin *plugin = api->cls;
1674 /* Stop reporting addresses to transport service */
1675 stop_report_addresses (plugin);
1677 /* cleaning up sessions */
1681 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1682 "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
1683 if (s->inbound == GNUNET_NO)
1684 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1686 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1690 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
1692 server_stop (plugin);
1694 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n");
1696 client_stop (plugin);
1698 /* deleting up sessions */
1702 struct Session *t = s->next;
1704 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
1706 struct HTTP_Message *msg = s->msg_head;
1707 struct HTTP_Message *tmp = NULL;
1713 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
1714 if (msg->transmit_cont != NULL)
1716 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
1726 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1727 "Plugin `%s' unloaded\n", plugin->name);
1728 GNUNET_free_non_null (plugin->server_addr_v4);
1729 GNUNET_free_non_null (plugin->server_addr_v6);
1730 GNUNET_free (plugin);
1735 /* end of plugin_transport_http.c */