GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-service-nat-auto.c File Reference

NAT autoconfiguration service. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_nat_service.h"
#include "gnunet_statistics_service.h"
#include "nat-auto.h"
#include <gcrypt.h>
Include dependency graph for gnunet-service-nat-auto.c:

Go to the source code of this file.

Data Structures

struct  ClientHandle
 Struct containing information about a client, handle to connect to it, and any pending messages that need to be sent to it. More...
 
struct  AutoconfigContext
 Context for autoconfiguration operations. More...
 

Macros

#define AUTOCONFIG_TIMEOUT
 How long do we wait until we forcefully terminate autoconfiguration?
 

Functions

static int check_autoconfig_request (void *cls, const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *message)
 Check validity of #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.
 
static void terminate_ac_activities (struct AutoconfigContext *ac)
 Stop all pending activities with respect to the ac.
 
static void conclude_autoconfig_request (void *cls)
 Finish handling the autoconfiguration request and send the response to the client.
 
static void check_autoconfig_finished (struct AutoconfigContext *ac)
 Check if all autoconfiguration operations have concluded, and if they have, send the result back to the client.
 
static void update_enable_upnpc_option (struct AutoconfigContext *ac)
 Update ENABLE_UPNPC configuration option.
 
static void handle_autoconfig_request (void *cls, const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *message)
 Handler for #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.
 
