aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_address_lookup.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-09-11 09:54:37 +0000
committerChristian Grothoff <christian@grothoff.org>2011-09-11 09:54:37 +0000
commit39589dd2116957e3265c8bd55cf1b9633b1e0b1a (patch)
treed2449b5a9a30afa9735a780c193ae4dfd9bb1405 /src/transport/transport_api_address_lookup.c
parentfcef0fe54948e3219fffde41a4ff7c5542c6f072 (diff)
downloadgnunet-39589dd2116957e3265c8bd55cf1b9633b1e0b1a.tar.gz
gnunet-39589dd2116957e3265c8bd55cf1b9633b1e0b1a.zip
allow cancellation of certain transport API operations
Diffstat (limited to 'src/transport/transport_api_address_lookup.c')
-rw-r--r--src/transport/transport_api_address_lookup.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 1cbafdab0..a760f4775 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -30,7 +30,7 @@
30/** 30/**
31 * Context for the address lookup. 31 * Context for the address lookup.
32 */ 32 */
33struct AddressLookupCtx 33struct GNUNET_TRANSPORT_AddressLookupContext
34{ 34{
35 /** 35 /**
36 * Function to call with the human-readable address. 36 * Function to call with the human-readable address.
@@ -57,14 +57,14 @@ struct AddressLookupCtx
57/** 57/**
58 * Function called with responses from the service. 58 * Function called with responses from the service.
59 * 59 *
60 * @param cls our 'struct AddressLookupCtx*' 60 * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*'
61 * @param msg NULL on timeout or error, otherwise presumably a 61 * @param msg NULL on timeout or error, otherwise presumably a
62 * message with the human-readable address 62 * message with the human-readable address
63 */ 63 */
64static void 64static void
65address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg) 65address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
66{ 66{
67 struct AddressLookupCtx *alucb = cls; 67 struct GNUNET_TRANSPORT_AddressLookupContext *alucb = cls;
68 const char *address; 68 const char *address;
69 uint16_t size; 69 uint16_t size;
70 70
@@ -115,8 +115,9 @@ address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
115 * @param timeout how long is the lookup allowed to take at most 115 * @param timeout how long is the lookup allowed to take at most
116 * @param aluc function to call with the results 116 * @param aluc function to call with the results
117 * @param aluc_cls closure for aluc 117 * @param aluc_cls closure for aluc
118 * @return handle to cancel the operation, NULL on error
118 */ 119 */
119void 120struct GNUNET_TRANSPORT_AddressLookupContext *
120GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, 121GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
121 const char *address, size_t addressLen, 122 const char *address, size_t addressLen,
122 int numeric, const char *nameTrans, 123 int numeric, const char *nameTrans,
@@ -127,7 +128,7 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
127 size_t slen; 128 size_t slen;
128 size_t len; 129 size_t len;
129 struct AddressLookupMessage *msg; 130 struct AddressLookupMessage *msg;
130 struct AddressLookupCtx *aluCB; 131 struct GNUNET_TRANSPORT_AddressLookupContext *alc;
131 struct GNUNET_CLIENT_Connection *client; 132 struct GNUNET_CLIENT_Connection *client;
132 char *addrbuf; 133 char *addrbuf;
133 134
@@ -136,15 +137,11 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
136 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 137 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
137 { 138 {
138 GNUNET_break (0); 139 GNUNET_break (0);
139 aluc (aluc_cls, NULL); 140 return NULL;
140 return;
141 } 141 }
142 client = GNUNET_CLIENT_connect ("transport", cfg); 142 client = GNUNET_CLIENT_connect ("transport", cfg);
143 if (client == NULL) 143 if (client == NULL)
144 { 144 return NULL;
145 aluc (aluc_cls, NULL);
146 return;
147 }
148 msg = GNUNET_malloc (len); 145 msg = GNUNET_malloc (len);
149 msg->header.size = htons (len); 146 msg->header.size = htons (len);
150 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); 147 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
@@ -154,17 +151,33 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
154 addrbuf = (char *) &msg[1]; 151 addrbuf = (char *) &msg[1];
155 memcpy (addrbuf, address, addressLen); 152 memcpy (addrbuf, address, addressLen);
156 memcpy (&addrbuf[addressLen], nameTrans, slen); 153 memcpy (&addrbuf[addressLen], nameTrans, slen);
157 aluCB = GNUNET_malloc (sizeof (struct AddressLookupCtx)); 154 alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_AddressLookupContext));
158 aluCB->cb = aluc; 155 alc->cb = aluc;
159 aluCB->cb_cls = aluc_cls; 156 alc->cb_cls = aluc_cls;
160 aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout); 157 alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
161 aluCB->client = client; 158 alc->client = client;
162 GNUNET_assert (GNUNET_OK == 159 GNUNET_assert (GNUNET_OK ==
163 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header, 160 GNUNET_CLIENT_transmit_and_get_response (client, &msg->header,
164 timeout, GNUNET_YES, 161 timeout, GNUNET_YES,
165 &address_response_processor, 162 &address_response_processor,
166 aluCB)); 163 alc));
167 GNUNET_free (msg); 164 GNUNET_free (msg);
165 return alc;
168} 166}
169 167
168
169/**
170 * Cancel request for address conversion.
171 *
172 * @param alc handle for the request to cancel
173 */
174void
175GNUNET_TRANSPORT_address_lookup_cancel (struct GNUNET_TRANSPORT_AddressLookupContext *alc)
176{
177 GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
178 GNUNET_free (alc);
179}
180
181
182
170/* end of transport_api_address_lookup.c */ 183/* end of transport_api_address_lookup.c */