aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_peer_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_peer_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_peer_address_lookup.c')
-rw-r--r--src/transport/transport_api_peer_address_lookup.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c
index c84874b4b..83ed074a3 100644
--- a/src/transport/transport_api_peer_address_lookup.c
+++ b/src/transport/transport_api_peer_address_lookup.c
@@ -42,7 +42,7 @@
42/** 42/**
43 * Context for the address lookup. 43 * Context for the address lookup.
44 */ 44 */
45struct AddressLookupCtx 45struct GNUNET_TRANSPORT_PeerAddressLookupContext
46{ 46{
47 /** 47 /**
48 * Function to call with the human-readable address. 48 * Function to call with the human-readable address.
@@ -69,7 +69,7 @@ struct AddressLookupCtx
69/** 69/**
70 * Function called with responses from the service. 70 * Function called with responses from the service.
71 * 71 *
72 * @param cls our 'struct AddressLookupCtx*' 72 * @param cls our 'struct GNUNET_TRANSPORT_PeerAddressLookupContext*'
73 * @param msg NULL on timeout or error, otherwise presumably a 73 * @param msg NULL on timeout or error, otherwise presumably a
74 * message with the human-readable address 74 * message with the human-readable address
75 */ 75 */
@@ -77,7 +77,7 @@ static void
77peer_address_response_processor (void *cls, 77peer_address_response_processor (void *cls,
78 const struct GNUNET_MessageHeader *msg) 78 const struct GNUNET_MessageHeader *msg)
79{ 79{
80 struct AddressLookupCtx *alucb = cls; 80 struct GNUNET_TRANSPORT_PeerAddressLookupContext *alucb = cls;
81 const char *address; 81 const char *address;
82 uint16_t size; 82 uint16_t size;
83 83
@@ -124,8 +124,9 @@ peer_address_response_processor (void *cls,
124 * @param timeout how long is the lookup allowed to take at most 124 * @param timeout how long is the lookup allowed to take at most
125 * @param peer_address_callback function to call with the results 125 * @param peer_address_callback function to call with the results
126 * @param peer_address_callback_cls closure for peer_address_callback 126 * @param peer_address_callback_cls closure for peer_address_callback
127 * @return handle to cancel the operation, NULL on error
127 */ 128 */
128void 129struct GNUNET_TRANSPORT_PeerAddressLookupContext *
129GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle 130GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
130 *cfg, 131 *cfg,
131 const struct GNUNET_PeerIdentity *peer, 132 const struct GNUNET_PeerIdentity *peer,
@@ -135,29 +136,41 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
135 void *peer_address_callback_cls) 136 void *peer_address_callback_cls)
136{ 137{
137 struct PeerAddressLookupMessage msg; 138 struct PeerAddressLookupMessage msg;
138 struct AddressLookupCtx *peer_address_lookup_cb; 139 struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc;
139 struct GNUNET_CLIENT_Connection *client; 140 struct GNUNET_CLIENT_Connection *client;
140 141
141 client = GNUNET_CLIENT_connect ("transport", cfg); 142 client = GNUNET_CLIENT_connect ("transport", cfg);
142 if (client == NULL) 143 if (client == NULL)
143 { 144 return NULL;
144 peer_address_callback (peer_address_callback_cls, NULL);
145 return;
146 }
147 msg.header.size = htons (sizeof (struct PeerAddressLookupMessage)); 145 msg.header.size = htons (sizeof (struct PeerAddressLookupMessage));
148 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP); 146 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP);
149 msg.timeout = GNUNET_TIME_relative_hton (timeout); 147 msg.timeout = GNUNET_TIME_relative_hton (timeout);
150 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity)); 148 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
151 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx)); 149 alc = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PeerAddressLookupContext));
152 peer_address_lookup_cb->cb = peer_address_callback; 150 alc->cb = peer_address_callback;
153 peer_address_lookup_cb->cb_cls = peer_address_callback_cls; 151 alc->cb_cls = peer_address_callback_cls;
154 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout); 152 alc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
155 peer_address_lookup_cb->client = client; 153 alc->client = client;
156 GNUNET_assert (GNUNET_OK == 154 GNUNET_assert (GNUNET_OK ==
157 GNUNET_CLIENT_transmit_and_get_response (client, &msg.header, 155 GNUNET_CLIENT_transmit_and_get_response (client, &msg.header,
158 timeout, GNUNET_YES, 156 timeout, GNUNET_YES,
159 &peer_address_response_processor, 157 &peer_address_response_processor,
160 peer_address_lookup_cb)); 158 alc));
159 return alc;
161} 160}
162 161
162
163/**
164 * Cancel request for address conversion.
165 *
166 * @param alc handle for the request to cancel
167 */
168void
169GNUNET_TRANSPORT_peer_address_lookup_cancel (struct GNUNET_TRANSPORT_PeerAddressLookupContext *alc)
170{
171 GNUNET_CLIENT_disconnect (alc->client, GNUNET_NO);
172 GNUNET_free (alc);
173}
174
175
163/* end of transport_api_peer_address_lookup.c */ 176/* end of transport_api_peer_address_lookup.c */