GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions | Variables
gnunet-daemon-pt.c File Reference

tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_dns_service.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_cadet_service.h"
#include "gnunet_tun_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_vpn_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_applications.h"
#include "block_dns.h"
Include dependency graph for gnunet-daemon-pt.c:

Go to the source code of this file.

Data Structures

struct  ReplyContext
 Information tracked per DNS reply that we are processing. More...
 
struct  CadetExit
 Handle to a peer that advertised that it is willing to serve as a DNS exit. More...
 
struct  RequestContext
 State we keep for a request that is going out via CADET. More...
 
struct  DnsResponseMessage
 Message with a DNS response. More...
 

Macros

#define TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 After how long do we time out if we could not get an IP from VPN or CADET? More...
 
#define MAX_DNS_SIZE   (8 * 1024)
 How many bytes of payload do we allow at most for a DNS reply? Given that this is pretty much limited to loopback, we can be pretty high (Linux loopback defaults to 16k, most local UDP packets should survive up to 9k (NFS), so 8k should be pretty safe in general). More...
 
#define MAX_OPEN_TUNNELS   4
 How many channels do we open at most at the same time? More...
 

Enumerations

enum  RequestGroup { ANSWERS = 0, AUTHORITY_RECORDS = 1, ADDITIONAL_RECORDS = 2, END = 3 }
 Which group of DNS records are we currently processing? More...
 

Functions

static void try_open_exit (void)
 We are short on cadet exits, try to open another one. More...
 
static uint32_t get_channel_weight (struct CadetExit *exit)
 Compute the weight of the given exit. More...
 
static struct CadetExitchoose_exit ()
 Choose a cadet exit for a DNS request. More...
 
static void finish_request (struct ReplyContext *rc)
 We're done modifying all records in the response. More...
 
static void submit_request (struct ReplyContext *rc)
 Process the next record of the given request context. More...
 
static void vpn_allocation_callback (void *cls, int af, const void *address)
 Callback invoked from the VPN service once a redirection is available. More...
 
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. More...
 
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. More...
 
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. More...
 
static void timeout_request (void *cls)
 Task run if the time to answer a DNS request via CADET is over. More...
 
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. More...
 
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. More...
 
static void handle_dns_response (void *cls, const struct DnsResponseMessage *msg)
 Process a request via cadet to perform a DNS query. More...
 
static void abort_all_requests (struct CadetExit *exit)
 Abort all pending DNS requests with the given cadet exit. More...
 
static void cleanup (void *cls)
 Function scheduled as very last function, cleans up after us. More...
 
static void cadet_channel_end_cb (void *cls, const struct GNUNET_CADET_Channel *channel)
 Function called whenever a channel is destroyed. More...
 
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. More...
 
static void handle_dht_result (void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *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. More...
 
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. More...
 
int main (int argc, char *const *argv)
 The main function. More...
 

Variables

static struct CadetExitexit_head
 Head of DLL of cadet exits. More...
 
static struct CadetExitexit_tail
 Tail of DLL of cadet exits. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 The handle to the configuration used throughout the process. More...
 
static struct GNUNET_VPN_Handlevpn_handle
 The handle to the VPN. More...
 
static struct GNUNET_CADET_Handlecadet_handle
 The handle to the CADET service. More...
 
static struct GNUNET_STATISTICS_Handlestats
 Statistics. More...
 
static struct GNUNET_DNS_Handledns_post_handle
 The handle to DNS post-resolution modifications. More...
 
static struct GNUNET_DNS_Handledns_pre_handle
 The handle to DNS pre-resolution modifications. More...
 
static struct GNUNET_DHT_Handledht
 Handle to access the DHT. More...
 
static struct GNUNET_DHT_GetHandledht_get
 Our DHT GET operation to find DNS exits. More...
 
static int ipv4_pt
 Are we doing IPv4-pt? More...
 
static int ipv6_pt
 Are we doing IPv6-pt? More...
 
static int dns_channel
 Are we channeling DNS queries? More...
 
static unsigned int dns_exit_available
 Number of DNS exit peers we currently have in the cadet channel. More...
 

Detailed Description

tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet)

Author
Christian Grothoff

Definition in file gnunet-daemon-pt.c.

Macro Definition Documentation

◆ TIMEOUT

#define TIMEOUT   GNUNET_TIME_UNIT_MINUTES

After how long do we time out if we could not get an IP from VPN or CADET?

Definition at line 41 of file gnunet-daemon-pt.c.

Referenced by dns_pre_request_handler(), and modify_address().

◆ MAX_DNS_SIZE

#define MAX_DNS_SIZE   (8 * 1024)

How many bytes of payload do we allow at most for a DNS reply? Given that this is pretty much limited to loopback, we can be pretty high (Linux loopback defaults to 16k, most local UDP packets should survive up to 9k (NFS), so 8k should be pretty safe in general).

Definition at line 50 of file gnunet-daemon-pt.c.

Referenced by finish_request().

◆ MAX_OPEN_TUNNELS

#define MAX_OPEN_TUNNELS   4

How many channels do we open at most at the same time?

Definition at line 55 of file gnunet-daemon-pt.c.

Referenced by handle_dht_result().

Enumeration Type Documentation

◆ RequestGroup

Which group of DNS records are we currently processing?

Enumerator
ANSWERS 

DNS answers.

AUTHORITY_RECORDS 

DNS authority records.

ADDITIONAL_RECORDS 

DNS additional records.

END 

We're done processing.

Definition at line 61 of file gnunet-daemon-pt.c.

61  {
65  ANSWERS = 0,
66 
71 
76 
80  END = 3
81 };
DNS answers.
We're done processing.
DNS additional records.
DNS authority records.

Function Documentation

◆ try_open_exit()

static void try_open_exit ( void  )
static

We are short on cadet exits, try to open another one.

Definition at line 1048 of file gnunet-daemon-pt.c.

