GNUnet 0.22.2
dns_api.c File Reference

API to access the DNS service. More...

#include "platform.h"
#include "gnunet_dns_service.h"
#include "dns.h"
Include dependency graph for dns_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DNS_RequestHandle
 Handle to identify an individual DNS request. More...
 
struct  GNUNET_DNS_Handle
 DNS handle. More...
 

Functions

static void reconnect (void *cls)
 Reconnect to the DNS service. More...
 
static void force_reconnect (struct GNUNET_DNS_Handle *dh)
 Drop the existing connection and reconnect to the DNS service. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static int check_request (void *cls, const struct GNUNET_DNS_Request *req)
 This receives packets from the DNS service and calls the application to check that the request is well-formed. More...
 
static void handle_request (void *cls, const struct GNUNET_DNS_Request *req)
 This receives packets from the DNS service and calls the application to handle it. More...
 
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 global DNS for resolution. More...
 
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 should be generated. More...
 
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 data provided to this call (with the modifications the function might have made). More...
 
struct GNUNET_DNS_HandleGNUNET_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. More...
 
void GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh)
 Disconnect from the DNS service. More...
 

Detailed Description

API to access the DNS service.

Author
Christian Grothoff

Definition in file dns_api.c.

Function Documentation

◆ reconnect()

static void reconnect ( void *  cls)
static

Reconnect to the DNS service.

Parameters
clshandle with the connection to connect

Definition at line 196 of file dns_api.c.

197{
198 struct GNUNET_DNS_Handle *dh = cls;
202 struct GNUNET_DNS_Request,
203 dh),
205 };
206 struct GNUNET_MQ_Envelope *env;
207 struct GNUNET_DNS_Register *msg;
208
209 dh->reconnect_task = NULL;
210 dh->mq = GNUNET_CLIENT_connect (dh->cfg,
211 "dns",
212 handlers,
214 dh);
215 if (NULL == dh->mq)
216 return;
217 dh->generation++;
220 msg->flags = htonl (dh->flags);
221 GNUNET_MQ_send (dh->mq,
222 env);
223}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Definition: dns_api.c:139
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:40
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST
Type of messages between the gnunet-helper-dns and the service.
#define GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT
Initial message from client to DNS service for registration.
DNS handle.
Definition: dns_api.c:57
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
enum GNUNET_DNS_Flags flags
Flags for events we care about.
Definition: dns_api.c:91
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:86
Message from client to DNS service to register itself.
Definition: dns.h:36
Message from DNS service to client: please handle a request.
Definition: dns.h:53
Message handler for a specific message type.

References GNUNET_DNS_Handle::cfg, env, GNUNET_DNS_Handle::flags, GNUNET_DNS_Handle::generation, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_DNS_CLIENT_INIT, GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, GNUNET_DNS_Handle::mq, mq_error_handler(), msg, GNUNET_DNS_Handle::reconnect_task, and request.

Referenced by force_reconnect(), and GNUNET_DNS_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ force_reconnect()

static void force_reconnect ( struct GNUNET_DNS_Handle dh)
static

Drop the existing connection and reconnect to the DNS service.

Parameters
dhhandle with the connection

Definition at line 116 of file dns_api.c.

117{
118 if (NULL != dh->mq)
119 {
120 GNUNET_MQ_destroy (dh->mq);
121 dh->mq = NULL;
122 }
123 dh->reconnect_task =
125 &reconnect,
126 dh);
127}
static void reconnect(void *cls)
Reconnect to the DNS service.
Definition: dns_api.c:196
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
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:1277
#define GNUNET_TIME_UNIT_SECONDS
One second.

References GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_SECONDS, GNUNET_DNS_Handle::mq, reconnect(), and GNUNET_DNS_Handle::reconnect_task.

Referenced by mq_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_DNS_Handle *
errorerror code

Definition at line 139 of file dns_api.c.

141{
142 struct GNUNET_DNS_Handle *dh = cls;
143
144 force_reconnect (dh);
145}
static void force_reconnect(struct GNUNET_DNS_Handle *dh)
Drop the existing connection and reconnect to the DNS service.
Definition: dns_api.c:116

References force_reconnect().

Referenced by reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_request()

static int check_request ( void *  cls,
const struct GNUNET_DNS_Request req 
)
static

This receives packets from the DNS service and calls the application to check that the request is well-formed.

Parameters
clsthe struct GNUNET_DNS_Handle
reqmessage from the service (request)

Definition at line 156 of file dns_api.c.

158{
159 if (0 != ntohl (req->reserved))
160 {
161 GNUNET_break (0);
162 return GNUNET_SYSERR;
163 }
164 return GNUNET_OK;
165}
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
uint32_t reserved
Always zero.
Definition: dns.h:62

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, and GNUNET_DNS_Request::reserved.

◆ handle_request()

static void handle_request ( void *  cls,
const struct GNUNET_DNS_Request req 
)
static

This receives packets from the DNS service and calls the application to handle it.

Parameters
clsthe struct GNUNET_DNS_Handle *
reqmessage from the service (request)

Definition at line 176 of file dns_api.c.

178{
179 struct GNUNET_DNS_Handle *dh = cls;
180 size_t payload_length = ntohs (req->header.size) - sizeof(*req);
181 struct GNUNET_DNS_RequestHandle *rh;
182
184 rh->dh = dh;
185 rh->request_id = req->request_id;
186 rh->generation = dh->generation;
188 dh->rh (dh->rh_cls,
189 rh,
190 payload_length,
191 (const char *) &req[1]);
192}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
GNUNET_DNS_RequestHandler rh
Function to call to get replies.
Definition: dns_api.c:71
unsigned int pending_requests
Number of GNUNET_DNS_RequestHandles we have outstanding.
Definition: dns_api.c:97
void * rh_cls
Closure for rh.
Definition: dns_api.c:76
Handle to identify an individual DNS request.
Definition: dns_api.c:35
struct GNUNET_DNS_Handle * dh
Handle to DNS API.
Definition: dns_api.c:39
uint32_t generation
Re-connect counter, to make sure we did not reconnect in the meantime.
Definition: dns_api.c:49
uint64_t request_id
Stored in network byte order (as for us, it is just a random number).
Definition: dns_api.c:44
uint64_t request_id
Unique request ID.
Definition: dns.h:67
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_DNS_CLIENT_REQUEST.
Definition: dns.h:57

References GNUNET_DNS_RequestHandle::dh, GNUNET_DNS_RequestHandle::generation, GNUNET_DNS_Handle::generation, GNUNET_new, GNUNET_DNS_Request::header, GNUNET_DNS_Handle::pending_requests, GNUNET_DNS_Request::request_id, GNUNET_DNS_RequestHandle::request_id, GNUNET_DNS_Handle::rh, GNUNET_DNS_Handle::rh_cls, and GNUNET_MessageHeader::size.