From: Nathan S. Evans Date: Fri, 8 Jul 2011 16:47:03 +0000 (+0000) Subject: connected peer lookup X-Git-Tag: initial-import-from-subversion-38251~17931 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=51204303f98feef6d3f100ac0a344294a091fbe5;p=oweals%2Fgnunet.git connected peer lookup --- 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" /** - * FIXME: document. + * Default republication frequency for stored data in the DHT. */ #define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) 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" */ #define GNUNET_MESSAGE_TYPE_FRAGMENT 18 - /** * Message from the core saying that the transport * server should start giving it messages. This @@ -298,6 +297,11 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_NAT_PROBE_KEEPALIVE 58 +/** + * Request to look up addresses of peers. + */ +#define GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP 59 + /** * Welcome message between TCP transports. */ @@ -912,6 +916,10 @@ extern "C" +/******************************************************************************* + * CHAT message types START + ******************************************************************************/ + /** * Message sent from client to join a chat room. */ @@ -977,6 +985,28 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_CHAT_P2P_CONFIRMATION_RECEIPT 311 +/******************************************************************************* + * CHAT message types END + ******************************************************************************/ + +/******************************************************************************* + * NSE (network size estimation) message types START + ******************************************************************************/ + +/** + * client->service message indicating start + */ +#define GNUNET_MESSAGE_TYPE_NSE_START 321 + +/** + * P2P message sent from nearest peer + */ +#define GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD 322 + +/** + * service->client message indicating + */ +#define GNUNET_MESSAGE_TYPE_NSE_ESTIMATE 323 /** * 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, GNUNET_TRANSPORT_AddressLookUpCallback aluc, void *aluc_cls); +/** + * Return all the known addresses for a peer. + * + * @param cfg configuration to use + * @param peer peer identity to look up the addresses of + * @param timeout how long is the lookup allowed to take at most + * @param peer_address_callback function to call with the results + * @param peer_address_callback_cls closure for peer_address_callback + */ +void +GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_TIME_Relative timeout, + GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, + void *peer_address_callback_cls); + /** 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 endif bin_PROGRAMS = \ - gnunet-peerinfo + gnunet-peerinfo \ + gnunet-list-connections + +gnunet_list_connections_SOURCES = \ + gnunet-list-connections.c +gnunet_list_connections_LDADD = \ + $(top_builddir)/src/core/libgnunetcore.la \ + $(top_builddir)/src/transport/libgnunettransport.la \ + $(top_builddir)/src/hello/libgnunethello.la \ + $(top_builddir)/src/util/libgnunetutil.la gnunet_peerinfo_SOURCES = \ 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 = \ libgnunettransportnew_la_SOURCES = \ transport_api_new.c transport.h \ transport_api_blacklist.c \ - transport_api_address_lookup.c + transport_api_address_lookup.c \ + transport_api_peer_address_lookup.c libgnunettransportnew_la_LIBADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(top_builddir)/src/util/libgnunetutil.la \ @@ -71,7 +72,8 @@ libgnunettransportnew_la_LDFLAGS = \ libgnunettransport_la_SOURCES = \ transport_api.c transport.h \ transport_api_blacklist.c \ - transport_api_address_lookup.c + transport_api_address_lookup.c \ + transport_api_peer_address_lookup.c libgnunettransport_la_LIBADD = \ $(top_builddir)/src/hello/libgnunethello.la \ $(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 */ struct TransportPlugin { - /** * This is a linked list. */ @@ -1671,7 +1670,7 @@ try_transmission_to_peer (struct NeighbourList *n) force_address = GNUNET_YES; if (mq->specific_address == NULL) { - /* TODO: ADD ATS */ + /* TODO: ADD ATS */ mq->specific_address = get_preferred_ats_address(n); GNUNET_STATISTICS_update (stats, gettext_noop ("# transport selected peer address freely"), @@ -5824,6 +5823,92 @@ handle_address_lookup (void *cls, &transmit_address_to_client, tc); } +/** + * Handle AddressLookup-message. + * + * @param cls closure (always NULL) + * @param client identification of the client + * @param message the actual message + */ +static void +handle_peer_address_lookup (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct PeerAddressLookupMessage *peer_address_lookup; + struct NeighbourList *neighbor_iterator; + struct ReadyList *ready_iterator; + struct ForeignAddressList *foreign_address_iterator; + struct TransportPlugin *transport_plugin; + + uint16_t size; + struct GNUNET_SERVER_TransmitContext *tc; + struct GNUNET_TIME_Absolute timeout; + struct GNUNET_TIME_Relative rtimeout; + char *addr_buf; + + size = ntohs (message->size); + if (size < sizeof (struct PeerAddressLookupMessage)) + { + GNUNET_break_op (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + peer_address_lookup = (const struct PeerAddressLookupMessage *) message; + + timeout = GNUNET_TIME_absolute_ntoh (peer_address_lookup->timeout); + rtimeout = GNUNET_TIME_absolute_get_remaining (timeout); + + neighbor_iterator = neighbours; + while (neighbor_iterator != NULL) + { + if (0 == memcmp(&neighbor_iterator->id, &peer_address_lookup->peer, sizeof(struct GNUNET_PeerIdentity))) + break; + neighbor_iterator = neighbor_iterator->next; + } + + /* Found no neighbor matching this peer id (shouldn't be possible, but...) */ + if (neighbor_iterator == NULL) + { + GNUNET_break(0); + tc = GNUNET_SERVER_transmit_context_create (client); + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); + GNUNET_SERVER_transmit_context_run (tc, rtimeout); + return; + } + + ready_iterator = neighbor_iterator->plugins; + GNUNET_SERVER_disable_receive_done_warning (client); + tc = GNUNET_SERVER_transmit_context_create (client); + while(ready_iterator != NULL) + { + foreign_address_iterator = ready_iterator->addresses; + while (foreign_address_iterator != NULL) + { + transport_plugin = foreign_address_iterator->ready_list->plugin; + if (foreign_address_iterator->addr != NULL) + { + GNUNET_asprintf (&addr_buf, "%s --- %s", + a2s (transport_plugin->short_name, + foreign_address_iterator->addr, + foreign_address_iterator->addrlen), + (foreign_address_iterator->connected + == GNUNET_YES) ? "CONNECTED" + : "DISCONNECTED"); + transmit_address_to_client(tc, addr_buf); + GNUNET_free(addr_buf); + } + + foreign_address_iterator = foreign_address_iterator->next; + } + ready_iterator = ready_iterator->next; + } + GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, + GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); + GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); +} + /** * Setup the environment for this plugin. @@ -6265,6 +6350,9 @@ run (void *cls, {&handle_address_lookup, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0}, + {&handle_peer_address_lookup, NULL, + GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, + 0}, {&handle_blacklist_init, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, {&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 followed by the 0-terminated name of the transport */ }; +/** + * Message from the library to the transport service + * asking for human readable addresses known for a peer. + */ +struct PeerAddressLookupMessage +{ + /** + * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP + */ + struct GNUNET_MessageHeader header; + + /** + * timeout to give up. + */ + struct GNUNET_TIME_AbsoluteNBO timeout; + /** + * The identity of the peer to look up. + */ + struct GNUNET_PeerIdentity peer; +}; /** * 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, * @param aluc_cls closure for aluc */ void -GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, +GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *address, size_t addressLen, int numeric,