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>
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? More... | |
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. More... | |
static void | terminate_ac_activities (struct AutoconfigContext *ac) |
Stop all pending activities with respect to the ac. More... | |
static void | conclude_autoconfig_request (void *cls) |
Finish handling the autoconfiguration request and send the response to the client. More... | |
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. More... | |
static void | update_enable_upnpc_option (struct AutoconfigContext *ac) |
Update ENABLE_UPNPC configuration option. More... | |
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. More... | |
static void | shutdown_task (void *cls) |
Task run during shutdown. More... | |
static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service) |
Setup NAT service. More... | |
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. More... | |
static void | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) |
Callback called when a client disconnected from the service. More... | |
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. More... | |
Variables | |
static struct ClientHandle * | ch_head |
Head of client DLL. More... | |
static struct ClientHandle * | ch_tail |
Tail of client DLL. More... | |
static struct AutoconfigContext * | ac_head |
DLL of our autoconfiguration operations. More... | |
static struct AutoconfigContext * | ac_tail |
DLL of our autoconfiguration operations. More... | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Handle to our current configuration. More... | |
static struct GNUNET_STATISTICS_Handle * | stats |
Handle to the statistics service. More... | |
NAT autoconfiguration service.
TODO:
Definition in file gnunet-service-nat-auto.c.
#define AUTOCONFIG_TIMEOUT |
How long do we wait until we forcefully terminate autoconfiguration?
Definition at line 45 of file gnunet-service-nat-auto.c.
|
static |
Check validity of #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.
cls | client who sent the message |
message | the message received |
Definition at line 170 of file gnunet-service-nat-auto.c.
References GNUNET_OK.
|
static |
Stop all pending activities with respect to the ac.
ac | autoconfiguration to terminate activities for |
Definition at line 184 of file gnunet-service-nat-auto.c.
References GNUNET_SCHEDULER_cancel(), and AutoconfigContext::timeout_task.
Referenced by conclude_autoconfig_request(), and shutdown_task().
|
static |
Finish handling the autoconfiguration request and send the response to the client.
cls | the struct AutoconfigContext to conclude |
Definition at line 201 of file gnunet-service-nat-auto.c.
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().
|
static |
Check if all autoconfiguration operations have concluded, and if they have, send the result back to the client.
ac | autoconfiguation 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().
|
static |
Update ENABLE_UPNPC configuration option.
ac | autoconfiguration to update |
Definition at line 265 of file gnunet-service-nat-auto.c.
References AutoconfigContext::c, AutoconfigContext::enable_upnpc, GNUNET_CONFIGURATION_set_value_string(), GNUNET_NO, GNUNET_SYSERR, and GNUNET_YES.
Referenced by handle_autoconfig_request().
|
static |
Handler for #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG message from client.
cls | client who sent the message |
message | the message received |
Definition at line 298 of file gnunet-service-nat-auto.c.
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().
|
static |
Task run during shutdown.
cls | unused |
Definition at line 364 of file gnunet-service-nat-auto.c.
References ac_head, ac_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_destroy(), stats, and terminate_ac_activities().
Referenced by run().
|
static |
Setup NAT service.
cls | closure |
c | configuration to use |
service | the initialized service |
Definition at line 393 of file gnunet-service-nat-auto.c.
References AutoconfigContext::c, cfg, GNUNET_SCHEDULER_add_shutdown(), GNUNET_STATISTICS_create(), shutdown_task(), and stats.
|
static |
Callback called when a client connects to the service.
cls | closure for the service |
c | the new client that connected to the service |
mq | the message queue used to send messages to the client |
struct ClientHandle
Definition at line 414 of file gnunet-service-nat-auto.c.
References ch, ch_head, ch_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_new, mq, and GNUNET_CADET_Channel::mq.
|
static |
Callback called when a client disconnected from the service.
cls | closure for the service |
c | the client that disconnected |
internal_cls | a struct ClientHandle * |
Definition at line 438 of file gnunet-service-nat-auto.c.
References ch, ch_head, ch_tail, GNUNET_CONTAINER_DLL_remove, and GNUNET_free.
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.
|
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().
|
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().
|
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().
|
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().
|
static |
Handle to our current configuration.
Definition at line 153 of file gnunet-service-nat-auto.c.
Referenced by run().
|
static |
Handle to the statistics service.
Definition at line 158 of file gnunet-service-nat-auto.c.
Referenced by run(), and shutdown_task().