* @param hello the hello message
* @param cont continuation to call when HELLO has been sent
* @param cls closure for continuation
- *
*/
void
GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
GNUNET_SCHEDULER_Task cont, void *cls);
+/**
+ * Handle to cancel a pending address lookup.
+ */
+struct GNUNET_TRANSPORT_AddressLookupContext;
+
+
/**
* Convert a binary address into a human readable address.
*
* @param timeout how long is the lookup allowed to take at most
* @param aluc function to call with the results
* @param aluc_cls closure for aluc
+ * @return handle to cancel the operation, NULL on error
*/
-void
+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,
void *aluc_cls);
+/**
+ * Cancel request for address conversion.
+ *
+ * @param alc handle for the request to cancel
+ */
+void
+GNUNET_TRANSPORT_address_lookup_cancel (struct GNUNET_TRANSPORT_AddressLookupContext *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
*/
-void
+struct GNUNET_TRANSPORT_PeerAddressLookupContext *
GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
*cfg,
const struct GNUNET_PeerIdentity *peer,
void *peer_address_callback_cls);
+/**
+ * Cancel request for peer lookup.
+ *
+ * @param alc handle for the request to cancel
+ */
+void
+GNUNET_TRANSPORT_peer_address_lookup_cancel (struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc);
+
+
/**
* Return all the known addresses. FIXME: document better!
- * FIXME: use better name!
+ * FIXME: use better name! FIXME: extend API to allow cancellation!
*
* @param cfg configuration to use
* @param timeout how long is the lookup allowed to take at most
/**
* Context for the address lookup.
*/
-struct AddressLookupCtx
+struct GNUNET_TRANSPORT_AddressLookupContext
{
/**
* Function to call with the human-readable address.
/**
* Function called with responses from the service.
*
- * @param cls our 'struct AddressLookupCtx*'
+ * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*'
* @param msg NULL on timeout or error, otherwise presumably a
* message with the human-readable address
*/
static void
address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
{
- struct AddressLookupCtx *alucb = cls;
+ struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls;
const char *address;
uint16_t size;
* @param timeout how long is the lookup allowed to take at most
* @param aluc function to call with the results
* @param aluc_cls closure for aluc
+ * @return handle to cancel the operation, NULL on error
*/
-void
+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,
size_t slen;
size_t len;
struct AddressLookupMessage *msg;
- struct AddressLookupCtx *aluCB;
+ struct GNUNET_TRANSPORT_AddressLookupContext *alc;
struct GNUNET_CLIENT_Connection *client;
char *addrbuf;
if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
- aluc (aluc_cls, NULL);
- return;
+ return NULL;
}
client = GNUNET_CLIENT_connect ("transport", cfg);
- if (client == NULL)
- {
- aluc (aluc_cls, NULL);
- return;
- }
+ if (client == NULL)
+ return NULL;
msg = GNUNET_malloc (len);
msg->header.size = htons (len);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
addrbuf = (char *) &msg[1];
memcpy (addrbuf, address, addressLen);
memcpy (&addrbuf[addressLen], nameTrans, slen);
- aluCB = GNUNET_malloc (sizeof (struct AddressLookupCtx));
- aluCB->cb = aluc;
- aluCB->cb_cls = aluc_cls;
- aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- aluCB->client = client;
+ alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext));
+ alc->cb = aluc;
+ alc->cb_cls = aluc_cls;
+ alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+ alc->client = client;
GNUNET_assert (GNUNET_OK ==
GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
timeout, GNUNET_YES,
&address_response_processor,
- aluCB));
+ alc));
GNUNET_free (msg);
+ return alc;
}
+
+/**
+ * Cancel request for address conversion.
+ *
+ * @param alc handle for the request to cancel
+ */
+void
+GNUNET_TRANSPORT_address_lookup_cancel (struct GNUNET_TRANSPORT_AddressLookupContext *alc)
+{
+ GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
+ GNUNET_free (alc);
+}
+
+
+
/* end of transport_api_address_lookup.c */
/**
* Context for the address lookup.
*/
-struct AddressLookupCtx
+struct GNUNET_TRANSPORT_PeerAddressLookupContext
{
/**
* Function to call with the human-readable address.
/**
* Function called with responses from the service.
*
- * @param cls our 'struct AddressLookupCtx*'
+ * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
* @param msg NULL on timeout or error, otherwise presumably a
* message with the human-readable address
*/
peer_address_response_processor (void *cls,
const struct GNUNET_MessageHeader *msg)
{
- struct AddressLookupCtx *alucb = cls;
+ struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls;
const char *address;
uint16_t size;
* @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
*/
-void
+struct GNUNET_TRANSPORT_PeerAddressLookupContext *
GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
*cfg,
const struct GNUNET_PeerIdentity *peer,
void *peer_address_callback_cls)
{
struct PeerAddressLookupMessage msg;
- struct AddressLookupCtx *peer_address_lookup_cb;
+ struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc;
struct GNUNET_CLIENT_Connection *client;
client = GNUNET_CLIENT_connect ("transport", cfg);
if (client == NULL)
- {
- peer_address_callback (peer_address_callback_cls, NULL);
- return;
- }
+ return NULL;
msg.header.size = htons (sizeof (struct PeerAddressLookupMessage));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP);
msg.timeout = GNUNET_TIME_relative_hton (timeout);
memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
- peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));
- peer_address_lookup_cb->cb = peer_address_callback;
- peer_address_lookup_cb->cb_cls = peer_address_callback_cls;
- peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- peer_address_lookup_cb->client = client;
+ 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);
+ alc->client = client;
GNUNET_assert (GNUNET_OK ==
GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
timeout, GNUNET_YES,
&peer_address_response_processor,
- peer_address_lookup_cb));
+ alc));
+ return alc;
}
+
+/**
+ * Cancel request for address conversion.
+ *
+ * @param alc handle for the request to cancel
+ */
+void
+GNUNET_TRANSPORT_peer_address_lookup_cancel (struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc)
+{
+ GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
+ GNUNET_free (alc);
+}
+
+
/* end of transport_api_peer_address_lookup.c */