aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_http.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-13 16:02:44 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-13 16:02:44 +0000
commit2e2e5b4a8e5cebd71b880da8c613be4a49f44fe2 (patch)
tree270c64858fd4494c0d62970b7aa5926d185cef46 /src/transport/plugin_transport_http.c
parent5b9e61b9c3832e69164ee8574fff6711b2f18ef6 (diff)
downloadgnunet-2e2e5b4a8e5cebd71b880da8c613be4a49f44fe2.tar.gz
gnunet-2e2e5b4a8e5cebd71b880da8c613be4a49f44fe2.zip
removing legacy send functions from plugins and renaming new send function
Diffstat (limited to 'src/transport/plugin_transport_http.c')
-rw-r--r--src/transport/plugin_transport_http.c186
1 files changed, 1 insertions, 185 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index e40d2c8f8..b6e862aa3 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -685,189 +685,6 @@ http_plugin_send (void *cls,
685 685
686} 686}
687 687
688/**
689 * Function that can be used by the transport service to transmit
690 * a message using the plugin. Note that in the case of a
691 * peer disconnecting, the continuation MUST be called
692 * prior to the disconnect notification itself. This function
693 * will be called with this peer's HELLO message to initiate
694 * a fresh connection to another peer.
695 *
696 * @param cls closure
697 * @param target who should receive this message
698 * @param msgbuf the message to transmit
699 * @param msgbuf_size number of bytes in 'msgbuf'
700 * @param priority how important is the message (most plugins will
701 * ignore message priority and just FIFO)
702 * @param to how long to wait at most for the transmission (does not
703 * require plugins to discard the message after the timeout,
704 * just advisory for the desired delay; most plugins will ignore
705 * this as well)
706 * @param session which session must be used (or NULL for "any")
707 * @param addr the address to use (can be NULL if the plugin
708 * is "on its own" (i.e. re-use existing TCP connection))
709 * @param addrlen length of the address in bytes
710 * @param force_address GNUNET_YES if the plugin MUST use the given address,
711 * GNUNET_NO means the plugin may use any other address and
712 * GNUNET_SYSERR means that only reliable existing
713 * bi-directional connections should be used (regardless
714 * of address)
715 * @param cont continuation to call once the message has
716 * been transmitted (or if the transport is ready
717 * for the next transmission call; or if the
718 * peer disconnected...); can be NULL
719 * @param cont_cls closure for cont
720 * @return number of bytes used (on the physical network, with overheads);
721 * -1 on hard errors (i.e. address invalid); 0 is a legal value
722 * and does NOT mean that the message was not transmitted (DV)
723 */
724static ssize_t
725http_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
726 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
727 struct GNUNET_TIME_Relative to, struct Session *session,
728 const void *addr, size_t addrlen, int force_address,
729 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
730{
731 struct Plugin *plugin = cls;
732 struct HTTP_Message *msg;
733 struct Session *s;
734
735 GNUNET_assert (plugin != NULL);
736
737 int res = GNUNET_SYSERR;
738
739#if DEBUG_HTTP
740 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
741 "Sending %u bytes to peer `%s' on address `%s' %X %i\n",
742 msgbuf_size, GNUNET_i2s (target), ((addr != NULL) &&
743 (addrlen !=
744 0)) ?
745 http_plugin_address_to_string (plugin, addr,
746 addrlen) : "<inbound>",
747 session, force_address);
748#endif
749
750
751
752 if (addrlen != 0)
753 GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
754 (addrlen == sizeof (struct IPv6HttpAddress)));
755 /* look for existing connection */
756 s = lookup_session_old (plugin, target, session, addr, addrlen, 1);
757#if DEBUG_HTTP
758 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
759 "%s existing session: %s\n",
760 (s != NULL) ? "Found" : "NOT Found", ((s != NULL) &&
761 (s->inbound ==
762 GNUNET_YES)) ?
763 "inbound" : "outbound");
764#endif
765 /* create new outbound connection */
766 if (s == NULL)
767 {
768 if (plugin->max_connections <= plugin->cur_connections)
769 {
770 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
771 "Maximum number of connections reached, "
772 "cannot connect to peer `%s'\n", GNUNET_i2s (target));
773 return res;
774 }
775
776#if DEBUG_HTTP
777 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
778 "Initiiating new connection to peer `%s'\n",
779 GNUNET_i2s (target));
780#endif
781/* AAAAAAAAAAAAAAAAAAA */
782 int res = GNUNET_OK;
783 struct GNUNET_ATS_Information ats;
784 if ((addrlen == sizeof (struct IPv4HttpAddress)) && (addr != NULL))
785 {
786 struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
787 struct sockaddr_in s4;
788
789 s4.sin_family = AF_INET;
790 s4.sin_addr.s_addr = a4->ipv4_addr;
791 s4.sin_port = a4->u4_port;
792#if HAVE_SOCKADDR_IN_SIN_LEN
793 s4.sin_len = sizeof (struct sockaddr_in);
794#endif
795 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
796
797 if ((ntohs (a4->u4_port) == 0) || (plugin->ipv4 == GNUNET_NO))
798 res = GNUNET_SYSERR;
799 }
800 if ((addrlen == sizeof (struct IPv6HttpAddress)) && (addr != NULL))
801 {
802 struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
803 struct sockaddr_in6 s6;
804
805 s6.sin6_family = AF_INET6;
806 s6.sin6_addr = a6->ipv6_addr;
807 s6.sin6_port = a6->u6_port;
808#if HAVE_SOCKADDR_IN_SIN_LEN
809 s6.sin6_len = sizeof (struct sockaddr_in6);
810#endif
811 ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
812
813 if ((ntohs (a6->u6_port) == 0) || (plugin->ipv6 == GNUNET_NO))
814 res = GNUNET_SYSERR;
815 }
816 if (res == GNUNET_OK)
817 {
818 s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
819 s->ats_address_network_type = ats.value;
820 GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
821 // initiate new connection
822 res = client_connect (s);
823 }
824 if (res == GNUNET_SYSERR)
825 {
826 if (s != NULL)
827 {
828 GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
829 delete_session (s);
830 }
831 return GNUNET_SYSERR;
832 }
833 }
834
835 /* real sending */
836
837 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
838 msg->next = NULL;
839 msg->size = msgbuf_size;
840 msg->pos = 0;
841 msg->buf = (char *) &msg[1];
842 msg->transmit_cont = cont;
843 msg->transmit_cont_cls = cont_cls;
844 memcpy (msg->buf, msgbuf, msgbuf_size);
845
846 if (s->inbound == GNUNET_NO)
847 {
848#if DEBUG_HTTP
849 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
850 "Using outbound client session %p to send to `%s'\n", s,
851 GNUNET_i2s (target));
852#endif
853
854 client_send (s, msg);
855 res = msgbuf_size;
856 }
857 if (s->inbound == GNUNET_YES)
858 {
859#if DEBUG_HTTP
860 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
861 "Using inbound server %p session to send to `%s'\n", s,
862 GNUNET_i2s (target));
863#endif
864
865 server_send (s, msg);
866 res = msgbuf_size;
867 }
868 return res;
869}
870
871 688
872/** 689/**
873 * Function that can be used to force the plugin to disconnect 690 * Function that can be used to force the plugin to disconnect
@@ -1556,13 +1373,12 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
1556 plugin->env = env; 1373 plugin->env = env;
1557 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 1374 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1558 api->cls = plugin; 1375 api->cls = plugin;
1559 api->send = &http_plugin_send_old;
1560 api->disconnect = &http_plugin_disconnect; 1376 api->disconnect = &http_plugin_disconnect;
1561 api->address_pretty_printer = &http_plugin_address_pretty_printer; 1377 api->address_pretty_printer = &http_plugin_address_pretty_printer;
1562 api->check_address = &http_plugin_address_suggested; 1378 api->check_address = &http_plugin_address_suggested;
1563 api->address_to_string = &http_plugin_address_to_string; 1379 api->address_to_string = &http_plugin_address_to_string;
1564 api->get_session = &http_get_session; 1380 api->get_session = &http_get_session;
1565 api->send_with_session = &http_plugin_send; 1381 api->send = &http_plugin_send;
1566 1382
1567#if BUILD_HTTPS 1383#if BUILD_HTTPS
1568 plugin->name = "transport-https"; 1384 plugin->name = "transport-https";