/**
- * Function to call with a human-readable format of an address
+ * Function to call with a binary format of an address
*
* @param cls closure
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
const char *address);
+/**
+ * Function to call with a binary format of an address
+ *
+ * @param cls closure
+ * @param peer peer identity
+ * @param transport transport plugin
+ * @param addr address
+ * @param addrlen address length
+ */
+typedef void (*GNUNET_TRANSPORT_AddressLookUpBinaryCallback) (void *cls,
+ const struct
+ GNUNET_PeerIdentity
+ * peer,
+ const char
+ *transport,
+ const void *addr,
+ size_t addrlen);
+
+
/**
* Connect to the transport service. Note that the connection may
* complete (or fail) asynchronously.
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
+ GNUNET_TRANSPORT_AddressLookUpBinaryCallback
peer_address_callback,
void *peer_address_callback_cls);
* @param address the resolved name, NULL to indicate the last response
*/
static void
-transmit_address_to_client (void *cls, const char *address)
+transmit_address_to_client (void *cls, const char *buf)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
- if (NULL == address)
+ if (NULL == buf)
{
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);
return;
}
- GNUNET_SERVER_transmit_context_append_data (tc, address, strlen (address) + 1,
+ GNUNET_SERVER_transmit_context_append_data (tc, buf, strlen (buf + 1),
+ GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+}
+
+
+/**
+ * Take the given address and append it to the set of results sent back to
+ * the client.
+ *
+ * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
+ * @param address the resolved name, NULL to indicate the last response
+ */
+static void
+transmit_binary_to_client (void *cls, void *buf, size_t size)
+{
+ struct GNUNET_SERVER_TransmitContext *tc = cls;
+
+ if (NULL == buf)
+ {
+ 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);
+ return;
+ }
+ GNUNET_SERVER_transmit_context_append_data (tc, buf, size,
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
}
* @param ats_count number of entries in ats (excluding 0-termination)
*/
static void
-output_addresses (void *cls, const struct GNUNET_PeerIdentity *neighbour,
+output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *ats,
uint32_t ats_count)
{
struct GNUNET_SERVER_TransmitContext *tc = cls;
- char *addr_buf;
+ struct AddressIterateResponseMessage msg;
+ size_t size;
- /* FIXME: move to a binary format!!! */
- GNUNET_asprintf (&addr_buf, "%s: %s", GNUNET_i2s (neighbour),
- GST_plugins_a2s ("FIXME", NULL, 0));
- transmit_address_to_client (tc, addr_buf);
- GNUNET_free (addr_buf);
+ size =
+ sizeof (struct AddressIterateResponseMessage) -
+ sizeof (struct GNUNET_MessageHeader);
+ memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
+ msg.addrlen = ntohs (0);
+ msg.pluginlen = ntohs (0);
+
+ transmit_binary_to_client (tc, &msg, size);
}
GNUNET_assert (neighbours_connected > 0);
neighbours_connected--;
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# peers connected"),
- -1, GNUNET_NO);
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), -1,
+ GNUNET_NO);
disconnect_notify_cb (callback_cls, &n->id);
}
GNUNET_assert (GNUNET_YES ==
return;
neighbours_connected++;
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# peers connected"),
- 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1,
+ GNUNET_NO);
connect_notify_cb (callback_cls, target, n->ats, n->ats_count);
}
ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
struct GNUNET_TRANSPORT_ATS_Information ats;
+
ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
ats.value = htonl (0);
if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "SIZE!\n");
GNUNET_break_op (0);
return;
}
/* validity achieved, remember it! */
ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
struct GNUNET_TRANSPORT_ATS_Information ats;
+
ats.type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
ats.value = htonl (0);
GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->valid_until, ve->transport_name, NULL, ve->addr, ve->addrlen, &ats, 1); /* FIXME: compute and add latency here... */
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
static void
-process_address (void *cls, const char *address)
+process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
+ const char *transport, const void *addr, size_t addrlen)
{
#if VERBOSE
connection_count++;
#endif
- if (address != NULL)
- fprintf (stdout, "%s\n", address);
+ if ((peer != NULL) || (transport != NULL) ||
+ ((addr != NULL) && (addrlen > 0)))
+ fprintf (stdout, "Peer `%s' plugin: `%s' address `%s'\n",
+ (peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
+ (transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
+ (addrlen > 0) &&
+ (transport !=
+ NULL)) ?
+ "how do i resolve the name without transport service?" :
+ "<unknown>");
}
/**
* Function to call with the human-readable address.
*/
- GNUNET_TRANSPORT_AddressLookUpCallback cb;
+ GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb;
/**
* Closure for cb.
const struct GNUNET_MessageHeader *msg)
{
struct AddressLookupCtx *alucb = cls;
- const char *address;
+ struct AddressIterateResponseMessage *address;
uint16_t size;
+
if (msg == NULL)
{
- alucb->cb (alucb->cb_cls, NULL);
+ alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
+
GNUNET_break (ntohs (msg->type) ==
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
size = ntohs (msg->size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u\n",
+ ntohs (msg->type), size);
if (size == sizeof (struct GNUNET_MessageHeader))
{
/* done! */
- alucb->cb (alucb->cb_cls, NULL);
+ alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
- address = (const char *) &msg[1];
- if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
+ if (size != sizeof (struct AddressIterateResponseMessage))
{
/* invalid reply */
GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL);
+ alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
+
+ address = (struct AddressIterateResponseMessage *) msg;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "PEER: %s\n",
+ GNUNET_i2s (&address->peer));
+
+
/* expect more replies */
GNUNET_CLIENT_receive (alucb->client, &peer_address_response_processor, alucb,
GNUNET_TIME_absolute_get_remaining (alucb->timeout));
- alucb->cb (alucb->cb_cls, address);
+ alucb->cb (alucb->cb_cls, &address->peer, NULL, NULL, 0);
}
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
+ GNUNET_TRANSPORT_AddressLookUpBinaryCallback
peer_address_callback,
void *peer_address_callback_cls)
{
client = GNUNET_CLIENT_connect ("transport", cfg);
if (client == NULL)
{
- peer_address_callback (peer_address_callback_cls, NULL);
+ peer_address_callback (peer_address_callback_cls, NULL, NULL, NULL, 0);
return;
}
abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
- msg.header.size = htons (sizeof (struct AddressLookupMessage));
+ msg.header.size = htons (sizeof (struct AddressIterateMessage));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout);
peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));