static void shutdown_task (void *cls)
 Task run during shutdown.
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Setup NAT service.
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
 Callback called when a client connects to the service.
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
 Callback called when a client disconnected from the service.
 
 GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "nat-auto", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(autoconfig_request, GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG, struct GNUNET_NAT_AUTO_AutoconfigRequestMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro.
 

Variables

static struct ClientHandlech_head
 Head of client DLL.
 
static struct ClientHandlech_tail
 Tail of client DLL.
 
static struct AutoconfigContextac_head
 DLL of our autoconfiguration operations.
 
static struct AutoconfigContextac_tail
 DLL of our autoconfiguration operations.
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Handle to our current configuration.
 
static struct GNUNET_STATISTICS_Handlestats
 Handle to the statistics service.
 

Detailed Description

NAT autoconfiguration service.

Author
Christian Grothoff

TODO:

  • merge client handle and autoconfig context
  • implement "more" autoconfig:
    • re-work gnunet-nat-server & integrate!
    • integrate "legacy" code
    • test manually punched NAT (how?)

Definition in file gnunet-service-nat-auto.c.

Macro Definition Documentation

◆ AUTOCONFIG_TIMEOUT

#define AUTOCONFIG_TIMEOUT
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition time.c:486

How long do we wait until we forcefully terminate autoconfiguration?

Definition at line 45 of file gnunet-service-nat-auto.c.

52{
56 struct ClientHandle *next;
57
61 struct ClientHandle *prev;
62
66 struct GNUNET_SERVICE_Client *client;
67
71 struct GNUNET_MQ_Handle *mq;
72};
73
74
79{
83 struct AutoconfigContext *prev;
84
88 struct AutoconfigContext *next;
89
93 struct ClientHandle *ch;
94
99
104
109
115 int enable_upnpc;
116
121
126};
127
128
132static struct ClientHandle *ch_head;
133
137static struct ClientHandle *ch_tail;
138
142static struct AutoconfigContext *ac_head;
143
147static struct AutoconfigContext *ac_tail;
148
152static const struct GNUNET_CONFIGURATION_Handle *cfg;
153
157static struct GNUNET_STATISTICS_Handle *stats;
158
159
168static int
169check_autoconfig_request (void *cls,
170 const struct
172{
173 return GNUNET_OK; /* checked later */
174}
175
176
182static void
184{
185 if (NULL != ac->timeout_task)
186 {
188 ac->timeout_task = NULL;
189 }
190}
191
192
199static void
201{
202 struct AutoconfigContext *ac = cls;
203 struct ClientHandle *ch = ac->ch;
205 struct GNUNET_MQ_Envelope *env;
206 size_t c_size;
207 char *buf;
208 struct GNUNET_CONFIGURATION_Handle *diff;
209
210 ac->timeout_task = NULL;
212
213 /* Send back response */
215 ac->c);
217 &c_size);
220 c_size,
222 arm->status_code = htonl ((uint32_t) ac->status_code);
223 arm->type = htonl ((uint32_t) ac->type);
224 GNUNET_memcpy (&arm[1],
225 buf,
226 c_size);
227 GNUNET_free (buf);
229 env);
230
231 /* clean up */
235 ac_tail,
236 ac);
237 GNUNET_free (ac);
239}
240
241
248static void
250{
252 ac->timeout_task
254 ac);
255}
256
257
263static void
265{
266 switch (ac->enable_upnpc)
267 {
268 case GNUNET_YES:
270 "NAT",
271 "ENABLE_UPNP",
272 "YES");
273 break;
274
275 case GNUNET_NO:
277 "NAT",
278 "ENABLE_UPNP",
279 "NO");
280 break;
281
282 case GNUNET_SYSERR:
283 /* We are unsure, do not change option */
284 break;
285 }
286}
287
288
296static void
298 const struct
300{
301 struct ClientHandle *ch = cls;
302 size_t left = ntohs (message->header.size) - sizeof(*message);
303 struct AutoconfigContext *ac;
304
305 ac = GNUNET_new (struct AutoconfigContext);
307 ac->ch = ch;
309 if (GNUNET_OK !=
311 (const char *) &message[1],
312 left,
313 NULL))
314 {
315 GNUNET_break (0);
318 GNUNET_free (ac);
319 return;
320 }
322 "Received REQUEST_AUTO_CONFIG message from client\n");
323
325 ac_tail,
326 ac);
327 ac->orig
329 ac->timeout_task
332 ac);
333 ac->enable_upnpc = GNUNET_SYSERR; /* undecided */
334
335 /* Probe for upnpc */
336 if (GNUNET_SYSERR ==
338 GNUNET_NO,
339 NULL))
340 {
342 _ ("UPnP client `upnpc` command not found, disabling UPnP\n"));
344 }
345 else
346 {
347 /* We might at some point be behind NAT, try upnpc */
349 }
351
352 /* Finally, check if we are already done */
354}
355
356
362static void
363shutdown_task (void *cls)
364{
365 struct AutoconfigContext *ac;
366
367 while (NULL != (ac = ac_head))
368 {
370 ac_tail,
371 ac);
373 GNUNET_free (ac);
374 }
375 if (NULL != stats)
376 {
378 GNUNET_NO);
379 stats = NULL;
380 }
381}
382
383
391static void
392run (void *cls,
393 const struct GNUNET_CONFIGURATION_Handle *c,
395{
396 cfg = c;
398 NULL);
399 stats = GNUNET_STATISTICS_create ("nat-auto",
400 cfg);
401}
402
403
412static void *
413client_connect_cb (void *cls,
414 struct GNUNET_SERVICE_Client *c,
415 struct GNUNET_MQ_Handle *mq)
416{
417 struct ClientHandle *ch;
418
419 ch = GNUNET_new (struct ClientHandle);
420 ch->mq = mq;
421 ch->client = c;
423 ch_tail,
424 ch);
425 return ch;
426}
427
428
436static void
437client_disconnect_cb (void *cls,
438 struct GNUNET_SERVICE_Client *c,
439 void *internal_cls)
440{
441 struct ClientHandle *ch = internal_cls;
442
444 ch_tail,
445 ch);
446 GNUNET_free (ch);
447}
448
449
455 "nat-auto",
457 &run,
460 NULL,
461 GNUNET_MQ_hd_var_size (autoconfig_request,
464 NULL),
466
467
468#if defined(__linux__) && defined(__GLIBC__)
469#include <malloc.h>
470
471void __attribute__((constructor)) GNUNET_NAT_memory_init (void);
472
476void __attribute__ ((constructor))
477GNUNET_NAT_memory_init ()
478{
479 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
480 mallopt (M_TOP_PAD, 1 * 1024);
481 malloc_trim (0);
482}
483
484
485#endif
486
487/* end of gnunet-service-nat.c */
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static struct GNUNET_CADET_Channel * ch
Channel handle.
struct GNUNET_SCHEDULER_Task * shutdown_task
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static struct AutoconfigContext * ac_tail
DLL of our autoconfiguration operations.
static void handle_autoconfig_request(void *cls, const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *message)
Handler for #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.
static void conclude_autoconfig_request(void *cls)
Finish handling the autoconfiguration request and send the response to the client.
static int check_autoconfig_request(void *cls, const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *message)
Check validity of #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.
static struct ClientHandle * ch_head
Head of client DLL.
static struct AutoconfigContext * ac_head
DLL of our autoconfiguration operations.
static void update_enable_upnpc_option(struct AutoconfigContext *ac)
Update ENABLE_UPNPC configuration option.
#define AUTOCONFIG_TIMEOUT
How long do we wait until we forcefully terminate autoconfiguration?
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
static struct ClientHandle * ch_tail
Tail of client DLL.
static void terminate_ac_activities(struct AutoconfigContext *ac)
Stop all pending activities with respect to the ac.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Setup NAT service.
static void check_autoconfig_finished(struct AutoconfigContext *ac)
Check if all autoconfiguration operations have concluded, and if they have, send the result back to t...
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback called when a client connects to the service.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback called when a client disconnected from the service.
struct GNUNET_PQ_ResultSpec __attribute__
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, const char *source_filename)
De-serializes configuration.
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
#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.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
GNUNET_NAT_StatusCode
Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
GNUNET_NAT_Type
What the situation of the NAT connectivity.
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT
Message from NAT service with the autoconfiguration result.
#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG
Message to ask NAT service to request autoconfiguration.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304
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_SERVICE_MAIN(pd, service_name, service_options, init_cb, connect_cb, disconnect_cb, cls,...)
Creates the "main" function for a GNUnet service.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition service.c:2462
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition service.c:2433
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Context for autoconfiguration operations.
struct AutoconfigContext * prev
Kept in a DLL.
struct AutoconfigContext * next
Kept in a DLL.
int enable_upnpc
GNUNET_YES if upnpc should be used, GNUNET_NO if upnpc should not be used, GNUNET_SYSERR if we should...
struct GNUNET_CONFIGURATION_Handle * c
Configuration we are creating.
enum GNUNET_NAT_Type type
NAT type to return to the client.
struct GNUNET_CONFIGURATION_Handle * orig
Original configuration (for diffing).
enum GNUNET_NAT_StatusCode status_code
Status code to return to the client.
struct ClientHandle * ch
Which client asked the question.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task to force termination.
Struct containing information about a client, handle to connect to it, and any pending messages that ...
struct ClientHandle * prev
Kept in a DLL.
struct ClientHandle * next
Kept in a DLL.
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition cadet.h:142
Handle to a message queue.
Definition mq.c:87
Client requesting automatic configuration.
Definition nat-auto.h:71
struct GNUNET_MessageHeader header
Header with type #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG.
Definition nat-auto.h:75
Service responding with proposed configuration.
Definition nat-auto.h:85
int32_t type
An enum GNUNET_NAT_Type in NBO.
Definition nat-auto.h:99
int32_t status_code
An enum GNUNET_NAT_StatusCode in NBO.
Definition nat-auto.h:94
Entry in list of pending tasks.
Definition scheduler.c:136
Handle to a client that is connected to a service.
Definition service.c:249
Handle to a service.
Definition service.c:116
Handle for the service.

