41 #define TIMEOUT GNUNET_TIME_UNIT_MINUTES 50 #define MAX_DNS_SIZE (8 * 1024) 55 #define MAX_OPEN_TUNNELS 4 325 uint32_t good_percent;
338 if (UINT32_MAX / good_percent / good_percent < exit->num_transmitted)
359 uint64_t total_transmitted;
360 uint64_t selected_offset;
361 uint32_t channel_weight;
363 total_transmitted = 0;
364 for (pos = exit_head; NULL != pos; pos = pos->
next)
369 total_transmitted += channel_weight;
372 total_transmitted += channel_weight;
374 if (0 == total_transmitted)
381 total_transmitted = 0;
382 for (pos = exit_head; NULL != pos; pos = pos->
next)
387 total_transmitted += channel_weight;
390 total_transmitted += channel_weight;
391 if (total_transmitted > selected_offset)
418 _ (
"Failed to pack DNS request. Dropping.\n"));
487 sizeof(
struct in_addr));
494 sizeof(
struct in6_addr));
589 for (i = rc->
offset; i < ra_len; i++)
632 for (i = 0; i < ra_len; i++)
665 size_t request_length,
680 _ (
"Failed to parse DNS request. Dropping.\n"));
763 size_t request_length,
779 "# DNS requests dropped (DNS cadet channel down)"),
784 if (request_length <
sizeof(dns))
788 "# DNS requests dropped (malformed)"),
877 mlen = ntohs (msg->
header.
size) -
sizeof(*msg);
888 (
const void *) &msg->
dns);
939 "Protocol translation daemon is shutting down now\n");
940 if (NULL != vpn_handle)
945 while (NULL != (exit = exit_head))
958 if (NULL != cadet_handle)
963 if (NULL != dns_post_handle)
966 dns_post_handle = NULL;
968 if (NULL != dns_pre_handle)
971 dns_pre_handle = NULL;
1046 pos->
idle = window_size;
1057 uint32_t candidate_count;
1058 uint32_t candidate_selected;
1064 candidate_count = 0;
1065 for (pos = exit_head; NULL != pos; pos = pos->
next)
1068 if (0 == candidate_count)
1071 "No DNS exits available yet.\n");
1076 candidate_count = 0;
1077 for (pos = exit_head; NULL != pos; pos = pos->
next)
1081 if (candidate_selected < candidate_count)
1144 unsigned int get_path_length,
1146 unsigned int put_path_length,
1159 for (exit = exit_head; NULL != exit; exit = exit->
next)
1190 const char *cfgfile GNUNET_UNUSED,
1210 _ (
"No useful service enabled. Exiting.\n"));
1222 if (NULL == dns_post_handle)
1225 _ (
"Failed to connect to %s service. Exiting.\n"),
1231 if (NULL == vpn_handle)
1234 _ (
"Failed to connect to %s service. Exiting.\n"),
1247 if (NULL == dns_pre_handle)
1250 _ (
"Failed to connect to %s service. Exiting.\n"),
1256 if (NULL == cadet_handle)
1259 _ (
"Failed to connect to %s service. Exiting.\n"),
1268 _ (
"Failed to connect to %s service. Exiting.\n"),
1314 "Daemon to run to perform IP protocol translation to GNUnet"),
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_DNSPARSER_Record * answers
Array of all answers in the packet, must contain "num_answers" entries.
uint16_t type
See GNUNET_DNSPARSER_TYPE_*.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
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 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 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_DHT_GetHandle * dht_get
Our DHT GET operation to find DNS exits.
struct GNUNET_PeerIdentity peer
Identity of the peer that is providing the exit for us.
struct GNUNET_MessageHeader * msg
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
enum GNUNET_GenericReturnValue 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).
This is the structure describing an DNS exit service.
uint16_t mlen
Length of the request message that follows this struct.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Opaque handle to the service.
struct GNUNET_VPN_RedirectionRequest * rr
Active redirection request with the VPN.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
#define GNUNET_UNUSED
gcc-ism to document unused arguments
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
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.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
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.
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.
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.
struct GNUNET_MessageHeader header
GNUnet header, of type GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
void GNUNET_DNSPARSER_free_packet(struct GNUNET_DNSPARSER_Packet *p)
Free memory taken by a packet.
We're done processing.
struct GNUNET_TIME_Absolute expiration
At what time did the peer's advertisement expire?
Opaque handle to a channel.
static void vpn_allocation_callback(void *cls, int af, const void *address)
Callback invoked from the VPN service once a redirection is available.
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.
Definition of a command line option.
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.
#define GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET
Type of messages containing an DNS reply from a DNS exit service.
unsigned int num_answered
How many DNS requests were answered via this channel?
struct GNUNET_DNSPARSER_Record * additional_records
Array of all additional answers in the packet, must contain "num_additional_records" entries...
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_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
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.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
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_answers
Number of answers in the packet, should be 0 for queries.
unsigned int num_transmitted
How many DNS requests did we transmit via this channel?
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct CadetExit * exit
Exit that was chosen for this request.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
Connection to the DHT service.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Block for storing DNS exit service advertisements.
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.
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 GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
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.
void GNUNET_DNS_disconnect(struct GNUNET_DNS_Handle *dh)
Disconnect from the DNS service.
struct CadetExit * next
Kept in a DLL.
void * cls
Closure for mv and cb.
unsigned int num_additional_records
Number of additional records in the packet, should be 0 for queries.
static void handle_dns_response(void *cls, const struct DnsResponseMessage *msg)
Process a request via cadet to perform a DNS query.
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...
static int dns_channel
Are we channeling DNS queries?
#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.
struct GNUNET_SCHEDULER_Task * timeout_task
Task used to abort this operation with timeout.
static int ipv6_pt
Are we doing IPv6-pt?
struct RequestContext * next
We keep these in a DLL.
struct RequestContext * prev
We keep these in a DLL.
#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 struct GNUNET_DNS_Handle * dns_pre_handle
The handle to DNS pre-resolution modifications.
static void finish_request(struct ReplyContext *rc)
We're done modifying all records in the response.
void GNUNET_VPN_disconnect(struct GNUNET_VPN_Handle *vh)
Disconnect from the VPN service.
struct GNUNET_DNSPARSER_Record * rec
Record for which we have an active redirection request.
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.
union GNUNET_DNSPARSER_Record::@24 data
Payload of the record (which one of these is valid depends on the 'type').
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.
int main(int argc, char *const *argv)
The main function.
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_DNSPARSER_Record * authority_records
Array of all authority records in the packet, must contain "num_authority_records" entries...
static char * expiration
Credential TTL.
Message handler for a specific message type.
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
unsigned long long drop_percent
Set to non-zero values to create random drops to test retransmissions.
struct GNUNET_PeerIdentity peer
The peer providing this service.
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.
struct GNUNET_MQ_Envelope * env
Envelope with the request we are transmitting.
struct GNUNET_DNSPARSER_Packet * dns
DNS packet that is being modified.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
#define GNUNET_free_nz(ptr)
Wrapper around free.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
static int ipv4_pt
Are we doing IPv4-pt?
static unsigned int size
Size of the "table".
size_t data_len
Number of bytes in data.
static void try_open_exit(void)
We are short on cadet exits, try to open another one.
void * data
Binary record data.
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Opaque redirection request handle.
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
struct GNUNET_MQ_Envelope * env
static void cadet_channel_end_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever a channel is destroyed.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
unsigned int num_authority_records
Number of authoritative answers in the packet, should be 0 for queries.
static struct GNUNET_DHT_Handle * dht
Handle to access the DHT.
struct GNUNET_TUN_DnsHeader dns
DNS header.
static void abort_all_requests(struct CadetExit *exit)
Abort all pending DNS requests with the given cadet exit.
struct RequestContext * receive_queue_tail
Tail of DLL of requests waiting for a response.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
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...
struct GNUNET_VPN_Handle * GNUNET_VPN_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the VPN service.
The identity of the host (wraps the signing key of the peer).
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.
Handle to identify an individual DNS request.
#define GNUNET_DNSPARSER_TYPE_AAAA
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...
int idle
Size of the window, 0 if we are busy.
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.
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.
Easy-to-process, parsed version of a DNS packet.
Message with a DNS response.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
#define GNUNET_APPLICATION_PORT_INTERNET_RESOLVER
Internet DNS resolution (external DNS gateway).
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...
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".
RequestGroup
Which group of DNS records are we currently processing?
#define MAX_OPEN_TUNNELS
How many channels do we open at most at the same time?
This client should be called on requests that have not yet been resolved as this client provides a re...
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
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.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define TIMEOUT
After how long do we time out if we could not get an IP from VPN or CADET?
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does this signature expire?
static struct GNUNET_STATISTICS_Handle * stats
Statistics.
struct GNUNET_DNS_RequestHandle * rh
Handle to submit the final result.
Handle to a peer that advertised that it is willing to serve as a DNS exit.
uint32_t data
The data value.
struct GNUNET_MQ_Envelope * GNUNET_MQ_env_copy(struct GNUNET_MQ_Envelope *env)
Function to copy an envelope.
struct CadetExit * prev
Kept in a DLL.
struct GNUNET_DNS_RequestHandle * rh
Handle for interaction with DNS service.
static char * address
GNS address for this phone.
struct GNUNET_DNSPARSER_RawRecord raw
Raw data for all other types.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
#define GNUNET_DNSPARSER_TYPE_A
static void timeout_request(void *cls)
Task run if the time to answer a DNS request via CADET is over.
Information tracked per DNS reply that we are processing.
static struct GNUNET_DNS_Handle * dns_post_handle
The handle to DNS post-resolution modifications.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Each peer along the way should look at 'enc' (otherwise only the k-peers closest to the key should lo...
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
static void cleanup(void *cls)
Function scheduled as very last function, cleans up after us.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.