* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
static void
-process_resolved_address (void *cls, const char *address)
+process_resolved_address (void *cls, const struct GNUNET_HELLO_Address *address)
{
struct PrintContext *pc = cls;
struct AddressStringList *new_address;
#if VERBOSE
fprintf (stderr, "Received address %s\n", address);
#endif
- new_address->address_string = GNUNET_strdup (address);
+ // 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);
}
#endif
pc = GNUNET_malloc (sizeof (struct PrintContext));
pc->peer = *peer;
- GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, GNUNET_TIME_UNIT_MINUTES,
+ GNUNET_TRANSPORT_peer_get_active_addresses (cfg, peer, GNUNET_TIME_UNIT_MINUTES,
&process_resolved_address, pc);
}
#if VERBOSE
}
+/**
+ * Get the size of an address struct.
+ *
+ * @param address address
+ * @return the size
+ */
+size_t
+GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address)
+{
+ return sizeof (struct GNUNET_HELLO_Address) +
+ address->address_length +
+ strlen(address->transport_name) + 1;
+}
+
+
/**
* Copy an address struct.
*
const struct GNUNET_HELLO_Address *a2);
+/**
+ * Get the size of an address struct.
+ *
+ * @param address address
+ * @return the size
+ */
+size_t
+GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address);
/**
* Free an address.
* @param cls closure
* @param address NULL on error, otherwise 0-terminated printable UTF-8 string
*/
-// RENAME: AddressToStringCallback
-typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
+typedef void (*GNUNET_TRANSPORT_AddressToStringCallback) (void *cls,
const char *address);
* @param addrlen address length
*/
// FIXME: use GNUNET_HELLO_Address (as 2nd arg, replacing others)
-// FIXME: rename: remove "Binary"
// FIXME: use NULL for address on disconnect IF in monitor mode (one_shot = NO)
-typedef void (*GNUNET_TRANSPORT_AddressLookUpBinaryCallback) (void *cls,
- const struct
- GNUNET_PeerIdentity
- * peer,
- const char
- *transport,
- const void *addr,
- size_t addrlen);
+typedef void (*GNUNET_TRANSPORT_AddressLookUpCallback) (void *cls,
+ const struct GNUNET_HELLO_Address *address);
/**
/**
* Handle to cancel a pending address lookup.
*/
-struct GNUNET_TRANSPORT_AddressLookupContext;
+struct GNUNET_TRANSPORT_AddressToStringContext;
/**
* @param aluc_cls closure for aluc
* @return handle to cancel the operation, NULL on error
*/
-// FIXME: use 'GNUNET_HELLO_Address' here!
-// => rename: address_to_string
-struct GNUNET_TRANSPORT_AddressLookupContext *
-GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *address, size_t addressLen,
- int numeric, const char *nameTrans,
+struct GNUNET_TRANSPORT_AddressToStringContext *
+GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_HELLO_Address *address,
+ int numeric,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback aluc,
+ GNUNET_TRANSPORT_AddressToStringCallback aluc,
void *aluc_cls);
* @param alc handle for the request to cancel
*/
void
-GNUNET_TRANSPORT_address_lookup_cancel (struct
- GNUNET_TRANSPORT_AddressLookupContext
+GNUNET_TRANSPORT_address_to_string_cancel (struct
+ GNUNET_TRANSPORT_AddressToStringContext
*alc);
-/**
- * Handle to cancel a pending address lookup.
- */
-struct GNUNET_TRANSPORT_AddressLookupContext;
-
-
/**
* Return all the known addresses for a peer. FIXME: document better!
* FIXME: use better name!
* @param peer_address_callback function to call with the results
* @param peer_address_callback_cls closure for peer_address_callback
*/
-// RENAME: peer_get_active_addresses
struct GNUNET_TRANSPORT_PeerAddressLookupContext *
-GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
- *cfg,
+GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_PeerIdentity *peer,
// FIXME: add argument: one_shot
struct GNUNET_TIME_Relative timeout,
- // FIXME: change to the 'Binary' lookup callback (which will
- // be renamed, so the argument type actually won't change)
- GNUNET_TRANSPORT_AddressLookUpCallback
- peer_address_callback,
+ GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
void *peer_address_callback_cls);
* @param alc handle for the request to cancel
*/
void
-GNUNET_TRANSPORT_peer_address_lookup_cancel (struct
+GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
GNUNET_TRANSPORT_PeerAddressLookupContext
- *alc);
+*alc);
/**
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpBinaryCallback
+ GNUNET_TRANSPORT_AddressLookUpCallback
peer_address_callback,
void *peer_address_callback_cls);
struct GNUNET_TIME_Absolute expiration)
{
struct PrintContext *pc = cls;
-
- GNUNET_TRANSPORT_address_lookup (cfg,
- address->address,
- address->address_length, no_resolve,
- address->transport_name,
+ GNUNET_TRANSPORT_address_to_string (cfg,
+ address,
+ no_resolve,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 10),
&process_resolved_address, pc);
* @param addrlen number of bytes in addr
*/
static void
-process_address (void *cls, const struct GNUNET_PeerIdentity *peer,
- const char *transport, const void *addr, size_t addrlen)
+process_address (void *cls, const struct GNUNET_HELLO_Address *address)
{
- if ((peer != NULL) || (transport != NULL) ||
- ((addr != NULL) && (addrlen > 0)))
+ if ((address->transport_name != NULL) ||
+ ((address->address != NULL) && (address->address_length > 0)))
+ {
+ /* Call GNUNET_TRANSPORT_address_to_string to convert to human readable */
+ //GNUNET_TRANSPORT_address_to_string(cfg, address, GNUNET_NO)
+
+#if 0
fprintf (stdout, _("Peer `%s' plugin: `%s' address `%s'\n"),
(peer != NULL) ? GNUNET_i2s (peer) : "<unknown>",
(transport != NULL) ? transport : "<unknown>", ((addr != NULL) &&
NULL)) ?
"how do i resolve the name without transport service?" :
"<unknown>");
+#endif
+ }
}
/**
* Function to call with the human-readable address.
*/
- GNUNET_TRANSPORT_AddressLookUpBinaryCallback cb;
+ GNUNET_TRANSPORT_AddressLookUpCallback cb;
/**
* Closure for cb.
const struct GNUNET_MessageHeader *msg)
{
struct AddressLookupCtx *alucb = cls;
- struct AddressIterateResponseMessage *address;
+ struct AddressIterateResponseMessage *arm;
+ struct GNUNET_HELLO_Address * address;
uint16_t size;
- char *transport;
-
- //size_t transport_len;
- //void * addr;
- size_t addrlen;
if (msg == NULL)
{
- alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
+ alucb->cb (alucb->cb_cls, NULL);
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
if (size == sizeof (struct GNUNET_MessageHeader))
{
/* done! */
- alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
+ alucb->cb (alucb->cb_cls, NULL);
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
{
/* invalid reply */
GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL, NULL, NULL, 0);
+ alucb->cb (alucb->cb_cls, NULL);
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
- address = (struct AddressIterateResponseMessage *) &msg[1];
-
- transport = (char *) &address[0];
- //transport_len = ntohs(address->pluginlen);
- addrlen = ntohs (address->addrlen);
+ arm = (struct AddressIterateResponseMessage *) &msg[1];
+ address = (struct GNUNET_HELLO_Address *) &arm[1];
/* 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->peer, transport, NULL, addrlen);
+ alucb->cb (alucb->cb_cls, address);
}
void
GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpBinaryCallback
+ GNUNET_TRANSPORT_AddressLookUpCallback
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, NULL, NULL, 0);
+ peer_address_callback (peer_address_callback_cls, NULL);
return;
}
abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
/**
* Context for the address lookup.
*/
-struct GNUNET_TRANSPORT_AddressLookupContext
+struct GNUNET_TRANSPORT_AddressToStringContext
{
/**
* Function to call with the human-readable address.
*/
- GNUNET_TRANSPORT_AddressLookUpCallback cb;
+ GNUNET_TRANSPORT_AddressToStringCallback cb;
/**
* Closure for cb.
static void
address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
{
- struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls;
+ struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
const char *address;
uint16_t size;
* @param aluc_cls closure for aluc
* @return handle to cancel the operation, NULL on error
*/
-struct GNUNET_TRANSPORT_AddressLookupContext *
-GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *address, size_t addressLen,
- int numeric, const char *nameTrans,
+struct GNUNET_TRANSPORT_AddressToStringContext *
+GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const struct GNUNET_HELLO_Address *address,
+ int numeric,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback aluc,
+ GNUNET_TRANSPORT_AddressToStringCallback aluc,
void *aluc_cls)
{
- size_t slen;
size_t len;
+ size_t alen;
struct AddressLookupMessage *msg;
- struct GNUNET_TRANSPORT_AddressLookupContext *alc;
+ struct GNUNET_TRANSPORT_AddressToStringContext *alc;
struct GNUNET_CLIENT_Connection *client;
char *addrbuf;
- slen = strlen (nameTrans) + 1;
- len = sizeof (struct AddressLookupMessage) + addressLen + slen;
+ alen = GNUNET_HELLO_address_get_size (address);
+ len = sizeof (struct AddressLookupMessage) + alen;
if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
msg->numeric_only = htonl (numeric);
msg->timeout = GNUNET_TIME_relative_hton (timeout);
- msg->addrlen = htonl (addressLen);
+ msg->addrlen = htonl (alen);
addrbuf = (char *) &msg[1];
- memcpy (addrbuf, address, addressLen);
- memcpy (&addrbuf[addressLen], nameTrans, slen);
- alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext));
+ memcpy (addrbuf, address, alen);
+ alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressToStringContext));
alc->cb = aluc;
alc->cb_cls = aluc_cls;
alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
* @param alc handle for the request to cancel
*/
void
-GNUNET_TRANSPORT_address_lookup_cancel (struct
- GNUNET_TRANSPORT_AddressLookupContext
+GNUNET_TRANSPORT_address_to_string_cancel (struct
+ GNUNET_TRANSPORT_AddressToStringContext
*alc)
{
GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
const struct GNUNET_MessageHeader *msg)
{
struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls;
- const char *address;
+ const struct GNUNET_HELLO_Address *address;
uint16_t size;
if (msg == NULL)
if (size == sizeof (struct GNUNET_MessageHeader))
{
/* done! */
- alucb->cb (alucb->cb_cls, NULL);
+ alucb->cb (alucb->cb_cls, NULL );
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
- address = (const char *) &msg[1];
+ address = (const struct GNUNET_HELLO_Address *) &msg[1];
+#if 0
if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
{
/* invalid reply */
GNUNET_break (0);
- alucb->cb (alucb->cb_cls, NULL);
+ alucb->cb (alucb->cb_cls, NULL );
GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
+#endif
/* 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);
+
+ /* REFACTOR FIX THIS */
+ alucb->cb (alucb->cb_cls, address );
}
* @return handle to cancel the operation, NULL on error
*/
struct GNUNET_TRANSPORT_PeerAddressLookupContext *
-GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
- *cfg,
+GNUNET_TRANSPORT_peer_get_active_addresses (const struct GNUNET_CONFIGURATION_Handle *cfg,
const struct GNUNET_PeerIdentity *peer,
struct GNUNET_TIME_Relative timeout,
- GNUNET_TRANSPORT_AddressLookUpCallback
- peer_address_callback,
+ GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback,
void *peer_address_callback_cls)
{
struct PeerAddressLookupMessage msg;
msg.reserved = htonl (0);
msg.timeout = GNUNET_TIME_relative_hton (timeout);
memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
- alc =
- GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
+ alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
alc->cb = peer_address_callback;
alc->cb_cls = peer_address_callback_cls;
alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
* @param alc handle for the request to cancel
*/
void
-GNUNET_TRANSPORT_peer_address_lookup_cancel (struct
+GNUNET_TRANSPORT_peer_get_active_addresses_cancel (struct
GNUNET_TRANSPORT_PeerAddressLookupContext
*alc)
{