diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-10-30 19:35:07 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-10-30 19:35:07 +0000 |
commit | c1e5a964f324a33a131b27e681ac8e354f8f0624 (patch) | |
tree | f925ff1fb47a12e68a71a167cd86de36e0b8084a /src/vpn | |
parent | e55adbf04c994c8e72afcd0f080e3f001c16823d (diff) | |
download | gnunet-c1e5a964f324a33a131b27e681ac8e354f8f0624.tar.gz gnunet-c1e5a964f324a33a131b27e681ac8e354f8f0624.zip |
gnunet-daemon-exit uses the new mesh
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/Makefile.am | 2 | ||||
-rw-r--r-- | src/vpn/gnunet-daemon-exit.c | 103 |
2 files changed, 56 insertions, 49 deletions
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 0c61aa904..5627773aa 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -64,7 +64,7 @@ gnunet_daemon_exit_LDADD = \ | |||
64 | $(top_builddir)/src/core/libgnunetcore.la \ | 64 | $(top_builddir)/src/core/libgnunetcore.la \ |
65 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 65 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
66 | $(top_builddir)/src/util/libgnunetutil.la \ | 66 | $(top_builddir)/src/util/libgnunetutil.la \ |
67 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | 67 | $(top_builddir)/src/mesh/libgnunetmeshnew.la \ |
68 | $(GN_LIBINTL) | 68 | $(GN_LIBINTL) |
69 | 69 | ||
70 | #check_PROGRAMS = \ | 70 | #check_PROGRAMS = \ |
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 8b7a8cff3..605071837 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <gnunet_program_lib.h> | 28 | #include <gnunet_program_lib.h> |
29 | #include <gnunet_protocols.h> | 29 | #include <gnunet_protocols.h> |
30 | #include <gnunet_applications.h> | 30 | #include <gnunet_applications.h> |
31 | #include <gnunet_mesh_service.h> | 31 | #include <gnunet_mesh_service_new.h> |
32 | #include <gnunet_constants.h> | 32 | #include <gnunet_constants.h> |
33 | #include <string.h> | 33 | #include <string.h> |
34 | 34 | ||
@@ -159,6 +159,13 @@ struct tunnel_notify_queue | |||
159 | size_t len; | 159 | size_t len; |
160 | }; | 160 | }; |
161 | 161 | ||
162 | struct tunnel_state | ||
163 | { | ||
164 | struct tunnel_notify_queue *head; | ||
165 | struct tunnel_notify_queue *tail; | ||
166 | struct GNUNET_MESH_TransmitHandle *th; | ||
167 | }; | ||
168 | |||
162 | /** | 169 | /** |
163 | * Function that frees everything from a hashmap | 170 | * Function that frees everything from a hashmap |
164 | */ | 171 | */ |
@@ -191,6 +198,27 @@ cleanup (void *cls | |||
191 | } | 198 | } |
192 | } | 199 | } |
193 | 200 | ||
201 | static void * | ||
202 | new_tunnel (void *cls __attribute__((unused)), | ||
203 | struct GNUNET_MESH_Tunnel *tunnel, | ||
204 | const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), | ||
205 | const struct GNUNET_ATS_Information *ats __attribute__((unused))) | ||
206 | { | ||
207 | struct tunnel_state *s = GNUNET_malloc(sizeof *s); | ||
208 | s->head = NULL; | ||
209 | s->tail = NULL; | ||
210 | s->th = NULL; | ||
211 | return s; | ||
212 | } | ||
213 | |||
214 | static void | ||
215 | clean_tunnel (void *cls __attribute__((unused)), | ||
216 | const struct GNUNET_MESH_Tunnel *tunnel, | ||
217 | void *tunnel_ctx) | ||
218 | { | ||
219 | GNUNET_free(tunnel_ctx); | ||
220 | } | ||
221 | |||
194 | static void | 222 | static void |
195 | collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 223 | collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
196 | { | 224 | { |
@@ -247,18 +275,17 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
247 | memcpy (buf, hdr, ntohs (hdr->size)); | 275 | memcpy (buf, hdr, ntohs (hdr->size)); |
248 | size = ntohs (hdr->size); | 276 | size = ntohs (hdr->size); |
249 | 277 | ||
250 | if (NULL != GNUNET_MESH_tunnel_get_head (*tunnel)) | 278 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); |
279 | |||
280 | if (NULL != s->head) | ||
251 | { | 281 | { |
252 | struct tunnel_notify_queue *element = GNUNET_MESH_tunnel_get_head (*tunnel); | 282 | struct tunnel_notify_queue *element = s->head; |
253 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (*tunnel); | 283 | struct tunnel_notify_queue *head = s->head; |
254 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (*tunnel); | 284 | struct tunnel_notify_queue *tail = s->tail; |
255 | 285 | ||
256 | GNUNET_CONTAINER_DLL_remove (head, tail, element); | 286 | GNUNET_CONTAINER_DLL_remove (head, tail, element); |
257 | 287 | ||
258 | GNUNET_MESH_tunnel_set_head (*tunnel, head); | 288 | s->th = |
259 | GNUNET_MESH_tunnel_set_tail (*tunnel, tail); | ||
260 | |||
261 | struct GNUNET_MESH_TransmitHandle *th = | ||
262 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 289 | GNUNET_MESH_notify_transmit_ready (*tunnel, |
263 | GNUNET_NO, | 290 | GNUNET_NO, |
264 | 42, | 291 | 42, |
@@ -270,7 +297,6 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
270 | element->cls); | 297 | element->cls); |
271 | 298 | ||
272 | /* save the handle */ | 299 | /* save the handle */ |
273 | GNUNET_MESH_tunnel_set_data (*tunnel, th); | ||
274 | GNUNET_free (element); | 300 | GNUNET_free (element); |
275 | } | 301 | } |
276 | 302 | ||
@@ -370,10 +396,11 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
370 | 396 | ||
371 | memcpy (_udp, udp, ntohs (udp->len)); | 397 | memcpy (_udp, udp, ntohs (udp->len)); |
372 | 398 | ||
373 | if (NULL == GNUNET_MESH_tunnel_get_data (tunnel)) | 399 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(tunnel); |
400 | if (NULL == s->th) | ||
374 | { | 401 | { |
375 | /* No notify is pending */ | 402 | /* No notify is pending */ |
376 | struct GNUNET_MESH_TransmitHandle *th = | 403 | s->th = |
377 | GNUNET_MESH_notify_transmit_ready (tunnel, | 404 | GNUNET_MESH_notify_transmit_ready (tunnel, |
378 | GNUNET_NO, | 405 | GNUNET_NO, |
379 | 42, | 406 | 42, |
@@ -383,14 +410,11 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
383 | NULL, len, | 410 | NULL, len, |
384 | send_udp_to_peer_notify_callback, | 411 | send_udp_to_peer_notify_callback, |
385 | ctunnel); | 412 | ctunnel); |
386 | |||
387 | /* save the handle */ | ||
388 | GNUNET_MESH_tunnel_set_data (tunnel, th); | ||
389 | } | 413 | } |
390 | else | 414 | else |
391 | { | 415 | { |
392 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (tunnel); | 416 | struct tunnel_notify_queue *head = s->head; |
393 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (tunnel); | 417 | struct tunnel_notify_queue *tail = s->tail; |
394 | 418 | ||
395 | struct tunnel_notify_queue *element = | 419 | struct tunnel_notify_queue *element = |
396 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); | 420 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
@@ -398,8 +422,6 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
398 | element->len = len; | 422 | element->len = len; |
399 | 423 | ||
400 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); | 424 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); |
401 | GNUNET_MESH_tunnel_set_head (tunnel, head); | ||
402 | GNUNET_MESH_tunnel_set_tail (tunnel, tail); | ||
403 | } | 425 | } |
404 | } | 426 | } |
405 | 427 | ||
@@ -484,10 +506,11 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
484 | 506 | ||
485 | memcpy (_tcp, tcp, pktlen); | 507 | memcpy (_tcp, tcp, pktlen); |
486 | 508 | ||
487 | if (NULL == GNUNET_MESH_tunnel_get_data (tunnel)) | 509 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); |
510 | if (NULL == s->th) | ||
488 | { | 511 | { |
489 | /* No notify is pending */ | 512 | /* No notify is pending */ |
490 | struct GNUNET_MESH_TransmitHandle *th = | 513 | s->th = |
491 | GNUNET_MESH_notify_transmit_ready (tunnel, | 514 | GNUNET_MESH_notify_transmit_ready (tunnel, |
492 | GNUNET_NO, | 515 | GNUNET_NO, |
493 | 42, | 516 | 42, |
@@ -498,14 +521,11 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
498 | len, | 521 | len, |
499 | send_udp_to_peer_notify_callback, | 522 | send_udp_to_peer_notify_callback, |
500 | ctunnel); | 523 | ctunnel); |
501 | |||
502 | /* save the handle */ | ||
503 | GNUNET_MESH_tunnel_set_data (tunnel, th); | ||
504 | } | 524 | } |
505 | else | 525 | else |
506 | { | 526 | { |
507 | struct tunnel_notify_queue *head = GNUNET_MESH_tunnel_get_head (tunnel); | 527 | struct tunnel_notify_queue *head = s->head; |
508 | struct tunnel_notify_queue *tail = GNUNET_MESH_tunnel_get_tail (tunnel); | 528 | struct tunnel_notify_queue *tail = s->tail; |
509 | 529 | ||
510 | struct tunnel_notify_queue *element = | 530 | struct tunnel_notify_queue *element = |
511 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); | 531 | GNUNET_malloc (sizeof (struct tunnel_notify_queue)); |
@@ -513,8 +533,6 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
513 | element->len = len; | 533 | element->len = len; |
514 | 534 | ||
515 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); | 535 | GNUNET_CONTAINER_DLL_insert_tail (head, tail, element); |
516 | GNUNET_MESH_tunnel_set_head (tunnel, head); | ||
517 | GNUNET_MESH_tunnel_set_tail (tunnel, tail); | ||
518 | } | 536 | } |
519 | } | 537 | } |
520 | 538 | ||
@@ -1025,9 +1043,7 @@ receive_tcp_service (void *cls | |||
1025 | __attribute__ ((unused)), | 1043 | __attribute__ ((unused)), |
1026 | const struct GNUNET_MessageHeader *message, | 1044 | const struct GNUNET_MessageHeader *message, |
1027 | const struct GNUNET_ATS_Information *atsi | 1045 | const struct GNUNET_ATS_Information *atsi |
1028 | __attribute__ ((unused)), | 1046 | __attribute__ ((unused))) |
1029 | unsigned int atsi_count | ||
1030 | __attribute__ ((unused))) | ||
1031 | { | 1047 | { |
1032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n"); | 1048 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TCP-Packet\n"); |
1033 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1049 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
@@ -1135,9 +1151,7 @@ receive_tcp_remote (void *cls | |||
1135 | __attribute__ ((unused)), | 1151 | __attribute__ ((unused)), |
1136 | const struct GNUNET_MessageHeader *message, | 1152 | const struct GNUNET_MessageHeader *message, |
1137 | const struct GNUNET_ATS_Information *atsi | 1153 | const struct GNUNET_ATS_Information *atsi |
1138 | __attribute__ ((unused)), | 1154 | __attribute__ ((unused))) |
1139 | unsigned int atsi_count | ||
1140 | __attribute__ ((unused))) | ||
1141 | { | 1155 | { |
1142 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1156 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1143 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); | 1157 | struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); |
@@ -1213,9 +1227,7 @@ receive_udp_remote (void *cls | |||
1213 | __attribute__ ((unused)), | 1227 | __attribute__ ((unused)), |
1214 | const struct GNUNET_MessageHeader *message, | 1228 | const struct GNUNET_MessageHeader *message, |
1215 | const struct GNUNET_ATS_Information *atsi | 1229 | const struct GNUNET_ATS_Information *atsi |
1216 | __attribute__ ((unused)), | 1230 | __attribute__ ((unused))) |
1217 | unsigned int atsi_count | ||
1218 | __attribute__ ((unused))) | ||
1219 | { | 1231 | { |
1220 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1232 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1221 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); | 1233 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); |
@@ -1287,17 +1299,12 @@ receive_udp_remote (void *cls | |||
1287 | * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt | 1299 | * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt |
1288 | */ | 1300 | */ |
1289 | static int | 1301 | static int |
1290 | receive_udp_service (void *cls | 1302 | receive_udp_service (void *cls __attribute__ ((unused)), |
1291 | __attribute__ ((unused)), | 1303 | struct GNUNET_MESH_Tunnel *tunnel, |
1292 | struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx | 1304 | void **tunnel_ctx, |
1293 | __attribute__ ((unused)), | 1305 | const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), |
1294 | const struct GNUNET_PeerIdentity *sender | ||
1295 | __attribute__ ((unused)), | ||
1296 | const struct GNUNET_MessageHeader *message, | 1306 | const struct GNUNET_MessageHeader *message, |
1297 | const struct GNUNET_ATS_Information *atsi | 1307 | const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) |
1298 | __attribute__ ((unused)), | ||
1299 | unsigned int atsi_count | ||
1300 | __attribute__ ((unused))) | ||
1301 | { | 1308 | { |
1302 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1309 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1303 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); | 1310 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); |
@@ -1438,7 +1445,7 @@ connect_to_mesh () | |||
1438 | app_idx++; | 1445 | app_idx++; |
1439 | } | 1446 | } |
1440 | 1447 | ||
1441 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, handlers, apptypes); | 1448 | mesh_handle = GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, apptypes); |
1442 | } | 1449 | } |
1443 | 1450 | ||
1444 | 1451 | ||