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)
589 * Deleting the session
590 * Must not be used afterwards
594 delete_session (struct Session *s)
596 struct Plugin *plugin = s->plugin;
597 stop_session_timeout(s);
599 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
600 struct HTTP_Message *msg = s->msg_head;
601 struct HTTP_Message *tmp = NULL;
607 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
608 if (msg->transmit_cont != NULL)
610 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
616 if (s->msg_tk != NULL)
618 GNUNET_SERVER_mst_destroy (s->msg_tk);
621 GNUNET_free (s->addr);
622 GNUNET_free_non_null (s->server_recv);
623 GNUNET_free_non_null (s->server_send);
629 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
630 const void *addr, size_t addrlen)
632 struct Session *s = NULL;
633 struct GNUNET_ATS_Information ats;
635 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
636 (addrlen == sizeof (struct IPv4HttpAddress)));
641 if (addrlen == sizeof (struct IPv4HttpAddress))
643 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
644 struct sockaddr_in s4;
646 if (0 == ntohs(a4->u4_port))
649 s4.sin_family = AF_INET;
650 s4.sin_addr.s_addr = a4->ipv4_addr;
651 s4.sin_port = a4->u4_port;
652 #if HAVE_SOCKADDR_IN_SIN_LEN
653 s4.sin_len = sizeof (struct sockaddr_in);
655 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
657 if (addrlen == sizeof (struct IPv6HttpAddress))
659 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
660 struct sockaddr_in6 s6;
662 if (0 == ntohs(a6->u6_port))
665 s6.sin6_family = AF_INET6;
666 s6.sin6_addr = a6->ipv6_addr;
667 s6.sin6_port = a6->u6_port;
668 #if HAVE_SOCKADDR_IN_SIN_LEN
669 s6.sin6_len = sizeof (struct sockaddr_in6);
671 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
674 s = GNUNET_malloc (sizeof (struct Session));
675 memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
677 s->addr = GNUNET_malloc (addrlen);
678 memcpy (s->addr, addr, addrlen);
679 s->addrlen = addrlen;
680 s->ats_address_network_type = ats.value;
683 start_session_timeout(s);
689 notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
692 struct Plugin *plugin = cls;
694 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
695 "Notifying transport about ending session %p (`%s')\n",
697 http_plugin_address_to_string(NULL, s->addr,s->addrlen));
699 plugin->env->session_end (plugin->env->cls, peer, s);
705 * Creates a new outbound session the transport service will use to send data to the
708 * @param cls the plugin
709 * @param address the address
710 * @return the session or NULL of max connections exceeded
712 static struct Session *
713 http_get_session (void *cls,
714 const struct GNUNET_HELLO_Address *address)
716 struct Plugin *plugin = cls;
717 struct Session * s = NULL;
720 GNUNET_assert (plugin != NULL);
721 GNUNET_assert (address != NULL);
722 GNUNET_assert (address->address != NULL);
724 /* find existing session */
725 s = lookup_session (plugin, address);
729 if (plugin->max_connections <= plugin->cur_connections)
731 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
732 "Maximum number of connections reached, "
733 "cannot connect to peer `%s'\n", GNUNET_i2s (&address->peer));
737 /* create new session */
738 addrlen = address->address_length;
740 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
741 (addrlen == sizeof (struct IPv4HttpAddress)));
743 s = create_session (plugin, &address->peer, address->address, address->address_length);
745 /* add new session */
746 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
747 /* initiate new connection */
748 if (GNUNET_SYSERR == client_connect (s))
750 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
751 "Cannot connect to peer `%s' address `%s''\n",
752 http_plugin_address_to_string(NULL, s->addr, s->addrlen),
753 GNUNET_i2s (&s->target));
754 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
764 * Function that can be used by the transport service to transmit
765 * a message using the plugin. Note that in the case of a
766 * peer disconnecting, the continuation MUST be called
767 * prior to the disconnect notification itself. This function
768 * will be called with this peer's HELLO message to initiate
769 * a fresh connection to another peer.
772 * @param session which session must be used
773 * @param msgbuf the message to transmit
774 * @param msgbuf_size number of bytes in 'msgbuf'
775 * @param priority how important is the message (most plugins will
776 * ignore message priority and just FIFO)
777 * @param to how long to wait at most for the transmission (does not
778 * require plugins to discard the message after the timeout,
779 * just advisory for the desired delay; most plugins will ignore
781 * @param cont continuation to call once the message has
782 * been transmitted (or if the transport is ready
783 * for the next transmission call; or if the
784 * peer disconnected...); can be NULL
785 * @param cont_cls closure for cont
786 * @return number of bytes used (on the physical network, with overheads);
787 * -1 on hard errors (i.e. address invalid); 0 is a legal value
788 * and does NOT mean that the message was not transmitted (DV)
791 http_plugin_send (void *cls,
792 struct Session *session,
793 const char *msgbuf, size_t msgbuf_size,
794 unsigned int priority,
795 struct GNUNET_TIME_Relative to,
796 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
798 struct Plugin *plugin = cls;
799 struct HTTP_Message *msg;
803 GNUNET_assert (plugin != NULL);
804 GNUNET_assert (session != NULL);
806 /* lookup if session is really existing */
810 if ((tmp == session) &&
811 (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) &&
812 (session->addrlen == tmp->addrlen) &&
813 (0 == memcmp (session->addr, tmp->addr, tmp->addrlen)))
823 /* create new message and schedule */
824 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
826 msg->size = msgbuf_size;
828 msg->buf = (char *) &msg[1];
829 msg->transmit_cont = cont;
830 msg->transmit_cont_cls = cont_cls;
831 memcpy (msg->buf, msgbuf, msgbuf_size);
833 reschedule_session_timeout (session);
835 if (session->inbound == GNUNET_NO)
837 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
838 "Using outbound client session %p to send to `%s'\n", session,
839 GNUNET_i2s (&session->target));
840 client_send (session, msg);
843 if (session->inbound == GNUNET_YES)
845 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
846 "Using inbound server %p session to send to `%s'\n", session,
847 GNUNET_i2s (&session->target));
848 server_send (session, msg);
857 * Function that can be used to force the plugin to disconnect
858 * from the given peer and cancel all previous transmissions
859 * (and their continuationc).
862 * @param target peer from which to disconnect
865 http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
867 struct Plugin *plugin = cls;
868 struct Session *next = NULL;
869 struct Session *s = plugin->head;
871 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
872 "Transport tells me to disconnect `%s'\n",
873 GNUNET_i2s (target));
877 if (0 == memcmp (target, &s->target, sizeof (struct GNUNET_PeerIdentity)))
879 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
880 "Disconnecting %s session %p to `%s'\n",
881 (s->inbound == GNUNET_NO) ? "outbound" : "inbound",
882 s, GNUNET_i2s (target));
884 if (s->inbound == GNUNET_NO)
885 GNUNET_assert (GNUNET_OK == client_disconnect (s));
887 GNUNET_assert (GNUNET_OK == server_disconnect (s));
895 find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
898 struct IPv4HttpAddressWrapper *w_t4 = NULL;
899 struct IPv6HttpAddressWrapper *w_t6 = NULL;
901 af = addr->sa_family;
905 w_t4 = plugin->ipv4_addr_head;
906 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
910 int res = memcmp (&w_t4->addr.ipv4_addr,
912 sizeof (struct in_addr));
916 if (a4->sin_port != w_t4->addr.u4_port)
927 w_t6 = plugin->ipv6_addr_head;
928 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
932 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
933 sizeof (struct in6_addr));
937 if (a6->sin6_port != w_t6->addr6.u6_port)
954 nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
957 struct Plugin *plugin = cls;
958 struct IPv4HttpAddressWrapper *w_t4 = NULL;
959 struct IPv6HttpAddressWrapper *w_t6 = NULL;
962 af = addr->sa_family;
966 w_t4 = find_address (plugin, addr, addrlen);
969 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
970 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
971 memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
972 w_t4->addr.u4_port = a4->sin_port;
974 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
975 plugin->ipv4_addr_tail, w_t4);
977 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
978 "Notifying transport to add IPv4 address `%s'\n",
979 http_plugin_address_to_string (NULL, &w_t4->addr,
982 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
983 sizeof (struct IPv4HttpAddress));
987 w_t6 = find_address (plugin, addr, addrlen);
990 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
991 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
992 memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
993 w_t6->addr6.u6_port = a6->sin6_port;
995 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
996 plugin->ipv6_addr_tail, w_t6);
998 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
999 "Notifying transport to add IPv6 address `%s'\n",
1000 http_plugin_address_to_string (NULL, &w_t6->addr6,
1003 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
1004 sizeof (struct IPv6HttpAddress));
1015 nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
1018 struct Plugin *plugin = cls;
1019 struct IPv4HttpAddressWrapper *w_t4 = NULL;
1020 struct IPv6HttpAddressWrapper *w_t6 = NULL;
1023 af = addr->sa_family;
1027 w_t4 = find_address (plugin, addr, addrlen);
1032 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1033 "Notifying transport to remove IPv4 address `%s'\n",
1034 http_plugin_address_to_string (NULL, &w_t4->addr,
1037 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
1038 sizeof (struct IPv4HttpAddress));
1040 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1045 w_t6 = find_address (plugin, addr, addrlen);
1049 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1050 "Notifying transport to remove IPv6 address `%s'\n",
1051 http_plugin_address_to_string (NULL, &w_t6->addr6,
1055 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
1056 sizeof (struct IPv6HttpAddress));
1058 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1069 * Our external IP address/port mapping has changed.
1071 * @param cls closure, the 'struct LocalAddrList'
1072 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
1073 * the previous (now invalid) one
1074 * @param addr either the previous or the new public IP address
1075 * @param addrlen actual lenght of the address
1078 nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
1081 GNUNET_assert (cls != NULL);
1082 struct Plugin *plugin = cls;
1084 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1085 "NPMC called %s to address `%s'\n",
1086 (add_remove == GNUNET_NO) ? "remove" : "add",
1087 GNUNET_a2s (addr, addrlen));
1092 nat_add_address (cls, add_remove, addr, addrlen);
1095 nat_remove_address (cls, add_remove, addr, addrlen);
1102 http_check_ipv6 (struct Plugin *plugin)
1104 struct GNUNET_NETWORK_Handle *desc = NULL;
1106 if (plugin->ipv6 == GNUNET_YES)
1108 /* probe IPv6 support */
1109 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1112 if ((errno == ENOBUFS) || (errno == ENOMEM) || (errno == ENFILE) ||
1115 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1117 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
1119 ("Disabling IPv6 since it is not supported on this system!\n"));
1120 plugin->ipv6 = GNUNET_NO;
1124 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
1128 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1129 "Testing IPv6 on this system: %s\n",
1130 (plugin->ipv6 == GNUNET_YES) ? "successful" : "failed");
1136 http_get_addresses (struct Plugin *plugin, const char *serviceName,
1137 const struct GNUNET_CONFIGURATION_Handle *cfg,
1138 struct sockaddr ***addrs, socklen_t ** addr_lens)
1141 unsigned long long port;
1142 struct addrinfo hints;
1143 struct addrinfo *res;
1144 struct addrinfo *pos;
1145 struct addrinfo *next;
1149 struct sockaddr **saddrs;
1150 socklen_t *saddrlens;
1156 disablev6 = !plugin->ipv6;
1159 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
1161 GNUNET_break (GNUNET_OK ==
1162 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
1166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1168 ("Require valid port number for service in configuration!\n"));
1169 return GNUNET_SYSERR;
1174 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, plugin->name,
1175 "Starting in listen only mode\n");
1176 return -1; /* listen only */
1180 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
1182 GNUNET_break (GNUNET_OK ==
1183 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
1184 "BINDTO", &hostname));
1189 if (hostname != NULL)
1191 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1192 "Resolving `%s' since that is where `%s' will bind to.\n",
1193 hostname, serviceName);
1194 memset (&hints, 0, sizeof (struct addrinfo));
1196 hints.ai_family = AF_INET;
1197 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
1201 hostname, gai_strerror (ret));
1202 GNUNET_free (hostname);
1203 return GNUNET_SYSERR;
1207 while (NULL != (pos = next))
1209 next = pos->ai_next;
1210 if ((disablev6) && (pos->ai_family == AF_INET6))
1216 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1217 _("Failed to find %saddress for `%s'.\n"),
1218 disablev6 ? "IPv4 " : "", hostname);
1220 GNUNET_free (hostname);
1221 return GNUNET_SYSERR;
1224 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1225 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1228 while (NULL != (pos = next))
1230 next = pos->ai_next;
1231 if ((disablev6) && (pos->ai_family == AF_INET6))
1233 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
1234 continue; /* not TCP */
1235 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
1236 continue; /* huh? */
1237 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1238 "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
1240 if (pos->ai_family == AF_INET)
1242 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
1243 saddrlens[i] = pos->ai_addrlen;
1244 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1245 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1246 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1250 GNUNET_assert (pos->ai_family == AF_INET6);
1251 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
1252 saddrlens[i] = pos->ai_addrlen;
1253 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1254 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1255 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1259 GNUNET_free (hostname);
1265 /* will bind against everything, just set port */
1271 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1272 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1274 saddrlens[i] = sizeof (struct sockaddr_in);
1275 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1276 #if HAVE_SOCKADDR_IN_SIN_LEN
1277 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1279 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1280 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1286 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1287 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1289 saddrlens[i] = sizeof (struct sockaddr_in6);
1290 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1291 #if HAVE_SOCKADDR_IN_SIN_LEN
1292 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1294 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1295 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1297 saddrlens[i] = sizeof (struct sockaddr_in);
1298 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1299 #if HAVE_SOCKADDR_IN_SIN_LEN
1300 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1302 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1303 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1307 *addr_lens = saddrlens;
1312 start_report_addresses (struct Plugin *plugin)
1314 int res = GNUNET_OK;
1315 struct sockaddr **addrs;
1316 socklen_t *addrlens;
1319 http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs,
1321 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1322 _("Found %u addresses to report to NAT service\n"), res);
1324 if (GNUNET_SYSERR == res)
1331 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
1333 (const struct sockaddr **) addrs, addrlens,
1334 &nat_port_map_callback, NULL, plugin);
1338 GNUNET_assert (addrs[res] != NULL);
1339 GNUNET_free (addrs[res]);
1341 GNUNET_free_non_null (addrs);
1342 GNUNET_free_non_null (addrlens);
1347 stop_report_addresses (struct Plugin *plugin)
1350 /* Stop NAT handle */
1351 if (NULL != plugin->nat)
1352 GNUNET_NAT_unregister (plugin->nat);
1354 /* Clean up addresses */
1355 struct IPv4HttpAddressWrapper *w_t4;
1356 struct IPv6HttpAddressWrapper *w_t6;
1358 while (plugin->ipv4_addr_head != NULL)
1360 w_t4 = plugin->ipv4_addr_head;
1361 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1366 while (plugin->ipv6_addr_head != NULL)
1368 w_t6 = plugin->ipv6_addr_head;
1369 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1377 configure_plugin (struct Plugin *plugin)
1379 int res = GNUNET_OK;
1382 if (GNUNET_CONFIGURATION_have_value
1383 (plugin->env->cfg, plugin->name, "USE_IPv4"))
1386 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1390 plugin->ipv4 = GNUNET_YES;
1393 if (GNUNET_CONFIGURATION_have_value
1394 (plugin->env->cfg, plugin->name, "USE_IPv6"))
1397 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1401 plugin->ipv6 = GNUNET_YES;
1403 if ((plugin->ipv4 == GNUNET_NO) && (plugin->ipv6 == GNUNET_NO))
1405 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1407 ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"),
1409 res = GNUNET_SYSERR;
1412 /* Reading port number from config file */
1413 unsigned long long port;
1416 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1417 "PORT", &port)) || (port > 65535))
1419 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1420 _("Port is required! Fix in configuration\n"),
1422 res = GNUNET_SYSERR;
1425 plugin->port = port;
1427 plugin->client_only = GNUNET_NO;
1428 if (plugin->port == 0)
1430 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1431 _("Port 0, client only mode\n"));
1432 plugin->client_only = GNUNET_YES;
1435 char *bind4_address = NULL;
1437 if ((plugin->ipv4 == GNUNET_YES) &&
1439 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1440 "BINDTO", &bind4_address)))
1442 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1443 "Binding %s plugin to specific IPv4 address: `%s'\n",
1444 plugin->protocol, bind4_address);
1445 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
1447 inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
1449 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1451 ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1452 bind4_address, plugin->protocol);
1453 GNUNET_free (plugin->server_addr_v4);
1454 plugin->server_addr_v4 = NULL;
1458 plugin->server_addr_v4->sin_family = AF_INET;
1459 plugin->server_addr_v4->sin_port = htons (plugin->port);
1461 GNUNET_free (bind4_address);
1465 char *bind6_address = NULL;
1467 if ((plugin->ipv6 == GNUNET_YES) &&
1469 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1470 "BINDTO6", &bind6_address)))
1472 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1473 "Binding %s plugin to specific IPv6 address: `%s'\n",
1474 plugin->protocol, bind6_address);
1475 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
1477 inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
1479 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1481 ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1482 bind6_address, plugin->protocol);
1483 GNUNET_free (plugin->server_addr_v6);
1484 plugin->server_addr_v6 = NULL;
1488 plugin->server_addr_v6->sin6_family = AF_INET6;
1489 plugin->server_addr_v6->sin6_port = htons (plugin->port);
1491 GNUNET_free (bind6_address);
1495 /* Optional parameters */
1496 unsigned long long maxneigh;
1499 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1500 "MAX_CONNECTIONS", &maxneigh))
1502 plugin->max_connections = maxneigh;
1508 #define TESTING GNUNET_NO
1511 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_ERROR
1512 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
1514 #define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
1515 #define TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
1520 * Session was idle, so disconnect it
1523 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1525 GNUNET_assert (NULL != cls);
1526 struct Session *s = cls;
1528 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1529 GNUNET_log (TIMEOUT_LOG,
1530 "Session %p was idle for %llu ms, disconnecting\n",
1531 s, (unsigned long long) TIMEOUT.rel_value);
1533 /* call session destroy function */
1534 if (s->inbound == GNUNET_NO)
1535 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1537 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1542 * Start session timeout
1545 start_session_timeout (struct Session *s)
1547 GNUNET_assert (NULL != s);
1548 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
1549 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1552 GNUNET_log (TIMEOUT_LOG,
1553 "Timeout for session %p set to %llu ms\n",
1554 s, (unsigned long long) TIMEOUT.rel_value);
1559 * Increment session timeout due to activity
1562 reschedule_session_timeout (struct Session *s)
1564 GNUNET_assert (NULL != s);
1565 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
1567 GNUNET_SCHEDULER_cancel (s->timeout_task);
1568 s->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1571 GNUNET_log (TIMEOUT_LOG,
1572 "Timeout rescheduled for session %p set to %llu ms\n",
1573 s, (unsigned long long) TIMEOUT.rel_value);
1581 stop_session_timeout (struct Session *s)
1583 GNUNET_assert (NULL != s);
1585 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
1587 GNUNET_SCHEDULER_cancel (s->timeout_task);
1588 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1589 GNUNET_log (TIMEOUT_LOG,
1590 "Timeout stopped for session %p\n",
1596 * Entry point for the plugin.
1599 LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1601 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1602 struct GNUNET_TRANSPORT_PluginFunctions *api;
1603 struct Plugin *plugin;
1606 if (NULL == env->receive)
1608 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1609 initialze the plugin or the API */
1610 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1612 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1613 api->address_to_string = &http_plugin_address_to_string;
1614 api->string_to_address = &http_string_to_address;
1618 plugin = GNUNET_malloc (sizeof (struct Plugin));
1620 plugin->outbound_sessions = 0;
1621 plugin->inbound_sessions = 0;
1622 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1624 api->disconnect = &http_plugin_disconnect;
1625 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1626 api->check_address = &http_plugin_address_suggested;
1627 api->address_to_string = &http_plugin_address_to_string;
1628 api->string_to_address = &http_string_to_address;
1629 api->get_session = &http_get_session;
1630 api->send = &http_plugin_send;
1633 plugin->name = "transport-https";
1634 plugin->protocol = "https";
1636 plugin->name = "transport-http";
1637 plugin->protocol = "http";
1639 /* Configure plugin from configuration */
1640 res = configure_plugin (plugin);
1641 if (res == GNUNET_SYSERR)
1643 GNUNET_free_non_null (plugin->server_addr_v4);
1644 GNUNET_free_non_null (plugin->server_addr_v6);
1645 GNUNET_free (plugin);
1650 /* checking IPv6 support */
1651 http_check_ipv6 (plugin);
1654 res = client_start (plugin);
1655 if (res == GNUNET_SYSERR)
1657 GNUNET_free_non_null (plugin->server_addr_v4);
1658 GNUNET_free_non_null (plugin->server_addr_v6);
1659 GNUNET_free (plugin);
1665 if (plugin->client_only == GNUNET_NO)
1667 res = server_start (plugin);
1668 if (res == GNUNET_SYSERR)
1670 server_stop (plugin);
1671 client_stop (plugin);
1673 GNUNET_free_non_null (plugin->server_addr_v4);
1674 GNUNET_free_non_null (plugin->server_addr_v6);
1675 GNUNET_free (plugin);
1680 /* Report addresses to transport service */
1681 start_report_addresses (plugin);
1683 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1684 "Plugin `%s' loaded\n", plugin->name);
1690 * Exit point from the plugin.
1693 LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1695 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1696 struct Plugin *plugin = api->cls;
1698 struct Session *next;
1706 /* Stop reporting addresses to transport service */
1707 stop_report_addresses (plugin);
1709 /* cleaning up sessions */
1714 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1715 "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
1716 if (s->inbound == GNUNET_NO)
1717 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1719 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1723 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
1725 server_stop (plugin);
1727 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n");
1729 client_stop (plugin);
1731 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1732 "Plugin `%s' unloaded\n", plugin->name);
1733 GNUNET_free_non_null (plugin->server_addr_v4);
1734 GNUNET_free_non_null (plugin->server_addr_v6);
1735 GNUNET_free (plugin);
1740 /* end of plugin_transport_http.c */