diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 102 |
1 files changed, 68 insertions, 34 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 7c4a9d712..6bd3e34d5 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -468,16 +468,21 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) | |||
468 | */ | 468 | */ |
469 | static void | 469 | static void |
470 | notify_client_about_neighbour (void *cls, | 470 | notify_client_about_neighbour (void *cls, |
471 | const struct GNUNET_PeerIdentity *peer, | 471 | const struct GNUNET_PeerIdentity *peer, |
472 | const struct GNUNET_HELLO_Address *address, | 472 | const struct GNUNET_HELLO_Address *address, |
473 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 473 | enum GNUNET_TRANSPORT_PeerState state, |
474 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 474 | struct GNUNET_TIME_Absolute state_timeout, |
475 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
476 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | ||
475 | { | 477 | { |
476 | struct TransportClient *tc = cls; | 478 | struct TransportClient *tc = cls; |
477 | struct ConnectInfoMessage *cim; | 479 | struct ConnectInfoMessage *cim; |
478 | size_t size = sizeof (struct ConnectInfoMessage); | 480 | size_t size = sizeof (struct ConnectInfoMessage); |
479 | char buf[size] GNUNET_ALIGN; | 481 | char buf[size] GNUNET_ALIGN; |
480 | 482 | ||
483 | if (GNUNET_NO == GST_neighbours_test_connected (peer)) | ||
484 | return; | ||
485 | |||
481 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 486 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
482 | cim = (struct ConnectInfoMessage *) buf; | 487 | cim = (struct ConnectInfoMessage *) buf; |
483 | cim->header.size = htons (size); | 488 | cim->header.size = htons (size); |
@@ -873,7 +878,7 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer | |||
873 | msg = GNUNET_malloc (size); | 878 | msg = GNUNET_malloc (size); |
874 | msg->header.size = htons (size); | 879 | msg->header.size = htons (size); |
875 | msg->header.type = | 880 | msg->header.type = |
876 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); | 881 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); |
877 | msg->reserved = htonl (0); | 882 | msg->reserved = htonl (0); |
878 | msg->peer = *peer; | 883 | msg->peer = *peer; |
879 | msg->addrlen = htonl (alen); | 884 | msg->addrlen = htonl (alen); |
@@ -888,33 +893,55 @@ compose_address_iterate_response_message (const struct GNUNET_PeerIdentity *peer | |||
888 | } | 893 | } |
889 | 894 | ||
890 | 895 | ||
896 | struct PeerIterationContext | ||
897 | { | ||
898 | struct GNUNET_SERVER_TransmitContext *tc; | ||
899 | |||
900 | struct GNUNET_PeerIdentity id; | ||
901 | |||
902 | int all; | ||
903 | }; | ||
904 | |||
891 | /** | 905 | /** |
892 | * Output the active address of connected neighbours to the given client. | 906 | * Output information of neighbours to the given client. |
893 | * | 907 | * |
894 | * @param cls the 'struct GNUNET_SERVER_TransmitContext' for transmission to the client | 908 | * @param cls the 'struct PeerIterationContext' |
895 | * @param peer identity of the neighbour | 909 | * @param peer identity of the neighbour |
896 | * @param address the address | 910 | * @param address the address |
897 | * @param bandwidth_in inbound quota in NBO | 911 | * @param bandwidth_in inbound quota in NBO |
898 | * @param bandwidth_out outbound quota in NBO | 912 | * @param bandwidth_out outbound quota in NBO |
899 | */ | 913 | */ |
900 | static void | 914 | static void |
901 | output_address (void *cls, const struct GNUNET_PeerIdentity *peer, | 915 | send_peer_information (void *cls, |
902 | const struct GNUNET_HELLO_Address *address, | 916 | const struct GNUNET_PeerIdentity *peer, |
903 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 917 | const struct GNUNET_HELLO_Address *address, |
904 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | 918 | enum GNUNET_TRANSPORT_PeerState state, |
919 | struct GNUNET_TIME_Absolute state_timeout, | ||
920 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
921 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) | ||
905 | { | 922 | { |
906 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 923 | struct PeerIterationContext *pc = cls; |
907 | struct PeerIterateResponseMessage *msg; | 924 | struct PeerIterateResponseMessage *msg; |
908 | 925 | ||
909 | msg = compose_address_iterate_response_message (peer, address); | 926 | if ( (GNUNET_YES == pc->all) || |
910 | GNUNET_SERVER_transmit_context_append_message (tc, &msg->header); | 927 | (0 == memcmp (peer, &pc->id, sizeof (pc->id))) ) |
911 | GNUNET_free (msg); | 928 | { |
929 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
930 | "Sending information about `%s' using address `%s' in state `%s'\n", | ||
931 | GNUNET_i2s(peer), address); | ||
932 | msg = compose_address_iterate_response_message (peer, address); | ||
933 | msg->state = htonl (state); | ||
934 | msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout); | ||
935 | GNUNET_SERVER_transmit_context_append_message (pc->tc, &msg->header); | ||
936 | GNUNET_free (msg); | ||
937 | } | ||
912 | } | 938 | } |
913 | 939 | ||
914 | 940 | ||
941 | |||
942 | |||
915 | /** | 943 | /** |
916 | * Client asked to obtain information about all actively used addresses | 944 | * Client asked to obtain information about a specific or all peers |
917 | * of connected peers | ||
918 | * Process the request. | 945 | * Process the request. |
919 | * | 946 | * |
920 | * @param cls unused | 947 | * @param cls unused |
@@ -922,27 +949,27 @@ output_address (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
922 | * @param message the peer address information request | 949 | * @param message the peer address information request |
923 | */ | 950 | */ |
924 | static void | 951 | static void |
925 | clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, | 952 | clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, |
926 | const struct GNUNET_MessageHeader *message) | 953 | const struct GNUNET_MessageHeader *message) |
927 | { | 954 | { |
928 | static struct GNUNET_PeerIdentity all_zeros; | 955 | static struct GNUNET_PeerIdentity all_zeros; |
929 | struct GNUNET_SERVER_TransmitContext *tc; | 956 | struct GNUNET_SERVER_TransmitContext *tc; |
930 | struct PeerIterateMessage *msg; | 957 | struct PeerMonitorMessage *msg; |
931 | struct GNUNET_HELLO_Address *address; | 958 | struct PeerIterationContext pc; |
932 | 959 | ||
933 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE) | 960 | if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST) |
934 | { | 961 | { |
935 | GNUNET_break (0); | 962 | GNUNET_break (0); |
936 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 963 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
937 | return; | 964 | return; |
938 | } | 965 | } |
939 | if (ntohs (message->size) != sizeof (struct PeerIterateMessage)) | 966 | if (ntohs (message->size) != sizeof (struct PeerMonitorMessage)) |
940 | { | 967 | { |
941 | GNUNET_break (0); | 968 | GNUNET_break (0); |
942 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 969 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
943 | return; | 970 | return; |
944 | } | 971 | } |
945 | msg = (struct PeerIterateMessage *) message; | 972 | msg = (struct PeerMonitorMessage *) message; |
946 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && | 973 | if ( (GNUNET_YES != ntohl (msg->one_shot)) && |
947 | (NULL != lookup_monitoring_client (client)) ) | 974 | (NULL != lookup_monitoring_client (client)) ) |
948 | { | 975 | { |
@@ -954,26 +981,33 @@ clients_handle_address_iterate (void *cls, struct GNUNET_SERVER_Client *client, | |||
954 | return; | 981 | return; |
955 | } | 982 | } |
956 | GNUNET_SERVER_disable_receive_done_warning (client); | 983 | GNUNET_SERVER_disable_receive_done_warning (client); |
957 | tc = GNUNET_SERVER_transmit_context_create (client); | 984 | pc.tc = tc = GNUNET_SERVER_transmit_context_create (client); |
985 | |||
986 | /* Send initial list */ | ||
958 | if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) | 987 | if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) |
959 | { | 988 | { |
960 | /* iterate over all neighbours */ | 989 | /* iterate over all neighbours */ |
961 | GST_neighbours_iterate (&output_address, tc); | 990 | pc.all = GNUNET_YES; |
991 | pc.id = msg->peer; | ||
962 | } | 992 | } |
963 | else | 993 | else |
964 | { | 994 | { |
965 | /* just return one neighbour */ | 995 | /* just return one neighbour */ |
966 | address = GST_neighbour_get_current_address (&msg->peer); | 996 | pc.all = GNUNET_NO; |
967 | if (address != NULL) | 997 | pc.id = msg->peer; |
968 | output_address (tc, &msg->peer, address, | ||
969 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | ||
970 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT); | ||
971 | } | 998 | } |
999 | GST_neighbours_iterate (&send_peer_information, &pc); | ||
1000 | |||
972 | if (GNUNET_YES != ntohl (msg->one_shot)) | 1001 | if (GNUNET_YES != ntohl (msg->one_shot)) |
1002 | { | ||
973 | setup_monitoring_client (client, &msg->peer); | 1003 | setup_monitoring_client (client, &msg->peer); |
1004 | } | ||
974 | else | 1005 | else |
1006 | { | ||
975 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | 1007 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
976 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE); | 1008 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); |
1009 | } | ||
1010 | |||
977 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 1011 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
978 | } | 1012 | } |
979 | 1013 | ||
@@ -998,9 +1032,9 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
998 | sizeof (struct TransportRequestConnectMessage)}, | 1032 | sizeof (struct TransportRequestConnectMessage)}, |
999 | {&clients_handle_address_to_string, NULL, | 1033 | {&clients_handle_address_to_string, NULL, |
1000 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, | 1034 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0}, |
1001 | {&clients_handle_address_iterate, NULL, | 1035 | {&clients_handle_monitor_peers, NULL, |
1002 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, | 1036 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, |
1003 | sizeof (struct PeerIterateMessage)}, | 1037 | sizeof (struct PeerMonitorMessage)}, |
1004 | {&GST_blacklist_handle_init, NULL, | 1038 | {&GST_blacklist_handle_init, NULL, |
1005 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, | 1039 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, |
1006 | sizeof (struct GNUNET_MessageHeader)}, | 1040 | sizeof (struct GNUNET_MessageHeader)}, |