References CadetExit::cadet_channel, cadet_channel_end_cb(), channel_idle_notify_cb(), dns_exit_available, GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, GNUNET_assert, GNUNET_break, GNUNET_CADET_channel_create(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, CadetExit::next, and CadetExit::peer.

Referenced by cadet_channel_end_cb(), handle_dht_result(), and timeout_request().

1049 {
1050  struct CadetExit *pos;
1051  uint32_t candidate_count;
1052  uint32_t candidate_selected;
1053  struct GNUNET_HashCode port;
1054 
1057  &port);
1058  candidate_count = 0;
1059  for (pos = exit_head; NULL != pos; pos = pos->next)
1060  if (NULL == pos->cadet_channel)
1061  candidate_count++;
1062  if (0 == candidate_count)
1063  {
1065  "No DNS exits available yet.\n");
1066  return;
1067  }
1069  candidate_count);
1070  candidate_count = 0;
1071  for (pos = exit_head; NULL != pos; pos = pos->next)
1072  if (NULL == pos->cadet_channel)
1073  {
1074  candidate_count++;
1075  if (candidate_selected < candidate_count)
1076  {
1077  struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
1078  GNUNET_MQ_hd_var_size(dns_response,
1080  struct DnsResponseMessage,
1081  pos),
1083  };
1084 
1085 
1086  /* move to the head of the DLL */
1087  pos->cadet_channel
1089  pos,
1090  &pos->peer,
1091  &port,
1094  cadet_handlers);
1095  if (NULL == pos->cadet_channel)
1096  {
1097  GNUNET_break(0);
1098  continue;
1099  }
1101  exit_tail,
1102  pos);
1104  exit_tail,
1105  pos);
1107  return;
1108  }
1109  }
1110  GNUNET_assert(NULL == exit_head);
1111 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_PeerIdentity peer
Identity of the peer that is providing the exit for us.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CADET_Handle * cadet_handle
The handle to the CADET service.
#define GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET
Type of messages containing an DNS reply from a DNS exit service.
static unsigned int dns_exit_available
Number of DNS exit peers we currently have in the cadet channel.
static struct CadetExit * exit_head
Head of DLL of cadet exits.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialze a channel to this peer yet...
struct CadetExit * next
Kept in a DLL.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
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.
A 512-bit hashcode.
Message handler for a specific message type.
static void cadet_channel_end_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever a channel is destroyed.
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:1065
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
Message with a DNS response.
#define GNUNET_log(kind,...)
#define GNUNET_APPLICATION_PORT_INTERNET_RESOLVER
Internet DNS resolution (external DNS gateway).
static struct CadetExit * exit_tail
Tail of DLL of cadet exits.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_channel_weight()

static uint32_t get_channel_weight ( struct CadetExit exit)
static

Compute the weight of the given exit.

The higher the weight, the more likely it will be that the channel will be chosen. A weigt of zero means that we should close the channel as it is so bad, that we should not use it.

Parameters
exitexit to calculate the weight for
Returns
weight of the channel

Definition at line 318 of file gnunet-daemon-pt.c.

References drop_percent, GNUNET_assert, CadetExit::num_answered, and CadetExit::num_transmitted.

Referenced by choose_exit(), and timeout_request().

319 {
320  uint32_t dropped;
321  uint32_t drop_percent;
322  uint32_t good_percent;
323 
325  dropped = exit->num_transmitted - exit->num_answered;
326  if (exit->num_transmitted > 0)
327  drop_percent = (uint32_t)((100LL * dropped) / exit->num_transmitted);
328  else
329  drop_percent = 50; /* no data */
330  if ((exit->num_transmitted > 20) &&
331  (drop_percent > 25))
332  return 0; /* statistically significant, and > 25% loss, die */
333  good_percent = 100 - drop_percent;
334  GNUNET_assert(0 != good_percent);
335  if (UINT32_MAX / good_percent / good_percent < exit->num_transmitted)
336  return UINT32_MAX; /* formula below would overflow */
337  return 1 + good_percent * good_percent * exit->num_transmitted;
338 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
unsigned int num_answered
How many DNS requests were answered via this channel?
unsigned int num_transmitted
How many DNS requests did we transmit via this channel?
unsigned long long drop_percent
Set to non-zero values to create random drops to test retransmissions.
Here is the caller graph for this function:

◆ choose_exit()

static struct CadetExit* choose_exit ( )
static

Choose a cadet exit for a DNS request.

We try to use a channel that is reliable and currently available. All existing channels are given a base weight of 1, plus a score relating to the total number of queries answered in relation to the total number of queries we sent to that channel. That score is doubled if the channel is currently idle.

Returns
NULL if no exit is known, otherwise the exit that we should use to queue a message with

Definition at line 353 of file gnunet-daemon-pt.c.

References CadetExit::cadet_channel, exit_head, get_channel_weight(), GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), CadetExit::idle, and CadetExit::next.

Referenced by cadet_channel_end_cb(), and dns_pre_request_handler().

354 {
355  struct CadetExit *pos;
356  uint64_t total_transmitted;
357  uint64_t selected_offset;
358  uint32_t channel_weight;
359 
360  total_transmitted = 0;
361  for (pos = exit_head; NULL != pos; pos = pos->next)
362  {
363  if (NULL == pos->cadet_channel)
364  break;
365  channel_weight = get_channel_weight(pos);
366  total_transmitted += channel_weight;
367  /* double weight for idle channels */
368  if (0 != pos->idle)
369  total_transmitted += channel_weight;
370  }
371  if (0 == total_transmitted)
372  {
373  /* no channels available, or only a very bad one... */
374  return exit_head;
375  }
377  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 }
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
static struct CadetExit * exit_head
Head of DLL of cadet exits.
static uint32_t get_channel_weight(struct CadetExit *exit)
Compute the weight of the given exit.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialze a channel to this peer yet...
struct CadetExit * next
Kept in a DLL.
int idle
Size of the window, 0 if we are busy.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ finish_request()

static void finish_request ( struct ReplyContext rc)
static

We're done modifying all records in the response.

Submit the reply and free the resources of the rc.

Parameters
rccontext to process

Definition at line 403 of file gnunet-daemon-pt.c.

