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)
272 struct Plugin *plugin = cls;
273 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
274 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
278 GNUNET_assert (cls != NULL);
279 if ((addrlen != sizeof (struct sockaddr_in)) ||
280 (addrlen != sizeof (struct sockaddr_in6)))
281 return GNUNET_SYSERR;
283 if (addrlen == sizeof (struct IPv4HttpAddress))
285 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
287 while (w_tv4 != NULL)
290 memcmp (&w_tv4->addr.ipv4_addr, &a4->ipv4_addr,
291 sizeof (struct in_addr))) &&
292 (w_tv4->addr.u4_port == a4->u4_port))
299 return GNUNET_SYSERR;
301 if (addrlen == sizeof (struct sockaddr_in6))
303 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
305 while (w_tv6 != NULL)
308 memcmp (&w_tv6->addr6.ipv6_addr, &a6->ipv6_addr,
309 sizeof (struct in6_addr))) &&
310 (w_tv6->addr6.u6_port == a6->u6_port))
317 return GNUNET_SYSERR;
322 struct GNUNET_TIME_Relative
323 http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
324 const struct GNUNET_MessageHeader *message,
325 struct Session *session, const char *sender_address,
326 uint16_t sender_address_len)
328 struct Session *s = cls;
329 struct Plugin *plugin = s->plugin;
330 struct GNUNET_TIME_Relative delay;
331 struct GNUNET_ATS_Information atsi[2];
333 atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
334 atsi[0].value = htonl (1);
335 atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
336 atsi[1].value = session->ats_address_network_type;
337 GNUNET_break (session->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED));
339 reschedule_session_timeout (session);
342 plugin->env->receive (plugin->env->cls, &s->target, message,
343 (const struct GNUNET_ATS_Information *) &atsi,
344 2, s, s->addr, s->addrlen);
350 * Function called to convert a string address to
353 * @param cls closure ('struct Plugin*')
354 * @param addr string address
355 * @param addrlen length of the address
356 * @param buf location to store the buffer
357 * If the function returns GNUNET_SYSERR, its contents are undefined.
358 * @param added length of created address
359 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
361 int http_string_to_address (void *cls,
368 char *protocol = "http";
370 char *protocol = "https";
372 char *addr_str = NULL;
373 struct sockaddr_in addr_4;
374 struct sockaddr_in6 addr_6;
375 struct IPv4HttpAddress * http_4addr;
376 struct IPv6HttpAddress * http_6addr;
378 if ((NULL == addr) || (addrlen == 0))
381 return GNUNET_SYSERR;
384 if ('\0' != addr[addrlen - 1])
387 return GNUNET_SYSERR;
390 if (strlen (addr) != addrlen - 1)
393 return GNUNET_SYSERR;
396 /* protocoll + "://" + ":" */
397 if (addrlen <= (strlen (protocol) + 4))
399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
400 "Invalid address string `%s' to convert to address\n",
403 return GNUNET_SYSERR;
406 if (NULL == (addr_str = strstr(addr, "://")))
408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
409 "Invalid address string `%s' to convert to address\n",
412 return GNUNET_SYSERR;
414 addr_str = &addr_str[3];
416 if (addr_str[strlen(addr_str)-1] == '/')
417 addr_str[strlen(addr_str)-1] = '\0';
419 if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr_str, strlen(addr_str), &addr_4))
421 http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
422 http_4addr->u4_port = addr_4.sin_port;
423 http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr;
425 (*added) = sizeof (struct IPv4HttpAddress);
428 else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
430 http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
431 http_6addr->u6_port = addr_6.sin6_port;
432 http_6addr->ipv6_addr = addr_6.sin6_addr;
434 (*added) = sizeof (struct IPv6HttpAddress);
439 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
440 "Invalid address string `%s' to convert to address\n",
443 return GNUNET_SYSERR;
450 * Function called for a quick conversion of the binary address to
451 * a numeric address. Note that the caller must not free the
452 * address and that the next call to this function is allowed
453 * to override the address again.
456 * @param addr binary address
457 * @param addrlen length of the address
458 * @return string representing the same address
461 http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
464 struct IPv4HttpAddress *a4;
465 struct IPv6HttpAddress *a6;
467 static char rbuf[INET6_ADDRSTRLEN + 13];
471 if (addrlen == sizeof (struct IPv6HttpAddress))
473 a6 = (struct IPv6HttpAddress *) addr;
474 address = GNUNET_malloc (INET6_ADDRSTRLEN);
475 GNUNET_assert (NULL !=
476 inet_ntop (AF_INET6, &a6->ipv6_addr, address,
478 port = ntohs (a6->u6_port);
480 else if (addrlen == sizeof (struct IPv4HttpAddress))
482 a4 = (struct IPv4HttpAddress *) addr;
483 address = GNUNET_malloc (INET_ADDRSTRLEN);
484 GNUNET_assert (NULL !=
485 inet_ntop (AF_INET, &(a4->ipv4_addr), address,
487 port = ntohs (a4->u4_port);
491 /* invalid address */
496 char *protocol = "http";
498 char *protocol = "https";
501 GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13));
502 if (addrlen == sizeof (struct IPv6HttpAddress))
504 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol,
506 else if (addrlen == sizeof (struct IPv4HttpAddress))
508 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address,
511 GNUNET_free (address);
512 GNUNET_assert (res != 0);
517 lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
518 struct Session *session, const void *addr, size_t addrlen,
525 for (t = plugin->head; NULL != t; t = t->next)
528 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
529 "Comparing peer `%s' address `%s' len %i session %X to \n",
530 GNUNET_i2s (target), GNUNET_a2s (addr, addrlen), addrlen,
532 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
533 "peer `%s' address `%s' len %i session %X \n\n",
534 GNUNET_i2s (&t->target), GNUNET_a2s (t->addr, t->addrlen),
536 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, "memcmp %i \n",
537 memcmp (addr, t->addr, addrlen));
541 if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity)))
544 if ( (addrlen == t->addrlen) &&
545 (0 == memcmp (addr, t->addr, addrlen)) )
547 if ( (t == session) &&
548 (t->addrlen == session->addrlen) &&
549 (0 == memcmp (session->addr, t->addr, t->addrlen)) )
553 if ( ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO)) ||
554 ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES)) ||
555 ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR)) )
562 lookup_session (struct Plugin *plugin,
563 const struct GNUNET_HELLO_Address *address)
567 for (pos = plugin->head; NULL != pos; pos = pos->next)
568 if ( (0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) &&
569 (address->address_length == pos->addrlen) &&
570 (0 == memcmp (address->address, pos->addr, pos->addrlen)) )
576 exist_session (struct Plugin *plugin, struct Session *s)
578 struct Session * head;
580 GNUNET_assert (NULL != plugin);
581 GNUNET_assert (NULL != s);
583 for (head = plugin->head; head != NULL; head = head->next)
594 delete_session (struct Session *s)
596 stop_session_timeout(s);
598 if (s->msg_tk != NULL)
600 GNUNET_SERVER_mst_destroy (s->msg_tk);
603 GNUNET_free (s->addr);
604 GNUNET_free_non_null (s->server_recv);
605 GNUNET_free_non_null (s->server_send);
610 create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
611 const void *addr, size_t addrlen)
613 struct Session *s = NULL;
615 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
616 (addrlen == sizeof (struct IPv4HttpAddress)));
617 s = GNUNET_malloc (sizeof (struct Session));
618 memcpy (&s->target, target, sizeof (struct GNUNET_PeerIdentity));
620 s->addr = GNUNET_malloc (addrlen);
621 memcpy (s->addr, addr, addrlen);
622 s->addrlen = addrlen;
623 s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
624 start_session_timeout(s);
631 notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
634 struct Plugin *plugin = cls;
636 plugin->env->session_end (plugin->env->cls, peer, s);
637 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
642 * Creates a new outbound session the transport service will use to send data to the
645 * @param cls the plugin
646 * @param address the address
647 * @return the session or NULL of max connections exceeded
650 static struct Session *
651 http_get_session (void *cls,
652 const struct GNUNET_HELLO_Address *address)
654 struct Plugin *plugin = cls;
655 struct Session * s = NULL;
656 struct GNUNET_ATS_Information ats;
659 GNUNET_assert (plugin != NULL);
660 GNUNET_assert (address != NULL);
661 GNUNET_assert (address->address != NULL);
663 ats.type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
664 ats.value = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
666 /* find existing session */
667 s = lookup_session (plugin, address);
671 if (plugin->max_connections <= plugin->cur_connections)
673 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
674 "Maximum number of connections reached, "
675 "cannot connect to peer `%s'\n", GNUNET_i2s (&address->peer));
679 /* create new session */
680 addrlen = address->address_length;
682 GNUNET_assert ((addrlen == sizeof (struct IPv6HttpAddress)) ||
683 (addrlen == sizeof (struct IPv4HttpAddress)));
685 s = create_session (plugin, &address->peer, address->address, address->address_length);
688 if (addrlen == sizeof (struct IPv4HttpAddress))
690 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) address->address;
691 struct sockaddr_in s4;
693 s4.sin_family = AF_INET;
694 s4.sin_addr.s_addr = a4->ipv4_addr;
695 s4.sin_port = a4->u4_port;
696 #if HAVE_SOCKADDR_IN_SIN_LEN
697 s4.sin_len = sizeof (struct sockaddr_in);
699 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
701 if (addrlen == sizeof (struct IPv6HttpAddress))
703 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) address->address;
704 struct sockaddr_in6 s6;
706 s6.sin6_family = AF_INET6;
707 s6.sin6_addr = a6->ipv6_addr;
708 s6.sin6_port = a6->u6_port;
709 #if HAVE_SOCKADDR_IN_SIN_LEN
710 s6.sin6_len = sizeof (struct sockaddr_in6);
712 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
714 s->ats_address_network_type = ats.value;
716 /* add new session */
717 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
718 /* initiate new connection */
719 if (GNUNET_SYSERR == client_connect (s))
721 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
722 "Cannot connect to peer `%s' address `%s''\n",
723 http_plugin_address_to_string(NULL, s->addr, s->addrlen),
724 GNUNET_i2s (&s->target));
725 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
734 * Function that can be used by the transport service to transmit
735 * a message using the plugin. Note that in the case of a
736 * peer disconnecting, the continuation MUST be called
737 * prior to the disconnect notification itself. This function
738 * will be called with this peer's HELLO message to initiate
739 * a fresh connection to another peer.
742 * @param session which session must be used
743 * @param msgbuf the message to transmit
744 * @param msgbuf_size number of bytes in 'msgbuf'
745 * @param priority how important is the message (most plugins will
746 * ignore message priority and just FIFO)
747 * @param to how long to wait at most for the transmission (does not
748 * require plugins to discard the message after the timeout,
749 * just advisory for the desired delay; most plugins will ignore
751 * @param cont continuation to call once the message has
752 * been transmitted (or if the transport is ready
753 * for the next transmission call; or if the
754 * peer disconnected...); can be NULL
755 * @param cont_cls closure for cont
756 * @return number of bytes used (on the physical network, with overheads);
757 * -1 on hard errors (i.e. address invalid); 0 is a legal value
758 * and does NOT mean that the message was not transmitted (DV)
761 http_plugin_send (void *cls,
762 struct Session *session,
763 const char *msgbuf, size_t msgbuf_size,
764 unsigned int priority,
765 struct GNUNET_TIME_Relative to,
766 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
768 struct Plugin *plugin = cls;
769 struct HTTP_Message *msg;
773 GNUNET_assert (plugin != NULL);
774 GNUNET_assert (session != NULL);
776 /* lookup if session is really existing */
780 if ((tmp == session) &&
781 (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) &&
782 (session->addrlen == tmp->addrlen) &&
783 (0 == memcmp (session->addr, tmp->addr, tmp->addrlen)))
793 /* create new message and schedule */
795 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
797 msg->size = msgbuf_size;
799 msg->buf = (char *) &msg[1];
800 msg->transmit_cont = cont;
801 msg->transmit_cont_cls = cont_cls;
802 memcpy (msg->buf, msgbuf, msgbuf_size);
804 reschedule_session_timeout (session);
806 if (session->inbound == GNUNET_NO)
808 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
809 "Using outbound client session %p to send to `%s'\n", session,
810 GNUNET_i2s (&session->target));
811 client_send (session, msg);
814 if (session->inbound == GNUNET_YES)
816 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
817 "Using inbound server %p session to send to `%s'\n", session,
818 GNUNET_i2s (&session->target));
819 server_send (session, msg);
828 * Function that can be used to force the plugin to disconnect
829 * from the given peer and cancel all previous transmissions
830 * (and their continuationc).
833 * @param target peer from which to disconnect
836 http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
838 struct Plugin *plugin = cls;
839 struct Session *next = NULL;
840 struct Session *s = plugin->head;
842 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
843 "Transport tells me to disconnect `%s'\n",
844 GNUNET_i2s (target));
848 if (0 == memcmp (target, &s->target, sizeof (struct GNUNET_PeerIdentity)))
850 if (s->inbound == GNUNET_NO)
851 GNUNET_assert (GNUNET_OK == client_disconnect (s));
853 GNUNET_assert (GNUNET_OK == server_disconnect (s));
854 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
856 struct HTTP_Message *msg = s->msg_head;
857 struct HTTP_Message *tmp = NULL;
863 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
864 if (msg->transmit_cont != NULL)
866 msg->transmit_cont (msg->transmit_cont_cls, target, GNUNET_SYSERR);
879 find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
882 struct IPv4HttpAddressWrapper *w_t4 = NULL;
883 struct IPv6HttpAddressWrapper *w_t6 = NULL;
885 af = addr->sa_family;
889 w_t4 = plugin->ipv4_addr_head;
890 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
894 int res = memcmp (&w_t4->addr.ipv4_addr,
896 sizeof (struct in_addr));
900 if (a4->sin_port != w_t4->addr.u4_port)
911 w_t6 = plugin->ipv6_addr_head;
912 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
916 int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
917 sizeof (struct in6_addr));
921 if (a6->sin6_port != w_t6->addr6.u6_port)
937 nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
940 struct Plugin *plugin = cls;
941 struct IPv4HttpAddressWrapper *w_t4 = NULL;
942 struct IPv6HttpAddressWrapper *w_t6 = NULL;
945 af = addr->sa_family;
949 w_t4 = find_address (plugin, addr, addrlen);
952 struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
953 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
954 memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
955 w_t4->addr.u4_port = a4->sin_port;
957 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
958 plugin->ipv4_addr_tail, w_t4);
960 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
961 "Notifying transport to add IPv4 address `%s'\n",
962 http_plugin_address_to_string (NULL, &w_t4->addr,
965 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
966 sizeof (struct IPv4HttpAddress));
970 w_t6 = find_address (plugin, addr, addrlen);
973 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
974 struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
975 memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
976 w_t6->addr6.u6_port = a6->sin6_port;
978 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
979 plugin->ipv6_addr_tail, w_t6);
981 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
982 "Notifying transport to add IPv6 address `%s'\n",
983 http_plugin_address_to_string (NULL, &w_t6->addr6,
986 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
987 sizeof (struct IPv6HttpAddress));
997 nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
1000 struct Plugin *plugin = cls;
1001 struct IPv4HttpAddressWrapper *w_t4 = NULL;
1002 struct IPv6HttpAddressWrapper *w_t6 = NULL;
1005 af = addr->sa_family;
1009 w_t4 = find_address (plugin, addr, addrlen);
1014 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1015 "Notifying transport to remove IPv4 address `%s'\n",
1016 http_plugin_address_to_string (NULL, &w_t4->addr,
1019 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
1020 sizeof (struct IPv4HttpAddress));
1022 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1027 w_t6 = find_address (plugin, addr, addrlen);
1031 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1032 "Notifying transport to remove IPv6 address `%s'\n",
1033 http_plugin_address_to_string (NULL, &w_t6->addr6,
1037 plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
1038 sizeof (struct IPv6HttpAddress));
1040 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1051 * Our external IP address/port mapping has changed.
1053 * @param cls closure, the 'struct LocalAddrList'
1054 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean
1055 * the previous (now invalid) one
1056 * @param addr either the previous or the new public IP address
1057 * @param addrlen actual lenght of the address
1060 nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
1063 GNUNET_assert (cls != NULL);
1064 struct Plugin *plugin = cls;
1066 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1067 "NPMC called %s to address `%s'\n",
1068 (add_remove == GNUNET_NO) ? "remove" : "add",
1069 GNUNET_a2s (addr, addrlen));
1074 nat_add_address (cls, add_remove, addr, addrlen);
1077 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");
1116 http_get_addresses (struct Plugin *plugin, const char *serviceName,
1117 const struct GNUNET_CONFIGURATION_Handle *cfg,
1118 struct sockaddr ***addrs, socklen_t ** addr_lens)
1121 unsigned long long port;
1122 struct addrinfo hints;
1123 struct addrinfo *res;
1124 struct addrinfo *pos;
1125 struct addrinfo *next;
1129 struct sockaddr **saddrs;
1130 socklen_t *saddrlens;
1136 disablev6 = !plugin->ipv6;
1139 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "PORT"))
1141 GNUNET_break (GNUNET_OK ==
1142 GNUNET_CONFIGURATION_get_value_number (cfg, serviceName,
1146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1148 ("Require valid port number for service in configuration!\n"));
1149 return GNUNET_SYSERR;
1153 if (GNUNET_CONFIGURATION_have_value (cfg, serviceName, "BINDTO"))
1155 GNUNET_break (GNUNET_OK ==
1156 GNUNET_CONFIGURATION_get_value_string (cfg, serviceName,
1157 "BINDTO", &hostname));
1162 if (hostname != NULL)
1164 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1165 "Resolving `%s' since that is where `%s' will bind to.\n",
1166 hostname, serviceName);
1167 memset (&hints, 0, sizeof (struct addrinfo));
1169 hints.ai_family = AF_INET;
1170 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to resolve `%s': %s\n"),
1174 hostname, gai_strerror (ret));
1175 GNUNET_free (hostname);
1176 return GNUNET_SYSERR;
1180 while (NULL != (pos = next))
1182 next = pos->ai_next;
1183 if ((disablev6) && (pos->ai_family == AF_INET6))
1189 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1190 _("Failed to find %saddress for `%s'.\n"),
1191 disablev6 ? "IPv4 " : "", hostname);
1193 GNUNET_free (hostname);
1194 return GNUNET_SYSERR;
1197 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1198 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1201 while (NULL != (pos = next))
1203 next = pos->ai_next;
1204 if ((disablev6) && (pos->ai_family == AF_INET6))
1206 if ((pos->ai_protocol != IPPROTO_TCP) && (pos->ai_protocol != 0))
1207 continue; /* not TCP */
1208 if ((pos->ai_socktype != SOCK_STREAM) && (pos->ai_socktype != 0))
1209 continue; /* huh? */
1210 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1211 "Service will bind to `%s'\n", GNUNET_a2s (pos->ai_addr,
1213 if (pos->ai_family == AF_INET)
1215 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
1216 saddrlens[i] = pos->ai_addrlen;
1217 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1218 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1219 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1223 GNUNET_assert (pos->ai_family == AF_INET6);
1224 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
1225 saddrlens[i] = pos->ai_addrlen;
1226 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1227 memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1228 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1232 GNUNET_free (hostname);
1238 /* will bind against everything, just set port */
1244 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1245 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1247 saddrlens[i] = sizeof (struct sockaddr_in);
1248 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1249 #if HAVE_SOCKADDR_IN_SIN_LEN
1250 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1252 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1253 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1259 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1260 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1262 saddrlens[i] = sizeof (struct sockaddr_in6);
1263 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1264 #if HAVE_SOCKADDR_IN_SIN_LEN
1265 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1267 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1268 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1270 saddrlens[i] = sizeof (struct sockaddr_in);
1271 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1272 #if HAVE_SOCKADDR_IN_SIN_LEN
1273 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1275 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1276 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1280 *addr_lens = saddrlens;
1285 start_report_addresses (struct Plugin *plugin)
1287 int res = GNUNET_OK;
1288 struct sockaddr **addrs;
1289 socklen_t *addrlens;
1292 http_get_addresses (plugin, plugin->name, plugin->env->cfg, &addrs,
1294 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1295 _("Found %u addresses to report to NAT service\n"), res);
1297 if (res != GNUNET_SYSERR)
1300 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, plugin->port,
1302 (const struct sockaddr **) addrs, addrlens,
1303 &nat_port_map_callback, NULL, plugin);
1308 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name, _("FREEING %s\n"),
1309 GNUNET_a2s (addrs[res], addrlens[res]));
1311 GNUNET_assert (addrs[res] != NULL);
1312 GNUNET_free (addrs[res]);
1314 GNUNET_free_non_null (addrs);
1315 GNUNET_free_non_null (addrlens);
1320 GNUNET_NAT_register (plugin->env->cfg, GNUNET_YES, 0, 0, NULL, NULL,
1321 NULL, NULL, plugin);
1326 stop_report_addresses (struct Plugin *plugin)
1328 /* Stop NAT handle */
1329 GNUNET_NAT_unregister (plugin->nat);
1331 /* Clean up addresses */
1332 struct IPv4HttpAddressWrapper *w_t4;
1333 struct IPv6HttpAddressWrapper *w_t6;
1335 while (plugin->ipv4_addr_head != NULL)
1337 w_t4 = plugin->ipv4_addr_head;
1338 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
1343 while (plugin->ipv6_addr_head != NULL)
1345 w_t6 = plugin->ipv6_addr_head;
1346 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
1353 configure_plugin (struct Plugin *plugin)
1355 int res = GNUNET_OK;
1358 if (GNUNET_CONFIGURATION_have_value
1359 (plugin->env->cfg, plugin->name, "USE_IPv4"))
1362 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1366 plugin->ipv4 = GNUNET_YES;
1369 if (GNUNET_CONFIGURATION_have_value
1370 (plugin->env->cfg, plugin->name, "USE_IPv6"))
1373 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, plugin->name,
1377 plugin->ipv6 = GNUNET_YES;
1379 if ((plugin->ipv4 == GNUNET_NO) && (plugin->ipv6 == GNUNET_NO))
1381 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1383 ("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"),
1385 res = GNUNET_SYSERR;
1388 /* Reading port number from config file */
1389 unsigned long long port;
1392 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1393 "PORT", &port)) || (port > 65535))
1395 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1396 _("Port is required! Fix in configuration\n"),
1398 res = GNUNET_SYSERR;
1401 plugin->port = port;
1403 plugin->client_only = GNUNET_NO;
1404 if (plugin->port == 0)
1406 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1407 _("Port 0, client only mode\n"));
1408 plugin->client_only = GNUNET_YES;
1411 char *bind4_address = NULL;
1413 if ((plugin->ipv4 == GNUNET_YES) &&
1415 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1416 "BINDTO", &bind4_address)))
1418 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1419 "Binding %s plugin to specific IPv4 address: `%s'\n",
1420 plugin->protocol, bind4_address);
1421 plugin->server_addr_v4 = GNUNET_malloc (sizeof (struct sockaddr_in));
1423 inet_pton (AF_INET, bind4_address, &plugin->server_addr_v4->sin_addr))
1425 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1427 ("Specific IPv4 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1428 bind4_address, plugin->protocol);
1429 GNUNET_free (plugin->server_addr_v4);
1430 plugin->server_addr_v4 = NULL;
1434 plugin->server_addr_v4->sin_family = AF_INET;
1435 plugin->server_addr_v4->sin_port = htons (plugin->port);
1437 GNUNET_free (bind4_address);
1441 char *bind6_address = NULL;
1443 if ((plugin->ipv6 == GNUNET_YES) &&
1445 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, plugin->name,
1446 "BINDTO6", &bind6_address)))
1448 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1449 "Binding %s plugin to specific IPv6 address: `%s'\n",
1450 plugin->protocol, bind6_address);
1451 plugin->server_addr_v6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
1453 inet_pton (AF_INET6, bind6_address, &plugin->server_addr_v6->sin6_addr))
1455 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
1457 ("Specific IPv6 address `%s' for plugin %s in configuration file is invalid! Binding to all addresses!\n"),
1458 bind6_address, plugin->protocol);
1459 GNUNET_free (plugin->server_addr_v6);
1460 plugin->server_addr_v6 = NULL;
1464 plugin->server_addr_v6->sin6_family = AF_INET6;
1465 plugin->server_addr_v6->sin6_port = htons (plugin->port);
1467 GNUNET_free (bind6_address);
1471 /* Optional parameters */
1472 unsigned long long maxneigh;
1475 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, plugin->name,
1476 "MAX_CONNECTIONS", &maxneigh))
1478 plugin->max_connections = maxneigh;
1486 * Session was idle, so disconnect it
1489 session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1491 GNUNET_assert (NULL != cls);
1492 struct Session *s = cls;
1494 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %p was idle for %llu, disconnecting\n",
1497 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1499 /* call session destroy function */
1500 if (s->inbound == GNUNET_NO)
1501 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1503 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1508 * Start session timeout
1511 start_session_timeout (struct Session *s)
1513 GNUNET_assert (NULL != s);
1514 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
1516 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p set to %llu\n",
1521 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1525 * Increment session timeout due to activity
1528 reschedule_session_timeout (struct Session *s)
1530 GNUNET_assert (NULL != s);
1531 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
1533 GNUNET_SCHEDULER_cancel (s->timeout_task);
1534 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p set to %llu\n",
1539 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1546 stop_session_timeout (struct Session *s)
1548 GNUNET_assert (NULL != s);
1550 if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task)
1552 GNUNET_SCHEDULER_cancel (s->timeout_task);
1553 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout rescheduled for session %p canceled\n",
1556 s, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value);
1560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Timeout for session %p was not active\n",
1567 * Entry point for the plugin.
1570 LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1572 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1573 struct GNUNET_TRANSPORT_PluginFunctions *api;
1574 struct Plugin *plugin;
1577 if (NULL == env->receive)
1579 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1580 initialze the plugin or the API */
1581 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1583 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1584 api->address_to_string = &http_plugin_address_to_string;
1585 api->string_to_address = &http_string_to_address;
1589 plugin = GNUNET_malloc (sizeof (struct Plugin));
1591 plugin->outbound_sessions = 0;
1592 plugin->inbound_sessions = 0;
1593 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1595 api->disconnect = &http_plugin_disconnect;
1596 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1597 api->check_address = &http_plugin_address_suggested;
1598 api->address_to_string = &http_plugin_address_to_string;
1599 api->string_to_address = &http_string_to_address;
1600 api->get_session = &http_get_session;
1601 api->send = &http_plugin_send;
1604 plugin->name = "transport-https";
1605 plugin->protocol = "https";
1607 plugin->name = "transport-http";
1608 plugin->protocol = "http";
1610 /* Configure plugin from configuration */
1611 res = configure_plugin (plugin);
1612 if (res == GNUNET_SYSERR)
1614 GNUNET_free_non_null (plugin->server_addr_v4);
1615 GNUNET_free_non_null (plugin->server_addr_v6);
1616 GNUNET_free (plugin);
1621 /* checking IPv6 support */
1622 http_check_ipv6 (plugin);
1625 res = client_start (plugin);
1626 if (res == GNUNET_SYSERR)
1628 GNUNET_free_non_null (plugin->server_addr_v4);
1629 GNUNET_free_non_null (plugin->server_addr_v6);
1630 GNUNET_free (plugin);
1636 if (plugin->client_only == GNUNET_NO)
1638 res = server_start (plugin);
1639 if (res == GNUNET_SYSERR)
1641 server_stop (plugin);
1642 client_stop (plugin);
1644 GNUNET_free_non_null (plugin->server_addr_v4);
1645 GNUNET_free_non_null (plugin->server_addr_v6);
1646 GNUNET_free (plugin);
1651 /* Report addresses to transport service */
1652 start_report_addresses (plugin);
1654 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1655 "Plugin `%s' loaded\n", plugin->name);
1661 * Exit point from the plugin.
1664 LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
1666 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1667 struct Plugin *plugin = api->cls;
1676 /* Stop reporting addresses to transport service */
1677 stop_report_addresses (plugin);
1679 /* cleaning up sessions */
1683 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1684 "Disconnecting `%s' \n", GNUNET_i2s (&s->target));
1685 if (s->inbound == GNUNET_NO)
1686 GNUNET_assert (GNUNET_OK == client_disconnect (s));
1688 GNUNET_assert (GNUNET_OK == server_disconnect (s));
1692 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping server\n");
1694 server_stop (plugin);
1696 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Stopping client\n");
1698 client_stop (plugin);
1700 /* deleting up sessions */
1704 struct Session *t = s->next;
1706 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
1708 struct HTTP_Message *msg = s->msg_head;
1709 struct HTTP_Message *tmp = NULL;
1715 GNUNET_CONTAINER_DLL_remove (s->msg_head, s->msg_tail, msg);
1716 if (msg->transmit_cont != NULL)
1718 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_SYSERR);
1728 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
1729 "Plugin `%s' unloaded\n", plugin->name);
1730 GNUNET_free_non_null (plugin->server_addr_v4);
1731 GNUNET_free_non_null (plugin->server_addr_v6);
1732 GNUNET_free (plugin);
1737 /* end of plugin_transport_http.c */