GNUnet 0.28.0-dev.2-27-gc87478450
 
Loading...
Searching...
No Matches
gnunet-daemon-pt.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012, 2017 Christian Grothoff
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_dns_service.h"
29#include "gnunet_dht_service.h"
30#include "gnunet_vpn_service.h"
32#include "gnunet_applications.h"
33#include "block_dns.h"
34
35
39#define TIMEOUT GNUNET_TIME_UNIT_MINUTES
40
48#define MAX_DNS_SIZE (8 * 1024)
49
53#define MAX_OPEN_TUNNELS 4
54
55
81
82
118
119
126{
131
136
142
147
152
157
162
166 unsigned int num_transmitted;
167
171 unsigned int num_answered;
172
176 /* unsigned */ int idle;
177};
178
179
184{
189
194
199
204
209
214
218 uint16_t mlen;
219
223 uint16_t dns_id;
224};
225
226
232static struct CadetExit *exit_head;
233
237static struct CadetExit *exit_tail;
238
242static const struct GNUNET_CONFIGURATION_Handle *cfg;
243
248
253
258
263
268
272static struct GNUNET_DHT_Handle *dht;
273
278
282static int ipv4_pt;
283
287static int ipv6_pt;
288
292static int dns_channel;
293
299static unsigned int dns_exit_available;
300
301
305static void
306try_open_exit (void);
307
308
318static uint32_t
320{
321 uint32_t dropped;
322 uint32_t drop_percent;
323 uint32_t good_percent;
324
326 dropped = exit->num_transmitted - exit->num_answered;
327 if (exit->num_transmitted > 0)
328 drop_percent = (uint32_t) ((100LL * dropped) / exit->num_transmitted);
329 else
330 drop_percent = 50; /* no data */
331 if ((exit->num_transmitted > 20) &&
332 (drop_percent > 25))
333 return 0; /* statistically significant, and > 25% loss, die */
334 good_percent = 100 - drop_percent;
335 GNUNET_assert (0 != good_percent);
336 if (UINT32_MAX / good_percent / good_percent < exit->num_transmitted)
337 return UINT32_MAX; /* formula below would overflow */
338 return 1 + good_percent * good_percent * exit->num_transmitted;
339}
340
341
353static struct CadetExit *
355{
356 struct CadetExit *pos;
357 uint64_t total_transmitted;
358 uint64_t selected_offset;
359 uint32_t channel_weight;
360
361 total_transmitted = 0;
362 for (pos = exit_head; NULL != pos; pos = pos->next)
363 {
364 if (NULL == pos->cadet_channel)
365 break;
366 channel_weight = get_channel_weight (pos);
367 total_transmitted += channel_weight;
368 /* double weight for idle channels */
369 if (0 != pos->idle)
370 total_transmitted += channel_weight;
371 }
372 if (0 == total_transmitted)
373 {
374 /* no channels available, or only a very bad one... */
375 return exit_head;
376 }
377 selected_offset = GNUNET_CRYPTO_random_u64 (total_transmitted);
378 total_transmitted = 0;
379 for (pos = exit_head; NULL != pos; pos = pos->next)
380 {
381 if (NULL == pos->cadet_channel)
382 break;
383 channel_weight = get_channel_weight (pos);
384 total_transmitted += channel_weight;
385 /* double weight for idle channels */
386 if (0 != pos->idle)
387 total_transmitted += channel_weight;
388 if (total_transmitted > selected_offset)
389 return pos;
390 }
391 GNUNET_break (0);
392 return NULL;
393}
394
395
402static void
404{
405 char *buf;
406 size_t buf_len;
407
408 if (GNUNET_SYSERR ==
411 &buf,
412 &buf_len))
413 {
415 _ ("Failed to pack DNS request. Dropping.\n"));
417 }
418 else
419 {
421 gettext_noop ("# DNS requests mapped to VPN"),
422 1, GNUNET_NO);
424 buf_len,
425 buf);
426 GNUNET_free (buf);
427 }
429 GNUNET_free (rc);
430}
431
432
440static void
441submit_request (struct ReplyContext *rc);
442
443
459static void
461 int af,
462 const void *address)
463{
464 struct ReplyContext *rc = cls;
465
466 rc->rr = NULL;
467 if (af == AF_UNSPEC)
468 {
471 GNUNET_free (rc);
472 return;
473 }
475 gettext_noop ("# DNS records modified"),
476 1,
477 GNUNET_NO);
478 switch (rc->rec->type)
479 {
481 GNUNET_assert (AF_INET == af);
483 address,
484 sizeof(struct in_addr));
485 break;
486
488 GNUNET_assert (AF_INET6 == af);
490 address,
491 sizeof(struct in6_addr));
492 break;
493
494 default:
495 GNUNET_assert (0);
496 return;
497 }
498 rc->rec = NULL;
499 submit_request (rc);
500}
501
502
512static void
515{
516 int af;
517
518 switch (rec->type)
519 {
521 af = AF_INET;
522 GNUNET_assert (rec->data.raw.data_len == sizeof(struct in_addr));
523 break;
524
526 af = AF_INET6;
527 GNUNET_assert (rec->data.raw.data_len == sizeof(struct in6_addr));
528 break;
529
530 default:
531 GNUNET_assert (0);
532 return;
533 }
534 rc->rec = rec;
536 af,
537 af,
538 rec->data.raw.data,
540 TIMEOUT),
542 rc);
543}
544
545
553static void
555{
556 struct GNUNET_DNSPARSER_Record *ra;
557 unsigned int ra_len;
558 unsigned int i;
559
560 while (1)
561 {
562 switch (rc->group)
563 {
564 case ANSWERS:
565 ra = rc->dns->answers;
566 ra_len = rc->dns->num_answers;
567 break;
568
570 ra = rc->dns->authority_records;
571 ra_len = rc->dns->num_authority_records;
572 break;
573
575 ra = rc->dns->additional_records;
576 ra_len = rc->dns->num_additional_records;
577 break;
578
579 case END:
580 finish_request (rc);
581 return;
582
583 default:
584 GNUNET_assert (0);
585 }
586 for (i = rc->offset; i < ra_len; i++)
587 {
588 switch (ra[i].type)
589 {
591 if (ipv4_pt)
592 {
593 rc->offset = i + 1;
594 modify_address (rc,
595 &ra[i]);
596 return;
597 }
598 break;
599
601 if (ipv6_pt)
602 {
603 rc->offset = i + 1;
604 modify_address (rc,
605 &ra[i]);
606 return;
607 }
608 break;
609 }
610 }
611 rc->group++;
612 }
613}
614
615
623static int
625 unsigned int ra_len)
626{
627 unsigned int i;
628
629 for (i = 0; i < ra_len; i++)
630 {
631 switch (ra[i].type)
632 {
634 if (ipv4_pt)
635 return GNUNET_YES;
636 break;
637
639 if (ipv6_pt)
640 return GNUNET_YES;
641 break;
642 }
643 }
644 return GNUNET_NO;
645}
646
647
659static void
661 struct GNUNET_DNS_RequestHandle *rh,
662 size_t request_length,
663 const char *request)
664{
665 struct GNUNET_DNSPARSER_Packet *dns;
666 struct ReplyContext *rc;
667 int work;
668
670 gettext_noop ("# DNS replies intercepted"),
671 1, GNUNET_NO);
673 request_length);
674 if (NULL == dns)
675 {
677 _ ("Failed to parse DNS request. Dropping.\n"));
679 return;
680 }
681 work = GNUNET_NO;
688 if (! work)
689 {
692 return;
693 }
694 rc = GNUNET_new (struct ReplyContext);
695 rc->rh = rh;
696 rc->dns = dns;
697 rc->offset = 0;
698 rc->group = ANSWERS;
699 submit_request (rc);
700}
701
702
708static void
710{
711 struct RequestContext *rc = cls;
712 struct CadetExit *exit = rc->exit;
713
715 gettext_noop ("# DNS requests dropped (timeout)"),
716 1,
717 GNUNET_NO);
719 GNUNET_free (rc);
720 if ((0 == get_channel_weight (exit)) &&
721 (NULL == exit->receive_queue_head))
722 {
723 /* this straw broke the camel's back: this channel now has
724 such a low score that it will not be used; close it! */
726 exit->cadet_channel = NULL;
728 exit_tail,
729 exit);
731 exit_tail,
732 exit);
733 /* go back to semi-innocent: mark as not great, but
734 avoid a prohibitively negative score (see
735 #get_channel_weight(), which checks for a certain
736 minimum number of transmissions before making
737 up an opinion) */exit->num_transmitted = 5;
738 exit->num_answered = 0;
740 /* now try to open an alternative exit */
741 try_open_exit ();
742 }
743}
744
745
757static void
759 struct GNUNET_DNS_RequestHandle *rh,
760 size_t request_length,
761 const char *request)
762{
763 struct RequestContext *rc;
764 struct GNUNET_MQ_Envelope *env;
765 struct GNUNET_MessageHeader *hdr;
766 struct GNUNET_TUN_DnsHeader dns;
767 struct CadetExit *exit;
768
770 gettext_noop ("# DNS requests intercepted"),
771 1, GNUNET_NO);
772 if (0 == dns_exit_available)
773 {
776 "# DNS requests dropped (DNS cadet channel down)"),
777 1, GNUNET_NO);
779 return;
780 }
781 if (request_length < sizeof(dns))
782 {
785 "# DNS requests dropped (malformed)"),
786 1, GNUNET_NO);
788 return;
789 }
790 exit = choose_exit ();
791 GNUNET_assert (NULL != exit);
792 GNUNET_assert (NULL != exit->cadet_channel);
793
795 request_length,
797 GNUNET_memcpy (&hdr[1],
798 request,
799 request_length);
800 rc = GNUNET_new (struct RequestContext);
801 rc->exit = exit;
802 rc->rh = rh;
805 rc);
806 GNUNET_memcpy (&dns,
807 request,
808 sizeof(dns));
809 rc->dns_id = dns.id;
810 rc->env = env;
812 exit->receive_queue_tail,
813 rc);
814 if (0 < exit->idle)
815 exit->idle--;
816 exit->num_transmitted++;
819}
820
821
823
828{
833
838
839 /* Followed by more DNS payload */
840};
841
843
852static int
854 const struct DnsResponseMessage *msg)
855{
856 return GNUNET_OK; /* all OK */
857}
858
859
866static void
868 const struct DnsResponseMessage *msg)
869{
870 struct CadetExit *exit = cls;
871 size_t mlen;
872 struct RequestContext *rc;
873
874 mlen = ntohs (msg->header.size) - sizeof(*msg);
875 for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next)
876 {
877 if (msg->dns.id == rc->dns_id)
878 {
880 gettext_noop ("# DNS replies received"),
881 1,
882 GNUNET_NO);
884 mlen + sizeof(struct GNUNET_TUN_DnsHeader),
885 (const void *) &msg->dns);
888 rc);
891 GNUNET_free (rc);
893 return;
894 }
895 }
897 gettext_noop ("# DNS replies dropped (too late?)"),
898 1, GNUNET_NO);
899}
900
901
907static void
909{
910 struct RequestContext *rc;
911
912 while (NULL != (rc = exit->receive_queue_head))
913 {
916 rc);
920 GNUNET_free (rc);
921 }
922}
923
924
930static void
931cleanup (void *cls)
932{
933 struct CadetExit *exit;
934
936 "Protocol translation daemon is shutting down now\n");
937 if (NULL != vpn_handle)
938 {
940 vpn_handle = NULL;
941 }
942 while (NULL != (exit = exit_head))
943 {
945 exit_tail,
946 exit);
947 if (NULL != exit->cadet_channel)
948 {
950 exit->cadet_channel = NULL;
951 }
952 abort_all_requests (exit);
953 GNUNET_free (exit);
954 }
955 if (NULL != cadet_handle)
956 {
958 cadet_handle = NULL;
959 }
960 if (NULL != dns_post_handle)
961 {
963 dns_post_handle = NULL;
964 }
965 if (NULL != dns_pre_handle)
966 {
968 dns_pre_handle = NULL;
969 }
970 if (NULL != stats)
971 {
973 stats = NULL;
974 }
975 if (NULL != dht_get)
976 {
978 dht_get = NULL;
979 }
980 if (NULL != dht)
981 {
983 dht = NULL;
984 }
985}
986
987
999static void
1001 const struct GNUNET_CADET_Channel *channel)
1002{
1003 struct CadetExit *exit = cls;
1004 struct CadetExit *alt;
1005 struct RequestContext *rc;
1006
1007 exit->cadet_channel = NULL;
1009 /* open alternative channels */
1010 /* our channel is now closed, move our requests to an alternative
1011 channel */
1012 alt = choose_exit ();
1013 while (NULL != (rc = exit->receive_queue_head))
1014 {
1017 rc);
1018 rc->exit = alt;
1020 alt->receive_queue_tail,
1021 rc);
1023 GNUNET_MQ_env_copy (rc->env));
1024 }
1025 try_open_exit ();
1026}
1027
1028
1036static void
1038 const struct GNUNET_CADET_Channel *channel,
1039 int window_size)
1040{
1041 struct CadetExit *pos = cls;
1042
1043 pos->idle = window_size;
1044}
1045
1046
1050static void
1052{
1053 struct CadetExit *pos;
1054 uint32_t candidate_count;
1055 uint32_t candidate_selected;
1056 struct GNUNET_HashCode port;
1057
1060 &port);
1061 candidate_count = 0;
1062 for (pos = exit_head; NULL != pos; pos = pos->next)
1063 if (NULL == pos->cadet_channel)
1064 candidate_count++;
1065 if (0 == candidate_count)
1066 {
1068 "No DNS exits available yet.\n");
1069 return;
1070 }
1071 candidate_selected = GNUNET_CRYPTO_random_u32 (candidate_count);
1072 candidate_count = 0;
1073 for (pos = exit_head; NULL != pos; pos = pos->next)
1074 if (NULL == pos->cadet_channel)
1075 {
1076 candidate_count++;
1077 if (candidate_selected < candidate_count)
1078 {
1079 struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
1080 GNUNET_MQ_hd_var_size (dns_response,
1082 struct DnsResponseMessage,
1083 pos),
1085 };
1086
1087
1088 /* move to the head of the DLL */
1089 pos->cadet_channel
1091 pos,
1092 &pos->peer,
1093 &port,
1096 cadet_handlers);
1097 if (NULL == pos->cadet_channel)
1098 {
1099 GNUNET_break (0);
1100 continue;
1101 }
1103 exit_tail,
1104 pos);
1106 exit_tail,
1107 pos);
1109 return;
1110 }
1111 }
1112 GNUNET_assert (NULL == exit_head);
1113}
1114
1115
1136static void
1138 struct GNUNET_TIME_Absolute exp,
1139 const struct GNUNET_HashCode *key,
1140 const struct GNUNET_PeerIdentity *trunc_peer,
1141 const struct GNUNET_DHT_PathElement *get_path,
1142 unsigned int get_path_length,
1143 const struct GNUNET_DHT_PathElement *put_path,
1144 unsigned int put_path_length,
1146 size_t size, const void *data)
1147{
1148 const struct GNUNET_DNS_Advertisement *ad;
1149 struct CadetExit *exit;
1150
1151 if (sizeof(struct GNUNET_DNS_Advertisement) != size)
1152 {
1153 GNUNET_break (0);
1154 return;
1155 }
1156 ad = data;
1157 for (exit = exit_head; NULL != exit; exit = exit->next)
1158 if (0 == GNUNET_memcmp (&ad->peer,
1159 &exit->peer))
1160 break;
1161 if (NULL == exit)
1162 {
1163 exit = GNUNET_new (struct CadetExit);
1164 exit->peer = ad->peer;
1165 /* channel is closed, so insert at the end */
1167 exit_tail,
1168 exit);
1169 }
1172 ad->expiration_time));
1174 try_open_exit ();
1175}
1176
1177
1186static void
1187run (void *cls, char *const *args GNUNET_UNUSED,
1188 const char *cfgfile GNUNET_UNUSED,
1189 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1190{
1191 struct GNUNET_HashCode dns_key;
1192
1193 cfg = cfg_;
1195 cfg);
1197 "pt",
1198 "TUNNEL_IPV4");
1200 "pt",
1201 "TUNNEL_IPV6");
1203 "pt",
1204 "TUNNEL_DNS");
1205 if (! (ipv4_pt || ipv6_pt || dns_channel))
1206 {
1208 _ ("No useful service enabled. Exiting.\n"));
1210 return;
1211 }
1213 if (ipv4_pt || ipv6_pt)
1214 {
1219 NULL);
1220 if (NULL == dns_post_handle)
1221 {
1223 _ ("Failed to connect to %s service. Exiting.\n"),
1224 "DNS");
1226 return;
1227 }
1229 if (NULL == vpn_handle)
1230 {
1232 _ ("Failed to connect to %s service. Exiting.\n"),
1233 "VPN");
1235 return;
1236 }
1237 }
1238 if (dns_channel)
1239 {
1244 NULL);
1245 if (NULL == dns_pre_handle)
1246 {
1248 _ ("Failed to connect to %s service. Exiting.\n"),
1249 "DNS");
1251 return;
1252 }
1254 if (NULL == cadet_handle)
1255 {
1257 _ ("Failed to connect to %s service. Exiting.\n"),
1258 "CADET");
1260 return;
1261 }
1262 dht = GNUNET_DHT_connect (cfg, 1);
1263 if (NULL == dht)
1264 {
1266 _ ("Failed to connect to %s service. Exiting.\n"),
1267 "DHT");
1269 return;
1270 }
1271 GNUNET_CRYPTO_hash ("dns",
1272 strlen ("dns"),
1273 &dns_key);
1276 &dns_key,
1277 1,
1279 NULL, 0,
1281 NULL);
1282 }
1283}
1284
1285
1293int
1294main (int argc,
1295 char *const *argv)
1296{
1297 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1299 };
1300 int ret;
1301
1302 ret = (GNUNET_OK ==
1304 argc,
1305 argv,
1306 "gnunet-daemon-pt",
1307 gettext_noop (
1308 "Daemon to run to perform IP protocol translation to GNUnet"),
1309 options,
1310 &run,
1311 NULL))
1312 ? 0
1313 : 1;
1314 return ret;
1315}
1316
1317
1318/* end of gnunet-daemon-pt.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
DNS network structs.
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static int ret
Final status code.
Definition gnunet-arm.c:93
static void work(void *cls)
Function called to process work items.
static uint16_t port
Port number.
Definition gnunet-bcd.c:146
static char * address
GNS address for this phone.
static struct GNUNET_DNS_Handle * dns_pre_handle
The handle to DNS pre-resolution modifications.
static struct GNUNET_DHT_Handle * dht
Handle to access the DHT.
static void dns_pre_request_handler(void *cls, struct GNUNET_DNS_RequestHandle *rh, size_t request_length, const char *request)
This function is called before the DNS request has been given to a "local" DNS resolver.
static int ipv4_pt
Are we doing IPv4-pt?
static int work_test(const struct GNUNET_DNSPARSER_Record *ra, unsigned int ra_len)
Test if any of the given records need protocol-translation work.
static struct GNUNET_VPN_Handle * vpn_handle
The handle to the VPN.
#define TIMEOUT
After how long do we time out if we could not get an IP from VPN or CADET?
static struct GNUNET_DNS_Handle * dns_post_handle
The handle to DNS post-resolution modifications.
static void abort_all_requests(struct CadetExit *exit)
Abort all pending DNS requests with the given cadet exit.
static GNUNET_NETWORK_STRUCT_END int check_dns_response(void *cls, const struct DnsResponseMessage *msg)
Process a request via cadet to perform a DNS query.
static int ipv6_pt
Are we doing IPv6-pt?
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg_)
Main function that will be run by the scheduler.
static void modify_address(struct ReplyContext *rc, struct GNUNET_DNSPARSER_Record *rec)
Modify the given DNS record by asking VPN to create a channel to the given address.
static uint32_t get_channel_weight(struct CadetExit *exit)
Compute the weight of the given exit.
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
static int dns_channel
Are we channeling DNS queries?
static const struct GNUNET_CONFIGURATION_Handle * cfg
The handle to the configuration used throughout the process.
static void vpn_allocation_callback(void *cls, int af, const void *address)
Callback invoked from the VPN service once a redirection is available.
static struct CadetExit * exit_head
Head of DLL of cadet exits.
static struct CadetExit * choose_exit()
Choose a cadet exit for a DNS request.
static unsigned int dns_exit_available
Number of DNS exit peers we currently have in the cadet channel.
#define MAX_DNS_SIZE
How many bytes of payload do we allow at most for a DNS reply? Given that this is pretty much limited...
static void try_open_exit(void)
We are short on cadet exits, try to open another one.
static void channel_idle_notify_cb(void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
Function called whenever a channel has excess capacity.
static void submit_request(struct ReplyContext *rc)
Process the next record of the given request context.
static void handle_dht_result(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Function called whenever we find an advertisement for a DNS exit in the DHT.
static struct GNUNET_CADET_Handle * cadet_handle
The handle to the CADET service.
static void dns_post_request_handler(void *cls, struct GNUNET_DNS_RequestHandle *rh, size_t request_length, const char *request)
This function is called AFTER we got an IP address for a DNS request.
RequestGroup
Which group of DNS records are we currently processing?
@ ANSWERS
DNS answers.
@ ADDITIONAL_RECORDS
DNS additional records.
@ END
We're done processing.
@ AUTHORITY_RECORDS
DNS authority records.
#define MAX_OPEN_TUNNELS
How many channels do we open at most at the same time?
static void finish_request(struct ReplyContext *rc)
We're done modifying all records in the response.
static void handle_dns_response(void *cls, const struct DnsResponseMessage *msg)
Process a request via cadet to perform a DNS query.
static struct CadetExit * exit_tail
Tail of DLL of cadet exits.
static void cadet_channel_end_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever a channel is destroyed.
static struct GNUNET_DHT_GetHandle * dht_get
Our DHT GET operation to find DNS exits.
static struct GNUNET_TIME_Relative timeout_request
User supplied timeout value.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
unsigned long long drop_percent
Set to non-zero values to create random drops to test retransmissions.
static void cleanup()
Cleanup task.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition gnunet-vpn.c:40
Constants for network applications operating on top of the CADET service.
CADET service; establish channels to distant peers.
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_DNS
Block for storing DNS exit service advertisements.
API to the DHT service.
API to access the DNS service.
API to create, modify and access statistics.
API to access the VPN service.
#define GNUNET_APPLICATION_PORT_INTERNET_RESOLVER
Internet DNS resolution (external DNS gateway).
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition cadet_api.c:897
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition cadet_api.c:833
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected channel.
Definition cadet_api.c:1081
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition cadet_api.c:777
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
Definition cadet_api.c:1030
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
uint64_t GNUNET_CRYPTO_random_u64(uint64_t max)
Generate a random unsigned 64-bit value.
uint32_t GNUNET_CRYPTO_random_u32(uint32_t i)
Produce a random value.
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition dht_api.c:1036
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition dht_api.c:1238
struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
Perform an asynchronous GET operation on the DHT identified.
Definition dht_api.c:1165
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition dht_api.c:1058
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition dnsparser.c:967
#define GNUNET_DNSPARSER_TYPE_A
#define GNUNET_DNSPARSER_TYPE_AAAA
int GNUNET_DNSPARSER_pack(const struct GNUNET_DNSPARSER_Packet *p, uint16_t max, char **buf, size_t *buf_length)
Given a DNS packet p, generate the corresponding UDP payload.
Definition dnsparser.c:1417
struct GNUNET_DNSPARSER_Packet * GNUNET_DNSPARSER_parse(const char *udp_payload, size_t udp_payload_length)
Parse a UDP payload of a DNS packet in to a nice struct for further processing and manipulation.
Definition dnsparser.c:746
void GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh)
Disconnect from the DNS service.
Definition dns_api.c:363
void GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh)
If a GNUNET_DNS_RequestHandler calls this function, the client has no desire to interfere with the re...
Definition dns_api.c:237
void GNUNET_DNS_request_answer(struct GNUNET_DNS_RequestHandle *rh, uint16_t reply_length, const char *reply)
If a GNUNET_DNS_RequestHandler calls this function, the request is supposed to be answered with the d...
Definition dns_api.c:296
struct GNUNET_DNS_Handle * GNUNET_DNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_DNS_Flags flags, GNUNET_DNS_RequestHandler rh, void *rh_cls)
Connect to the service-dns.
Definition dns_api.c:340
void GNUNET_DNS_request_drop(struct GNUNET_DNS_RequestHandle *rh)
If a GNUNET_DNS_RequestHandler calls this function, the request is to be dropped and no response shou...
Definition dns_api.c:265
@ GNUNET_DNS_FLAG_PRE_RESOLUTION
This client should be called on requests that have not yet been resolved as this client provides a re...
@ GNUNET_DNS_FLAG_POST_RESOLUTION
This client wants to be called on the results of a DNS resolution (either resolved by PRE-RESOLUTION ...
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_log(kind,...)
void * cls
Closure for mv and cb.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_UNUSED
gcc-ism to document unused arguments
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
Definition mq.c:373
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition mq.c:285
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:406
#define GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET
Type of messages containing an DNS request for a DNS exit service.
#define GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET
Type of messages containing an DNS reply from a DNS exit service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1283
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the maximum of two absolute time values.
Definition time.c:368
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
Definition vpn_api.c:490
struct GNUNET_VPN_RedirectionRequest * GNUNET_VPN_redirect_to_ip(struct GNUNET_VPN_Handle *vh, int result_af, int addr_af, const void *addr, struct GNUNET_TIME_Absolute expiration_time, GNUNET_VPN_AllocationCallback cb, void *cb_cls)
Tell the VPN that forwarding to the Internet via some exit node is requested.
Definition vpn_api.c:439
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
Definition vpn_api.c:512
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
Handle to a peer that advertised that it is willing to serve as a DNS exit.
struct CadetExit * next
Kept in a DLL.
struct RequestContext * receive_queue_tail
Tail of DLL of requests waiting for a response.
struct CadetExit * prev
Kept in a DLL.
unsigned int num_answered
How many DNS requests were answered via this channel?
struct GNUNET_TIME_Absolute expiration
At what time did the peer's advertisement expire?
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialize a channel to this peer yet.
int idle
Size of the window, 0 if we are busy.
struct GNUNET_PeerIdentity peer
Identity of the peer that is providing the exit for us.
unsigned int num_transmitted
How many DNS requests did we transmit via this channel?
struct RequestContext * receive_queue_head
Head of DLL of requests waiting for a response.
Message with a DNS response.
struct GNUNET_MessageHeader header
GNUnet header, of type GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET.
struct GNUNET_TUN_DnsHeader dns
DNS header.
Opaque handle to a channel.
Definition cadet.h:116
Opaque handle to the service.
Definition cadet_api.c:39
Handle to a GET request.
Definition dht_api.c:79
Connection to the DHT service.
Definition dht_api.c:235
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
Easy-to-process, parsed version of a DNS packet.
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
void * data
Binary record data.
size_t data_len
Number of bytes in data.
A DNS response record.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
union GNUNET_DNSPARSER_Record::@24 data
Payload of the record (which one of these is valid depends on the 'type').
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
This is the structure describing an DNS exit service.
Definition block_dns.h:45
struct GNUNET_PeerIdentity peer
The peer providing this service.
Definition block_dns.h:65
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does this signature expire?
Definition block_dns.h:60
DNS handle.
Definition dns_api.c:57
Handle to identify an individual DNS request.
Definition dns_api.c:35
Definition of a command line option.
A 512-bit hashcode.
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:141
Handle for the service.
Time for absolute times used by GNUnet, in microseconds.
uint16_t id
Unique identifier for the request/response.
Opaque VPN handle.
Definition vpn_api.c:35
Opaque redirection request handle.
Definition vpn_api.c:77
Information tracked per DNS reply that we are processing.
struct GNUNET_DNS_RequestHandle * rh
Handle to submit the final result.
struct GNUNET_DNSPARSER_Packet * dns
DNS packet that is being modified.
unsigned int offset
Offset in the current record group that is being modified.
struct GNUNET_DNSPARSER_Record * rec
Record for which we have an active redirection request.
struct GNUNET_VPN_RedirectionRequest * rr
Active redirection request with the VPN.
enum RequestGroup group
Group that is being modified.
State we keep for a request that is going out via CADET.
struct GNUNET_SCHEDULER_Task * timeout_task
Task used to abort this operation with timeout.
struct RequestContext * next
We keep these in a DLL.
struct CadetExit * exit
Exit that was chosen for this request.
struct GNUNET_MQ_Envelope * env
Envelope with the request we are transmitting.
uint16_t mlen
Length of the request message that follows this struct.
struct GNUNET_DNS_RequestHandle * rh
Handle for interaction with DNS service.
struct RequestContext * prev
We keep these in a DLL.
uint16_t dns_id
ID of the original DNS request (used to match the reply).