References _, buf, ReplyContext::dns, gettext_noop, GNUNET_DNS_request_answer(), GNUNET_DNS_request_drop(), GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_pack(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, MAX_DNS_SIZE, ReplyContext::rh, and submit_request().

Referenced by submit_request().

404 {
405  char *buf;
406  size_t buf_len;
407 
408  if (GNUNET_SYSERR ==
410  MAX_DNS_SIZE,
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 }
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:1256
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:853
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#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 char buf[2048]
struct GNUNET_DNSPARSER_Packet * dns
DNS packet that is being modified.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:301
#define GNUNET_log(kind,...)
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:270
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
struct GNUNET_DNS_RequestHandle * rh
Handle to submit the final result.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ submit_request()

static void submit_request ( struct ReplyContext rc)
static

Process the next record of the given request context.

When done, submit the reply and free the resources of the rc.

Parameters
rccontext to process

Definition at line 553 of file gnunet-daemon-pt.c.

References ADDITIONAL_RECORDS, GNUNET_DNSPARSER_Packet::additional_records, ANSWERS, GNUNET_DNSPARSER_Packet::answers, AUTHORITY_RECORDS, GNUNET_DNSPARSER_Packet::authority_records, ReplyContext::dns, END, finish_request(), GNUNET_assert, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, ReplyContext::group, ipv4_pt, ipv6_pt, modify_address(), GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, ReplyContext::offset, and type.

Referenced by dns_post_request_handler(), finish_request(), and vpn_allocation_callback().

554 {
555  struct GNUNET_DNSPARSER_Record *ra;
556  unsigned int ra_len;
557  unsigned int i;
558 
559  while (1)
560  {
561  switch (rc->group)
562  {
563  case ANSWERS:
564  ra = rc->dns->answers;
565  ra_len = rc->dns->num_answers;
566  break;
567 
568  case AUTHORITY_RECORDS:
569  ra = rc->dns->authority_records;
570  ra_len = rc->dns->num_authority_records;
571  break;
572 
573  case ADDITIONAL_RECORDS:
574  ra = rc->dns->additional_records;
575  ra_len = rc->dns->num_additional_records;
576  break;
577 
578  case END:
579  finish_request(rc);
580  return;
581 
582  default:
583  GNUNET_assert(0);
584  }
585  for (i = rc->offset; i < ra_len; i++)
586  {
587  switch (ra[i].type)
588  {
590  if (ipv4_pt)
591  {
592  rc->offset = i + 1;
593  modify_address(rc,
594  &ra[i]);
595  return;
596  }
597  break;
598 
600  if (ipv6_pt)
601  {
602  rc->offset = i + 1;
603  modify_address(rc,
604  &ra[i]);
605  return;
606  }
607  break;
608  }
609  }
610  rc->group++;
611  }
612 }
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
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.
unsigned int offset
Offset in the current record group that is being modified.
DNS answers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
We&#39;re done processing.
enum RequestGroup group
Group that is being modified.
DNS additional records.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
DNS authority records.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
static int ipv6_pt
Are we doing IPv6-pt?
static void finish_request(struct ReplyContext *rc)
We&#39;re done modifying all records in the response.
A DNS response record.
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
struct GNUNET_DNSPARSER_Packet * dns
DNS packet that is being modified.
static int ipv4_pt
Are we doing IPv4-pt?
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
#define GNUNET_DNSPARSER_TYPE_AAAA
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_DNSPARSER_TYPE_A
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vpn_allocation_callback()

static void vpn_allocation_callback ( void *  cls,
int  af,
const void *  address 
)
static

Callback invoked from the VPN service once a redirection is available.

Provides the IP address that can now be used to reach the requested destination. We substitute the active record and then continue with 'submit_request' to look at the other records.

Parameters
clsour struct ReplyContext
afaddress family, AF_INET or AF_INET6; AF_UNSPEC on error; will match 'result_af' from the request
addressIP address (struct in_addr or struct in_addr6, depending on 'af') that the VPN allocated for the redirection; traffic to this IP will now be redirected to the specified target peer; NULL on error

Definition at line 460 of file gnunet-daemon-pt.c.

References GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, ReplyContext::dns, gettext_noop, GNUNET_assert, GNUNET_DNS_request_drop(), GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_free, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_DNSPARSER_Record::raw, ReplyContext::rec, ReplyContext::rh, ReplyContext::rr, submit_request(), and GNUNET_DNSPARSER_Record::type.

Referenced by modify_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 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
static void submit_request(struct ReplyContext *rc)
Process the next record of the given request context.
struct GNUNET_VPN_RedirectionRequest * rr
Active redirection request with the VPN.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:853
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_DNSPARSER_Record * rec
Record for which we have an active redirection request.
struct GNUNET_DNSPARSER_Packet * dns
DNS packet that is being modified.
void * data
Binary record data.
#define GNUNET_DNSPARSER_TYPE_AAAA
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:270
union GNUNET_DNSPARSER_Record::@27 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
struct GNUNET_DNS_RequestHandle * rh
Handle to submit the final result.
static char * address
GNS address for this phone.
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
#define GNUNET_DNSPARSER_TYPE_A
Information tracked per DNS reply that we are processing.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modify_address()

static void modify_address ( struct ReplyContext rc,
struct GNUNET_DNSPARSER_Record rec 
)
static

Modify the given DNS record by asking VPN to create a channel to the given address.

When done, continue with submitting other records from the request context ('submit_request' is our continuation).

Parameters
rccontext to process
recrecord to modify

Definition at line 513 of file gnunet-daemon-pt.c.

References GNUNET_DNSPARSER_RawRecord::data, GNUNET_DNSPARSER_Record::data, GNUNET_DNSPARSER_RawRecord::data_len, GNUNET_assert, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_TIME_relative_to_absolute(), GNUNET_VPN_redirect_to_ip(), GNUNET_DNSPARSER_Record::raw, ReplyContext::rec, ReplyContext::rr, TIMEOUT, GNUNET_DNSPARSER_Record::type, and vpn_allocation_callback().

Referenced by submit_request().

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,
541  rc);
542 }
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
struct GNUNET_VPN_RedirectionRequest * rr
Active redirection request with the VPN.
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:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 GNUNET_VPN_Handle * vpn_handle
The handle to the VPN.
struct GNUNET_DNSPARSER_Record * rec
Record for which we have an active redirection request.
size_t data_len
Number of bytes in data.
void * data
Binary record data.
#define GNUNET_DNSPARSER_TYPE_AAAA
#define TIMEOUT
After how long do we time out if we could not get an IP from VPN or CADET?
union GNUNET_DNSPARSER_Record::@27 data
Payload of the record (which one of these is valid depends on the &#39;type&#39;).
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
#define GNUNET_DNSPARSER_TYPE_A
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:456
Here is the call graph for this function:
Here is the caller graph for this function:

◆ work_test()

static int work_test ( const struct GNUNET_DNSPARSER_Record ra,
unsigned int  ra_len 
)
static

Test if any of the given records need protocol-translation work.

Parameters
raarray of records
ra_lennumber of entries in ra
Returns
GNUNET_YES if any of the given records require protocol-translation

Definition at line 623 of file gnunet-daemon-pt.c.

References GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_NO, GNUNET_YES, ipv4_pt, ipv6_pt, and type.

Referenced by dns_post_request_handler().

625 {
626  unsigned int i;
627 
628  for (i = 0; i < ra_len; i++)
629  {
630  switch (ra[i].type)
631  {
633  if (ipv4_pt)
634  return GNUNET_YES;
635  break;
636 
638  if (ipv6_pt)
639  return GNUNET_YES;
640  break;
641  }
642  }
643  return GNUNET_NO;
644 }
#define GNUNET_NO
Definition: gnunet_common.h:78
static int ipv6_pt
Are we doing IPv6-pt?
static int ipv4_pt
Are we doing IPv4-pt?
#define GNUNET_DNSPARSER_TYPE_AAAA
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_DNSPARSER_TYPE_A
Here is the caller graph for this function:

◆ dns_post_request_handler()

static void dns_post_request_handler ( void *  cls,
struct GNUNET_DNS_RequestHandle rh,
size_t  request_length,
const char *  request 
)
static

This function is called AFTER we got an IP address for a DNS request.

Now, the PT daemon has the chance to substitute the IP address with one from the VPN range to channel requests destined for this IP address via VPN and CADET.

Parameters
clsclosure
rhrequest handle to user for reply
request_lengthnumber of bytes in request
requestudp payload of the DNS request

Definition at line 659 of file gnunet-daemon-pt.c.

References _, GNUNET_DNSPARSER_Packet::additional_records, ANSWERS, GNUNET_DNSPARSER_Packet::answers, GNUNET_DNSPARSER_Packet::authority_records, ReplyContext::dns, gettext_noop, GNUNET_DNS_request_drop(), GNUNET_DNS_request_forward(), GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_parse(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), ReplyContext::group, GNUNET_DNSPARSER_Packet::num_additional_records, GNUNET_DNSPARSER_Packet::num_answers, GNUNET_DNSPARSER_Packet::num_authority_records, ReplyContext::offset, ReplyContext::rh, submit_request(), work(), and work_test().

Referenced by run().

663 {
664  struct GNUNET_DNSPARSER_Packet *dns;
665  struct ReplyContext *rc;
666  int work;
667 
669  gettext_noop("# DNS replies intercepted"),
670  1, GNUNET_NO);
672  request_length);
673  if (NULL == dns)
674  {
676  _("Failed to parse DNS request. Dropping.\n"));
678  return;
679  }
680  work = GNUNET_NO;
681  work |= work_test(dns->answers,
682  dns->num_answers);
683  work |= work_test(dns->authority_records,
684  dns->num_authority_records);
685  work |= work_test(dns->additional_records,
687  if (!work)
688  {
691  return;
692  }
693  rc = GNUNET_new(struct ReplyContext);
694  rc->rh = rh;
695  rc->dns = dns;
696  rc->offset = 0;
697  rc->group = ANSWERS;
698  submit_request(rc);
699 }
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
static void submit_request(struct ReplyContext *rc)
Process the next record of the given request context.
unsigned int offset
Offset in the current record group that is being modified.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
DNS answers.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
Definition: dnsparser.c:853
#define GNUNET_NO
Definition: gnunet_common.h:78
enum RequestGroup group
Group that is being modified.
static void work(void *cls)
Function called to process work items.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned int num_answers
Number of answers in the packet, should be 0 for queries.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
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:656
struct GNUNET_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
struct GNUNET_DNSPARSER_Packet * dns
DNS packet that is being modified.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
void GNUNET_DNS_request_forward(struct GNUNET_DNS_RequestHandle *rh)
If a GNUNET_DNS_RequestHandler calls this function, the request is given to other clients or the glob...
Definition: dns_api.c:242
Easy-to-process, parsed version of a DNS packet.
#define GNUNET_log(kind,...)
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:270
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
struct GNUNET_DNS_RequestHandle * rh
Handle to submit the final result.
Information tracked per DNS reply that we are processing.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeout_request()