Function Documentation

◆ check_autoconfig_request()

static int check_autoconfig_request ( void *  cls,
const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage message 
)
static

Check validity of #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.

Parameters
clsclient who sent the message
messagethe message received
Returns
GNUNET_OK if message is well-formed

Definition at line 170 of file gnunet-service-nat-auto.c.

173{
174 return GNUNET_OK; /* checked later */
175}

References GNUNET_OK.

◆ terminate_ac_activities()

static void terminate_ac_activities ( struct AutoconfigContext ac)
static

Stop all pending activities with respect to the ac.

Parameters
acautoconfiguration to terminate activities for

Definition at line 184 of file gnunet-service-nat-auto.c.

185{
186 if (NULL != ac->timeout_task)
187 {
189 ac->timeout_task = NULL;
190 }
191}

References GNUNET_SCHEDULER_cancel(), and AutoconfigContext::timeout_task.

Referenced by conclude_autoconfig_request(), and shutdown_task().

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

◆ conclude_autoconfig_request()

static void conclude_autoconfig_request ( void *  cls)
static

Finish handling the autoconfiguration request and send the response to the client.

Parameters
clsthe struct AutoconfigContext to conclude

Definition at line 201 of file gnunet-service-nat-auto.c.

202{
203 struct AutoconfigContext *ac = cls;
204 struct ClientHandle *ch = ac->ch;
206 struct GNUNET_MQ_Envelope *env;
207 size_t c_size;
208 char *buf;
209 struct GNUNET_CONFIGURATION_Handle *diff;
210
211 ac->timeout_task = NULL;
213
214 /* Send back response */
216 ac->c);
218 &c_size);
221 c_size,
223 arm->status_code = htonl ((uint32_t) ac->status_code);
224 arm->type = htonl ((uint32_t) ac->type);
225 GNUNET_memcpy (&arm[1],
226 buf,
227 c_size);
228 GNUNET_free (buf);
230 env);
231
232 /* clean up */
236 ac_tail,
237 ac);
238 GNUNET_free (ac);
240}

