[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r16755 - in gnunet/src: include transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r16755 - in gnunet/src: include transport |
Date: |
Sun, 11 Sep 2011 11:54:37 +0200 |
Author: grothoff
Date: 2011-09-11 11:54:37 +0200 (Sun, 11 Sep 2011)
New Revision: 16755
Modified:
gnunet/src/include/gnunet_transport_service.h
gnunet/src/transport/transport_api_address_lookup.c
gnunet/src/transport/transport_api_peer_address_lookup.c
Log:
allow cancellation of certain transport API operations
Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h 2011-09-11 08:44:59 UTC
(rev 16754)
+++ gnunet/src/include/gnunet_transport_service.h 2011-09-11 09:54:37 UTC
(rev 16755)
@@ -629,7 +629,6 @@
* @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,
@@ -638,6 +637,12 @@
/**
+ * Handle to cancel a pending address lookup.
+ */
+struct GNUNET_TRANSPORT_AddressLookupContext;
+
+
+/**
* Convert a binary address into a human readable address.
*
* @param cfg configuration to use
@@ -649,8 +654,9 @@
* @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,
@@ -660,6 +666,21 @@
/**
+ * 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!
*
@@ -669,7 +690,7 @@
* @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,
@@ -680,8 +701,17 @@
/**
+ * 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
Modified: gnunet/src/transport/transport_api_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_address_lookup.c 2011-09-11 08:44:59 UTC
(rev 16754)
+++ gnunet/src/transport/transport_api_address_lookup.c 2011-09-11 09:54:37 UTC
(rev 16755)
@@ -30,7 +30,7 @@
/**
* Context for the address lookup.
*/
-struct AddressLookupCtx
+struct GNUNET_TRANSPORT_AddressLookupContext
{
/**
* Function to call with the human-readable address.
@@ -57,14 +57,14 @@
/**
* 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;
@@ -115,8 +115,9 @@
* @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,
@@ -127,7 +128,7 @@
size_t slen;
size_t len;
struct AddressLookupMessage *msg;
- struct AddressLookupCtx *aluCB;
+ struct GNUNET_TRANSPORT_AddressLookupContext *alc;
struct GNUNET_CLIENT_Connection *client;
char *addrbuf;
@@ -136,15 +137,11 @@
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);
@@ -154,17 +151,33 @@
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 */
Modified: gnunet/src/transport/transport_api_peer_address_lookup.c
===================================================================
--- gnunet/src/transport/transport_api_peer_address_lookup.c 2011-09-11
08:44:59 UTC (rev 16754)
+++ gnunet/src/transport/transport_api_peer_address_lookup.c 2011-09-11
09:54:37 UTC (rev 16755)
@@ -42,7 +42,7 @@
/**
* Context for the address lookup.
*/
-struct AddressLookupCtx
+struct GNUNET_TRANSPORT_PeerAddressLookupContext
{
/**
* Function to call with the human-readable address.
@@ -69,7 +69,7 @@
/**
* 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
*/
@@ -77,7 +77,7 @@
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;
@@ -124,8 +124,9 @@
* @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,
@@ -135,29 +136,41 @@
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 */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r16755 - in gnunet/src: include transport,
gnunet <=