aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-29 20:03:12 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-29 20:03:12 +0000
commit75bbeaffe2a1467b6f9f4d80bc4d87ed0d9f14a8 (patch)
tree63885d0e8e55d47ecae25cef37181597115c8980 /src/transport/gnunet-service-transport_clients.c
parent56c32ea37a52b239494a7f91933e60eb7caf30f3 (diff)
downloadgnunet-75bbeaffe2a1467b6f9f4d80bc4d87ed0d9f14a8.tar.gz
gnunet-75bbeaffe2a1467b6f9f4d80bc4d87ed0d9f14a8.zip
-cleaning up message format and code related to recent transport address stringification code
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r--src/transport/gnunet-service-transport_clients.c175
1 files changed, 42 insertions, 133 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index d787c7aab..2aea7aa7e 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -612,6 +612,7 @@ static void
612transmit_address_to_client (void *cls, const char *buf) 612transmit_address_to_client (void *cls, const char *buf)
613{ 613{
614 struct GNUNET_SERVER_TransmitContext *tc = cls; 614 struct GNUNET_SERVER_TransmitContext *tc = cls;
615
615 if (NULL == buf) 616 if (NULL == buf)
616 { 617 {
617 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 618 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
@@ -625,31 +626,6 @@ transmit_address_to_client (void *cls, const char *buf)
625 626
626 627
627/** 628/**
628 * Take the given address and append it to the set of results sent back to
629 * the client.
630 *
631 * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
632 * @param buf data to transmit
633 * @param size number of bytes in buf
634 */
635static void
636transmit_binary_to_client (void *cls, void *buf, size_t size)
637{
638 struct GNUNET_SERVER_TransmitContext *tc = cls;
639
640 if (NULL == buf)
641 {
642 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
643 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
644 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
645 return;
646 }
647 GNUNET_SERVER_transmit_context_append_data (tc, buf, size,
648 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
649}
650
651
652/**
653 * Client asked to resolve an address. Process the request. 629 * Client asked to resolve an address. Process the request.
654 * 630 *
655 * @param cls unused 631 * @param cls unused
@@ -658,7 +634,7 @@ transmit_binary_to_client (void *cls, void *buf, size_t size)
658 */ 634 */
659static void 635static void
660clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client, 636clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client,
661 const struct GNUNET_MessageHeader *message) 637 const struct GNUNET_MessageHeader *message)
662{ 638{
663 const struct AddressLookupMessage *alum; 639 const struct AddressLookupMessage *alum;
664 struct GNUNET_TRANSPORT_PluginFunctions *papi; 640 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -678,7 +654,7 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
678 return; 654 return;
679 } 655 }
680 alum = (const struct AddressLookupMessage *) message; 656 alum = (const struct AddressLookupMessage *) message;
681 address_len = ntohl (alum->addrlen); 657 address_len = ntohs (alum->addrlen);
682 if (size <= sizeof (struct AddressLookupMessage) + address_len) 658 if (size <= sizeof (struct AddressLookupMessage) + address_len)
683 { 659 {
684 GNUNET_break (0); 660 GNUNET_break (0);
@@ -695,7 +671,7 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
695 return; 671 return;
696 } 672 }
697 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); 673 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
698 numeric = ntohl (alum->numeric_only); 674 numeric = ntohs (alum->numeric_only);
699 tc = GNUNET_SERVER_transmit_context_create (client); 675 tc = GNUNET_SERVER_transmit_context_create (client);
700 papi = GST_plugins_find (plugin_name); 676 papi = GST_plugins_find (plugin_name);
701 if (NULL == papi) 677 if (NULL == papi)
@@ -711,73 +687,6 @@ clients_handle_address_to_string (void *cls, struct GNUNET_SERVER_Client *client
711 tc); 687 tc);
712} 688}
713 689
714#if 0
715
716THIS FUNCTIONALITY IS NOT USED ANYWHERE!
717
718/**
719 * Send an address to the client.
720 *
721 * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending)
722 * @param public_key public key for the peer, never NULL
723 * @param valid_until until what time do we consider the address valid?
724 * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO)
725 * is ZERO if the address is considered valid (no validation needed)
726 * is a time in the future if we're currently denying re-validation
727 * @param address address to transmit
728 */
729static void
730send_address_to_client (void *cls,
731 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
732 *public_key,
733 struct GNUNET_TIME_Absolute valid_until,
734 struct GNUNET_TIME_Absolute validation_block,
735 const struct GNUNET_HELLO_Address *address)
736{
737 struct GNUNET_SERVER_TransmitContext *tc = cls;
738 char *addr_buf;
739
740 /* FIXME: move to a binary format!!! */
741 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
742 GST_plugins_a2s (address),
743 (GNUNET_YES ==
744 GST_neighbours_test_connected (&address->peer)) ? "CONNECTED" :
745 "DISCONNECTED",
746 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
747 0) ? "VALIDATED" : "UNVALIDATED");
748 transmit_address_to_client (tc, addr_buf);
749 GNUNET_free (addr_buf);
750}
751
752
753/**
754 * Client asked to obtain information about all addresses of a peer.
755 * Process the request.
756 *
757 * @param cls unused
758 * @param client the client
759 * @param message the peer address information request
760 */
761static void
762clients_handle_peer_address_iterate (void *cls,
763 struct GNUNET_SERVER_Client *client,
764 const struct GNUNET_MessageHeader *message)
765{
766 const struct PeerAddressLookupMessage *peer_address_lookup;
767 struct GNUNET_SERVER_TransmitContext *tc;
768
769 peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
770 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
771 tc = GNUNET_SERVER_transmit_context_create (client);
772
773 GST_validation_get_addresses (&peer_address_lookup->peer,
774 &send_address_to_client, tc);
775
776 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
777 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
778 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
779}
780#endif
781 690
782/** 691/**
783 * Output the active address of connected neighbours to the given client. 692 * Output the active address of connected neighbours to the given client.
@@ -789,9 +698,9 @@ clients_handle_peer_address_iterate (void *cls,
789 * @param address the address 698 * @param address the address
790 */ 699 */
791static void 700static void
792output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, 701output_address (void *cls, const struct GNUNET_PeerIdentity *peer,
793 const struct GNUNET_ATS_Information *ats, uint32_t ats_count, 702 const struct GNUNET_ATS_Information *ats, uint32_t ats_count,
794 const struct GNUNET_HELLO_Address *address) 703 const struct GNUNET_HELLO_Address *address)
795{ 704{
796 struct GNUNET_SERVER_TransmitContext *tc = cls; 705 struct GNUNET_SERVER_TransmitContext *tc = cls;
797 struct AddressIterateResponseMessage *msg; 706 struct AddressIterateResponseMessage *msg;
@@ -802,19 +711,23 @@ output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
802 711
803 tlen = strlen (address->transport_name) + 1; 712 tlen = strlen (address->transport_name) + 1;
804 alen = address->address_length; 713 alen = address->address_length;
805
806 size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen); 714 size = (sizeof (struct AddressIterateResponseMessage) + alen + tlen);
807 msg = GNUNET_malloc (size); 715 {
808 msg->addrlen = htonl (alen); 716 char buf[size];
809 msg->pluginlen = htonl (tlen); 717
810 msg->peer = *peer; 718 msg = (struct AddressIterateResponseMessage*) buf;
811 719 msg->reserved = htonl (0);
812 addr = (char *) &msg[1]; 720 msg->peer = *peer;
813 memcpy(addr,address->address, alen); 721 msg->addrlen = htonl (alen);
814 memcpy(&addr[alen], address->transport_name, tlen); 722 msg->pluginlen = htonl (tlen);
815 723 addr = (char *) &msg[1];
816 transmit_binary_to_client (tc, msg, size); 724 memcpy (addr,address->address, alen);
817 GNUNET_free (msg); 725 memcpy (&addr[alen], address->transport_name, tlen);
726 GNUNET_SERVER_transmit_context_append_data (tc,
727 &buf[sizeof(struct GNUNET_MessageHeader)],
728 size - sizeof (struct GNUNET_MessageHeader),
729 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
730 }
818} 731}
819 732
820 733
@@ -831,44 +744,47 @@ static void
831clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, 744clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client,
832 const struct GNUNET_MessageHeader *message) 745 const struct GNUNET_MessageHeader *message)
833{ 746{
747 static struct GNUNET_PeerIdentity all_zeros;
834 struct GNUNET_SERVER_TransmitContext *tc; 748 struct GNUNET_SERVER_TransmitContext *tc;
835 struct AddressIterateMessage * msg; 749 struct AddressIterateMessage * msg;
836 struct GNUNET_PeerIdentity dummy; 750 struct GNUNET_HELLO_Address *address;
837 struct GNUNET_HELLO_Address * address;
838
839
840 GNUNET_SERVER_disable_receive_done_warning (client);
841 tc = GNUNET_SERVER_transmit_context_create (client);
842 751
843 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE) 752 if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
844 { 753 {
845 GNUNET_break_op(0); 754 GNUNET_break (0);
755 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
846 return; 756 return;
847 } 757 }
848 if (ntohs (message->size) != sizeof (struct AddressIterateMessage)) 758 if (ntohs (message->size) != sizeof (struct AddressIterateMessage))
849 { 759 {
850 GNUNET_break_op(0); 760 GNUNET_break (0);
761 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
851 return; 762 return;
852 } 763 }
853
854 msg = (struct AddressIterateMessage *) message; 764 msg = (struct AddressIterateMessage *) message;
855 memset (&dummy, 0, sizeof (struct GNUNET_PeerIdentity)); 765 if (GNUNET_YES != ntohl (msg->one_shot))
856 766 {
857 if (0 == memcmp (&msg->peer, &dummy, sizeof (struct GNUNET_PeerIdentity))) 767 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
768 "Address monitoring not implemented\n");
769 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
770 return;
771 }
772 GNUNET_SERVER_disable_receive_done_warning (client);
773 tc = GNUNET_SERVER_transmit_context_create (client);
774 if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity)))
858 { 775 {
859 /* iterate over all neighbours */ 776 /* iterate over all neighbours */
860 GST_neighbours_iterate (&output_addresses, tc); 777 GST_neighbours_iterate (&output_address, tc);
861 } 778 }
862 else 779 else
863 { 780 {
864 /* just return one neighbour */ 781 /* just return one neighbour */
865 address = GST_neighbour_get_current_address(&msg->peer); 782 address = GST_neighbour_get_current_address(&msg->peer);
866 if (address != NULL) 783 if (address != NULL)
867 output_addresses(tc, &msg->peer, NULL, 0, address); 784 output_address (tc, &msg->peer, NULL, 0, address);
868 } 785 }
869
870 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 786 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
871 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); 787 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
872 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 788 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
873} 789}
874 790
@@ -891,15 +807,8 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server)
891 {&clients_handle_request_connect, NULL, 807 {&clients_handle_request_connect, NULL,
892 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, 808 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
893 sizeof (struct TransportRequestConnectMessage)}, 809 sizeof (struct TransportRequestConnectMessage)},
894 /* converts a binary address to a human readable address */
895 {&clients_handle_address_to_string, NULL, 810 {&clients_handle_address_to_string, NULL,
896 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, 811 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
897#if 0
898 /* Not used at the moment, gets all addresses of a peer */
899 {&clients_handle_peer_address_iterate, NULL,
900 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
901 sizeof (struct PeerAddressLookupMessage)},
902#endif
903 {&clients_handle_address_iterate, NULL, 812 {&clients_handle_address_iterate, NULL,
904 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, 813 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
905 sizeof (struct AddressIterateMessage)}, 814 sizeof (struct AddressIterateMessage)},