diff options
Diffstat (limited to 'src/vpn/gnunet-daemon-exit.c')
-rw-r--r-- | src/vpn/gnunet-daemon-exit.c | 178 |
1 files changed, 96 insertions, 82 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c index 45076250d..838893882 100644 --- a/src/vpn/gnunet-daemon-exit.c +++ b/src/vpn/gnunet-daemon-exit.c | |||
@@ -199,24 +199,26 @@ cleanup (void *cls | |||
199 | } | 199 | } |
200 | 200 | ||
201 | static void * | 201 | static void * |
202 | new_tunnel (void *cls __attribute__((unused)), | 202 | new_tunnel (void *cls |
203 | struct GNUNET_MESH_Tunnel *tunnel, | 203 | __attribute__ ((unused)), struct GNUNET_MESH_Tunnel *tunnel, |
204 | const struct GNUNET_PeerIdentity *initiator __attribute__((unused)), | 204 | const struct GNUNET_PeerIdentity *initiator |
205 | const struct GNUNET_ATS_Information *ats __attribute__((unused))) | 205 | __attribute__ ((unused)), const struct GNUNET_ATS_Information *ats |
206 | __attribute__ ((unused))) | ||
206 | { | 207 | { |
207 | struct tunnel_state *s = GNUNET_malloc(sizeof *s); | 208 | struct tunnel_state *s = GNUNET_malloc (sizeof *s); |
208 | s->head = NULL; | 209 | |
209 | s->tail = NULL; | 210 | s->head = NULL; |
210 | s->th = NULL; | 211 | s->tail = NULL; |
211 | return s; | 212 | s->th = NULL; |
213 | return s; | ||
212 | } | 214 | } |
213 | 215 | ||
214 | static void | 216 | static void |
215 | clean_tunnel (void *cls __attribute__((unused)), | 217 | clean_tunnel (void *cls |
216 | const struct GNUNET_MESH_Tunnel *tunnel, | 218 | __attribute__ ((unused)), const struct GNUNET_MESH_Tunnel *tunnel, |
217 | void *tunnel_ctx) | 219 | void *tunnel_ctx) |
218 | { | 220 | { |
219 | GNUNET_free(tunnel_ctx); | 221 | GNUNET_free (tunnel_ctx); |
220 | } | 222 | } |
221 | 223 | ||
222 | static void | 224 | static void |
@@ -236,7 +238,8 @@ collect_connections (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
236 | /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */ | 238 | /* FIXME! GNUNET_MESH_close_tunnel(state->tunnel); */ |
237 | 239 | ||
238 | GNUNET_assert (GNUNET_OK == | 240 | GNUNET_assert (GNUNET_OK == |
239 | GNUNET_CONTAINER_multihashmap_remove (state->hashmap, &state->hash, state)); | 241 | GNUNET_CONTAINER_multihashmap_remove (state->hashmap, |
242 | &state->hash, state)); | ||
240 | 243 | ||
241 | GNUNET_free (state); | 244 | GNUNET_free (state); |
242 | } | 245 | } |
@@ -275,7 +278,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
275 | memcpy (buf, hdr, ntohs (hdr->size)); | 278 | memcpy (buf, hdr, ntohs (hdr->size)); |
276 | size = ntohs (hdr->size); | 279 | size = ntohs (hdr->size); |
277 | 280 | ||
278 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(*tunnel); | 281 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (*tunnel); |
279 | 282 | ||
280 | if (NULL != s->head) | 283 | if (NULL != s->head) |
281 | { | 284 | { |
@@ -284,9 +287,7 @@ send_udp_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
284 | GNUNET_CONTAINER_DLL_remove (s->head, s->tail, element); | 287 | GNUNET_CONTAINER_DLL_remove (s->head, s->tail, element); |
285 | 288 | ||
286 | s->th = | 289 | s->th = |
287 | GNUNET_MESH_notify_transmit_ready (*tunnel, | 290 | GNUNET_MESH_notify_transmit_ready (*tunnel, GNUNET_NO, 42, |
288 | GNUNET_NO, | ||
289 | 42, | ||
290 | GNUNET_TIME_relative_divide | 291 | GNUNET_TIME_relative_divide |
291 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 292 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
292 | (const struct GNUNET_PeerIdentity *) | 293 | (const struct GNUNET_PeerIdentity *) |
@@ -394,14 +395,13 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen) | |||
394 | 395 | ||
395 | memcpy (_udp, udp, ntohs (udp->len)); | 396 | memcpy (_udp, udp, ntohs (udp->len)); |
396 | 397 | ||
397 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data(tunnel); | 398 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); |
399 | |||
398 | if (NULL == s->th) | 400 | if (NULL == s->th) |
399 | { | 401 | { |
400 | /* No notify is pending */ | 402 | /* No notify is pending */ |
401 | s->th = | 403 | s->th = |
402 | GNUNET_MESH_notify_transmit_ready (tunnel, | 404 | GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42, |
403 | GNUNET_NO, | ||
404 | 42, | ||
405 | GNUNET_TIME_relative_divide | 405 | GNUNET_TIME_relative_divide |
406 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 406 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
407 | (const struct GNUNET_PeerIdentity *) | 407 | (const struct GNUNET_PeerIdentity *) |
@@ -502,18 +502,16 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen, | |||
502 | memcpy (_tcp, tcp, pktlen); | 502 | memcpy (_tcp, tcp, pktlen); |
503 | 503 | ||
504 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); | 504 | struct tunnel_state *s = GNUNET_MESH_tunnel_get_data (tunnel); |
505 | |||
505 | if (NULL == s->th) | 506 | if (NULL == s->th) |
506 | { | 507 | { |
507 | /* No notify is pending */ | 508 | /* No notify is pending */ |
508 | s->th = | 509 | s->th = |
509 | GNUNET_MESH_notify_transmit_ready (tunnel, | 510 | GNUNET_MESH_notify_transmit_ready (tunnel, GNUNET_NO, 42, |
510 | GNUNET_NO, | ||
511 | 42, | ||
512 | GNUNET_TIME_relative_divide | 511 | GNUNET_TIME_relative_divide |
513 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), | 512 | (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2), |
514 | (const struct GNUNET_PeerIdentity *) | 513 | (const struct GNUNET_PeerIdentity *) |
515 | NULL, | 514 | NULL, len, |
516 | len, | ||
517 | send_udp_to_peer_notify_callback, | 515 | send_udp_to_peer_notify_callback, |
518 | ctunnel); | 516 | ctunnel); |
519 | } | 517 | } |
@@ -684,44 +682,57 @@ read_service_conf (void *cls __attribute__ ((unused)), const char *section) | |||
684 | } | 682 | } |
685 | else | 683 | else |
686 | { | 684 | { |
687 | struct addrinfo* res; | 685 | struct addrinfo *res; |
688 | 686 | ||
689 | int ret = getaddrinfo(hostname, NULL, NULL, &res); | 687 | int ret = getaddrinfo (hostname, NULL, NULL, &res); |
690 | 688 | ||
691 | if (ret != 0) | 689 | if (ret != 0) |
690 | { | ||
691 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", | ||
692 | hostname); | ||
693 | GNUNET_free (serv); | ||
694 | continue; | ||
695 | } | ||
696 | else | ||
697 | { | ||
698 | char buf[256]; | ||
699 | struct addrinfo *c = res; | ||
700 | |||
701 | if (c) | ||
692 | { | 702 | { |
693 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No addresses found for %s!\n", hostname); | 703 | if (c->ai_family == AF_INET) |
694 | GNUNET_free (serv); | 704 | { |
695 | continue; | 705 | serv->version = 4; |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
707 | "Found %s as address for %s\n", | ||
708 | inet_ntop (c->ai_family, | ||
709 | &((struct sockaddr_in *) (c-> | ||
710 | ai_addr))->sin_addr, | ||
711 | (char *) &buf, 256), hostname); | ||
712 | memcpy (serv->v4.ip4address, | ||
713 | &((struct sockaddr_in *) (c->ai_addr))->sin_addr, 4); | ||
714 | } | ||
715 | else if (c->ai_family == AF_INET6) | ||
716 | { | ||
717 | serv->version = 6; | ||
718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
719 | "Found %s as address for %s\n", | ||
720 | inet_ntop (c->ai_family, | ||
721 | &((struct sockaddr_in6 *) (c-> | ||
722 | ai_addr))->sin6_addr, | ||
723 | (char *) &buf, 256), hostname); | ||
724 | memcpy (serv->v6.ip6address, | ||
725 | &((struct sockaddr_in6 *) (c->ai_addr))->sin6_addr, 16); | ||
726 | } | ||
696 | } | 727 | } |
697 | else | 728 | else |
698 | { | 729 | { |
699 | char buf[256]; | 730 | freeaddrinfo (res); |
700 | struct addrinfo* c = res; | 731 | GNUNET_free (serv); |
701 | 732 | continue; | |
702 | if(c) | ||
703 | { | ||
704 | if (c->ai_family == AF_INET) | ||
705 | { | ||
706 | serv->version = 4; | ||
707 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, (char*)&buf, 256), hostname); | ||
708 | memcpy(serv->v4.ip4address, &((struct sockaddr_in *)(c->ai_addr))->sin_addr, 4); | ||
709 | } | ||
710 | else if (c->ai_family == AF_INET6) | ||
711 | { | ||
712 | serv->version = 6; | ||
713 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Found %s as address for %s\n", inet_ntop(c->ai_family, &((struct sockaddr_in6*)(c->ai_addr))->sin6_addr, (char*)&buf, 256), hostname); | ||
714 | memcpy(serv->v6.ip6address, &((struct sockaddr_in6 *)(c->ai_addr))->sin6_addr, 16); | ||
715 | } | ||
716 | } | ||
717 | else | ||
718 | { | ||
719 | freeaddrinfo(res); | ||
720 | GNUNET_free (serv); | ||
721 | continue; | ||
722 | } | ||
723 | freeaddrinfo(res); | ||
724 | } | 733 | } |
734 | freeaddrinfo (res); | ||
735 | } | ||
725 | } | 736 | } |
726 | serv->remote_port = atoi (hostport); | 737 | serv->remote_port = atoi (hostport); |
727 | if (UDP == proto) | 738 | if (UDP == proto) |
@@ -1095,14 +1106,12 @@ receive_tcp_service (void *cls | |||
1095 | switch (serv->version) | 1106 | switch (serv->version) |
1096 | { | 1107 | { |
1097 | case 4: | 1108 | case 4: |
1098 | prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, | 1109 | prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v4.ip4address, |
1099 | &serv->v4.ip4address, tunnel, state, | 1110 | tunnel, state, (struct ip_pkt *) buf); |
1100 | (struct ip_pkt *) buf); | ||
1101 | break; | 1111 | break; |
1102 | case 6: | 1112 | case 6: |
1103 | prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, | 1113 | prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &serv->v6.ip6address, |
1104 | &serv->v6.ip6address, tunnel, state, | 1114 | tunnel, state, (struct ip6_pkt *) buf); |
1105 | (struct ip6_pkt *) buf); | ||
1106 | 1115 | ||
1107 | break; | 1116 | break; |
1108 | default: | 1117 | default: |
@@ -1171,12 +1180,12 @@ receive_tcp_remote (void *cls | |||
1171 | switch (s->addrlen) | 1180 | switch (s->addrlen) |
1172 | { | 1181 | { |
1173 | case 4: | 1182 | case 4: |
1174 | prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, | 1183 | prepare_ipv4_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel, |
1175 | &s->addr, tunnel, state, (struct ip_pkt *) buf); | 1184 | state, (struct ip_pkt *) buf); |
1176 | break; | 1185 | break; |
1177 | case 16: | 1186 | case 16: |
1178 | prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, | 1187 | prepare_ipv6_packet (len, pkt_len, pkt, IPPROTO_TCP, &s->addr, tunnel, |
1179 | &s->addr, tunnel, state, (struct ip6_pkt *) buf); | 1188 | state, (struct ip6_pkt *) buf); |
1180 | break; | 1189 | break; |
1181 | default: | 1190 | default: |
1182 | GNUNET_free (state); | 1191 | GNUNET_free (state); |
@@ -1252,12 +1261,12 @@ receive_udp_remote (void *cls | |||
1252 | switch (s->addrlen) | 1261 | switch (s->addrlen) |
1253 | { | 1262 | { |
1254 | case 4: | 1263 | case 4: |
1255 | prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, | 1264 | prepare_ipv4_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr, |
1256 | &s->addr, tunnel, state, (struct ip_pkt *) buf); | 1265 | tunnel, state, (struct ip_pkt *) buf); |
1257 | break; | 1266 | break; |
1258 | case 16: | 1267 | case 16: |
1259 | prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, | 1268 | prepare_ipv6_packet (len, ntohs (pkt->len), pkt, IPPROTO_UDP, &s->addr, |
1260 | &s->addr, tunnel, state, (struct ip6_pkt *) buf); | 1269 | tunnel, state, (struct ip6_pkt *) buf); |
1261 | break; | 1270 | break; |
1262 | default: | 1271 | default: |
1263 | GNUNET_assert (0); | 1272 | GNUNET_assert (0); |
@@ -1291,12 +1300,14 @@ receive_udp_remote (void *cls | |||
1291 | * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt | 1300 | * The messages are one GNUNET_HashCode for the service, followed by a struct udp_pkt |
1292 | */ | 1301 | */ |
1293 | static int | 1302 | static int |
1294 | receive_udp_service (void *cls __attribute__ ((unused)), | 1303 | receive_udp_service (void *cls |
1295 | struct GNUNET_MESH_Tunnel *tunnel, | 1304 | __attribute__ ((unused)), |
1296 | void **tunnel_ctx, | 1305 | struct GNUNET_MESH_Tunnel *tunnel, void **tunnel_ctx, |
1297 | const struct GNUNET_PeerIdentity *sender __attribute__ ((unused)), | 1306 | const struct GNUNET_PeerIdentity *sender |
1307 | __attribute__ ((unused)), | ||
1298 | const struct GNUNET_MessageHeader *message, | 1308 | const struct GNUNET_MessageHeader *message, |
1299 | const struct GNUNET_ATS_Information *atsi __attribute__ ((unused))) | 1309 | const struct GNUNET_ATS_Information *atsi |
1310 | __attribute__ ((unused))) | ||
1300 | { | 1311 | { |
1301 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); | 1312 | GNUNET_HashCode *desc = (GNUNET_HashCode *) (message + 1); |
1302 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); | 1313 | struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); |
@@ -1437,7 +1448,9 @@ connect_to_mesh () | |||
1437 | app_idx++; | 1448 | app_idx++; |
1438 | } | 1449 | } |
1439 | 1450 | ||
1440 | mesh_handle = GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, apptypes); | 1451 | mesh_handle = |
1452 | GNUNET_MESH_connect (cfg, 42, NULL, new_tunnel, clean_tunnel, handlers, | ||
1453 | apptypes); | ||
1441 | } | 1454 | } |
1442 | 1455 | ||
1443 | 1456 | ||
@@ -1468,11 +1481,11 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile | |||
1468 | 1481 | ||
1469 | if (GNUNET_OK != | 1482 | if (GNUNET_OK != |
1470 | GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_UDP_CONNECTIONS", | 1483 | GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_UDP_CONNECTIONS", |
1471 | &max_udp_connections)) | 1484 | &max_udp_connections)) |
1472 | max_udp_connections = 1024; | 1485 | max_udp_connections = 1024; |
1473 | if (GNUNET_OK != | 1486 | if (GNUNET_OK != |
1474 | GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS", | 1487 | GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_TCP_CONNECTIONS", |
1475 | &max_tcp_connections)) | 1488 | &max_tcp_connections)) |
1476 | max_tcp_connections = 256; | 1489 | max_tcp_connections = 256; |
1477 | GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL); | 1490 | GNUNET_CONFIGURATION_iterate_sections (cfg, read_service_conf, NULL); |
1478 | GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL); | 1491 | GNUNET_SCHEDULER_add_now (start_helper_and_schedule, NULL); |
@@ -1481,7 +1494,7 @@ run (void *cls, char *const *args __attribute__ ((unused)), const char *cfgfile | |||
1481 | 1494 | ||
1482 | 1495 | ||
1483 | /** | 1496 | /** |
1484 | * The main function | 1497 | * The main function |
1485 | * | 1498 | * |
1486 | * @param argc number of arguments from the command line | 1499 | * @param argc number of arguments from the command line |
1487 | * @param argv command line arguments | 1500 | * @param argv command line arguments |
@@ -1495,8 +1508,9 @@ main (int argc, char *const *argv) | |||
1495 | }; | 1508 | }; |
1496 | 1509 | ||
1497 | return (GNUNET_OK == | 1510 | return (GNUNET_OK == |
1498 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit", | 1511 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-exit", |
1499 | gettext_noop ("Daemon to run to provide an IP exit node for the VPN"), | 1512 | gettext_noop |
1513 | ("Daemon to run to provide an IP exit node for the VPN"), | ||
1500 | options, &run, NULL)) ? ret : 1; | 1514 | options, &run, NULL)) ? ret : 1; |
1501 | } | 1515 | } |
1502 | 1516 | ||