References ac_head, ac_tail, AutoconfigContext::c, ch, AutoconfigContext::ch, env, GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_serialize(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_SERVICE_client_continue(), GNUNET_CADET_Channel::mq, AutoconfigContext::orig, AutoconfigContext::status_code, GNUNET_NAT_AUTO_AutoconfigResultMessage::status_code, terminate_ac_activities(), AutoconfigContext::timeout_task, AutoconfigContext::type, and GNUNET_NAT_AUTO_AutoconfigResultMessage::type.

Referenced by check_autoconfig_finished(), and handle_autoconfig_request().

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

◆ check_autoconfig_finished()

static void check_autoconfig_finished ( struct AutoconfigContext ac)
static

Check if all autoconfiguration operations have concluded, and if they have, send the result back to the client.

Parameters
acautoconfiguation context to check

Definition at line 250 of file gnunet-service-nat-auto.c.

References conclude_autoconfig_request(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), and AutoconfigContext::timeout_task.

Referenced by handle_autoconfig_request().

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

◆ update_enable_upnpc_option()

static void update_enable_upnpc_option ( struct AutoconfigContext ac)
static

Update ENABLE_UPNPC configuration option.

Parameters
acautoconfiguration to update

Definition at line 265 of file gnunet-service-nat-auto.c.

266{
267 switch (ac->enable_upnpc)
268 {
269 case GNUNET_YES:
271 "NAT",
272 "ENABLE_UPNP",
273 "YES");
274 break;
275
276 case GNUNET_NO:
278 "NAT",
279 "ENABLE_UPNP",
280 "NO");
281 break;
282
283 case GNUNET_SYSERR:
284 /* We are unsure, do not change option */
285 break;
286 }
287}

References AutoconfigContext::c, AutoconfigContext::enable_upnpc, GNUNET_CONFIGURATION_set_value_string(), GNUNET_NO, GNUNET_SYSERR, and GNUNET_YES.

Referenced by handle_autoconfig_request().

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

◆ handle_autoconfig_request()

static void handle_autoconfig_request ( void *  cls,
const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage message 
)
static

Handler for #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 298 of file gnunet-service-nat-auto.c.

301{
302 struct ClientHandle *ch = cls;
303 size_t left = ntohs (message->header.size) - sizeof(*message);
304 struct AutoconfigContext *ac;
305
306 ac = GNUNET_new (struct AutoconfigContext);
308 ac->ch = ch;
310 if (GNUNET_OK !=
312 (const char *) &message[1],
313 left,
314 NULL))
315 {
316 GNUNET_break (0);
319 GNUNET_free (ac);
320 return;
321 }
323 "Received REQUEST_AUTO_CONFIG message from client\n");
324
326 ac_tail,
327 ac);
328 ac->orig
330 ac->timeout_task
333 ac);
334 ac->enable_upnpc = GNUNET_SYSERR; /* undecided */
335
336 /* Probe for upnpc */
337 if (GNUNET_SYSERR ==
339 GNUNET_NO,
340 NULL))
341 {
343 _ ("UPnP client `upnpc` command not found, disabling UPnP\n"));
345 }
346 else
347 {
348 /* We might at some point be behind NAT, try upnpc */
350 }
352
353 /* Finally, check if we are already done */
355}

