#define GNUNET_NAT_AUTO_SERVICE_H
#include "gnunet_util_lib.h"
+#include "gnunet_nat_service.h"
/**
* Handle to a NAT test.
*/
-struct GNUNET_NAT_Test;
-
-
-/**
- * Function called to report success or failure for
- * NAT configuration test.
- *
- * @param cls closure
- * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
- */
-typedef void
-(*GNUNET_NAT_TestCallback) (void *cls,
- enum GNUNET_NAT_StatusCode result);
-
-
-/**
- * Handle an incoming STUN message. This function is useful as
- * some GNUnet service may be listening on a UDP port and might
- * thus receive STUN messages while trying to receive other data.
- * In this case, this function can be used to process replies
- * to STUN requests.
- *
- * The function does some basic sanity checks on packet size and
- * content, try to extract a bit of information.
- *
- * At the moment this only processes BIND requests, and returns the
- * externally visible address of the request to the rest of the
- * NAT logic.
- *
- * @param nh handle to the NAT service
- * @param sender_addr address from which we got @a data
- * @param sender_addr_len number of bytes in @a sender_addr
- * @param data the packet
- * @param data_size number of bytes in @a data
- * @return #GNUNET_OK on success
- * #GNUNET_NO if the packet is not a STUN packet
- * #GNUNET_SYSERR on internal error handling the packet
- */
-int
-GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nh,
- const struct sockaddr *sender_addr,
- size_t sender_addr_len,
- const void *data,
- size_t data_size);
-
-
-/**
- * Handle to a request given to the resolver. Can be used to cancel
- * the request prior to the timeout or successful execution. Also
- * used to track our internal state for the request.
- */
-struct GNUNET_NAT_STUN_Handle;
-
-
-/**
- * Make Generic STUN request. Sends a generic stun request to the
- * server specified using the specified socket. If we do this,
- * we need to watch for possible responses and call
- * #GNUNET_NAT_stun_handle_packet() on incoming packets.
- *
- * @param server the address of the stun server
- * @param port port of the stun server, in host byte order
- * @param sock the socket used to send the request, must be a
- * UDP socket
- * @param cb callback in case of error
- * @param cb_cls closure for @a cb
- * @return NULL on error
- */
-struct GNUNET_NAT_STUN_Handle *
-GNUNET_NAT_stun_make_request (const char *server,
- uint16_t port,
- struct GNUNET_NETWORK_Handle *sock,
- GNUNET_NAT_TestCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel active STUN request. Frees associated resources
- * and ensures that the callback is no longer invoked.
- *
- * @param rh request to cancel
- */
-void
-GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh);
+struct GNUNET_NAT_AUTO_Test;
/**
* @param report_cls closure for @a report
* @return handle to cancel NAT test
*/
-struct GNUNET_NAT_Test *
-GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- uint8_t proto,
- struct in_addr bind_ip,
- uint16_t bnd_port,
- struct in_addr extern_ip,
- uint16_t extern_port,
- GNUNET_NAT_TestCallback report,
- void *report_cls);
+struct GNUNET_NAT_AUTO_Test *
+GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ uint8_t proto,
+ struct in_addr bind_ip,
+ uint16_t bnd_port,
+ struct in_addr extern_ip,
+ uint16_t extern_port,
+ GNUNET_NAT_TestCallback report,
+ void *report_cls);
/**
* @param tst test to stop.
*/
void
-GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst);
+GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst);
/**
* Handle to auto-configuration in progress.
*/
-struct GNUNET_NAT_AutoHandle;
+struct GNUNET_NAT_AUTO_AutoHandle;
/**
* @return point to a static string containing the error code
*/
const char *
-GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err);
+GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err);
/**
* @param type what the situation of the NAT
*/
typedef void
-(*GNUNET_NAT_AutoResultCallback)(void *cls,
- const struct GNUNET_CONFIGURATION_Handle *diff,
- enum GNUNET_NAT_StatusCode result,
- enum GNUNET_NAT_Type type);
+(*GNUNET_NAT_AUTO_AutoResultCallback)(void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *diff,
+ enum GNUNET_NAT_StatusCode result,
+ enum GNUNET_NAT_Type type);
/**
* @param cb_cls closure for @a cb
* @return handle to cancel operation
*/
-struct GNUNET_NAT_AutoHandle *
-GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_NAT_AutoResultCallback cb,
- void *cb_cls);
+struct GNUNET_NAT_AUTO_AutoHandle *
+GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_NAT_AUTO_AutoResultCallback cb,
+ void *cb_cls);
/**
* @param ah handle for operation to abort
*/
void
-GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah);
+GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah);
#endif
size_t data_size);
+/**
+ * Handle to a request given to the resolver. Can be used to cancel
+ * the request prior to the timeout or successful execution. Also
+ * used to track our internal state for the request.
+ */
+struct GNUNET_NAT_STUN_Handle;
+
+
+/**
+ * Function called to report success or failure for
+ * NAT configuration test.
+ *
+ * @param cls closure
+ * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
+ */
+typedef void
+(*GNUNET_NAT_TestCallback) (void *cls,
+ enum GNUNET_NAT_StatusCode result);
+
+
+/**
+ * Make Generic STUN request. Sends a generic stun request to the
+ * server specified using the specified socket. If we do this,
+ * we need to watch for possible responses and call
+ * #GNUNET_NAT_stun_handle_packet() on incoming packets.
+ *
+ * @param server the address of the stun server
+ * @param port port of the stun server, in host byte order
+ * @param sock the socket used to send the request, must be a
+ * UDP socket
+ * @param cb callback in case of error
+ * @param cb_cls closure for @a cb
+ * @return NULL on error
+ */
+struct GNUNET_NAT_STUN_Handle *
+GNUNET_NAT_stun_make_request (const char *server,
+ uint16_t port,
+ struct GNUNET_NETWORK_Handle *sock,
+ GNUNET_NAT_TestCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel active STUN request. Frees associated resources
+ * and ensures that the callback is no longer invoked.
+ *
+ * @param rh request to cancel
+ */
+void
+GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh);
+
+
#endif
/** @} */ /* end of group */
/**
* Handle to ongoing autoconfiguration.
*/
-static struct GNUNET_NAT_AutoHandle *ah;
+static struct GNUNET_NAT_AUTO_AutoHandle *ah;
/**
* If we do auto-configuration, should we write the result
/**
* Handle to a NAT test operation.
*/
-static struct GNUNET_NAT_Test *nt;
+static struct GNUNET_NAT_AUTO_Test *nt;
/**
* Flag set to 1 if we use IPPROTO_UDP.
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
"NAT status: %s/%s\n",
- GNUNET_NAT_status2string (result),
+ GNUNET_NAT_AUTO_status2string (result),
nat_type);
/* Shortcut: if there are no changes suggested, bail out early. */
{
nt = NULL;
PRINTF ("NAT test result: %s\n",
- GNUNET_NAT_status2string (result));
+ GNUNET_NAT_AUTO_status2string (result));
test_finished ();
}
{
if (NULL != ah)
{
- GNUNET_NAT_autoconfig_cancel (ah);
+ GNUNET_NAT_AUTO_autoconfig_cancel (ah);
ah = NULL;
}
if (NULL != nt)
{
- GNUNET_NAT_test_stop (nt);
+ GNUNET_NAT_AUTO_test_stop (nt);
nt = NULL;
}
}
if (do_auto)
{
- ah = GNUNET_NAT_autoconfig_start (c,
+ ah = GNUNET_NAT_AUTO_autoconfig_start (c,
&auto_config_cb,
NULL);
}
{
if (NULL == extern_addr)
extern_sa = bind_sa;
- nt = GNUNET_NAT_test_start (c,
- proto,
- bind_sa.sin_addr,
- ntohs (bind_sa.sin_port),
- extern_sa.sin_addr,
- ntohs (extern_sa.sin_port),
- &test_report_cb,
- NULL);
+ nt = GNUNET_NAT_AUTO_test_start (c,
+ proto,
+ bind_sa.sin_addr,
+ ntohs (bind_sa.sin_port),
+ extern_sa.sin_addr,
+ ntohs (extern_sa.sin_port),
+ &test_report_cb,
+ NULL);
}
test_finished ();
}
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *msg)
{
- const struct GNUNET_NAT_TestMessage *tm;
+ const struct GNUNET_NAT_AUTO_TestMessage *tm;
uint16_t dport;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received test request\n");
- tm = (const struct GNUNET_NAT_TestMessage *) msg;
+ tm = (const struct GNUNET_NAT_AUTO_TestMessage *) msg;
dport = ntohs (tm->dport);
if (0 == dport)
try_anat (tm->dst_ipv4,
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
{&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST,
- sizeof (struct GNUNET_NAT_TestMessage)},
+ sizeof (struct GNUNET_NAT_AUTO_TestMessage)},
{NULL, NULL, 0, 0}
};
unsigned int port;
*/
static int
check_autoconfig_request (void *cls,
- const struct GNUNET_NAT_AutoconfigRequestMessage *message)
+ const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *message)
{
return GNUNET_OK; /* checked later */
}
{
struct AutoconfigContext *ac = cls;
struct ClientHandle *ch = ac->ch;
- struct GNUNET_NAT_AutoconfigResultMessage *arm;
+ struct GNUNET_NAT_AUTO_AutoconfigResultMessage *arm;
struct GNUNET_MQ_Envelope *env;
size_t c_size;
char *buf;
*/
static void
handle_autoconfig_request (void *cls,
- const struct GNUNET_NAT_AutoconfigRequestMessage *message)
+ const struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *message)
{
struct ClientHandle *ch = cls;
size_t left = ntohs (message->header.size) - sizeof (*message);
NULL,
GNUNET_MQ_hd_var_size (autoconfig_request,
GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG,
- struct GNUNET_NAT_AutoconfigRequestMessage,
+ struct GNUNET_NAT_AUTO_AutoconfigRequestMessage,
NULL),
GNUNET_MQ_handler_end ());
* Request to test NAT traversal, sent to the gnunet-nat-server
* (not the service!).
*/
-struct GNUNET_NAT_TestMessage
+struct GNUNET_NAT_AUTO_TestMessage
{
/**
* Header with type #GNUNET_MESSAGE_TYPE_NAT_TEST
/**
* Client requesting automatic configuration.
*/
-struct GNUNET_NAT_AutoconfigRequestMessage
+struct GNUNET_NAT_AUTO_AutoconfigRequestMessage
{
/**
* Header with type #GNUNET_MESSAGE_TYPE_NAT_REQUEST_AUTO_CFG
/**
* Service responding with proposed configuration.
*/
-struct GNUNET_NAT_AutoconfigResultMessage
+struct GNUNET_NAT_AUTO_AutoconfigResultMessage
{
/**
* Header with type #GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT
-
/*
This file is part of GNUnet.
- Copyright (C) 2007-2016 GNUnet e.V.
+ Copyright (C) 2007-2017 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* @author Christian Grothoff
* @author Milan Bouchet-Valat
*
- * @file nat/nat_auto_api.c
+ * @file nat-auto/nat_auto_api.c
* Routines for NAT auto configuration.
*/
#include "platform.h"
/**
* Handle to auto-configuration in progress.
*/
-struct GNUNET_NAT_AutoHandle
+struct GNUNET_NAT_AUTO_AutoHandle
{
/**
/**
* Function called with the result from the autoconfiguration.
*/
- GNUNET_NAT_AutoResultCallback arc;
+ GNUNET_NAT_AUTO_AutoResultCallback arc;
/**
* Closure for @e arc.
* @return point to a static string containing the error code
*/
const char *
-GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err)
+GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err)
{
switch (err)
{
/**
* Check result from autoconfiguration attempt.
*
- * @param cls the `struct GNUNET_NAT_AutoHandle`
+ * @param cls the `struct GNUNET_NAT_AUTO_AutoHandle`
* @param res the result
* @return #GNUNET_OK if @a res is well-formed (always for now)
*/
static int
check_auto_result (void *cls,
- const struct GNUNET_NAT_AutoconfigResultMessage *res)
+ const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res)
{
return GNUNET_OK;
}
/**
* Handle result from autoconfiguration attempt.
*
- * @param cls the `struct GNUNET_NAT_AutoHandle`
+ * @param cls the `struct GNUNET_NAT_AUTO_AutoHandle`
* @param res the result
*/
static void
handle_auto_result (void *cls,
- const struct GNUNET_NAT_AutoconfigResultMessage *res)
+ const struct GNUNET_NAT_AUTO_AutoconfigResultMessage *res)
{
- struct GNUNET_NAT_AutoHandle *ah = cls;
+ struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
size_t left;
struct GNUNET_CONFIGURATION_Handle *cfg;
enum GNUNET_NAT_Type type
type);
}
GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_NAT_autoconfig_cancel (ah);
+ GNUNET_NAT_AUTO_autoconfig_cancel (ah);
}
/**
* Handle queue errors by reporting autoconfiguration failure.
*
- * @param cls the `struct GNUNET_NAT_AutoHandle *`
+ * @param cls the `struct GNUNET_NAT_AUTO_AutoHandle *`
* @param error details about the error
*/
static void
ah_error_handler (void *cls,
enum GNUNET_MQ_Error error)
{
- struct GNUNET_NAT_AutoHandle *ah = cls;
+ struct GNUNET_NAT_AUTO_AutoHandle *ah = cls;
ah->arc (ah->arc_cls,
NULL,
GNUNET_NAT_ERROR_IPC_FAILURE,
GNUNET_NAT_TYPE_UNKNOWN);
- GNUNET_NAT_autoconfig_cancel (ah);
+ GNUNET_NAT_AUTO_autoconfig_cancel (ah);
}
* @param cb_cls closure for @a cb
* @return handle to cancel operation
*/
-struct GNUNET_NAT_AutoHandle *
-GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_NAT_AutoResultCallback cb,
+struct GNUNET_NAT_AUTO_AutoHandle *
+GNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ GNUNET_NAT_AUTO_AutoResultCallback cb,
void *cb_cls)
{
- struct GNUNET_NAT_AutoHandle *ah = GNUNET_new (struct GNUNET_NAT_AutoHandle);
+ struct GNUNET_NAT_AUTO_AutoHandle *ah = GNUNET_new (struct GNUNET_NAT_AUTO_AutoHandle);
struct GNUNET_MQ_MessageHandler handlers[] = {
GNUNET_MQ_hd_var_size (auto_result,
GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT,
- struct GNUNET_NAT_AutoconfigResultMessage,
+ struct GNUNET_NAT_AUTO_AutoconfigResultMessage,
ah),
GNUNET_MQ_handler_end ()
};
struct GNUNET_MQ_Envelope *env;
- struct GNUNET_NAT_AutoconfigRequestMessage *req;
+ struct GNUNET_NAT_AUTO_AutoconfigRequestMessage *req;
char *buf;
size_t size;
* @param ah handle for operation to abort
*/
void
-GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah)
+GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah)
{
GNUNET_MQ_destroy (ah->mq);
GNUNET_free (ah);
/**
* Handle of the master context.
*/
- struct GNUNET_NAT_Test *h;
+ struct GNUNET_NAT_AUTO_Test *h;
/**
* Task reading from the incoming connection.
/**
* Handle to overall NAT test.
*/
- struct GNUNET_NAT_Test *h;
+ struct GNUNET_NAT_AUTO_Test *h;
};
/**
* Handle to a NAT test.
*/
-struct GNUNET_NAT_Test
+struct GNUNET_NAT_AUTO_Test
{
/**
const struct sockaddr *addr,
socklen_t addrlen)
{
- struct GNUNET_NAT_Test *h = cls;
+ struct GNUNET_NAT_AUTO_Test *h = cls;
const struct sockaddr_in *sa;
if (sizeof (struct sockaddr_in) != addrlen)
* Activity on our incoming socket. Read data from the
* incoming connection.
*
- * @param cls the `struct GNUNET_NAT_Test`
+ * @param cls the `struct GNUNET_NAT_AUTO_Test`
*/
static void
do_udp_read (void *cls)
{
- struct GNUNET_NAT_Test *tst = cls;
+ struct GNUNET_NAT_AUTO_Test *tst = cls;
uint16_t data;
const struct GNUNET_SCHEDULER_TaskContext *tc;
do_read (void *cls)
{
struct NatActivity *na = cls;
- struct GNUNET_NAT_Test *tst;
+ struct GNUNET_NAT_AUTO_Test *tst;
uint16_t data;
const struct GNUNET_SCHEDULER_TaskContext *tc;
* Activity on our listen socket. Accept the
* incoming connection.
*
- * @param cls the `struct GNUNET_NAT_Test`
+ * @param cls the `struct GNUNET_NAT_AUTO_Test`
*/
static void
do_accept (void *cls)
{
- struct GNUNET_NAT_Test *tst = cls;
+ struct GNUNET_NAT_AUTO_Test *tst = cls;
struct GNUNET_NETWORK_Handle *s;
struct NatActivity *wl;
enum GNUNET_MQ_Error error)
{
struct ClientActivity *ca = cls;
- struct GNUNET_NAT_Test *tst = ca->h;
+ struct GNUNET_NAT_AUTO_Test *tst = ca->h;
GNUNET_CONTAINER_DLL_remove (tst->ca_head,
tst->ca_tail,
const struct sockaddr *addr,
socklen_t addrlen)
{
- struct GNUNET_NAT_Test *h = cls;
+ struct GNUNET_NAT_AUTO_Test *h = cls;
struct ClientActivity *ca;
struct GNUNET_MQ_Envelope *env;
- struct GNUNET_NAT_TestMessage *msg;
+ struct GNUNET_NAT_AUTO_TestMessage *msg;
const struct sockaddr_in *sa;
if (GNUNET_YES != add_remove)
static void
do_timeout (void *cls)
{
- struct GNUNET_NAT_Test *nh = cls;
+ struct GNUNET_NAT_AUTO_Test *nh = cls;
nh->ttask = NULL;
nh->report (nh->report_cls,
* @param report_cls closure for @a report
* @return handle to cancel NAT test or NULL. The error is always indicated via the report callback
*/
-struct GNUNET_NAT_Test *
-GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
+struct GNUNET_NAT_AUTO_Test *
+GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
int is_tcp,
uint16_t bnd_port,
uint16_t adv_port,
GNUNET_NAT_TestCallback report,
void *report_cls)
{
- struct GNUNET_NAT_Test *nh;
+ struct GNUNET_NAT_AUTO_Test *nh;
struct sockaddr_in sa;
const struct sockaddr *addrs[] = {
(const struct sockaddr *) &sa
sa.sin_len = sizeof (sa);
#endif
- nh = GNUNET_new (struct GNUNET_NAT_Test);
+ nh = GNUNET_new (struct GNUNET_NAT_AUTO_Test);
nh->cfg = cfg;
nh->is_tcp = is_tcp;
nh->data = bnd_port;
* @param tst test to stop.
*/
void
-GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst)
+GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst)
{
struct NatActivity *pos;
struct ClientActivity *cpos;
GNUNET_free (tst);
}
-/* end of nat_test.c */
+/* end of nat_auto_api_test.c */
/*
This file is part of GNUnet.
- Copyright (C) 2011-2014, 2016 GNUnet e.V.
+ Copyright (C) 2011-2014, 2016, 2017 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
/**
* Task identifier for the timeout.
*/
- struct GNUNET_SCHEDULER_Task * tsk;
+ struct GNUNET_SCHEDULER_Task *tsk;
/**
* Name of plugin under test.