static void timeout_request ( void *  cls)
static

Task run if the time to answer a DNS request via CADET is over.

Parameters
clsthe struct RequestContext to abort

Definition at line 708 of file gnunet-daemon-pt.c.

References CadetExit::cadet_channel, dns_exit_available, RequestContext::exit, get_channel_weight(), gettext_noop, GNUNET_CADET_channel_destroy(), GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_DNS_request_drop(), GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_update(), CadetExit::num_answered, CadetExit::num_transmitted, CadetExit::receive_queue_head, RequestContext::rh, and try_open_exit().

Referenced by dns_pre_request_handler().

709 {
710  struct RequestContext *rc = cls;
711  struct CadetExit *exit = rc->exit;
712 
714  gettext_noop("# DNS requests dropped (timeout)"),
715  1,
716  GNUNET_NO);
718  GNUNET_free(rc);
719  if ((0 == get_channel_weight(exit)) &&
720  (NULL == exit->receive_queue_head))
721  {
722  /* this straw broke the camel's back: this channel now has
723  such a low score that it will not be used; close it! */
725  exit->cadet_channel = NULL;
727  exit_tail,
728  exit);
730  exit_tail,
731  exit);
732  /* go back to semi-innocent: mark as not great, but
733  avoid a prohibitively negative score (see
734  #get_channel_weight(), which checks for a certain
735  minimum number of transmissions before making
736  up an opinion) */
737  exit->num_transmitted = 5;
738  exit->num_answered = 0;
740  /* now try to open an alternative exit */
741  try_open_exit();
742  }
743 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_NO
Definition: gnunet_common.h:78
unsigned int num_answered
How many DNS requests were answered via this channel?
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static unsigned int dns_exit_available
Number of DNS exit peers we currently have in the cadet channel.
static struct CadetExit * exit_head
Head of DLL of cadet exits.
static uint32_t get_channel_weight(struct CadetExit *exit)
Compute the weight of the given exit.
unsigned int num_transmitted
How many DNS requests did we transmit via this channel?
struct CadetExit * exit
Exit that was chosen for this request.
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialze a channel to this peer yet...
State we keep for a request that is going out via CADET.
static void try_open_exit(void)
We are short on cadet exits, try to open another one.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
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:270
struct RequestContext * receive_queue_head
Head of DLL of requests waiting for a response.
static struct CadetExit * exit_tail
Tail of DLL of cadet exits.
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
struct GNUNET_DNS_RequestHandle * rh
Handle for interaction with DNS service.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dns_pre_request_handler()