References _, ac_head, ac_tail, AUTOCONFIG_TIMEOUT, AutoconfigContext::c, ch, AutoconfigContext::ch, check_autoconfig_finished(), conclude_autoconfig_request(), AutoconfigContext::enable_upnpc, GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_deserialize(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_dup(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NAT_ERROR_SUCCESS, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_project_data_gnunet(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SERVICE_client_drop(), GNUNET_SYSERR, GNUNET_YES, GNUNET_NAT_AUTO_AutoconfigRequestMessage::header, AutoconfigContext::orig, GNUNET_MessageHeader::size, AutoconfigContext::status_code, AutoconfigContext::timeout_task, and update_enable_upnpc_option().

Here is the call graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 364 of file gnunet-service-nat-auto.c.

365{
366 struct AutoconfigContext *ac;
367
368 while (NULL != (ac = ac_head))
369 {
371 ac_tail,
372 ac);
374 GNUNET_free (ac);
375 }
376 if (NULL != stats)
377 {
379 GNUNET_NO);
380 stats = NULL;
381 }
382}

References ac_head, ac_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_destroy(), stats, and terminate_ac_activities().

Here is the call graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle service 
)
static

Setup NAT service.

Parameters
clsclosure
cconfiguration to use
servicethe initialized service

Definition at line 393 of file gnunet-service-nat-auto.c.

396{
397 cfg = c;
399 NULL);
400 stats = GNUNET_STATISTICS_create ("nat-auto",
401 cfg);
402}

References AutoconfigContext::c, cfg, GNUNET_SCHEDULER_add_shutdown(), GNUNET_STATISTICS_create(), shutdown_task, and stats.

Here is the call graph for this function:

◆ client_connect_cb()

static void * client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
struct GNUNET_MQ_Handle mq 
)
static

Callback called when a client connects to the service.

Parameters
clsclosure for the service
cthe new client that connected to the service
mqthe message queue used to send messages to the client
Returns
a struct ClientHandle

Definition at line 414 of file gnunet-service-nat-auto.c.

417{
418 struct ClientHandle *ch;
419
420 ch = GNUNET_new (struct ClientHandle);
421 ch->mq = mq;
422 ch->client = c;
424 ch_tail,
425 ch);
426 return ch;
427}

References ch, ch_head, ch_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_new, mq, and GNUNET_CADET_Channel::mq.

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
void *  internal_cls 
)
static

Callback called when a client disconnected from the service.

Parameters
clsclosure for the service
cthe client that disconnected
internal_clsa struct ClientHandle *

Definition at line 438 of file gnunet-service-nat-auto.c.

441{
442 struct ClientHandle *ch = internal_cls;
443
445 ch_tail,
446 ch);
447 GNUNET_free (ch);
448}

References ch, ch_head, ch_tail, GNUNET_CONTAINER_DLL_remove, and GNUNET_free.

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( GNUNET_OS_project_data_gnunet()  ,
"nat-auto"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_var_size(autoconfig_request, GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG, struct GNUNET_NAT_AUTO_AutoconfigRequestMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Variable Documentation

◆ ch_head

struct ClientHandle* ch_head
static

Head of client DLL.

Definition at line 133 of file gnunet-service-nat-auto.c.

Referenced by client_connect_cb(), and client_disconnect_cb().

◆ ch_tail

struct ClientHandle* ch_tail
static

Tail of client DLL.

Definition at line 138 of file gnunet-service-nat-auto.c.

Referenced by client_connect_cb(), and client_disconnect_cb().

◆ ac_head

struct AutoconfigContext* ac_head
static

DLL of our autoconfiguration operations.

Definition at line 143 of file gnunet-service-nat-auto.c.

Referenced by conclude_autoconfig_request(), handle_autoconfig_request(), and shutdown_task().

◆ ac_tail

struct AutoconfigContext* ac_tail
static

DLL of our autoconfiguration operations.

Definition at line 148 of file gnunet-service-nat-auto.c.

Referenced by conclude_autoconfig_request(), handle_autoconfig_request(), and shutdown_task().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Handle to our current configuration.

Definition at line 153 of file gnunet-service-nat-auto.c.

Referenced by run().

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Handle to the statistics service.

Definition at line 158 of file gnunet-service-nat-auto.c.

Referenced by run(), and shutdown_task().