diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-07-08 16:47:03 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-07-08 16:47:03 +0000 |
commit | 51204303f98feef6d3f100ac0a344294a091fbe5 (patch) | |
tree | a04e1260d8ce79a0e74120c3cf1716b8dc37d22e /src | |
parent | 893a40187d3343a46294d657a915bdb663c49536 (diff) | |
download | gnunet-51204303f98feef6d3f100ac0a344294a091fbe5.tar.gz gnunet-51204303f98feef6d3f100ac0a344294a091fbe5.zip |
connected peer lookup
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_dht_service.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 32 | ||||
-rw-r--r-- | src/include/gnunet_transport_service.h | 16 | ||||
-rw-r--r-- | src/peerinfo-tool/Makefile.am | 11 | ||||
-rw-r--r-- | src/transport/Makefile.am | 6 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 92 | ||||
-rw-r--r-- | src/transport/transport.h | 20 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 2 |
8 files changed, 173 insertions, 8 deletions
diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index e57dd718c..027986a85 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h | |||
@@ -41,7 +41,7 @@ extern "C" | |||
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * FIXME: document. | 44 | * Default republication frequency for stored data in the DHT. |
45 | */ | 45 | */ |
46 | #define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) | 46 | #define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) |
47 | 47 | ||
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 957bcd0eb..960ec60ab 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -102,7 +102,6 @@ extern "C" | |||
102 | */ | 102 | */ |
103 | #define GNUNET_MESSAGE_TYPE_FRAGMENT 18 | 103 | #define GNUNET_MESSAGE_TYPE_FRAGMENT 18 |
104 | 104 | ||
105 | |||
106 | /** | 105 | /** |
107 | * Message from the core saying that the transport | 106 | * Message from the core saying that the transport |
108 | * server should start giving it messages. This | 107 | * server should start giving it messages. This |
@@ -299,6 +298,11 @@ extern "C" | |||
299 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_KEEPALIVE 58 | 298 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_KEEPALIVE 58 |
300 | 299 | ||
301 | /** | 300 | /** |
301 | * Request to look up addresses of peers. | ||
302 | */ | ||
303 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP 59 | ||
304 | |||
305 | /** | ||
302 | * Welcome message between TCP transports. | 306 | * Welcome message between TCP transports. |
303 | */ | 307 | */ |
304 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME 60 | 308 | #define GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME 60 |
@@ -912,6 +916,10 @@ extern "C" | |||
912 | 916 | ||
913 | 917 | ||
914 | 918 | ||
919 | /******************************************************************************* | ||
920 | * CHAT message types START | ||
921 | ******************************************************************************/ | ||
922 | |||
915 | /** | 923 | /** |
916 | * Message sent from client to join a chat room. | 924 | * Message sent from client to join a chat room. |
917 | */ | 925 | */ |
@@ -977,6 +985,28 @@ extern "C" | |||
977 | */ | 985 | */ |
978 | #define GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT 311 | 986 | #define GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT 311 |
979 | 987 | ||
988 | /******************************************************************************* | ||
989 | * CHAT message types END | ||
990 | ******************************************************************************/ | ||
991 | |||
992 | /******************************************************************************* | ||
993 | * NSE (network size estimation) message types START | ||
994 | ******************************************************************************/ | ||
995 | |||
996 | /** | ||
997 | * client->service message indicating start | ||
998 | */ | ||
999 | #define GNUNET_MESSAGE_TYPE_NSE_START 321 | ||
1000 | |||
1001 | /** | ||
1002 | * P2P message sent from nearest peer | ||
1003 | */ | ||
1004 | #define GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD 322 | ||
1005 | |||
1006 | /** | ||
1007 | * service->client message indicating | ||
1008 | */ | ||
1009 | #define GNUNET_MESSAGE_TYPE_NSE_ESTIMATE 323 | ||
980 | 1010 | ||
981 | /** | 1011 | /** |
982 | * Type used to match 'all' message types. | 1012 | * Type used to match 'all' message types. |
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index 9a7093a10..607389ae7 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h | |||
@@ -645,6 +645,22 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
645 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, | 645 | GNUNET_TRANSPORT_AddressLookUpCallback aluc, |
646 | void *aluc_cls); | 646 | void *aluc_cls); |
647 | 647 | ||
648 | /** | ||
649 | * Return all the known addresses for a peer. | ||
650 | * | ||
651 | * @param cfg configuration to use | ||
652 | * @param peer peer identity to look up the addresses of | ||
653 | * @param timeout how long is the lookup allowed to take at most | ||
654 | * @param peer_address_callback function to call with the results | ||
655 | * @param peer_address_callback_cls closure for peer_address_callback | ||
656 | */ | ||
657 | void | ||
658 | GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
659 | const struct GNUNET_PeerIdentity *peer, | ||
660 | struct GNUNET_TIME_Relative timeout, | ||
661 | GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, | ||
662 | void *peer_address_callback_cls); | ||
663 | |||
648 | 664 | ||
649 | 665 | ||
650 | /** | 666 | /** |
diff --git a/src/peerinfo-tool/Makefile.am b/src/peerinfo-tool/Makefile.am index 8c5fd8fbb..a11c500df 100644 --- a/src/peerinfo-tool/Makefile.am +++ b/src/peerinfo-tool/Makefile.am | |||
@@ -10,7 +10,16 @@ if USE_COVERAGE | |||
10 | endif | 10 | endif |
11 | 11 | ||
12 | bin_PROGRAMS = \ | 12 | bin_PROGRAMS = \ |
13 | gnunet-peerinfo | 13 | gnunet-peerinfo \ |
14 | gnunet-list-connections | ||
15 | |||
16 | gnunet_list_connections_SOURCES = \ | ||
17 | gnunet-list-connections.c | ||
18 | gnunet_list_connections_LDADD = \ | ||
19 | $(top_builddir)/src/core/libgnunetcore.la \ | ||
20 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
21 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
22 | $(top_builddir)/src/util/libgnunetutil.la | ||
14 | 23 | ||
15 | gnunet_peerinfo_SOURCES = \ | 24 | gnunet_peerinfo_SOURCES = \ |
16 | gnunet-peerinfo.c | 25 | gnunet-peerinfo.c |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 96c25b15e..72612e5bb 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -59,7 +59,8 @@ lib_LTLIBRARIES = \ | |||
59 | libgnunettransportnew_la_SOURCES = \ | 59 | libgnunettransportnew_la_SOURCES = \ |
60 | transport_api_new.c transport.h \ | 60 | transport_api_new.c transport.h \ |
61 | transport_api_blacklist.c \ | 61 | transport_api_blacklist.c \ |
62 | transport_api_address_lookup.c | 62 | transport_api_address_lookup.c \ |
63 | transport_api_peer_address_lookup.c | ||
63 | libgnunettransportnew_la_LIBADD = \ | 64 | libgnunettransportnew_la_LIBADD = \ |
64 | $(top_builddir)/src/hello/libgnunethello.la \ | 65 | $(top_builddir)/src/hello/libgnunethello.la \ |
65 | $(top_builddir)/src/util/libgnunetutil.la \ | 66 | $(top_builddir)/src/util/libgnunetutil.la \ |
@@ -71,7 +72,8 @@ libgnunettransportnew_la_LDFLAGS = \ | |||
71 | libgnunettransport_la_SOURCES = \ | 72 | libgnunettransport_la_SOURCES = \ |
72 | transport_api.c transport.h \ | 73 | transport_api.c transport.h \ |
73 | transport_api_blacklist.c \ | 74 | transport_api_blacklist.c \ |
74 | transport_api_address_lookup.c | 75 | transport_api_address_lookup.c \ |
76 | transport_api_peer_address_lookup.c | ||
75 | libgnunettransport_la_LIBADD = \ | 77 | libgnunettransport_la_LIBADD = \ |
76 | $(top_builddir)/src/hello/libgnunethello.la \ | 78 | $(top_builddir)/src/hello/libgnunethello.la \ |
77 | $(top_builddir)/src/util/libgnunetutil.la \ | 79 | $(top_builddir)/src/util/libgnunetutil.la \ |
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index fdd86ac3e..4c4e848a8 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -287,7 +287,6 @@ struct OwnAddressList | |||
287 | */ | 287 | */ |
288 | struct TransportPlugin | 288 | struct TransportPlugin |
289 | { | 289 | { |
290 | |||
291 | /** | 290 | /** |
292 | * This is a linked list. | 291 | * This is a linked list. |
293 | */ | 292 | */ |
@@ -1671,7 +1670,7 @@ try_transmission_to_peer (struct NeighbourList *n) | |||
1671 | force_address = GNUNET_YES; | 1670 | force_address = GNUNET_YES; |
1672 | if (mq->specific_address == NULL) | 1671 | if (mq->specific_address == NULL) |
1673 | { | 1672 | { |
1674 | /* TODO: ADD ATS */ | 1673 | /* TODO: ADD ATS */ |
1675 | mq->specific_address = get_preferred_ats_address(n); | 1674 | mq->specific_address = get_preferred_ats_address(n); |
1676 | GNUNET_STATISTICS_update (stats, | 1675 | GNUNET_STATISTICS_update (stats, |
1677 | gettext_noop ("# transport selected peer address freely"), | 1676 | gettext_noop ("# transport selected peer address freely"), |
@@ -5824,6 +5823,92 @@ handle_address_lookup (void *cls, | |||
5824 | &transmit_address_to_client, tc); | 5823 | &transmit_address_to_client, tc); |
5825 | } | 5824 | } |
5826 | 5825 | ||
5826 | /** | ||
5827 | * Handle AddressLookup-message. | ||
5828 | * | ||
5829 | * @param cls closure (always NULL) | ||
5830 | * @param client identification of the client | ||
5831 | * @param message the actual message | ||
5832 | */ | ||
5833 | static void | ||
5834 | handle_peer_address_lookup (void *cls, | ||
5835 | struct GNUNET_SERVER_Client *client, | ||
5836 | const struct GNUNET_MessageHeader *message) | ||
5837 | { | ||
5838 | const struct PeerAddressLookupMessage *peer_address_lookup; | ||
5839 | struct NeighbourList *neighbor_iterator; | ||
5840 | struct ReadyList *ready_iterator; | ||
5841 | struct ForeignAddressList *foreign_address_iterator; | ||
5842 | struct TransportPlugin *transport_plugin; | ||
5843 | |||
5844 | uint16_t size; | ||
5845 | struct GNUNET_SERVER_TransmitContext *tc; | ||
5846 | struct GNUNET_TIME_Absolute timeout; | ||
5847 | struct GNUNET_TIME_Relative rtimeout; | ||
5848 | char *addr_buf; | ||
5849 | |||
5850 | size = ntohs (message->size); | ||
5851 | if (size < sizeof (struct PeerAddressLookupMessage)) | ||
5852 | { | ||
5853 | GNUNET_break_op (0); | ||
5854 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
5855 | return; | ||
5856 | } | ||
5857 | peer_address_lookup = (const struct PeerAddressLookupMessage *) message; | ||
5858 | |||
5859 | timeout = GNUNET_TIME_absolute_ntoh (peer_address_lookup->timeout); | ||
5860 | rtimeout = GNUNET_TIME_absolute_get_remaining (timeout); | ||
5861 | |||
5862 | neighbor_iterator = neighbours; | ||
5863 | while (neighbor_iterator != NULL) | ||
5864 | { | ||
5865 | if (0 == memcmp(&neighbor_iterator->id, &peer_address_lookup->peer, sizeof(struct GNUNET_PeerIdentity))) | ||
5866 | break; | ||
5867 | neighbor_iterator = neighbor_iterator->next; | ||
5868 | } | ||
5869 | |||
5870 | /* Found no neighbor matching this peer id (shouldn't be possible, but...) */ | ||
5871 | if (neighbor_iterator == NULL) | ||
5872 | { | ||
5873 | GNUNET_break(0); | ||
5874 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
5875 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
5876 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
5877 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); | ||
5878 | return; | ||
5879 | } | ||
5880 | |||
5881 | ready_iterator = neighbor_iterator->plugins; | ||
5882 | GNUNET_SERVER_disable_receive_done_warning (client); | ||
5883 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
5884 | while(ready_iterator != NULL) | ||
5885 | { | ||
5886 | foreign_address_iterator = ready_iterator->addresses; | ||
5887 | while (foreign_address_iterator != NULL) | ||
5888 | { | ||
5889 | transport_plugin = foreign_address_iterator->ready_list->plugin; | ||
5890 | if (foreign_address_iterator->addr != NULL) | ||
5891 | { | ||
5892 | GNUNET_asprintf (&addr_buf, "%s --- %s", | ||
5893 | a2s (transport_plugin->short_name, | ||
5894 | foreign_address_iterator->addr, | ||
5895 | foreign_address_iterator->addrlen), | ||
5896 | (foreign_address_iterator->connected | ||
5897 | == GNUNET_YES) ? "CONNECTED" | ||
5898 | : "DISCONNECTED"); | ||
5899 | transmit_address_to_client(tc, addr_buf); | ||
5900 | GNUNET_free(addr_buf); | ||
5901 | } | ||
5902 | |||
5903 | foreign_address_iterator = foreign_address_iterator->next; | ||
5904 | } | ||
5905 | ready_iterator = ready_iterator->next; | ||
5906 | } | ||
5907 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
5908 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
5909 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
5910 | } | ||
5911 | |||
5827 | 5912 | ||
5828 | /** | 5913 | /** |
5829 | * Setup the environment for this plugin. | 5914 | * Setup the environment for this plugin. |
@@ -6265,6 +6350,9 @@ run (void *cls, | |||
6265 | {&handle_address_lookup, NULL, | 6350 | {&handle_address_lookup, NULL, |
6266 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, | 6351 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, |
6267 | 0}, | 6352 | 0}, |
6353 | {&handle_peer_address_lookup, NULL, | ||
6354 | GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, | ||
6355 | 0}, | ||
6268 | {&handle_blacklist_init, NULL, | 6356 | {&handle_blacklist_init, NULL, |
6269 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, | 6357 | GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, |
6270 | {&handle_blacklist_reply, NULL, | 6358 | {&handle_blacklist_reply, NULL, |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 73ebe6820..133eb6887 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -312,7 +312,27 @@ struct AddressLookupMessage | |||
312 | followed by the 0-terminated name of the transport */ | 312 | followed by the 0-terminated name of the transport */ |
313 | }; | 313 | }; |
314 | 314 | ||
315 | /** | ||
316 | * Message from the library to the transport service | ||
317 | * asking for human readable addresses known for a peer. | ||
318 | */ | ||
319 | struct PeerAddressLookupMessage | ||
320 | { | ||
321 | /** | ||
322 | * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP | ||
323 | */ | ||
324 | struct GNUNET_MessageHeader header; | ||
325 | |||
326 | /** | ||
327 | * timeout to give up. | ||
328 | */ | ||
329 | struct GNUNET_TIME_AbsoluteNBO timeout; | ||
315 | 330 | ||
331 | /** | ||
332 | * The identity of the peer to look up. | ||
333 | */ | ||
334 | struct GNUNET_PeerIdentity peer; | ||
335 | }; | ||
316 | 336 | ||
317 | /** | 337 | /** |
318 | * Change in blacklisting (either request or notification, | 338 | * Change in blacklisting (either request or notification, |
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index 022d5f03b..c6244c28f 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -119,7 +119,7 @@ address_response_processor (void *cls, | |||
119 | * @param aluc_cls closure for aluc | 119 | * @param aluc_cls closure for aluc |
120 | */ | 120 | */ |
121 | void | 121 | void |
122 | GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 122 | GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, |
123 | const char *address, | 123 | const char *address, |
124 | size_t addressLen, | 124 | size_t addressLen, |
125 | int numeric, | 125 | int numeric, |