static void dns_pre_request_handler ( void *  cls,
struct GNUNET_DNS_RequestHandle rh,
size_t  request_length,
const char *  request 
)
static

This function is called before the DNS request has been given to a "local" DNS resolver.

Channeling for DNS requests was enabled, so we now need to send the request via some CADET channel to a DNS EXIT for resolution.

Parameters
clsclosure
rhrequest handle to user for reply
request_lengthnumber of bytes in request
requestudp payload of the DNS request

Definition at line 758 of file gnunet-daemon-pt.c.

References CadetExit::cadet_channel, choose_exit(), dns_exit_available, RequestContext::dns_id, env, RequestContext::env, RequestContext::exit, gettext_noop, GNUNET_assert, GNUNET_CADET_get_mq(), GNUNET_CONTAINER_DLL_remove, GNUNET_DNS_request_drop(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET, GNUNET_MQ_env_copy(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NETWORK_STRUCT_BEGIN, GNUNET_NETWORK_STRUCT_END, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TUN_DnsHeader::id, CadetExit::idle, CadetExit::num_transmitted, CadetExit::receive_queue_head, CadetExit::receive_queue_tail, ReplyContext::rh, RequestContext::rh, TIMEOUT, timeout_request(), and RequestContext::timeout_task.

Referenced by run().

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  {
775  gettext_noop("# DNS requests dropped (DNS cadet channel down)"),
776  1, GNUNET_NO);
778  return;
779  }
780  if (request_length < sizeof(dns))
781  {
783  gettext_noop("# DNS requests dropped (malformed)"),
784  1, GNUNET_NO);
786  return;
787  }
788  exit = choose_exit();
789  GNUNET_assert(NULL != exit);
790  GNUNET_assert(NULL != exit->cadet_channel);
791 
792  env = GNUNET_MQ_msg_extra(hdr,
793  request_length,
795  GNUNET_memcpy(&hdr[1],
796  request,
797  request_length);
798  rc = GNUNET_new(struct RequestContext);
799  rc->exit = exit;
800  rc->rh = rh;
803  rc);
804  GNUNET_memcpy(&dns,
805  request,
806  sizeof(dns));
807  rc->dns_id = dns.id;
808  rc->env = env;
810  exit->receive_queue_tail,
811  rc);
812  if (0 < exit->idle)
813  exit->idle--;
814  exit->num_transmitted++;
816  GNUNET_MQ_env_copy(env));
817 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static unsigned int dns_exit_available
Number of DNS exit peers we currently have in the cadet channel.
unsigned int num_transmitted
How many DNS requests did we transmit via this channel?
struct CadetExit * exit
Exit that was chosen for this request.
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialze a channel to this peer yet...
#define GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET
Type of messages containing an DNS request for a DNS exit service.
static struct CadetExit * choose_exit()
Choose a cadet exit for a DNS request.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
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:1237
struct GNUNET_SCHEDULER_Task * timeout_task
Task used to abort this operation with timeout.
State we keep for a request that is going out via CADET.
uint16_t dns_id
ID of the original DNS request (used to match the reply).
struct GNUNET_MQ_Envelope * env
Envelope with the request we are transmitting.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct RequestContext * receive_queue_tail
Tail of DLL of requests waiting for a response.
int idle
Size of the window, 0 if we are busy.
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:270
Header for all communications.
struct RequestContext * receive_queue_head
Head of DLL of requests waiting for a response.
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:351
#define TIMEOUT
After how long do we time out if we could not get an IP from VPN or CADET?
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
Definition: mq.c:412
struct GNUNET_DNS_RequestHandle * rh
Handle for interaction with DNS service.
static void timeout_request(void *cls)
Task run if the time to answer a DNS request via CADET is over.
#define gettext_noop(String)
Definition: gettext.h:69
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_dns_response()

static GNUNET_NETWORK_STRUCT_END int check_dns_response ( void *  cls,
const struct DnsResponseMessage msg 
)
static

Process a request via cadet to perform a DNS query.

Parameters
clsthe struct CadetExit which got the message
msgthe actual message
Returns
GNUNET_OK to keep the connection open, GNUNET_SYSERR to close it (signal serious error)

Definition at line 850 of file gnunet-daemon-pt.c.

References GNUNET_OK.

852 {
853  return GNUNET_OK; /* all OK */
854 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_dns_response()

static void handle_dns_response ( void *  cls,
const struct DnsResponseMessage msg 
)
static

Process a request via cadet to perform a DNS query.

Parameters
clsthe struct CadetExit which got the message
msgthe actual message

Definition at line 864 of file gnunet-daemon-pt.c.

References DnsResponseMessage::dns, RequestContext::dns_id, RequestContext::env, gettext_noop, GNUNET_CONTAINER_DLL_remove, GNUNET_DNS_request_answer(), GNUNET_free, GNUNET_MQ_discard(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), DnsResponseMessage::header, GNUNET_TUN_DnsHeader::id, RequestContext::next, CadetExit::num_answered, CadetExit::receive_queue_head, CadetExit::receive_queue_tail, RequestContext::rh, GNUNET_MessageHeader::size, and RequestContext::timeout_task.

866 {
867  struct CadetExit *exit = cls;
868  size_t mlen;
869  struct RequestContext *rc;
870 
871  mlen = ntohs(msg->header.size) - sizeof(*msg);
872  for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next)
873  {
874  if (msg->dns.id == rc->dns_id)
875  {
877  gettext_noop("# DNS replies received"),
878  1,
879  GNUNET_NO);
881  mlen + sizeof(struct GNUNET_TUN_DnsHeader),
882  (const void*)&msg->dns);
884  exit->receive_queue_tail,
885  rc);
887  GNUNET_MQ_discard(rc->env);
888  GNUNET_free(rc);
889  exit->num_answered++;
890  return;
891  }
892  }
894  gettext_noop("# DNS replies dropped (too late?)"),
895  1, GNUNET_NO);
896 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MessageHeader header
GNUnet header, of type GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET.
#define GNUNET_NO
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
unsigned int num_answered
How many DNS requests were answered via this channel?
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint16_t id
Unique identifier for the request/response.
struct GNUNET_SCHEDULER_Task * timeout_task
Task used to abort this operation with timeout.
struct RequestContext * next
We keep these in a DLL.
State we keep for a request that is going out via CADET.
uint16_t dns_id
ID of the original DNS request (used to match the reply).
struct GNUNET_MQ_Envelope * env
Envelope with the request we are transmitting.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:319
struct GNUNET_TUN_DnsHeader dns
DNS header.
struct RequestContext * receive_queue_tail
Tail of DLL of requests waiting for a response.
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:301
struct RequestContext * receive_queue_head
Head of DLL of requests waiting for a response.
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
struct GNUNET_DNS_RequestHandle * rh
Handle for interaction with DNS service.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:

◆ abort_all_requests()

static void abort_all_requests ( struct CadetExit exit)
static

Abort all pending DNS requests with the given cadet exit.

Parameters
exitcadet exit to abort requests for

Definition at line 905 of file gnunet-daemon-pt.c.

References RequestContext::env, GNUNET_CONTAINER_DLL_remove, GNUNET_DNS_request_drop(), GNUNET_free, GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), CadetExit::receive_queue_head, CadetExit::receive_queue_tail, RequestContext::rh, and RequestContext::timeout_task.

Referenced by cleanup().

906 {
907  struct RequestContext *rc;
908 
909  while (NULL != (rc = exit->receive_queue_head))
910  {
912  exit->receive_queue_tail,
913  rc);
916  GNUNET_MQ_discard(rc->env);
917  GNUNET_free(rc);
918  }
919 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SCHEDULER_Task * timeout_task
Task used to abort this operation with timeout.
State we keep for a request that is going out via CADET.
struct GNUNET_MQ_Envelope * env
Envelope with the request we are transmitting.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:319
struct RequestContext * receive_queue_tail
Tail of DLL of requests waiting for a response.
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:270
struct RequestContext * receive_queue_head
Head of DLL of requests waiting for a response.
struct GNUNET_DNS_RequestHandle * rh
Handle for interaction with DNS service.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup()

static void cleanup ( void *  cls)
static

Function scheduled as very last function, cleans up after us.

Parameters
clsclosure, NULL

Definition at line 928 of file gnunet-daemon-pt.c.

References abort_all_requests(), CadetExit::cadet_channel, GNUNET_CADET_channel_destroy(), GNUNET_CADET_disconnect(), GNUNET_CONTAINER_DLL_remove, GNUNET_DHT_disconnect(), GNUNET_DHT_get_stop(), GNUNET_DNS_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_STATISTICS_destroy(), GNUNET_VPN_disconnect(), and GNUNET_YES.

Referenced by run().

929 {
930  struct CadetExit *exit;
931 
933  "Protocol translation daemon is shutting down now\n");
934  if (NULL != vpn_handle)
935  {
937  vpn_handle = NULL;
938  }
939  while (NULL != (exit = exit_head))
940  {
942  exit_tail,
943  exit);
944  if (NULL != exit->cadet_channel)
945  {
947  exit->cadet_channel = NULL;
948  }
949  abort_all_requests(exit);
950  GNUNET_free(exit);
951  }
952  if (NULL != cadet_handle)
953  {
955  cadet_handle = NULL;
956  }
957  if (NULL != dns_post_handle)
958  {
960  dns_post_handle = NULL;
961  }
962  if (NULL != dns_pre_handle)
963  {
965  dns_pre_handle = NULL;
966  }
967  if (NULL != stats)
968  {
970  stats = NULL;
971  }
972  if (NULL != dht_get)
973  {
975  dht_get = NULL;
976  }
977  if (NULL != dht)
978  {
980  dht = NULL;
981  }
982 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:838
static struct GNUNET_DHT_GetHandle * dht_get
Our DHT GET operation to find DNS exits.
static struct GNUNET_CADET_Handle * cadet_handle
The handle to the CADET service.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static struct CadetExit * exit_head
Head of DLL of cadet exits.
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialze a channel to this peer yet...
static struct GNUNET_VPN_Handle * vpn_handle
The handle to the VPN.
void GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh)
Disconnect from the DNS service.
Definition: dns_api.c:368
static struct GNUNET_DNS_Handle * dns_pre_handle
The handle to DNS pre-resolution modifications.
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
Definition: vpn_api.c:529
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1150
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:913
static struct GNUNET_DHT_Handle * dht
Handle to access the DHT.
static void abort_all_requests(struct CadetExit *exit)
Abort all pending DNS requests with the given cadet exit.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct CadetExit * exit_tail
Tail of DLL of cadet exits.
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
static struct GNUNET_DNS_Handle * dns_post_handle
The handle to DNS post-resolution modifications.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadet_channel_end_cb()

static void cadet_channel_end_cb ( void *  cls,
const struct GNUNET_CADET_Channel channel 
)
static

Function called whenever a channel is destroyed.

Should clean up the associated state and attempt to build a new one.

It must NOT call GNUNET_CADET_channel_destroy on the channel.

Parameters
clsclosure (the struct CadetExit set from GNUNET_CADET_connect)
channelconnection to the other end (henceforth invalid)
channel_ctxplace where local state associated with the channel is stored

Definition at line 997 of file gnunet-daemon-pt.c.

