aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/test_core_api.c2
-rw-r--r--src/core/test_core_api_reliability.c2
-rw-r--r--src/core/test_core_quota_compliance.c4
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c2
-rw-r--r--src/include/gnunet_transport_service.h54
-rw-r--r--src/testbed/gnunet-service-testbed.c4
-rw-r--r--src/testing_old/testing.c6
-rw-r--r--src/topology/gnunet-daemon-topology.c2
-rw-r--r--src/transport/gnunet-transport.c4
-rw-r--r--src/transport/test_transport_api_restart_1peer.c2
-rw-r--r--src/transport/test_transport_api_restart_2peers.c2
-rw-r--r--src/transport/transport-testing.c2
-rw-r--r--src/transport/transport_api.c238
13 files changed, 241 insertions, 83 deletions
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index 68ae39df2..ab96fb47e 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -267,7 +267,7 @@ connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "Asking transport (1) to connect to peer `%4s'\n", 268 "Asking transport (1) to connect to peer `%4s'\n",
269 GNUNET_i2s (&p2.id)); 269 GNUNET_i2s (&p2.id));
270 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 270 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id, NULL, NULL); /*FIXME TRY_CONNECT change */
271} 271}
272 272
273 273
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 38c40da12..061158d71 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -174,7 +174,7 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
174 connect_task = 174 connect_task =
175 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, 175 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
176 NULL); 176 NULL);
177 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 177 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id, NULL, NULL); /*FIXME TRY_CONNECT change */
178} 178}
179 179
180 180
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 7f675a637..884d5fa5e 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -189,8 +189,8 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 connect_task = 189 connect_task =
190 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, 190 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
191 NULL); 191 NULL);
192 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); 192 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id, NULL, NULL); /*FIXME TRY_CONNECT change */
193 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); 193 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id, NULL, NULL); /*FIXME TRY_CONNECT change */
194} 194}
195 195
196/** 196/**
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 198b64f53..f865d9042 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -1948,7 +1948,7 @@ handle_dht_p2p_result (void *cls, const struct GNUNET_PeerIdentity *peer,
1948 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL); 1948 GNUNET_TRANSPORT_offer_hello (GDS_transport_handle, h, NULL, NULL);
1949 if (GNUNET_YES != 1949 if (GNUNET_YES !=
1950 disable_try_connect) 1950 disable_try_connect)
1951 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid); 1951 GNUNET_TRANSPORT_try_connect (GDS_transport_handle, &pid, NULL, NULL); /*FIXME TRY_CONNECT change */
1952 } 1952 }
1953 } 1953 }
1954 } 1954 }
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 908489c6a..188b84110 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -99,6 +99,18 @@ typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
99 99
100 100
101/** 101/**
102 * Function to call with result of the try connect request.
103 *
104 *
105 * @param cls closure
106 * @param result GNUNET_OK if message was transmitted to transport service
107 * GNUNET_SYSERR if message was not transmitted to transport service
108 */
109typedef void (*GNUNET_TRANSPORT_TryConnectCallback) (void *cls,
110 const int result);
111
112
113/**
102 * Function to call with a textual representation of an address. 114 * Function to call with a textual representation of an address.
103 * This function will be called several times with different possible 115 * This function will be called several times with different possible
104 * textual representations, and a last time with NULL to signal the end 116 * textual representations, and a last time with NULL to signal the end
@@ -159,21 +171,39 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
159 171
160 172
161/** 173/**
174 * Opaque handle for a transmission-ready request.
175 */
176struct GNUNET_TRANSPORT_TryConnectHandle;
177
178
179/**
162 * Ask the transport service to establish a connection to 180 * Ask the transport service to establish a connection to
163 * the given peer. 181 * the given peer.
164 * 182 *
165 * @param handle connection to transport service 183 * @param handle connection to transport service
166 * @param target who we should try to connect to 184 * @param target who we should try to connect to
167 * @return GNUNET_OK if request can be scheduled 185 * @param cb callback to be called when request was transmitted to transport
168 * GNUNET_NO please retry later because we are reconnecting 186 * service
169 * GNUNET_SYSERR on failure 187 * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
188 * NULL on failure (cb will not be called)
170 */ 189 */
171int 190struct GNUNET_TRANSPORT_TryConnectHandle *
172GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, 191GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
173 const struct GNUNET_PeerIdentity *target); 192 const struct GNUNET_PeerIdentity *target,
193 GNUNET_TRANSPORT_TryConnectCallback cb,
194 void *cb_cls);
174 195
175 196
176/** 197/**
198 * Cancel the request to transport to try a connect
199 * Callback will not be called
200 *
201 * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
202 */
203void
204GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch);
205
206/**
177 * Opaque handle for a transmission-ready request. 207 * Opaque handle for a transmission-ready request.
178 */ 208 */
179struct GNUNET_TRANSPORT_TransmitHandle; 209struct GNUNET_TRANSPORT_TransmitHandle;
@@ -255,7 +285,7 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
255/** 285/**
256 * Stop receiving updates about changes to our HELLO message. 286 * Stop receiving updates about changes to our HELLO message.
257 * 287 *
258 * @param ghh handle returned from 'GNUNET_TRANSPORT_get_hello') 288 * @param ghh handle to cancel
259 */ 289 */
260void 290void
261GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh); 291GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
@@ -270,14 +300,24 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh);
270 * @param hello the hello message 300 * @param hello the hello message
271 * @param cont continuation to call when HELLO has been sent 301 * @param cont continuation to call when HELLO has been sent
272 * @param cls closure for continuation 302 * @param cls closure for continuation
303 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure
304 *
273 */ 305 */
274void 306struct GNUNET_TRANSPORT_OfferHelloHandle *
275GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, 307GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
276 const struct GNUNET_MessageHeader *hello, 308 const struct GNUNET_MessageHeader *hello,
277 GNUNET_SCHEDULER_Task cont, void *cls); 309 GNUNET_SCHEDULER_Task cont, void *cls);
278 310
279 311
280/** 312/**
313 * Cancel the request to transport to offer the HELLO message
314 *
315 * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
316 */
317void
318GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh);
319
320/**
281 * Handle to cancel a pending address lookup. 321 * Handle to cancel a pending address lookup.
282 */ 322 */
283struct GNUNET_TRANSPORT_AddressToStringContext; 323struct GNUNET_TRANSPORT_AddressToStringContext;
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 2f606928a..bdff6dd13 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -2964,7 +2964,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2964 2964
2965 /* FIXME: once offer_hello offers a handle to cancel remove the following lines */ 2965 /* FIXME: once offer_hello offers a handle to cancel remove the following lines */
2966 GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL); 2966 GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL);
2967 GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity); 2967 GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity, NULL, NULL); /*FIXME TRY_CONNECT change */
2968 occ->send_hello_task = 2968 occ->send_hello_task =
2969 GNUNET_SCHEDULER_add_delayed 2969 GNUNET_SCHEDULER_add_delayed
2970 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2970 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
@@ -3518,7 +3518,7 @@ attempt_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3518 3518
3519 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK; 3519 rocc->attempt_connect_task_id = GNUNET_SCHEDULER_NO_TASK;
3520 GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL); 3520 GNUNET_TRANSPORT_offer_hello (rocc->th, rocc->hello, NULL, NULL);
3521 GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id); 3521 GNUNET_TRANSPORT_try_connect (rocc->th, &rocc->a_id, NULL, NULL); /*FIXME TRY_CONNECT change */
3522 rocc->attempt_connect_task_id = 3522 rocc->attempt_connect_task_id =
3523 GNUNET_SCHEDULER_add_delayed 3523 GNUNET_SCHEDULER_add_delayed
3524 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 3524 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
diff --git a/src/testing_old/testing.c b/src/testing_old/testing.c
index 5a3095935..8084a8d59 100644
--- a/src/testing_old/testing.c
+++ b/src/testing_old/testing.c
@@ -1860,7 +1860,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1860 "Sending connect request to TRANSPORT of %s for peer %s\n", 1860 "Sending connect request to TRANSPORT of %s for peer %s\n",
1861 GNUNET_i2s (&ctx->d1->id), 1861 GNUNET_i2s (&ctx->d1->id),
1862 GNUNET_h2s (&ctx->d2->id.hashPubKey)); 1862 GNUNET_h2s (&ctx->d2->id.hashPubKey));
1863 GNUNET_TRANSPORT_try_connect (ctx->d1th, &ctx->d2->id); 1863 GNUNET_TRANSPORT_try_connect (ctx->d1th, &ctx->d2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
1864 ctx->timeout_hello = 1864 ctx->timeout_hello =
1865 GNUNET_TIME_relative_add (ctx->timeout_hello, 1865 GNUNET_TIME_relative_add (ctx->timeout_hello,
1866 GNUNET_TIME_relative_multiply 1866 GNUNET_TIME_relative_multiply
@@ -1887,7 +1887,7 @@ core_init_notify (void *cls, struct GNUNET_CORE_Handle *server,
1887 1887
1888 if (connect_ctx->send_hello == GNUNET_NO) 1888 if (connect_ctx->send_hello == GNUNET_NO)
1889 { 1889 {
1890 GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, &connect_ctx->d2->id); 1890 GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, &connect_ctx->d2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
1891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1892 "Sending connect request to TRANSPORT of %s for peer %s\n", 1892 "Sending connect request to TRANSPORT of %s for peer %s\n",
1893 connect_ctx->d1->shortname, connect_ctx->d2->shortname); 1893 connect_ctx->d1->shortname, connect_ctx->d2->shortname);
@@ -2012,7 +2012,7 @@ reattempt_daemons_connect (void *cls,
2012 { 2012 {
2013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reconnect %s to %s\n", 2013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reconnect %s to %s\n",
2014 ctx->d1->shortname, ctx->d2->shortname); 2014 ctx->d1->shortname, ctx->d2->shortname);
2015 GNUNET_TRANSPORT_try_connect (ctx->d1th, &ctx->d2->id); 2015 GNUNET_TRANSPORT_try_connect (ctx->d1th, &ctx->d2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
2016 } 2016 }
2017 ctx->timeout_task = 2017 ctx->timeout_task =
2018 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout, 2018 GNUNET_SCHEDULER_add_delayed (ctx->relative_timeout,
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index d6e95ad18..c6d359f4b 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -386,7 +386,7 @@ attempt_connect (struct Peer *pos)
386 gettext_noop 386 gettext_noop
387 ("# connect requests issued to transport"), 1, 387 ("# connect requests issued to transport"), 1,
388 GNUNET_NO); 388 GNUNET_NO);
389 GNUNET_TRANSPORT_try_connect (transport, &pos->pid); 389 GNUNET_TRANSPORT_try_connect (transport, &pos->pid, NULL, NULL); /*FIXME TRY_CONNECT change */
390} 390}
391 391
392 392
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index 0297b4624..b3a971b96 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -752,7 +752,7 @@ testservice_task (void *cls,
752 ret = 1; 752 ret = 1;
753 return; 753 return;
754 } 754 }
755 GNUNET_TRANSPORT_try_connect (handle, &pid); 755 GNUNET_TRANSPORT_try_connect (handle, &pid, NULL, NULL); /*FIXME TRY_CONNECT change */
756 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 756 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
757 &operation_timeout, NULL); 757 &operation_timeout, NULL);
758 758
@@ -776,7 +776,7 @@ testservice_task (void *cls,
776 ret = 1; 776 ret = 1;
777 return; 777 return;
778 } 778 }
779 GNUNET_TRANSPORT_try_connect (handle, &pid); 779 GNUNET_TRANSPORT_try_connect (handle, &pid, NULL, NULL); /*FIXME TRY_CONNECT change */
780 start_time = GNUNET_TIME_absolute_get (); 780 start_time = GNUNET_TIME_absolute_get ();
781 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, 781 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
782 &operation_timeout, NULL); 782 &operation_timeout, NULL);
diff --git a/src/transport/test_transport_api_restart_1peer.c b/src/transport/test_transport_api_restart_1peer.c
index 5f8f97b75..9927946de 100644
--- a/src/transport/test_transport_api_restart_1peer.c
+++ b/src/transport/test_transport_api_restart_1peer.c
@@ -146,7 +146,7 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146 146
147 reconnect_task = GNUNET_SCHEDULER_NO_TASK; 147 reconnect_task = GNUNET_SCHEDULER_NO_TASK;
148 148
149 GNUNET_TRANSPORT_try_connect (p->th, &p2->id); 149 GNUNET_TRANSPORT_try_connect (p->th, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
150 reconnect_task = 150 reconnect_task =
151 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p); 151 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p);
152} 152}
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c
index bdf14744f..6e55f5734 100644
--- a/src/transport/test_transport_api_restart_2peers.c
+++ b/src/transport/test_transport_api_restart_2peers.c
@@ -138,7 +138,7 @@ reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138 struct PeerContext *p = cls; 138 struct PeerContext *p = cls;
139 139
140 reconnect_task = GNUNET_SCHEDULER_NO_TASK; 140 reconnect_task = GNUNET_SCHEDULER_NO_TASK;
141 GNUNET_TRANSPORT_try_connect (p1->th, &p2->id); 141 GNUNET_TRANSPORT_try_connect (p1->th, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
142 reconnect_task = 142 reconnect_task =
143 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p); 143 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p);
144} 144}
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 0c51ef334..32331d9d9 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -208,7 +208,7 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
208 GNUNET_TRANSPORT_offer_hello (cc->th_p1, 208 GNUNET_TRANSPORT_offer_hello (cc->th_p1,
209 (const struct GNUNET_MessageHeader *) cc-> 209 (const struct GNUNET_MessageHeader *) cc->
210 p2->hello, NULL, NULL); 210 p2->hello, NULL, NULL);
211 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id); 211 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
212 212
213 cc->tct = 213 cc->tct =
214 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, cc); 214 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, cc);
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index aa8db1474..768ed36da 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -187,6 +187,41 @@ struct GNUNET_TRANSPORT_GetHelloHandle
187 187
188}; 188};
189 189
190/**
191 * Linked list for all try-connect requests
192 */
193struct GNUNET_TRANSPORT_TryConnectHandle
194{
195 struct GNUNET_TRANSPORT_TryConnectHandle *prev;
196 struct GNUNET_TRANSPORT_TryConnectHandle *next;
197
198 struct GNUNET_PeerIdentity pid;
199
200 struct GNUNET_TRANSPORT_Handle *th;
201 struct GNUNET_TRANSPORT_TransmitHandle *tth;
202 GNUNET_TRANSPORT_TryConnectCallback cb;
203 void *cb_cls;
204};
205
206
207/**
208 * Linked list for all try-connect requests
209 */
210struct GNUNET_TRANSPORT_OfferHelloHandle
211{
212 struct GNUNET_TRANSPORT_OfferHelloHandle *prev;
213 struct GNUNET_TRANSPORT_OfferHelloHandle *next;
214
215 struct GNUNET_TRANSPORT_Handle *th;
216
217 struct GNUNET_TRANSPORT_TransmitHandle *tth;
218 GNUNET_SCHEDULER_Task cont;
219
220 void *cls;
221
222 struct GNUNET_MessageHeader *msg;
223};
224
190 225
191/** 226/**
192 * Handle for the transport service (includes all of the 227 * Handle for the transport service (includes all of the
@@ -252,6 +287,26 @@ struct GNUNET_TRANSPORT_Handle
252 struct GNUNET_TRANSPORT_GetHelloHandle *hwl_tail; 287 struct GNUNET_TRANSPORT_GetHelloHandle *hwl_tail;
253 288
254 /** 289 /**
290 * Linked list of pending try connect requests head
291 */
292 struct GNUNET_TRANSPORT_TryConnectHandle *tc_head;
293
294 /**
295 * Linked list of pending try connect requests tail
296 */
297 struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail;
298
299 /**
300 * Linked list of pending offer HELLO requests head
301 */
302 struct GNUNET_TRANSPORT_OfferHelloHandle *oh_head;
303
304 /**
305 * Linked list of pending offer HELLO requests tail
306 */
307 struct GNUNET_TRANSPORT_OfferHelloHandle *oh_tail;
308
309 /**
255 * My configuration. 310 * My configuration.
256 */ 311 */
257 const struct GNUNET_CONFIGURATION_Handle *cfg; 312 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -306,6 +361,7 @@ struct GNUNET_TRANSPORT_Handle
306}; 361};
307 362
308 363
364
309/** 365/**
310 * Schedule the task to send one message, either from the control 366 * Schedule the task to send one message, either from the control
311 * list or the peer message queues to the service. 367 * list or the peer message queues to the service.
@@ -830,8 +886,9 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
830 * @param size number of bytes to be transmitted 886 * @param size number of bytes to be transmitted
831 * @param notify function to call to get the content 887 * @param notify function to call to get the content
832 * @param notify_cls closure for notify 888 * @param notify_cls closure for notify
889 * @return a GNUNET_TRANSPORT_TransmitHandle
833 */ 890 */
834static void 891static struct GNUNET_TRANSPORT_TransmitHandle *
835schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size, 892schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
836 GNUNET_CONNECTION_TransmitReadyNotify notify, 893 GNUNET_CONNECTION_TransmitReadyNotify notify,
837 void *notify_cls) 894 void *notify_cls)
@@ -846,6 +903,7 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
846 th->notify_size = size; 903 th->notify_size = size;
847 GNUNET_CONTAINER_DLL_insert_tail (h->control_head, h->control_tail, th); 904 GNUNET_CONTAINER_DLL_insert_tail (h->control_head, h->control_tail, th);
848 schedule_transmission (h); 905 schedule_transmission (h);
906 return th;
849} 907}
850 908
851 909
@@ -961,6 +1019,26 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
961 1019
962 1020
963/** 1021/**
1022 * Cancel control request for transmission to the transport service.
1023 *
1024 * @param th handle to the transport service
1025 * @param tth transmit handle to cancel
1026 */
1027static void
1028cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th, struct GNUNET_TRANSPORT_TransmitHandle *tth)
1029{
1030 GNUNET_assert (NULL != th);
1031 GNUNET_assert (NULL != tth);
1032
1033 LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling transmit of contral transmission requested\n");
1034
1035 GNUNET_CONTAINER_DLL_remove (th->control_head, th->control_tail, tth);
1036 GNUNET_free (tth);
1037}
1038
1039
1040
1041/**
964 * Send REQUEST_CONNECT message to the service. 1042 * Send REQUEST_CONNECT message to the service.
965 * 1043 *
966 * @param cls the 'struct GNUNET_PeerIdentity' 1044 * @param cls the 'struct GNUNET_PeerIdentity'
@@ -971,24 +1049,30 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
971static size_t 1049static size_t
972send_try_connect (void *cls, size_t size, void *buf) 1050send_try_connect (void *cls, size_t size, void *buf)
973{ 1051{
974 struct GNUNET_PeerIdentity *pid = cls; 1052 struct GNUNET_TRANSPORT_TryConnectHandle *tch = cls;
975 struct TransportRequestConnectMessage msg; 1053 struct TransportRequestConnectMessage msg;
976 1054
977 if (buf == NULL) 1055 if (buf == NULL)
978 { 1056 {
979 GNUNET_free (pid); 1057 if (NULL != tch->cb)
1058 tch->cb (tch->cb_cls, GNUNET_SYSERR);
1059 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch);
1060 GNUNET_free (tch);
980 return 0; 1061 return 0;
981 } 1062 }
982 LOG (GNUNET_ERROR_TYPE_DEBUG, 1063 LOG (GNUNET_ERROR_TYPE_DEBUG,
983 "Transmitting `%s' request with respect to `%4s'.\n", "REQUEST_CONNECT", 1064 "Transmitting `%s' request with respect to `%4s'.\n", "REQUEST_CONNECT",
984 GNUNET_i2s (pid)); 1065 GNUNET_i2s (&tch->pid));
985 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); 1066 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
986 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); 1067 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
987 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); 1068 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
988 msg.reserved = htonl (0); 1069 msg.reserved = htonl (0);
989 msg.peer = *pid; 1070 msg.peer = tch->pid;
990 memcpy (buf, &msg, sizeof (msg)); 1071 memcpy (buf, &msg, sizeof (msg));
991 GNUNET_free (pid); 1072 if (NULL != tch->cb)
1073 tch->cb (tch->cb_cls, GNUNET_OK);
1074 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch);
1075 GNUNET_free (tch);
992 return sizeof (struct TransportRequestConnectMessage); 1076 return sizeof (struct TransportRequestConnectMessage);
993} 1077}
994 1078
@@ -998,40 +1082,52 @@ send_try_connect (void *cls, size_t size, void *buf)
998 * 1082 *
999 * @param handle connection to transport service 1083 * @param handle connection to transport service
1000 * @param target who we should try to connect to 1084 * @param target who we should try to connect to
1001 * @return GNUNET_OK if request can be scheduled 1085 * @param cb callback to be called when request was transmitted to transport
1002 * GNUNET_NO please retry later because we are reconnecting 1086 * service
1003 * GNUNET_SYSERR on failure 1087 * @return a GNUNET_TRANSPORT_TryConnectHandle handle or
1088 * NULL on failure (cb will not be called)
1004 */ 1089 */
1005int 1090struct GNUNET_TRANSPORT_TryConnectHandle *
1006GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, 1091GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1007 const struct GNUNET_PeerIdentity *target) 1092 const struct GNUNET_PeerIdentity *target,
1093 GNUNET_TRANSPORT_TryConnectCallback cb,
1094 void *cb_cls)
1008{ 1095{
1009 struct GNUNET_PeerIdentity *pid; 1096 struct GNUNET_TRANSPORT_TryConnectHandle *tch = NULL;
1010 if (NULL == handle->client)
1011 {
1012 if (GNUNET_SCHEDULER_NO_TASK == handle->reconnect_task)
1013 return GNUNET_SYSERR; /* this should never happen */
1014 else
1015 return GNUNET_NO; /* please retry */
1016 }
1017 1097
1018 pid = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 1098 if (NULL == handle->client)
1019 *pid = *target; 1099 return NULL;
1020 schedule_control_transmit (handle, 1100
1101 tch = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TryConnectHandle));
1102 tch->th = handle;
1103 tch->pid = *(target);
1104 tch->cb = cb;
1105 tch->cb_cls = cb_cls;
1106 tch->tth = schedule_control_transmit (handle,
1021 sizeof (struct TransportRequestConnectMessage), 1107 sizeof (struct TransportRequestConnectMessage),
1022 &send_try_connect, pid); 1108 &send_try_connect, tch);
1023 return GNUNET_OK; 1109 GNUNET_CONTAINER_DLL_insert(handle->tc_head, handle->tc_tail, tch);
1110 return tch;
1024} 1111}
1025 1112
1026 1113
1027struct SendHelloContext 1114/**
1115 * Cancel the request to transport to try a connect
1116 * Callback will not be called
1117 *
1118 * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel
1119 */
1120void
1121GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch)
1028{ 1122{
1029 GNUNET_SCHEDULER_Task cont; 1123 struct GNUNET_TRANSPORT_Handle *th;
1124 GNUNET_assert (NULL != tch);
1030 1125
1031 void *cls; 1126 th = tch->th;
1032 1127 cancel_control_transmit (th, tch->tth);
1033 struct GNUNET_MessageHeader *msg; 1128 GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch);
1034}; 1129 GNUNET_free (tch);
1130}
1035 1131
1036/** 1132/**
1037 * Send HELLO message to the service. 1133 * Send HELLO message to the service.
@@ -1044,8 +1140,8 @@ struct SendHelloContext
1044static size_t 1140static size_t
1045send_hello (void *cls, size_t size, void *buf) 1141send_hello (void *cls, size_t size, void *buf)
1046{ 1142{
1047 struct SendHelloContext *shc = cls; 1143 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls;
1048 struct GNUNET_MessageHeader *msg = shc->msg; 1144 struct GNUNET_MessageHeader *msg = ohh->msg;
1049 uint16_t ssize; 1145 uint16_t ssize;
1050 struct GNUNET_SCHEDULER_TaskContext tc; 1146 struct GNUNET_SCHEDULER_TaskContext tc;
1051 tc.read_ready = NULL; 1147 tc.read_ready = NULL;
@@ -1056,10 +1152,11 @@ send_hello (void *cls, size_t size, void *buf)
1056 { 1152 {
1057 LOG (GNUNET_ERROR_TYPE_DEBUG, 1153 LOG (GNUNET_ERROR_TYPE_DEBUG,
1058 "Timeout while trying to transmit `%s' request.\n", "HELLO"); 1154 "Timeout while trying to transmit `%s' request.\n", "HELLO");
1059 if (NULL != shc->cont) 1155 if (NULL != ohh->cont)
1060 shc->cont (shc->cls, &tc); 1156 ohh->cont (ohh->cls, &tc);
1061 GNUNET_free (msg); 1157 GNUNET_free (msg);
1062 GNUNET_free (shc); 1158 GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head, ohh->th->oh_tail, ohh);
1159 GNUNET_free (ohh);
1063 return 0; 1160 return 0;
1064 } 1161 }
1065 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "HELLO"); 1162 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "HELLO");
@@ -1068,9 +1165,10 @@ send_hello (void *cls, size_t size, void *buf)
1068 memcpy (buf, msg, ssize); 1165 memcpy (buf, msg, ssize);
1069 GNUNET_free (msg); 1166 GNUNET_free (msg);
1070 tc.reason = GNUNET_SCHEDULER_REASON_READ_READY; 1167 tc.reason = GNUNET_SCHEDULER_REASON_READ_READY;
1071 if (NULL != shc->cont) 1168 if (NULL != ohh->cont)
1072 shc->cont (shc->cls, &tc); 1169 ohh->cont (ohh->cls, &tc);
1073 GNUNET_free (shc); 1170 GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head, ohh->th->oh_tail, ohh);
1171 GNUNET_free (ohh);
1074 return ssize; 1172 return ssize;
1075} 1173}
1076 1174
@@ -1086,29 +1184,26 @@ send_hello (void *cls, size_t size, void *buf)
1086 * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail 1184 * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail
1087 * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success 1185 * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success
1088 * @param cls closure for continuation 1186 * @param cls closure for continuation
1187 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure,
1188 * in case of failure cont will not be called
1089 * 1189 *
1090 */ 1190 */
1091void 1191struct GNUNET_TRANSPORT_OfferHelloHandle *
1092GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, 1192GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1093 const struct GNUNET_MessageHeader *hello, 1193 const struct GNUNET_MessageHeader *hello,
1094 GNUNET_SCHEDULER_Task cont, void *cls) 1194 GNUNET_SCHEDULER_Task cont, void *cls)
1095{ 1195{
1096 uint16_t size; 1196 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
1097 struct GNUNET_PeerIdentity peer;
1098 struct GNUNET_MessageHeader *msg; 1197 struct GNUNET_MessageHeader *msg;
1099 struct SendHelloContext * shc; 1198 struct GNUNET_PeerIdentity peer;
1100 struct GNUNET_SCHEDULER_TaskContext tc; 1199 uint16_t size;
1101 1200
1102 tc.read_ready = NULL; 1201 GNUNET_assert (NULL != handle);
1103 tc.write_ready = NULL; 1202 GNUNET_assert (NULL != hello);
1104 tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
1105 1203
1106 if (NULL == handle->client) 1204 if (NULL == handle->client)
1107 { 1205 return NULL;
1108 if (NULL != cont) 1206
1109 cont (cls, &tc);
1110 return;
1111 }
1112 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); 1207 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1113 size = ntohs (hello->size); 1208 size = ntohs (hello->size);
1114 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader)); 1209 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
@@ -1116,25 +1211,46 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1116 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer)) 1211 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer))
1117 { 1212 {
1118 GNUNET_break (0); 1213 GNUNET_break (0);
1119 if (NULL != cont) 1214 return NULL;
1120 if (NULL != cont)
1121 cont (cls, &tc);
1122 return;
1123 } 1215 }
1216
1124 msg = GNUNET_malloc (size); 1217 msg = GNUNET_malloc (size);
1125 memcpy (msg, hello, size); 1218 memcpy (msg, hello, size);
1126 LOG (GNUNET_ERROR_TYPE_DEBUG, 1219 LOG (GNUNET_ERROR_TYPE_DEBUG,
1127 "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO", 1220 "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO",
1128 GNUNET_i2s (&peer)); 1221 GNUNET_i2s (&peer));
1129 shc = GNUNET_malloc (sizeof (struct SendHelloContext)); 1222
1130 shc->msg = msg; 1223 ohh = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_OfferHelloHandle));
1131 shc->cont = cont; 1224 ohh->th = handle;
1132 shc->cls = cls; 1225 ohh->cont = cont;
1133 schedule_control_transmit (handle, size, &send_hello, shc); 1226 ohh->cls = cls;
1227 ohh->msg = msg;
1228 ohh->tth = schedule_control_transmit (handle, size, &send_hello, ohh);
1229 GNUNET_CONTAINER_DLL_insert (handle->oh_head, handle->oh_tail, ohh);
1230 return ohh;
1134} 1231}
1135 1232
1136 1233
1137/** 1234/**
1235 * Cancel the request to transport to offer the HELLO message
1236 *
1237 * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
1238 */
1239void
1240GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
1241{
1242 struct GNUNET_TRANSPORT_Handle *th = ohh->th;
1243 GNUNET_assert (NULL != ohh);
1244
1245 cancel_control_transmit (ohh->th, ohh->tth);
1246 GNUNET_CONTAINER_DLL_remove (th->oh_head, th->oh_tail, ohh);
1247 GNUNET_free (ohh->msg);
1248 GNUNET_free (ohh);
1249}
1250
1251
1252
1253/**
1138 * Obtain the HELLO message for this peer. 1254 * Obtain the HELLO message for this peer.
1139 * 1255 *
1140 * @param handle connection to transport service 1256 * @param handle connection to transport service
@@ -1254,6 +1370,8 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1254 } 1370 }
1255 GNUNET_free_non_null (handle->my_hello); 1371 GNUNET_free_non_null (handle->my_hello);
1256 handle->my_hello = NULL; 1372 handle->my_hello = NULL;
1373 GNUNET_assert (handle->tc_head == NULL);
1374 GNUNET_assert (handle->tc_tail == NULL);
1257 GNUNET_assert (handle->hwl_head == NULL); 1375 GNUNET_assert (handle->hwl_head == NULL);
1258 GNUNET_assert (handle->hwl_tail == NULL); 1376 GNUNET_assert (handle->hwl_tail == NULL);
1259 GNUNET_CONTAINER_heap_destroy (handle->ready_heap); 1377 GNUNET_CONTAINER_heap_destroy (handle->ready_heap);