diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-07-27 07:28:18 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-07-27 07:28:18 +0000 |
commit | e8fac5ff0ff5dece01bdfd51a57a2af7b4117d52 (patch) | |
tree | 19a68ad459c01ef59dd77c9dc28cdc2bd371d65c /src/vpn | |
parent | 98760f1bfe7a96e87f762c6948825f12ab9bb736 (diff) | |
download | gnunet-e8fac5ff0ff5dece01bdfd51a57a2af7b4117d52.tar.gz gnunet-e8fac5ff0ff5dece01bdfd51a57a2af7b4117d52.zip |
queue transmits to tunnels
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-daemon-exit.c | 100 | ||||
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 67 | ||||
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 167 |
3 files changed, 287 insertions, 47 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index d12c59d20..cf9f58be3 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c | |||
@@ -150,6 +150,14 @@ struct redirect_state | |||
150 | static struct GNUNET_CONTAINER_MultiHashMap *udp_services; | 150 | static struct GNUNET_CONTAINER_MultiHashMap *udp_services; |
151 | static struct GNUNET_CONTAINER_MultiHashMap *tcp_services; | 151 | static struct GNUNET_CONTAINER_MultiHashMap *tcp_services; |
152 | 152 | ||
153 | struct tunnel_notify_queue | ||
154 | { | ||
155 | struct tunnel_notify_queue* next; | ||
156 | struct tunnel_notify_queue* prev; | ||
157 | void* cls; | ||
158 | size_t len; | ||
159 | }; | ||
160 | |||
153 | /** | 161 | /** |
154 | * Function that frees everything from a hashmap | 162 | * Function that frees everything from a hashmap |
155 | */ | 163 | */ |
@@ -223,11 +231,37 @@ hash_redirect_info(GNUNET_HashCode* hash, struct redirect_info* u_i, size_t addr | |||
223 | static size_t | 231 | static size_t |
224 | send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) | 232 | send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) |
225 | { | 233 | { |
226 | struct GNUNET_MessageHeader *hdr = cls; | 234 | struct GNUNET_MESH_Tunnel** tunnel = cls; |
235 | GNUNET_MESH_tunnel_set_data(*tunnel, NULL); | ||
236 | struct GNUNET_MessageHeader *hdr = (struct GNUNET_MessageHeader*)(tunnel + 1); | ||
227 | GNUNET_assert (size >= ntohs (hdr->size)); | 237 | GNUNET_assert (size >= ntohs (hdr->size)); |
228 | memcpy (buf, hdr, ntohs (hdr->size)); | 238 | memcpy (buf, hdr, ntohs (hdr->size)); |
229 | size = ntohs(hdr->size); | 239 | size = ntohs(hdr->size); |
230 | GNUNET_free (cls); | 240 | GNUNET_free (cls); |
241 | |||
242 | if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) | ||
243 | { | ||
244 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
245 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
246 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | ||
247 | |||
248 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | ||
249 | |||
250 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | ||
251 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | ||
252 | |||
253 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, | ||
254 | GNUNET_NO, | ||
255 | 42, | ||
256 | GNUNET_TIME_relative_divide | ||
257 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | ||
258 | (const struct GNUNET_PeerIdentity *) | ||
259 | NULL, element->len, | ||
260 | send_udp_to_peer_notify_callback, element->cls); | ||
261 | /* save the handle */ | ||
262 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | ||
263 | } | ||
264 | |||
231 | return size; | 265 | return size; |
232 | } | 266 | } |
233 | 267 | ||
@@ -301,7 +335,9 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
301 | len = | 335 | len = |
302 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + | 336 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + |
303 | ntohs (udp->len); | 337 | ntohs (udp->len); |
304 | msg = GNUNET_malloc (len); | 338 | struct GNUNET_MESH_Tunnel** ctunnel = GNUNET_malloc (sizeof(struct GNUNET_MESH_TUNNEL*) + len); |
339 | *ctunnel = tunnel; | ||
340 | msg = (struct GNUNET_MessageHeader*)(ctunnel + 1); | ||
305 | msg->size = htons (len); | 341 | msg->size = htons (len); |
306 | msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK : GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK); | 342 | msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK : GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK); |
307 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); | 343 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); |
@@ -312,14 +348,33 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
312 | void *_udp = desc + 1; | 348 | void *_udp = desc + 1; |
313 | memcpy (_udp, udp, ntohs (udp->len)); | 349 | memcpy (_udp, udp, ntohs (udp->len)); |
314 | 350 | ||
315 | GNUNET_MESH_notify_transmit_ready (tunnel, | 351 | if (NULL == GNUNET_MESH_tunnel_get_data(tunnel)) |
316 | GNUNET_NO, | 352 | { |
317 | 42, | 353 | /* No notify is pending */ |
318 | GNUNET_TIME_relative_divide | 354 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (tunnel, |
319 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 355 | GNUNET_NO, |
320 | (const struct GNUNET_PeerIdentity *) | 356 | 42, |
321 | NULL, len, | 357 | GNUNET_TIME_relative_divide |
322 | send_udp_to_peer_notify_callback, msg); | 358 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
359 | (const struct GNUNET_PeerIdentity *) | ||
360 | NULL, len, | ||
361 | send_udp_to_peer_notify_callback, ctunnel); | ||
362 | /* save the handle */ | ||
363 | GNUNET_MESH_tunnel_set_data(tunnel, th); | ||
364 | } | ||
365 | else | ||
366 | { | ||
367 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(tunnel); | ||
368 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(tunnel); | ||
369 | |||
370 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | ||
371 | element->cls = ctunnel; | ||
372 | element->len = len; | ||
373 | |||
374 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
375 | GNUNET_MESH_tunnel_set_head(tunnel, head); | ||
376 | GNUNET_MESH_tunnel_set_tail(tunnel, tail); | ||
377 | } | ||
323 | } | 378 | } |
324 | 379 | ||
325 | /** | 380 | /** |
@@ -378,7 +433,9 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
378 | len = | 433 | len = |
379 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen; | 434 | sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen; |
380 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen); | 435 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen); |
381 | msg = GNUNET_malloc (len); | 436 | struct GNUNET_MESH_Tunnel** ctunnel = GNUNET_malloc (sizeof(struct GNUNET_MESH_TUNNEL*) + len); |
437 | *ctunnel = tunnel; | ||
438 | msg = (struct GNUNET_MessageHeader*)(ctunnel + 1); | ||
382 | msg->size = htons (len); | 439 | msg->size = htons (len); |
383 | msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK : GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK); | 440 | msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK : GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK); |
384 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); | 441 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); |
@@ -389,14 +446,31 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
389 | void *_tcp = desc + 1; | 446 | void *_tcp = desc + 1; |
390 | memcpy (_tcp, tcp, pktlen); | 447 | memcpy (_tcp, tcp, pktlen); |
391 | 448 | ||
392 | GNUNET_MESH_notify_transmit_ready (tunnel, | 449 | if (NULL == GNUNET_MESH_tunnel_get_data(tunnel)) |
450 | { | ||
451 | /* No notify is pending */ | ||
452 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (tunnel, | ||
393 | GNUNET_NO, | 453 | GNUNET_NO, |
394 | 42, | 454 | 42, |
395 | GNUNET_TIME_relative_divide | 455 | GNUNET_TIME_relative_divide |
396 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 456 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
397 | (const struct GNUNET_PeerIdentity *)NULL, | 457 | (const struct GNUNET_PeerIdentity *)NULL, |
398 | len, send_udp_to_peer_notify_callback, | 458 | len, send_udp_to_peer_notify_callback, |
399 | msg); | 459 | ctunnel); |
460 | /* save the handle */ | ||
461 | GNUNET_MESH_tunnel_set_data(tunnel, th); | ||
462 | } | ||
463 | else | ||
464 | { | ||
465 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(tunnel); | ||
466 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(tunnel); | ||
467 | |||
468 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | ||
469 | element->cls = ctunnel; | ||
470 | element->len = len; | ||
471 | |||
472 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
473 | } | ||
400 | } | 474 | } |
401 | 475 | ||
402 | 476 | ||
diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 9ff43cd7f..ece7b554a 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c | |||
@@ -45,6 +45,14 @@ struct GNUNET_MESH_Handle *mesh_handle; | |||
45 | struct GNUNET_CONTAINER_MultiHashMap* hashmap; | 45 | struct GNUNET_CONTAINER_MultiHashMap* hashmap; |
46 | static struct GNUNET_CONTAINER_Heap *heap; | 46 | static struct GNUNET_CONTAINER_Heap *heap; |
47 | 47 | ||
48 | struct tunnel_notify_queue | ||
49 | { | ||
50 | struct tunnel_notify_queue* next; | ||
51 | struct tunnel_notify_queue* prev; | ||
52 | size_t len; | ||
53 | void* cls; | ||
54 | }; | ||
55 | |||
48 | /** | 56 | /** |
49 | * If there are at least this many address-mappings, old ones will be removed | 57 | * If there are at least this many address-mappings, old ones will be removed |
50 | */ | 58 | */ |
@@ -185,6 +193,7 @@ static size_t | |||
185 | send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) | 193 | send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) |
186 | { | 194 | { |
187 | struct GNUNET_MESH_Tunnel **tunnel = cls; | 195 | struct GNUNET_MESH_Tunnel **tunnel = cls; |
196 | GNUNET_MESH_tunnel_set_data(*tunnel, NULL); | ||
188 | struct GNUNET_MessageHeader *hdr = | 197 | struct GNUNET_MessageHeader *hdr = |
189 | (struct GNUNET_MessageHeader *) (tunnel + 1); | 198 | (struct GNUNET_MessageHeader *) (tunnel + 1); |
190 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, size); | 199 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "send_pkt_to_peer_notify_callback: buf = %x; size = %u;\n", buf, size); |
@@ -193,6 +202,30 @@ send_pkt_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
193 | size = ntohs(hdr->size); | 202 | size = ntohs(hdr->size); |
194 | GNUNET_free (cls); | 203 | GNUNET_free (cls); |
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); | 204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent!\n"); |
205 | |||
206 | if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) | ||
207 | { | ||
208 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
209 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
210 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | ||
211 | |||
212 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | ||
213 | |||
214 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | ||
215 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | ||
216 | |||
217 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, | ||
218 | GNUNET_NO, | ||
219 | 42, | ||
220 | GNUNET_TIME_relative_divide | ||
221 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | ||
222 | (const struct GNUNET_PeerIdentity *) | ||
223 | NULL, element->len, | ||
224 | send_pkt_to_peer_notify_callback, element->cls); | ||
225 | /* save the handle */ | ||
226 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | ||
227 | } | ||
228 | |||
196 | return size; | 229 | return size; |
197 | } | 230 | } |
198 | 231 | ||
@@ -217,14 +250,32 @@ send_pkt_to_peer (void *cls, | |||
217 | GNUNET_assert(NULL != tunnel); | 250 | GNUNET_assert(NULL != tunnel); |
218 | GNUNET_assert(NULL != *tunnel); | 251 | GNUNET_assert(NULL != *tunnel); |
219 | 252 | ||
220 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 253 | if (NULL == GNUNET_MESH_tunnel_get_data(*tunnel)) |
221 | GNUNET_NO, | 254 | { |
222 | 42, | 255 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, |
223 | GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 256 | GNUNET_NO, |
224 | (const struct GNUNET_PeerIdentity *)NULL, | 257 | 42, |
225 | ntohs(hdr->size), | 258 | GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
226 | send_pkt_to_peer_notify_callback, | 259 | (const struct GNUNET_PeerIdentity *)NULL, |
227 | cls); | 260 | ntohs(hdr->size), |
261 | send_pkt_to_peer_notify_callback, | ||
262 | cls); | ||
263 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
268 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | ||
269 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof *element); | ||
270 | |||
271 | element->cls = cls; | ||
272 | element->len = ntohs(hdr->size); | ||
273 | |||
274 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
275 | |||
276 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | ||
277 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | ||
278 | } | ||
228 | } | 279 | } |
229 | 280 | ||
230 | /** | 281 | /** |
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index b2b123a15..c0ef1411d 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_getopt_lib.h" | 26 | #include "gnunet_getopt_lib.h" |
27 | #include "gnunet_service_lib.h" | 27 | #include "gnunet_service_lib.h" |
28 | #include <gnunet_constants.h> | ||
28 | #include "gnunet_network_lib.h" | 29 | #include "gnunet_network_lib.h" |
29 | #include "gnunet_os_lib.h" | 30 | #include "gnunet_os_lib.h" |
30 | #include "gnunet-service-dns-p.h" | 31 | #include "gnunet-service-dns-p.h" |
@@ -107,6 +108,15 @@ struct receive_dht_cls { | |||
107 | struct GNUNET_DHT_GetHandle* handle; | 108 | struct GNUNET_DHT_GetHandle* handle; |
108 | }; | 109 | }; |
109 | 110 | ||
111 | struct tunnel_notify_queue | ||
112 | { | ||
113 | struct tunnel_notify_queue* next; | ||
114 | struct tunnel_notify_queue* prev; | ||
115 | void* cls; | ||
116 | size_t len; | ||
117 | GNUNET_CONNECTION_TransmitReadyNotify cb; | ||
118 | }; | ||
119 | |||
110 | /** | 120 | /** |
111 | * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port. | 121 | * Hijack all outgoing DNS-Traffic but for traffic leaving "our" port. |
112 | */ | 122 | */ |
@@ -212,7 +222,8 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
212 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 222 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); |
213 | struct GNUNET_MessageHeader *hdr = buf; | 223 | struct GNUNET_MessageHeader *hdr = buf; |
214 | uint32_t *sz = cls; | 224 | uint32_t *sz = cls; |
215 | struct dns_pkt *dns = (struct dns_pkt *) (sz + 1); | 225 | struct GNUNET_MESH_Tunnel **tunnel = (struct GNUNET_MESH_Tunnel**)(sz+1); |
226 | struct dns_pkt *dns = (struct dns_pkt *) (tunnel + 1); | ||
216 | hdr->type = htons (GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS); | 227 | hdr->type = htons (GNUNET_MESSAGE_TYPE_REMOTE_ANSWER_DNS); |
217 | hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader)); | 228 | hdr->size = htons (*sz + sizeof (struct GNUNET_MessageHeader)); |
218 | 229 | ||
@@ -224,6 +235,28 @@ mesh_send_response (void *cls, size_t size, void *buf) | |||
224 | 235 | ||
225 | memcpy (hdr + 1, dns, *sz); | 236 | memcpy (hdr + 1, dns, *sz); |
226 | GNUNET_free (cls); | 237 | GNUNET_free (cls); |
238 | |||
239 | if (NULL != GNUNET_MESH_tunnel_get_head(*tunnel)) | ||
240 | { | ||
241 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
242 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(*tunnel); | ||
243 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(*tunnel); | ||
244 | |||
245 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | ||
246 | |||
247 | GNUNET_MESH_tunnel_set_head(*tunnel, head); | ||
248 | GNUNET_MESH_tunnel_set_tail(*tunnel, tail); | ||
249 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (*tunnel, | ||
250 | GNUNET_NO, | ||
251 | 42, | ||
252 | GNUNET_TIME_relative_divide | ||
253 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | ||
254 | (const struct GNUNET_PeerIdentity *) | ||
255 | NULL, element->len, | ||
256 | element->cb, element->cls); | ||
257 | /* save the handle */ | ||
258 | GNUNET_MESH_tunnel_set_data(*tunnel, th); | ||
259 | } | ||
227 | return ntohs (hdr->size); | 260 | return ntohs (hdr->size); |
228 | } | 261 | } |
229 | 262 | ||
@@ -231,6 +264,7 @@ static size_t | |||
231 | mesh_send (void *cls, size_t size, void *buf) | 264 | mesh_send (void *cls, size_t size, void *buf) |
232 | { | 265 | { |
233 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; | 266 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
267 | GNUNET_MESH_tunnel_set_data(cls_->tunnel, NULL); | ||
234 | 268 | ||
235 | GNUNET_assert(cls_->hdr.size <= size); | 269 | GNUNET_assert(cls_->hdr.size <= size); |
236 | 270 | ||
@@ -238,23 +272,74 @@ mesh_send (void *cls, size_t size, void *buf) | |||
238 | cls_->hdr.size = htons(cls_->hdr.size); | 272 | cls_->hdr.size = htons(cls_->hdr.size); |
239 | 273 | ||
240 | memcpy(buf, &cls_->hdr, size); | 274 | memcpy(buf, &cls_->hdr, size); |
275 | |||
276 | if (NULL != GNUNET_MESH_tunnel_get_head(cls_->tunnel)) | ||
277 | { | ||
278 | struct tunnel_notify_queue* element = GNUNET_MESH_tunnel_get_head(cls_->tunnel); | ||
279 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(cls_->tunnel); | ||
280 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(cls_->tunnel); | ||
281 | |||
282 | GNUNET_CONTAINER_DLL_remove(head, tail, element); | ||
283 | |||
284 | GNUNET_MESH_tunnel_set_head(cls_->tunnel, head); | ||
285 | GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail); | ||
286 | struct GNUNET_MESH_TransmitHandle* th = GNUNET_MESH_notify_transmit_ready (cls_->tunnel, | ||
287 | GNUNET_NO, | ||
288 | 42, | ||
289 | GNUNET_TIME_relative_divide | ||
290 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | ||
291 | (const struct GNUNET_PeerIdentity *) | ||
292 | NULL, element->len, | ||
293 | element->cb, element->cls); | ||
294 | /* save the handle */ | ||
295 | GNUNET_MESH_tunnel_set_data(cls_->tunnel, th); | ||
296 | } | ||
297 | |||
298 | GNUNET_free(cls); | ||
241 | return size; | 299 | return size; |
242 | } | 300 | } |
243 | 301 | ||
244 | 302 | ||
245 | void mesh_connect (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi __attribute__((unused))) { | 303 | void |
246 | if (NULL == peer) return; | 304 | mesh_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
247 | struct tunnel_cls *cls_ = (struct tunnel_cls*)cls; | 305 | const struct GNUNET_TRANSPORT_ATS_Information *atsi |
248 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s, sending query with id %d\n", GNUNET_i2s(peer), ntohs(cls_->dns.s.id)); | 306 | __attribute__ ((unused))) |
249 | 307 | { | |
250 | GNUNET_MESH_notify_transmit_ready(cls_->tunnel, | 308 | if (NULL == peer) |
251 | GNUNET_YES, | 309 | return; |
252 | 42, | 310 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; |
253 | GNUNET_TIME_UNIT_MINUTES, | 311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
254 | NULL, | 312 | "Connected to peer %s, sending query with id %d\n", |
255 | cls_->hdr.size, | 313 | GNUNET_i2s (peer), ntohs (cls_->dns.s.id)); |
256 | mesh_send, | 314 | |
257 | cls); | 315 | if (NULL == GNUNET_MESH_tunnel_get_data (cls_->tunnel)) |
316 | { | ||
317 | struct GNUNET_MESH_TransmitHandle *th = | ||
318 | GNUNET_MESH_notify_transmit_ready (cls_->tunnel, | ||
319 | GNUNET_YES, | ||
320 | 42, | ||
321 | GNUNET_TIME_UNIT_MINUTES, | ||
322 | NULL, | ||
323 | cls_->hdr.size, | ||
324 | mesh_send, | ||
325 | cls); | ||
326 | |||
327 | GNUNET_MESH_tunnel_set_data (cls_->tunnel, th); | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(cls_->tunnel); | ||
332 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(cls_->tunnel); | ||
333 | |||
334 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | ||
335 | element->cls = cls; | ||
336 | element->len = cls_->hdr.size; | ||
337 | element->cb = mesh_send; | ||
338 | |||
339 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
340 | GNUNET_MESH_tunnel_set_head(cls_->tunnel, head); | ||
341 | GNUNET_MESH_tunnel_set_tail(cls_->tunnel, tail); | ||
342 | } | ||
258 | } | 343 | } |
259 | 344 | ||
260 | 345 | ||
@@ -814,7 +899,9 @@ open_port () | |||
814 | * Read a response-packet of the UDP-Socket | 899 | * Read a response-packet of the UDP-Socket |
815 | */ | 900 | */ |
816 | static void | 901 | static void |
817 | read_response (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_TaskContext *tc) | 902 | read_response (void *cls |
903 | __attribute__ ((unused)), | ||
904 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
818 | { | 905 | { |
819 | struct sockaddr_in addr; | 906 | struct sockaddr_in addr; |
820 | socklen_t addrlen = sizeof (addr); | 907 | socklen_t addrlen = sizeof (addr); |
@@ -859,14 +946,42 @@ read_response (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_ | |||
859 | { | 946 | { |
860 | if (query_states[dns->s.id].tunnel != NULL) | 947 | if (query_states[dns->s.id].tunnel != NULL) |
861 | { | 948 | { |
862 | uint32_t *c = GNUNET_malloc(4 + r); | 949 | /* This response should go through a tunnel */ |
950 | uint32_t *c = GNUNET_malloc (4 + sizeof(struct GNUNET_MESH_Tunnel*) + r); | ||
863 | *c = r; | 951 | *c = r; |
864 | memcpy(c+1, dns, r); | 952 | struct GNUNET_MESH_Tunnel** t = (struct GNUNET_MESH_Tunnel**)(c + 1); |
865 | GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, | 953 | *t = query_states[dns->s.id].tunnel; |
866 | GNUNET_YES, | 954 | memcpy (t + 1, dns, r); |
867 | 32, | 955 | if (NULL == |
868 | GNUNET_TIME_UNIT_MINUTES, | 956 | GNUNET_MESH_tunnel_get_data (query_states[dns->s.id].tunnel)) |
869 | NULL, r + sizeof(struct GNUNET_MessageHeader), mesh_send_response, c); | 957 | { |
958 | struct GNUNET_MESH_TransmitHandle *th = | ||
959 | GNUNET_MESH_notify_transmit_ready (query_states[dns->s.id].tunnel, | ||
960 | GNUNET_YES, | ||
961 | 32, | ||
962 | GNUNET_TIME_UNIT_MINUTES, | ||
963 | NULL, | ||
964 | r + | ||
965 | sizeof (struct | ||
966 | GNUNET_MessageHeader), | ||
967 | mesh_send_response, c); | ||
968 | GNUNET_MESH_tunnel_set_data (query_states[dns->s.id].tunnel, | ||
969 | th); | ||
970 | } | ||
971 | else | ||
972 | { | ||
973 | struct tunnel_notify_queue* head = GNUNET_MESH_tunnel_get_head(query_states[dns->s.id].tunnel); | ||
974 | struct tunnel_notify_queue* tail = GNUNET_MESH_tunnel_get_tail(query_states[dns->s.id].tunnel); | ||
975 | |||
976 | struct tunnel_notify_queue* element = GNUNET_malloc(sizeof(struct tunnel_notify_queue)); | ||
977 | element->cls = c; | ||
978 | element->len = r+sizeof(struct GNUNET_MessageHeader); | ||
979 | element->cb = mesh_send_response; | ||
980 | |||
981 | GNUNET_CONTAINER_DLL_insert_tail(head, tail, element); | ||
982 | GNUNET_MESH_tunnel_set_head(query_states[dns->s.id].tunnel, head); | ||
983 | GNUNET_MESH_tunnel_set_tail(query_states[dns->s.id].tunnel, tail); | ||
984 | } | ||
870 | } | 985 | } |
871 | else | 986 | else |
872 | { | 987 | { |
@@ -886,12 +1001,12 @@ read_response (void *cls __attribute__((unused)), const struct GNUNET_SCHEDULER_ | |||
886 | 1001 | ||
887 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); | 1002 | GNUNET_CONTAINER_DLL_insert_after (head, tail, tail, answer); |
888 | 1003 | ||
889 | GNUNET_SERVER_notify_transmit_ready (query_states[dns->s.id]. | 1004 | GNUNET_SERVER_notify_transmit_ready (query_states |
890 | client, len, | 1005 | [dns->s.id].client, len, |
891 | GNUNET_TIME_UNIT_FOREVER_REL, | 1006 | GNUNET_TIME_UNIT_FOREVER_REL, |
892 | &send_answer, | 1007 | &send_answer, |
893 | query_states[dns->s.id]. | 1008 | query_states[dns->s. |
894 | client); | 1009 | id].client); |
895 | } | 1010 | } |
896 | } | 1011 | } |
897 | } | 1012 | } |