References CadetExit::cadet_channel, choose_exit(), dns_exit_available, RequestContext::env, RequestContext::exit, GNUNET_CADET_get_mq(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_MQ_env_copy(), GNUNET_MQ_send(), CadetExit::receive_queue_head, CadetExit::receive_queue_tail, and try_open_exit().

Referenced by try_open_exit().

999 {
1000  struct CadetExit *exit = cls;
1001  struct CadetExit *alt;
1002  struct RequestContext *rc;
1003 
1004  exit->cadet_channel = NULL;
1006  /* open alternative channels */
1007  /* our channel is now closed, move our requests to an alternative
1008  channel */
1009  alt = choose_exit();
1010  while (NULL != (rc = exit->receive_queue_head))
1011  {
1013  exit->receive_queue_tail,
1014  rc);
1015  rc->exit = alt;
1017  alt->receive_queue_tail,
1018  rc);
1020  GNUNET_MQ_env_copy(rc->env));
1021  }
1022  try_open_exit();
1023 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static unsigned int dns_exit_available
Number of DNS exit peers we currently have in the cadet channel.
struct CadetExit * exit
Exit that was chosen for this request.
struct GNUNET_CADET_Channel * cadet_channel
Channel we use for DNS requests over CADET, NULL if we did not initialze a channel to this peer yet...
static struct CadetExit * choose_exit()
Choose a cadet exit for a DNS request.
State we keep for a request that is going out via CADET.
struct GNUNET_MQ_Envelope * env
Envelope with the request we are transmitting.
static void try_open_exit(void)
We are short on cadet exits, try to open another one.
struct RequestContext * receive_queue_tail
Tail of DLL of requests waiting for a response.
struct RequestContext * receive_queue_head
Head of DLL of requests waiting for a response.
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:351
Handle to a peer that advertised that it is willing to serve as a DNS exit.
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
Definition: mq.c:412
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1116
Here is the call graph for this function:
Here is the caller graph for this function:

◆ channel_idle_notify_cb()

static void channel_idle_notify_cb ( void *  cls,
const struct GNUNET_CADET_Channel channel,
int  window_size 
)
static

Function called whenever a channel has excess capacity.

Parameters
clsthe struct CadetExit
channelconnection to the other end
window_sizehow much capacity do we have

Definition at line 1034 of file gnunet-daemon-pt.c.

References CadetExit::idle.

Referenced by try_open_exit().

1037 {
1038  struct CadetExit *pos = cls;
1039 
1040  pos->idle = window_size;
1041 }
int idle
Size of the window, 0 if we are busy.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
Here is the caller graph for this function:

◆ handle_dht_result()

static void handle_dht_result ( void *  cls,
struct GNUNET_TIME_Absolute  exp,
const struct GNUNET_HashCode key,
const struct GNUNET_PeerIdentity get_path,
unsigned int  get_path_length,
const struct GNUNET_PeerIdentity put_path,
unsigned int  put_path_length,
enum GNUNET_BLOCK_Type  type,
size_t  size,
const void *  data 
)
static

Function called whenever we find an advertisement for a DNS exit in the DHT.

If we don't have a cadet channel, we should build one; otherwise, we should save the advertisement for later use.

Parameters
clsclosure
expwhen will this value expire
keykey of the result
get_pathpeers on reply path (or NULL if not recorded) [0] = datastore's first neighbor, [length - 1] = local peer
get_path_lengthnumber of entries in get_path
put_pathpeers on the PUT path (or NULL if not recorded) [0] = origin, [length - 1] = datastore
put_path_lengthnumber of entries in put_path
typetype of the result
sizenumber of bytes in data
datapointer to the result data

Definition at line 1134 of file gnunet-daemon-pt.c.

References data, dns_exit_available, CadetExit::expiration, GNUNET_DNS_Advertisement::expiration_time, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_memcmp, GNUNET_new, GNUNET_TIME_absolute_max(), GNUNET_TIME_absolute_ntoh(), MAX_OPEN_TUNNELS, CadetExit::next, CadetExit::peer, GNUNET_DNS_Advertisement::peer, and try_open_exit().

Referenced by run().

1143 {
1144  const struct GNUNET_DNS_Advertisement *ad;
1145  struct CadetExit *exit;
1146 
1147  if (sizeof(struct GNUNET_DNS_Advertisement) != size)
1148  {
1149  GNUNET_break(0);
1150  return;
1151  }
1152  ad = data;
1153  for (exit = exit_head; NULL != exit; exit = exit->next)
1154  if (0 == GNUNET_memcmp(&ad->peer,
1155  &exit->peer))
1156  break;
1157  if (NULL == exit)
1158  {
1159  exit = GNUNET_new(struct CadetExit);
1160  exit->peer = ad->peer;
1161  /* channel is closed, so insert at the end */
1163  exit_tail,
1164  exit);
1165  }
1169  try_open_exit();
1170 }
struct GNUNET_PeerIdentity peer
Identity of the peer that is providing the exit for us.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
This is the structure describing an DNS exit service.
Definition: block_dns.h:40
struct GNUNET_TIME_Absolute expiration
At what time did the peer&#39;s advertisement expire?
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static unsigned int dns_exit_available
Number of DNS exit peers we currently have in the cadet channel.
static struct CadetExit * exit_head
Head of DLL of cadet exits.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CadetExit * next
Kept in a DLL.
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:317
struct GNUNET_PeerIdentity peer
The peer providing this service.
Definition: block_dns.h:60
static unsigned int size
Size of the "table".
Definition: peer.c:66
static void try_open_exit(void)
We are short on cadet exits, try to open another one.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define MAX_OPEN_TUNNELS
How many channels do we open at most at the same time?
static struct CadetExit * exit_tail
Tail of DLL of cadet exits.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does this signature expire?
Definition: block_dns.h:55
Handle to a peer that advertised that it is willing to serve as a DNS exit.
uint32_t data
The data value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg_ 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfg_configuration

Definition at line 1182 of file gnunet-daemon-pt.c.

