process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address)
{
struct PrintContext *pc = cls;
- struct AddressStringList *new_address;
+// struct AddressStringList *new_address;
if (address == NULL)
{
return;
}
+ /* This does exactly the same as gnunet-transport -i !*/
+ /*
new_address = GNUNET_malloc (sizeof (struct AddressStringList));
#if VERBOSE
fprintf (stderr, "Received address %s\n", address);
#endif
- // FIXME : GNUNET_TRANSPORT_address_to_string
+
new_address->address_string = GNUNET_strdup ("FIXME");
GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail,
new_address);
+ */
}
* @param address address
*/
// FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
-typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
+typedef void (*GNUNET_TRANSPORT_PeerIterateCallback) (void *cls,
const struct GNUNET_HELLO_Address *address);
* @param peer_address_callback function to call with the results
* @param peer_address_callback_cls closure for peer_address_callback
*/
-struct GNUNET_TRANSPORT_PeerAddressLookupContext *
+struct GNUNET_TRANSPORT_PeerIterateContext *
GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_PeerIdentity *peer,
int one_shot,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
+ GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback,
void *peer_address_callback_cls);
*/
void
GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
- GNUNET_TRANSPORT_PeerAddressLookupContext
+ GNUNET_TRANSPORT_PeerIterateContext
*alc);
/**
- * Return all the known addresses. FIXME: document better!
- *
- * FIXME: remove, replace with new 'peer_address_lookup' API
- *
- *
+ * Return all the known addresses.
* @param cfg configuration to use
* @param timeout how long is the lookup allowed to take at most
* @param peer_address_callback function to call with the results
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
+ GNUNET_TRANSPORT_PeerIterateCallback
peer_address_callback,
void *peer_address_callback_cls);
transmit_address_to_client (void *cls, const char *buf)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
-
if (NULL == buf)
{
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
tc);
}
+#if 0
+
+THIS FUNCTIONALITY IS NOT USED ANYWHERE!
/**
* Send an address to the client.
/**
- * Client asked to obtain information about a peer's addresses.
+ * Client asked to obtain information about all addresses of a peer.
* Process the request.
- * FIXME: use better name!
*
* @param cls unused
* @param client the client
* @param message the peer address information request
*/
static void
-clients_handle_peer_address_lookup (void *cls,
+clients_handle_peer_address_iterate (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
tc = GNUNET_SERVER_transmit_context_create (client);
+
GST_validation_get_addresses (&peer_address_lookup->peer,
&send_address_to_client, tc);
+
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
}
-
+#endif
/**
* Output the active address of connected neighbours to the given client.
memcpy(&addr[alen], address->transport_name, tlen);
transmit_binary_to_client (tc, msg, size);
-
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "output_addresses: peer `%s' transport %s address %s %s\n",GNUNET_i2s(&msg->peer), &addr[alen], GNUNET_a2s((struct sockaddr *) addr, alen), GNUNET_a2s((struct sockaddr *) address->address, address->address_length));
GNUNET_free (msg);
}
/**
- * Client asked to obtain information about all actively used addresses.
- * Process the request. FIXME: use better name!
+ * Client asked to obtain information about all actively used addresses
+ * of connected peers
+ * Process the request.
*
* @param cls unused
* @param client the client
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_SERVER_TransmitContext *tc;
+ struct AddressIterateMessage * msg;
+ struct GNUNET_PeerIdentity dummy;
+ struct GNUNET_HELLO_Address * address;
+
GNUNET_SERVER_disable_receive_done_warning (client);
tc = GNUNET_SERVER_transmit_context_create (client);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "clients_handle_address_iterate: \n");
- GST_neighbours_iterate (&output_addresses, tc);
+
+ if (ntohs (message->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE)
+ {
+ GNUNET_break_op(0);
+ return;
+ }
+ if (ntohs (message->size) != sizeof (struct AddressIterateMessage))
+ {
+ GNUNET_break_op(0);
+ return;
+ }
+
+ msg = (struct AddressIterateMessage *) message;
+ memset (&dummy, 0, sizeof (struct GNUNET_PeerIdentity));
+
+ if (0 == memcmp (&msg->peer, &dummy, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* iterate over all neighbours */
+ GST_neighbours_iterate (&output_addresses, tc);
+ }
+ else
+ {
+ /* just return one neighbour */
+ address = GST_neighbour_get_current_address(&msg->peer);
+ if (address != NULL)
+ output_addresses(tc, &msg->peer, NULL, 0, address);
+ }
+
GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
{&clients_handle_request_connect, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
sizeof (struct TransportRequestConnectMessage)},
+ /* converts a binary address to a human readable address */
{&clients_handle_address_to_string, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 0},
- {&clients_handle_peer_address_lookup, NULL,
+#if 0
+ /* Not used at the moment, gets all addresses of a peer */
+ {&clients_handle_peer_address_iterate, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
sizeof (struct PeerAddressLookupMessage)},
- {&clients_handle_address_iterate, NULL,
+#endif
+ {&clients_handle_address_iterate, NULL,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
sizeof (struct AddressIterateMessage)},
{&GST_blacklist_handle_init, NULL,
return n->latency;
}
+/**
+ * Obtain current address information for the given neighbour.
+ *
+ * @param peer
+ * @return address currently used
+ */
+struct GNUNET_HELLO_Address *
+GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
+{
+ struct NeighbourMapEntry *n;
+
+ n = lookup_neighbour (peer);
+ if ( (NULL == n) ||
+ ( (n->address == NULL) && (n->session == NULL) ) )
+ return NULL;
+
+ return n->address;
+}
+
+
/**
* Create an entry in the neighbour map for the given peer
GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer);
+/**
+ * Obtain current address information for the given neighbour.
+ *
+ * @param peer
+ * @return address currently used
+ */
+struct GNUNET_HELLO_Address *
+GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
+
+
/**
* We received a disconnect message from the given peer,
* validate and process.
*/
static int test_configuration;
+/**
+ * Option -n.
+ */
+static int numeric;
+
/**
* Global return value (0 success).
*/
};
-struct GNUNET_CONFIGURATION_Handle * cfg;
/**
* Display the result of the test.
void process_string (void *cls,
const char *address)
{
- fprintf (stdout, _("process_string\n"));
+ struct GNUNET_PeerIdentity * peer = cls;
+
+ if ((address != NULL))
+ {
+ fprintf (stdout, _("Peer `%s' : %s\n"), GNUNET_i2s(peer), address);
+ }
+ else
+ {
+ /* done */
+ GNUNET_free (peer);
+ }
}
/**
static void
process_address (void *cls, const struct GNUNET_HELLO_Address *address)
{
+ const struct GNUNET_CONFIGURATION_Handle * cfg = cls;
+
if (address == NULL)
{
+ /* done */
return;
}
- fprintf (stdout, _("Peer `%s'\n"),
- GNUNET_i2s (&address->peer));
+ struct GNUNET_PeerIdentity * peer = GNUNET_malloc(sizeof (struct GNUNET_PeerIdentity));
+ *peer = address->peer;
/* Resolve address to string */
- /*
GNUNET_TRANSPORT_address_to_string (cfg,
- address,
- GNUNET_NO,
- GNUNET_TIME_UNIT_MINUTES,
- &process_string,
- NULL);
- */
+ address,
+ numeric,
+ GNUNET_TIME_UNIT_MINUTES,
+ &process_string,
+ peer);
}
run (void *cls, char *const *args, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- cfg = cfg;
if (test_configuration)
{
do_test_configuration (cfg);
if (iterate_connections)
{
GNUNET_TRANSPORT_address_iterate (cfg, GNUNET_TIME_UNIT_MINUTES,
- &process_address, NULL);
+ &process_address, (void *)cfg);
}
}
{'t', "test", NULL,
gettext_noop ("test transport configuration (involves external server)"),
0, &GNUNET_GETOPT_set_one, &test_configuration},
+ {'n', "numeric", NULL,
+ gettext_noop ("do not resolve hostnames"),
+ 0, &GNUNET_GETOPT_set_one, &numeric},
GNUNET_GETOPT_OPTION_VERBOSE (&verbosity),
GNUNET_GETOPT_OPTION_END
};
# BINDTO =
# REJECT_FROM =
# REJECT_FROM6 =
-# PREFIX =
+PREFIX = valgrind --leak-check=full
+
[transport-tcp]
# Use 0 to ONLY advertise as a peer behind NAT (no port binding)
/**
* Context for the address lookup.
*/
-struct GNUNET_TRANSPORT_PeerAddressLookupContext
+struct GNUNET_TRANSPORT_PeerIterateContext
{
/**
- * Function to call with the human-readable address.
+ * Function to call with the binary address.
*/
- GNUNET_TRANSPORT_AddressLookUpCallback cb;
+ GNUNET_TRANSPORT_PeerIterateCallback cb;
/**
* Closure for cb.
peer_address_response_processor (void *cls,
const struct GNUNET_MessageHeader *msg)
{
- struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx = cls;
- struct AddressIterateResponseMessage *air_msg = (struct AddressIterateResponseMessage *) &msg[1];
- const struct GNUNET_HELLO_Address *address;
+ struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx = cls;
+ struct AddressIterateResponseMessage *air_msg;
+ struct GNUNET_HELLO_Address *address;
uint16_t size;
- if (air_msg == NULL)
+
+ if (msg == NULL)
{
pal_ctx->cb (pal_ctx->cb_cls, NULL);
GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
return;
}
+ if (size < sizeof (struct GNUNET_MessageHeader) + sizeof (struct AddressIterateResponseMessage))
+ {
+ GNUNET_break_op (0);
+ pal_ctx->cb (pal_ctx->cb_cls, NULL );
+ GNUNET_CLIENT_disconnect (pal_ctx->client, GNUNET_NO);
+ GNUNET_free (pal_ctx);
+ return;
+ }
+
+ air_msg = (struct AddressIterateResponseMessage *) &msg[1];
size_t tlen = ntohl(air_msg->pluginlen);
size_t alen = ntohl(air_msg->addrlen);
char * addr = (char *) &air_msg[1];
char * transport_name = &addr[alen];
- if (transport_name[tlen] != '\0')
+ if (transport_name[tlen-1] != '\0')
{
GNUNET_break_op (0);
pal_ctx->cb (pal_ctx->cb_cls, NULL );
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "peer %s transport_name: %s\n",GNUNET_i2s(&air_msg->peer), transport_name);
-
address = GNUNET_HELLO_address_allocate(&air_msg->peer, transport_name, addr, alen);
/* expect more replies */
GNUNET_TIME_absolute_get_remaining (pal_ctx->timeout));
pal_ctx->cb (pal_ctx->cb_cls, address);
+ GNUNET_free (address);
}
/**
- * Return all the known addresses for a peer.
+ * Return all the known addresses for a specific peer or all peers.
+ * Returns continously all address if one_shot is set to GNUNET_NO
+ *
+ * CHANGE: Returns the address(es) that we are currently using for this
+ * peer. Upon completion, the 'AddressLookUpCallback' is called one more
+ * time with 'NULL' for the address and the peer. After this, the operation must no
+ * longer be explicitly cancelled.
*
* @param cfg configuration to use
- * @param peer peer identity to look up the addresses of
+ * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers
+ * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL),
+ * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly cancelled)
* @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
- * @return handle to cancel the operation, NULL on error
*/
-struct GNUNET_TRANSPORT_PeerAddressLookupContext *
+struct GNUNET_TRANSPORT_PeerIterateContext *
GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_PeerIdentity *peer,
int one_shot,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
+ GNUNET_TRANSPORT_PeerIterateCallback peer_address_callback,
void *peer_address_callback_cls)
{
- struct GNUNET_TRANSPORT_PeerAddressLookupContext *pal_ctx;
+ struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx;
struct AddressIterateMessage msg;
struct GNUNET_CLIENT_Connection *client;
struct GNUNET_TIME_Absolute abs_timeout;
else
memcpy (&msg.peer, peer , sizeof (struct GNUNET_PeerIdentity));
- pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
+ pal_ctx = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerIterateContext));
pal_ctx->cb = peer_address_callback;
pal_ctx->cb_cls = peer_address_callback_cls;
pal_ctx->timeout = abs_timeout;
*/
void
GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
- GNUNET_TRANSPORT_PeerAddressLookupContext
+ GNUNET_TRANSPORT_PeerIterateContext
*alc)
{
GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
}
/**
- * Return all the known addresses for all peers.
+ * Return all addresses for all peers.
*
* @param cfg configuration to use
* @param timeout how long is the lookup allowed to take at most
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
+ GNUNET_TRANSPORT_PeerIterateCallback
peer_address_callback,
void *peer_address_callback_cls)
{
return;
}
GNUNET_break (ntohs (msg->type) ==
- GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE_RESPONSE);
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
size = ntohs (msg->size);
if (size == sizeof (struct GNUNET_MessageHeader))
{
char *addrbuf;
GNUNET_assert (address != NULL);
- alen = GNUNET_HELLO_address_get_size (address);
- len = sizeof (struct AddressLookupMessage) + alen;
+ len = sizeof (struct AddressLookupMessage) + GNUNET_HELLO_address_get_size (address);
if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
return NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNUNET_TRANSPORT_address_to_string\n");
+
+ alen = address->address_length;
msg = GNUNET_malloc (len);
msg->header.size = htons (len);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
msg->timeout = GNUNET_TIME_relative_hton (timeout);
msg->addrlen = htonl (alen);
addrbuf = (char *) &msg[1];
- memcpy (addrbuf, address, alen);
+ memcpy (addrbuf, address->address, alen);
+ strcpy (&addrbuf[alen], address->transport_name);
+
alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext));
alc->cb = aluc;
alc->cb_cls = aluc_cls;
-/* end of transport_api_address_lookup.c */
+/* end of transport_api_address_to_string.c */