References _, cleanup(), dns_channel, dns_post_request_handler(), dns_pre_request_handler(), GNUNET_BLOCK_TYPE_DNS, GNUNET_CADET_connect(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CRYPTO_hash(), GNUNET_DHT_connect(), GNUNET_DHT_get_start(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DNS_connect(), GNUNET_DNS_FLAG_POST_RESOLUTION, GNUNET_DNS_FLAG_PRE_RESOLUTION, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_VPN_connect(), handle_dht_result(), ipv4_pt, and ipv6_pt.

Referenced by main().

1185 {
1186  struct GNUNET_HashCode dns_key;
1187 
1188  cfg = cfg_;
1190  cfg);
1192  "pt",
1193  "TUNNEL_IPV4");
1195  "pt",
1196  "TUNNEL_IPV6");
1198  "pt",
1199  "TUNNEL_DNS");
1200  if (!(ipv4_pt || ipv6_pt || dns_channel))
1201  {
1203  _("No useful service enabled. Exiting.\n"));
1205  return;
1206  }
1208  if (ipv4_pt || ipv6_pt)
1209  {
1211  = GNUNET_DNS_connect(cfg,
1214  NULL);
1215  if (NULL == dns_post_handle)
1216  {
1218  _("Failed to connect to %s service. Exiting.\n"),
1219  "DNS");
1221  return;
1222  }
1224  if (NULL == vpn_handle)
1225  {
1227  _("Failed to connect to %s service. Exiting.\n"),
1228  "VPN");
1230  return;
1231  }
1232  }
1233  if (dns_channel)
1234  {
1236  = GNUNET_DNS_connect(cfg,
1239  NULL);
1240  if (NULL == dns_pre_handle)
1241  {
1243  _("Failed to connect to %s service. Exiting.\n"),
1244  "DNS");
1246  return;
1247  }
1249  if (NULL == cadet_handle)
1250  {
1252  _("Failed to connect to %s service. Exiting.\n"),
1253  "CADET");
1255  return;
1256  }
1257  dht = GNUNET_DHT_connect(cfg, 1);
1258  if (NULL == dht)
1259  {
1261  _("Failed to connect to %s service. Exiting.\n"),
1262  "DHT");
1264  return;
1265  }
1266  GNUNET_CRYPTO_hash("dns",
1267  strlen("dns"),
1268  &dns_key);
1271  &dns_key,
1272  1,
1274  NULL, 0,
1276  NULL);
1277  }
1278 }
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 struct GNUNET_DHT_GetHandle * dht_get
Our DHT GET operation to find DNS exits.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
This client wants to be called on the results of a DNS resolution (either resolved by PRE-RESOLUTION ...
static const struct GNUNET_CONFIGURATION_Handle * cfg
The handle to the configuration used throughout the process.
static struct GNUNET_CADET_Handle * cadet_handle
The handle to the CADET service.
static void handle_dht_result(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *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 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.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:973
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Block for storing DNS exit service advertisements.
static struct GNUNET_VPN_Handle * vpn_handle
The handle to the VPN.
static int dns_channel
Are we channeling DNS queries?
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
static int ipv6_pt
Are we doing IPv6-pt?
static struct GNUNET_DNS_Handle * dns_pre_handle
The handle to DNS pre-resolution modifications.
A 512-bit hashcode.
static int ipv4_pt
Are we doing IPv4-pt?
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:885
static struct GNUNET_DHT_Handle * dht
Handle to access the DHT.
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:345
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
Definition: vpn_api.c:507
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:1062
#define GNUNET_log(kind,...)
This client should be called on requests that have not yet been resolved as this client provides a re...
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
int 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".
static struct GNUNET_DNS_Handle * dns_post_handle
The handle to DNS post-resolution modifications.
Each peer along the way should look at &#39;enc&#39; (otherwise only the k-peers closest to the key should lo...
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 1289 of file gnunet-daemon-pt.c.

References gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, and run().

1291 {
1292  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1294  };
1295  int ret;
1296 
1298  argv,
1299  &argc,
1300  &argv))
1301  return 2;
1302  ret = (GNUNET_OK ==
1303  GNUNET_PROGRAM_run(argc,
1304  argv,
1305  "gnunet-daemon-pt",
1306  gettext_noop("Daemon to run to perform IP protocol translation to GNUnet"),
1307  options,
1308  &run,
1309  NULL))
1310  ? 0
1311  : 1;
1312  GNUNET_free((void*)argv);
1313  return ret;
1314 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:367
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ exit_head

struct CadetExit* exit_head
static

Head of DLL of cadet exits.

Cadet exits with an open channel are always at the beginning (so we do not have to traverse the entire list to find them).

Definition at line 231 of file gnunet-daemon-pt.c.

Referenced by choose_exit().

◆ exit_tail

struct CadetExit* exit_tail
static

Tail of DLL of cadet exits.

Definition at line 236 of file gnunet-daemon-pt.c.

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

The handle to the configuration used throughout the process.

Definition at line 241 of file gnunet-daemon-pt.c.

◆ vpn_handle

struct GNUNET_VPN_Handle* vpn_handle
static

The handle to the VPN.

Definition at line 246 of file gnunet-daemon-pt.c.

◆ cadet_handle

struct GNUNET_CADET_Handle* cadet_handle
static

The handle to the CADET service.

Definition at line 251 of file gnunet-daemon-pt.c.

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Statistics.

Definition at line 256 of file gnunet-daemon-pt.c.

◆ dns_post_handle

struct GNUNET_DNS_Handle* dns_post_handle
static

The handle to DNS post-resolution modifications.

Definition at line 261 of file gnunet-daemon-pt.c.

◆ dns_pre_handle

struct GNUNET_DNS_Handle* dns_pre_handle
static

The handle to DNS pre-resolution modifications.

Definition at line 266 of file gnunet-daemon-pt.c.

◆ dht

struct GNUNET_DHT_Handle* dht
static

Handle to access the DHT.

Definition at line 271 of file gnunet-daemon-pt.c.

◆ dht_get

struct GNUNET_DHT_GetHandle* dht_get
static

Our DHT GET operation to find DNS exits.

Definition at line 276 of file gnunet-daemon-pt.c.

◆ ipv4_pt

int ipv4_pt
static

Are we doing IPv4-pt?

Definition at line 281 of file gnunet-daemon-pt.c.

Referenced by run(), submit_request(), and work_test().

◆ ipv6_pt

int ipv6_pt
static

Are we doing IPv6-pt?

Definition at line 286 of file gnunet-daemon-pt.c.

Referenced by run(), submit_request(), and work_test().

◆ dns_channel

int dns_channel
static

Are we channeling DNS queries?

Definition at line 291 of file gnunet-daemon-pt.c.

Referenced by run().

◆ dns_exit_available

unsigned int dns_exit_available
static

Number of DNS exit peers we currently have in the cadet channel.

Used to see if using the cadet channel makes any sense right now, as well as to decide if we should open new channels.

Definition at line 298 of file gnunet-daemon-pt.c.

Referenced by cadet_channel_end_cb(), dns_pre_request_handler(), handle_dht_result(), timeout_request(), and try_open_exit().