GNUnet 0.22.1
NAT library

Service for handling UPnP and NAT-PMP port forwarding and external IP address retrieval. More...

Collaboration diagram for NAT library:

Data Structures

struct  GNUNET_BurstSync
 Wrapper struct with the average RTT of message to some peer and if this peer und us is ready to sync. More...
 
struct  GNUNET_BurstMessage
 Message send during burst mode. More...
 
struct  GNUNET_StartBurstCls
 Struct wrapping information we use for starting the burst. More...
 
struct  GNUNET_UdpSocketInfo
 Struct with the socket we like to use to send messages to another peer. More...
 

Macros

#define GNUNET_NAT_LIB_H
 

Typedefs

typedef void(* GNUNET_NAT_AUTO_AutoResultCallback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *diff, enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type)
 Function called with the result from the autoconfiguration. More...
 
typedef void(* GNUNET_NotifyUdpSocket) (struct GNUNET_UdpSocketInfo *sock_info)
 
typedef void(* GNUNET_NAT_AddressCallback) (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes. More...
 
typedef void(* GNUNET_NAT_ReversalCallback) (void *cls, const struct sockaddr *remote_addr, socklen_t remote_addrlen)
 Signature of the callback passed to GNUNET_NAT_register(). More...
 
typedef void(* GNUNET_NAT_TestCallback) (void *cls, enum GNUNET_NAT_StatusCode result)
 Function called to report success or failure for NAT configuration test. More...
 

Enumerations

enum  GNUNET_NAT_AddressClass {
  GNUNET_NAT_AC_NONE = 0 , GNUNET_NAT_AC_OTHER = 1 , GNUNET_NAT_AC_PRIVATE = 2 , GNUNET_NAT_AC_GLOBAL = 4 ,
  GNUNET_NAT_AC_GLOBAL_PRIVATE = 6 , GNUNET_NAT_AC_LAN = 8 , GNUNET_NAT_AC_LAN_PRIVATE = 10 , GNUNET_NAT_AC_WLAN = 16 ,
  GNUNET_NAT_AC_BT = 32 , GNUNET_NAT_AC_LOOPBACK = 64 , GNUNET_NAT_AC_EXTERN = 128 , GNUNET_NAT_AC_MANUAL = 256 ,
  GNUNET_NAT_AC_ANY = 65535
}
 Some addresses contain sensitive information or are not suitable for global distribution. More...
 
enum  GNUNET_NAT_StatusCode {
  GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK , GNUNET_NAT_ERROR_IPC_FAILURE , GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR , GNUNET_NAT_ERROR_TIMEOUT ,
  GNUNET_NAT_ERROR_NOT_ONLINE , GNUNET_NAT_ERROR_UPNPC_NOT_FOUND , GNUNET_NAT_ERROR_UPNPC_FAILED , GNUNET_NAT_ERROR_UPNPC_TIMEOUT ,
  GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED , GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND , GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED , GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID ,
  GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID , GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO , GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND , GNUNET_NAT_ERROR_NAT_TEST_START_FAILED ,
  GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT , GNUNET_NAT_ERROR_NAT_REGISTER_FAILED , GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
}
 Error Types for the NAT subsystem (which can then later be converted/resolved to a string) More...
 
enum  GNUNET_NAT_Type {
  GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK , GNUNET_NAT_TYPE_UNREACHABLE_NAT , GNUNET_NAT_TYPE_STUN_PUNCHED_NAT , GNUNET_NAT_TYPE_UPNP_NAT ,
  GNUNET_NAT_TYPE_UNKNOWN
}
 What the situation of the NAT connectivity. More...
 

Functions

struct GNUNET_NAT_AUTO_TestGNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, uint8_t proto, const char *section_name, GNUNET_NAT_TestCallback report, void *report_cls)
 Start testing if NAT traversal works using the given configuration. More...
 
void GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst)
 Stop an active NAT test. More...
 
const char * GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err)
 Converts enum GNUNET_NAT_StatusCode to string. More...
 
struct GNUNET_NAT_AUTO_AutoHandleGNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NAT_AUTO_AutoResultCallback cb, void *cb_cls)
 Start auto-configuration routine. More...
 
void GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah)
 Abort autoconfiguration. More...
 
struct GNUNET_BurstSyncGNUNET_get_burst_sync_msg (struct GNUNET_TIME_Relative rtt_average, enum GNUNET_GenericReturnValue sync_ready)
 Create GNUNET_BurstSync message. More...
 
void GNUNET_is_burst_ready (struct GNUNET_TIME_Relative rtt_average, struct GNUNET_BurstSync *burst_sync, GNUNET_SCHEDULER_TaskCallback task, struct GNUNET_StartBurstCls *task_cls)
 Checks if we are ready and starts burst when we and the other peer is ready. More...
 
struct GNUNET_SCHEDULER_TaskGNUNET_get_udp_socket (struct GNUNET_UdpSocketInfo *sock_info, GNUNET_NotifyUdpSocket nus)
 Method to get a UDP socket for a peer that is natted. More...
 
void GNUNET_stop_burst (struct GNUNET_NETWORK_Handle *do_not_touch)
 Method to stop all sockets we established to the other peer. More...
 
struct GNUNET_NAT_HandleGNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
 Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on the local network. More...
 
void GNUNET_NAT_add_global_address (struct GNUNET_NAT_Handle *nh, char *addr, unsigned int address_length)
 Add global address to the list of addresses and notify clients. More...
 
int GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *nh, const void *addr, socklen_t addrlen)
 Test if the given address is (currently) a plausible IP address for this peer. More...
 
int GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
 We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP responses to cause that peer to connect to us (connection reversal). More...
 
void GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh)
 Stop port redirection and public IP address detection for the given handle. More...
 
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 an incoming STUN message. More...
 
struct GNUNET_NAT_STUN_HandleGNUNET_NAT_stun_make_request (const char *server, uint16_t port, struct GNUNET_NETWORK_Handle *sock, GNUNET_NAT_TestCallback cb, void *cb_cls)
 Make Generic STUN request. More...
 
void GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh)
 Cancel active STUN request. More...
 

Detailed Description

Service for handling UPnP and NAT-PMP port forwarding and external IP address retrieval.

Macro Definition Documentation

◆ GNUNET_NAT_LIB_H

#define GNUNET_NAT_LIB_H

Definition at line 38 of file gnunet_nat_lib.h.

Typedef Documentation

◆ GNUNET_NAT_AUTO_AutoResultCallback

typedef void(* GNUNET_NAT_AUTO_AutoResultCallback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *diff, enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type)

Function called with the result from the autoconfiguration.

Parameters
clsclosure
diffminimal suggested changes to the original configuration to make it work (as best as we can)
resultGNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
typewhat the situation of the NAT

Definition at line 101 of file gnunet_nat_auto_service.h.

◆ GNUNET_NotifyUdpSocket

typedef void(* GNUNET_NotifyUdpSocket) (struct GNUNET_UdpSocketInfo *sock_info)

Definition at line 114 of file gnunet_nat_lib.h.

◆ GNUNET_NAT_AddressCallback

typedef void(* GNUNET_NAT_AddressCallback) (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)

Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.

Parameters
clsclosure
app_ctx[in,out]location where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to add a new public IP address, GNUNET_NO to remove a previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual length of the addr

Definition at line 285 of file gnunet_nat_service.h.

◆ GNUNET_NAT_ReversalCallback

typedef void(* GNUNET_NAT_ReversalCallback) (void *cls, const struct sockaddr *remote_addr, socklen_t remote_addrlen)

Signature of the callback passed to GNUNET_NAT_register().

for a function to call whenever someone asks us to do connection reversal.

Parameters
clsclosure
remote_addrpublic IP address of the other peer
remote_addrlenactual length of the remote_addr

Definition at line 303 of file gnunet_nat_service.h.

◆ GNUNET_NAT_TestCallback

typedef void(* GNUNET_NAT_TestCallback) (void *cls, enum GNUNET_NAT_StatusCode result)

Function called to report success or failure for NAT configuration test.

Parameters
clsclosure
resultGNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code

Definition at line 460 of file gnunet_nat_service.h.

Enumeration Type Documentation

◆ GNUNET_NAT_AddressClass

Some addresses contain sensitive information or are not suitable for global distribution.

We use address classes to filter addresses by which domain they make sense to be used in. These are used in a bitmask.

FIXME: might want to define this elsewhere; we have an equivalent enum in gnunet_transport_hello_service.h; might ultimately belong with the new HELLO definition.

Enumerator
GNUNET_NAT_AC_NONE 

No address.

GNUNET_NAT_AC_OTHER 

Addresses that fall into no other category (i.e.

incoming which we cannot use elsewhere).

GNUNET_NAT_AC_PRIVATE 

Flag for addresses that are highly sensitive (i.e.

IPv6 with our MAC).

GNUNET_NAT_AC_GLOBAL 

Addresses that are global (i.e.

IPv4).

GNUNET_NAT_AC_GLOBAL_PRIVATE 

Addresses that are global and are sensitive (i.e.

IPv6 with our MAC).

GNUNET_NAT_AC_LAN 

Addresses useful in the local wired network, i.e.

a MAC. Sensitive, but obvious to people nearby.

Useful for broadcasts.

GNUNET_NAT_AC_LAN_PRIVATE 

Addresses useful in the local wired network, i.e.

a MAC. Sensitive, but obvious to people nearby. Useful for broadcasts.

GNUNET_NAT_AC_WLAN 

Addresses useful in the local wireless network, i.e.

a MAC. Sensitive, but obvious to people nearby. Useful for broadcasts.

GNUNET_NAT_AC_BT 

Addresses useful in the local bluetooth network.

Sensitive, but obvious to people nearby. Useful for broadcasts.

GNUNET_NAT_AC_LOOPBACK 

Loopback addresses, only useful under special circumstances.

GNUNET_NAT_AC_EXTERN 

Addresses that should be our external IP address on the outside of a NAT.

Might be incorrectly determined. Used as a bit in combination with GNUNET_NAT_AC_GLOBAL, or in case of double-NAT with GNUNET_NAT_AC_LAN.

GNUNET_NAT_AC_MANUAL 

Addresses that were manually configured by the user.

Used as a bit in combination with GNUNET_NAT_AC_GLOBAL.

GNUNET_NAT_AC_ANY 

Bitmask for "any" address.

Definition at line 53 of file gnunet_nat_service.h.

54{
59
65
71
76
82
90
97
104
109 GNUNET_NAT_AC_BT = 32,
110
115
124
130
134 GNUNET_NAT_AC_ANY = 65535
135};
@ GNUNET_NAT_AC_LAN_PRIVATE
Addresses useful in the local wired network, i.e.
@ GNUNET_NAT_AC_LAN
Addresses useful in the local wired network, i.e.
@ GNUNET_NAT_AC_GLOBAL_PRIVATE
Addresses that are global and are sensitive (i.e.
@ GNUNET_NAT_AC_GLOBAL
Addresses that are global (i.e.
@ GNUNET_NAT_AC_PRIVATE
Flag for addresses that are highly sensitive (i.e.
@ GNUNET_NAT_AC_EXTERN
Addresses that should be our external IP address on the outside of a NAT.
@ GNUNET_NAT_AC_ANY
Bitmask for "any" address.
@ GNUNET_NAT_AC_WLAN
Addresses useful in the local wireless network, i.e.
@ GNUNET_NAT_AC_OTHER
Addresses that fall into no other category (i.e.
@ GNUNET_NAT_AC_BT
Addresses useful in the local bluetooth network.
@ GNUNET_NAT_AC_NONE
No address.
@ GNUNET_NAT_AC_MANUAL
Addresses that were manually configured by the user.
@ GNUNET_NAT_AC_LOOPBACK
Loopback addresses, only useful under special circumstances.

◆ GNUNET_NAT_StatusCode

Error Types for the NAT subsystem (which can then later be converted/resolved to a string)

Enumerator
GNUNET_NAT_ERROR_SUCCESS 

Just the default.

GNUNET_NAT_ERROR_IPC_FAILURE 

IPC Failure.

GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR 

Failure in network subsystem, check permissions.

GNUNET_NAT_ERROR_TIMEOUT 

test timed out

GNUNET_NAT_ERROR_NOT_ONLINE 

detected that we are offline

GNUNET_NAT_ERROR_UPNPC_NOT_FOUND 

upnpc command not found

GNUNET_NAT_ERROR_UPNPC_FAILED 

Failed to run upnpc command.

GNUNET_NAT_ERROR_UPNPC_TIMEOUT 

‘upnpc’ command took too long, process killed

GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED 

‘upnpc’ command failed to establish port mapping

GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND 

‘external-ip’ command not found

GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED 

Failed to run external-ip command.

GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID 

‘external-ip’ command output invalid

GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID 

"no valid address was returned by `external-ip'"

GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO 

Could not determine interface with internal/local network address.

GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND 

No working gnunet-helper-nat-server found.

GNUNET_NAT_ERROR_NAT_TEST_START_FAILED 

NAT test could not be initialized.

GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT 

NAT test timeout.

GNUNET_NAT_ERROR_NAT_REGISTER_FAILED 

NAT test failed to initiate.

GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND 

Definition at line 141 of file gnunet_nat_service.h.

142{
147
152
157
162
167
172
177
182
187
192
197
202
207
212
217
222
227
232
237};
@ GNUNET_OK
@ GNUNET_NAT_ERROR_UPNPC_NOT_FOUND
upnpc command not found
@ GNUNET_NAT_ERROR_NOT_ONLINE
detected that we are offline
@ GNUNET_NAT_ERROR_UPNPC_TIMEOUT
‘upnpc’ command took too long, process killed
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID
‘external-ip’ command output invalid
@ GNUNET_NAT_ERROR_UPNPC_FAILED
Failed to run upnpc command.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED
Failed to run external-ip command.
@ GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR
Failure in network subsystem, check permissions.
@ GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
@ GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED
‘upnpc’ command failed to establish port mapping
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND
‘external-ip’ command not found
@ GNUNET_NAT_ERROR_NAT_REGISTER_FAILED
NAT test failed to initiate.
@ GNUNET_NAT_ERROR_IPC_FAILURE
IPC Failure.
@ GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO
Could not determine interface with internal/local network address.
@ GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND
No working gnunet-helper-nat-server found.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID
"no valid address was returned by `external-ip'"
@ GNUNET_NAT_ERROR_NAT_TEST_START_FAILED
NAT test could not be initialized.
@ GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT
NAT test timeout.
@ GNUNET_NAT_ERROR_TIMEOUT
test timed out

◆ GNUNET_NAT_Type

What the situation of the NAT connectivity.

Enumerator
GNUNET_NAT_TYPE_NO_NAT 

We have a direct connection.

GNUNET_NAT_TYPE_UNREACHABLE_NAT 

We are under a NAT but cannot traverse it.

GNUNET_NAT_TYPE_STUN_PUNCHED_NAT 

We can traverse using STUN.

GNUNET_NAT_TYPE_UPNP_NAT 

We can traverse using UPNP.

GNUNET_NAT_TYPE_UNKNOWN 

We know nothing about the NAT.

Definition at line 243 of file gnunet_nat_service.h.

244{
249
254
259
264
269};
@ GNUNET_NAT_TYPE_UPNP_NAT
We can traverse using UPNP.
@ GNUNET_NAT_TYPE_UNKNOWN
We know nothing about the NAT.
@ GNUNET_NAT_TYPE_UNREACHABLE_NAT
We are under a NAT but cannot traverse it.
@ GNUNET_NAT_TYPE_NO_NAT
We have a direct connection.
@ GNUNET_NAT_TYPE_STUN_PUNCHED_NAT
We can traverse using STUN.

Function Documentation

◆ GNUNET_NAT_AUTO_test_start()

struct GNUNET_NAT_AUTO_Test * GNUNET_NAT_AUTO_test_start ( const struct GNUNET_CONFIGURATION_Handle cfg,
uint8_t  proto,
const char *  section_name,
GNUNET_NAT_TestCallback  report,
void *  report_cls 
)

Start testing if NAT traversal works using the given configuration.

The transport adapters should be down while using this function.

Parameters
cfgconfiguration for the NAT traversal
protoprotocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
section_nameconfiguration section to use for configuration
reportfunction to call with the result of the test
report_clsclosure for report
Returns
handle to cancel NAT test

Definition at line 426 of file nat_auto_api_test.c.

431{
432 struct GNUNET_NAT_AUTO_Test *nh;
433 unsigned long long bnd_port;
434 struct sockaddr_in sa;
435 const struct sockaddr *addrs[] = { (const struct sockaddr *) &sa };
436 const socklen_t addrlens[] = { sizeof(sa) };
437
440 "PORT",
441 &bnd_port)) ||
442 (bnd_port > 65535))
443 {
445 _ ("Failed to find valid PORT in section `%s'\n"),
447 return NULL;
448 }
449
450 memset (&sa, 0, sizeof(sa));
451 sa.sin_family = AF_INET;
452 sa.sin_port = htons ((uint16_t) bnd_port);
453#if HAVE_SOCKADDR_IN_SIN_LEN
454 sa.sin_len = sizeof(sa);
455#endif
456
458 nh->cfg = cfg;
459 nh->proto = proto;
460 nh->section_name = GNUNET_strdup (section_name);
461 nh->report = report;
462 nh->report_cls = report_cls;
464 if (0 == bnd_port)
465 {
466 nh->nat = GNUNET_NAT_register (cfg,
468 proto,
469 0,
470 NULL,
471 NULL,
472 &addr_cb,
474 nh);
475 }
476 else
477 {
478 nh->lsock =
480 (IPPROTO_UDP == proto) ? SOCK_DGRAM
481 : SOCK_STREAM,
482 proto);
483 if ((NULL == nh->lsock) ||
485 (const struct sockaddr *) &sa,
486 sizeof(sa))))
487 {
489 _ ("Failed to create socket bound to `%s' for NAT test: %s\n"),
490 GNUNET_a2s ((const struct sockaddr *) &sa, sizeof(sa)),
491 strerror (errno));
492 if (NULL != nh->lsock)
493 {
495 nh->lsock = NULL;
496 }
499 return nh;
500 }
501 if (IPPROTO_TCP == proto)
502 {
505 nh->lsock,
506 &do_accept,
507 nh);
508 }
509 else
510 {
512 nh->lsock,
514 nh);
515 }
517 "NAT test listens on port %llu (%s)\n",
518 bnd_port,
519 (IPPROTO_TCP == proto) ? "tcp" : "udp");
520 nh->nat = GNUNET_NAT_register (cfg,
522 proto,
523 1,
524 addrs,
525 addrlens,
526 &addr_cb,
527 NULL,
528 nh);
529 if (NULL == nh->nat)
530 {
532 _ ("NAT test failed to start NAT library\n"));
533 if (NULL != nh->ltask)
534 {
536 nh->ltask = NULL;
537 }
538 if (NULL != nh->lsock)
539 {
541 nh->lsock = NULL;
542 }
545 return nh;
546 }
547 }
548 return nh;
549}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * section_name
Adapter we are supposed to test.
static uint8_t proto
Protocol to use.
struct GNUNET_NAT_Handle * nh
Handle for connect to the NAT service.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
Definition: nat_api.c:366
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:833
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:652
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1510
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:979
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:1303
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void reversal_cb(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Function called from GNUNET_NAT_register whenever someone asks us to do connection reversal.
static void do_fail(void *cls)
Calls the report-callback reporting failure.
static void do_accept(void *cls)
Activity on our listen socket.
static void do_udp_read(void *cls)
Activity on our incoming socket.
#define LOG(kind,...)
static void addr_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Address-callback, used to send message to gnunet-nat-server.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle to a NAT test.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: nat_api.c:76

References _, addr_cb(), cfg, GNUNET_NAT_Handle::cfg, do_accept(), do_fail(), do_udp_read(), GNUNET_a2s(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_register(), GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_listen(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, LOG, nh, proto, reversal_cb(), and section_name.

Referenced by run().

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

◆ GNUNET_NAT_AUTO_test_stop()

void GNUNET_NAT_AUTO_test_stop ( struct GNUNET_NAT_AUTO_Test tst)

Stop an active NAT test.

Parameters
tsttest to stop.

Definition at line 558 of file nat_auto_api_test.c.

559{
560 struct NatActivity *pos;
561 struct ClientActivity *cpos;
562
563 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n");
564 while (NULL != (cpos = tst->ca_head))
565 {
567 GNUNET_MQ_destroy (cpos->mq);
568 GNUNET_free (cpos);
569 }
570 while (NULL != (pos = tst->na_head))
571 {
575 GNUNET_free (pos);
576 }
577 if (NULL != tst->ttask)
578 {
580 tst->ttask = NULL;
581 }
582 if (NULL != tst->ltask)
583 {
585 tst->ltask = NULL;
586 }
587 if (NULL != tst->lsock)
588 {
590 tst->lsock = NULL;
591 }
592 if (NULL != tst->nat)
593 {
595 tst->nat = NULL;
596 }
598 GNUNET_free (tst);
599}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:703
Entry we keep for each connection to the gnunet-nat-service.
struct GNUNET_MQ_Handle * mq
Socket of the incoming connection.
char * section_name
Section name of plugin to test.
struct NatActivity * na_tail
Tail of list of nat activities.
struct GNUNET_NAT_Handle * nat
Handle to NAT traversal in use.
struct GNUNET_NETWORK_Handle * lsock
Handle to listen socket, or NULL.
struct NatActivity * na_head
Head of list of nat activities.
struct GNUNET_SCHEDULER_Task * ttask
Task identifier for the timeout (if any)
struct ClientActivity * ca_head
Head of list of client activities.
struct ClientActivity * ca_tail
Tail of list of client activities.
struct GNUNET_SCHEDULER_Task * ltask
Identity of task for the listen socket (if any)
Entry we keep for each incoming connection.
struct GNUNET_SCHEDULER_Task * rtask
Task reading from the incoming connection.
struct GNUNET_NETWORK_Handle * sock
Socket of the incoming connection.

References GNUNET_NAT_AUTO_Test::ca_head, GNUNET_NAT_AUTO_Test::ca_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NAT_unregister(), GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), LOG, GNUNET_NAT_AUTO_Test::lsock, GNUNET_NAT_AUTO_Test::ltask, ClientActivity::mq, GNUNET_NAT_AUTO_Test::na_head, GNUNET_NAT_AUTO_Test::na_tail, GNUNET_NAT_AUTO_Test::nat, NatActivity::rtask, GNUNET_NAT_AUTO_Test::section_name, NatActivity::sock, and GNUNET_NAT_AUTO_Test::ttask.

Referenced by do_shutdown().

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

◆ GNUNET_NAT_AUTO_status2string()

const char * GNUNET_NAT_AUTO_status2string ( enum GNUNET_NAT_StatusCode  err)

Converts enum GNUNET_NAT_StatusCode to string.

Parameters
errerror code to resolve to a string
Returns
point to a static string containing the error code

Definition at line 68 of file nat_auto_api.c.

69{
70 switch (err)
71 {
73 return _ ("Operation Successful");
74
76 return _ ("IPC failure");
77
79 return _ ("Failure in network subsystem, check permissions.");
80
82 return _ ("Encountered timeout while performing operation");
83
85 return _ ("detected that we are offline");
86
88 return _ ("`upnpc` command not found");
89
91 return _ ("Failed to run `upnpc` command");
92
94 return _ ("`upnpc' command took too long, process killed");
95
97 return _ ("`upnpc' command failed to establish port mapping");
98
100 return _ ("`external-ip' command not found");
101
103 return _ ("Failed to run `external-ip` command");
104
106 return _ ("`external-ip' command output invalid");
107
109 return _ ("no valid address was returned by `external-ip'");
110
112 return _ (
113 "Could not determine interface with internal/local network address");
114
116 return _ ("No functioning gnunet-helper-nat-server installation found");
117
119 return _ ("NAT test could not be initialized");
120
122 return _ ("NAT test timeout reached");
123
125 return _ ("could not register NAT");
126
128 return _ ("No working gnunet-helper-nat-client installation found");
129
130 default:
131 return "unknown status code";
132 }
133}

References _, GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND, GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND, GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, GNUNET_NAT_ERROR_IPC_FAILURE, GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, GNUNET_NAT_ERROR_NAT_TEST_START_FAILED, GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT, GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, GNUNET_NAT_ERROR_NOT_ONLINE, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_ERROR_TIMEOUT, GNUNET_NAT_ERROR_UPNPC_FAILED, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, and GNUNET_NAT_ERROR_UPNPC_TIMEOUT.

Referenced by auto_config_cb(), and test_report_cb().

Here is the caller graph for this function:

◆ GNUNET_NAT_AUTO_autoconfig_start()

struct GNUNET_NAT_AUTO_AutoHandle * GNUNET_NAT_AUTO_autoconfig_start ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_NAT_AUTO_AutoResultCallback  cb,
void *  cb_cls 
)

Start auto-configuration routine.

The transport adapters should be stopped while this function is called.

Parameters
cfginitial configuration
cbfunction to call with autoconfiguration result
cb_clsclosure for cb
Returns
handle to cancel operation

Definition at line 223 of file nat_auto_api.c.

226{
230 GNUNET_MQ_hd_var_size (auto_result,
233 ah),
235 };
236 struct GNUNET_MQ_Envelope *env;
238 char *buf;
239 size_t size;
240
242 &size);
243 if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req))
244 {
245 GNUNET_break (0);
246 GNUNET_free (buf);
247 GNUNET_free (ah);
248 return NULL;
249 }
250 ah->arc = cb;
251 ah->arc_cls = cb_cls;
253 "nat",
254 handlers,
256 ah);
257 if (NULL == ah->mq)
258 {
259 GNUNET_break (0);
260 GNUNET_free (buf);
261 GNUNET_free (ah);
262 return NULL;
263 }
265 size,
267 GNUNET_memcpy (&req[1],
268 buf,
269 size);
270 GNUNET_free (buf);
272 env);
273 return ah;
274}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#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.
static void ah_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handle queue errors by reporting autoconfiguration failure.
Definition: nat_auto_api.c:200
static unsigned int size
Size of the "table".
Definition: peer.c:68
Message handler for a specific message type.
Handle to auto-configuration in progress.
Definition: nat_auto_api.c:38
void * arc_cls
Closure for arc.
Definition: nat_auto_api.c:57
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
Definition: nat_auto_api.c:47
GNUNET_NAT_AUTO_AutoResultCallback arc
Function called with the result from the autoconfiguration.
Definition: nat_auto_api.c:52
Client requesting automatic configuration.
Definition: nat-auto.h:71
Service responding with proposed configuration.
Definition: nat-auto.h:85

References ah, ah_error_handler(), GNUNET_NAT_AUTO_AutoHandle::arc, GNUNET_NAT_AUTO_AutoHandle::arc_cls, cfg, env, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_CONFIGURATION_serialize(), GNUNET_free, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT, GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, handlers, GNUNET_NAT_AUTO_AutoHandle::mq, and size.

Referenced by run().

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

◆ GNUNET_NAT_AUTO_autoconfig_cancel()

void GNUNET_NAT_AUTO_autoconfig_cancel ( struct GNUNET_NAT_AUTO_AutoHandle ah)

Abort autoconfiguration.

Parameters
ahhandle for operation to abort

Definition at line 283 of file nat_auto_api.c.

284{
286 GNUNET_free (ah);
287}

References ah, GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_NAT_AUTO_AutoHandle::mq.

Referenced by ah_error_handler(), do_shutdown(), and handle_auto_result().

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

◆ GNUNET_get_burst_sync_msg()

struct GNUNET_BurstSync * GNUNET_get_burst_sync_msg ( struct GNUNET_TIME_Relative  rtt_average,
enum GNUNET_GenericReturnValue  sync_ready 
)

Create GNUNET_BurstSync message.

Parameters
rtt_averageThe average RTT for the peer to communicate with.
sync_readyIs this peer already ready to sync.
Returns
The GNUNET_BurstSync message to send to the other peer.
Parameters
rtt_averageThe average RTT for the peer to communicate with.
sync_readyIs this peer already ready to sync.

Definition at line 66 of file nat.c.

68{
69 struct GNUNET_BurstSync *burst_sync = GNUNET_new (struct GNUNET_BurstSync);
70
72 burst_sync->sync_ready = sync_ready;
73
74 return burst_sync;
75}
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:620
Wrapper struct with the average RTT of message to some peer and if this peer und us is ready to sync.
enum GNUNET_GenericReturnValue sync_ready
Is this peer already ready to sync.
struct GNUNET_TIME_RelativeNBO rtt_average
The average RTT for the peer to communicate with.

References GNUNET_new, GNUNET_TIME_relative_hton(), GNUNET_BurstSync::rtt_average, and GNUNET_BurstSync::sync_ready.

Here is the call graph for this function:

◆ GNUNET_is_burst_ready()

void GNUNET_is_burst_ready ( struct GNUNET_TIME_Relative  rtt_average,
struct GNUNET_BurstSync burst_sync,
GNUNET_SCHEDULER_TaskCallback  task,
struct GNUNET_StartBurstCls task_cls 
)

Checks if we are ready and starts burst when we and the other peer is ready.

Parameters
rtt_averageThe average RTT for the peer to communicate with.
sync_readyIs this peer already ready to sync.
burst_syncThe GNUNET_BurstSync from the other peer.
taskTask to be executed if both peers are ready.
task_clsClosure for the task.
Returns
Are we burst ready. This is independent from the other peer being ready.
Parameters
rtt_averageThe average RTT for the peer to communicate with.
burst_syncThe GNUNET_BurstSync from the other peer.
taskTask to be executed if both peers are ready.
task_clsClosure for the task.
Returns
Are we burst ready. This is independent from the other peer being ready.

Definition at line 89 of file nat.c.

93{
94 struct GNUNET_TIME_Relative other_rtt;
95 struct GNUNET_TIME_Relative rel1;
96 struct GNUNET_TIME_Relative rel2;
97
98 other_rtt = GNUNET_TIME_relative_ntoh (burst_sync->rtt_average);
99 rel1 = GNUNET_TIME_relative_subtract (other_rtt, rtt_average);
100 rel2 = GNUNET_TIME_relative_subtract (rtt_average, other_rtt);
102 "other sync ready %u, other rtt %lu and rtt %lu rel1 %lu rel2 %lu\n",
103 burst_sync->sync_ready,
104 (unsigned long) other_rtt.rel_value_us,
105 (unsigned long) rtt_average.rel_value_us,
106 (unsigned long) rel1.rel_value_us,
107 (unsigned long) rel2.rel_value_us);
108 if ((other_rtt.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us &&
109 rtt_average.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) &&
110 rel1.rel_value_us < RTT_DIFF.rel_value_us &&
111 rel2.rel_value_us < RTT_DIFF.rel_value_us)
112 {
114 "other sync ready 1\n");
115 if (GNUNET_YES == burst_sync->sync_ready)
116 {
118 "other sync ready 2\n");
119 task_cls->delay = GNUNET_TIME_relative_saturating_multiply (rtt_average,
120 2);
121 }
122 else
123 {
125 "other sync ready 3\n");
126 task_cls->delay = GNUNET_TIME_relative_saturating_multiply (rtt_average,
127 4);
128 }
129 task_cls->sync_ready = GNUNET_YES;
130 task (task_cls);
131 }
132 else
133 {
135 "other sync ready 6\n");
136 task_cls->sync_ready = GNUNET_NO;
137 }
138}
@ GNUNET_YES
@ GNUNET_NO
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Saturating multiply relative time by a given factor.
Definition: time.c:533
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Subtract relative timestamp from the other.
Definition: time.c:605
#define RTT_DIFF
Difference of the average RTT for the DistanceVector calculate by us and the target we are willing to...
Definition: nat.c:43
struct GNUNET_TIME_Relative delay
The delay - calculate from the RTT and which peer was ready to sync first, after we will start the bu...
unsigned int sync_ready
We are ready to start the burst.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.

References GNUNET_StartBurstCls::delay, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_TIME_relative_ntoh(), GNUNET_TIME_relative_saturating_multiply(), GNUNET_TIME_relative_subtract(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GNUNET_TIME_Relative::rel_value_us, GNUNET_BurstSync::rtt_average, RTT_DIFF, GNUNET_BurstSync::sync_ready, and GNUNET_StartBurstCls::sync_ready.

Referenced by handle_flow_control().

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

◆ GNUNET_get_udp_socket()

struct GNUNET_SCHEDULER_Task * GNUNET_get_udp_socket ( struct GNUNET_UdpSocketInfo sock_info,
GNUNET_NotifyUdpSocket  nus 
)

Method to get a UDP socket for a peer that is natted.

Parameters
sock_infoStruct with information correlated to a specific port at the other peer.
nusCallback to give the caller the struct GNUNET_UdpSocketInfo to use to connect the other peer.
Returns
The initial read task to read from the default socket.

Definition at line 509 of file nat.c.

511{
512 struct GNUNET_BurstMessage bm = {0};
514 char dgram[sizeof (struct GNUNET_BurstMessage)];
515 char *address;
516 struct sockaddr *in;
517 socklen_t in_len;
518
520 "%s:%u",
521 sock_info->address,
522 sock_info->std_port);
524 "2 sock addr %s addr %s rtt %s %u\n",
525 sock_info->address,
526 address,
527 GNUNET_TIME_relative2s (sock_info->rtt,
528 false),
529 sock_info->std_port);
530 bm.local_port = sock_info->std_port;
531 in = udp_address_to_sockaddr (address, &in_len);
532 memcpy (dgram, &bm, sizeof(bm));
533 if (-1 == GNUNET_NETWORK_socket_sendto (sock_info->udp_sock,
534 dgram,
535 sizeof(dgram),
536 in,
537 in_len))
538 {
540 "Sending burst to %s family %d failed sock %p\n",
541 GNUNET_a2s (in,
542 in_len),
543 in->sa_family,
544 sock_info->udp_sock);
545 }
546
547 nr_open_sockets = 0;
548 udp_port = 1024;
549 sock_info->has_port = GNUNET_NO;
550 sock_info->nus = nus;
551
552 GNUNET_memcpy (si, sock_info, sizeof (struct GNUNET_UdpSocketInfo));
553
555 &read_send,
556 si);
557 GNUNET_free (in);
559 return read_send_task;
560}
static char * address
GNS address for this phone.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:772
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:1276
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
Definition: time.c:264
static void read_send(void *cls)
Definition: nat.c:343
#define SEND_DELAY
Definition: nat.c:33
static struct GNUNET_SCHEDULER_Task * read_send_task
Definition: nat.c:50
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
Definition: nat.c:226
unsigned int nr_open_sockets
Maximum of open sockets.
Definition: nat.c:57
unsigned int udp_port
Definition: nat.c:52
Message send during burst mode.
unsigned int local_port
The local port the message was send from.
Struct with the socket we like to use to send messages to another peer.
enum GNUNET_GenericReturnValue has_port
Flag indicating, if the address is without port information.
struct GNUNET_TIME_Relative rtt
The actual RTT between the peers.
GNUNET_NotifyUdpSocket nus
The notify function to call if burst mode was successful.
char * address
The address of the other peer without port.
unsigned int std_port
Default local port we are bound to.
struct GNUNET_NETWORK_Handle * udp_sock

References address, GNUNET_UdpSocketInfo::address, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_memcpy, GNUNET_NETWORK_socket_sendto(), GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative2s(), GNUNET_UdpSocketInfo::has_port, GNUNET_BurstMessage::local_port, nr_open_sockets, GNUNET_UdpSocketInfo::nus, read_send(), read_send_task, GNUNET_UdpSocketInfo::rtt, SEND_DELAY, GNUNET_UdpSocketInfo::std_port, udp_address_to_sockaddr(), udp_port, and GNUNET_UdpSocketInfo::udp_sock.

Referenced by start_burst().

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

◆ GNUNET_stop_burst()

void GNUNET_stop_burst ( struct GNUNET_NETWORK_Handle do_not_touch)

Method to stop all sockets we established to the other peer.

Parameters
do_not_touchThe network handle we will use to connect to the other peer. This socket must not be closed.

Definition at line 564 of file nat.c.

565{
566 struct GNUNET_UdpSocketInfo *sock_info;
567 struct GNUNET_UdpSocketInfo *pos;
568
570 "stopping burst\n");
571 if (NULL != read_send_task)
572 {
574 read_send_task = NULL;
575 }
576 pos = sock_infos_head;
577 while (NULL != pos)
578 {
579 sock_info = pos;
580 pos = sock_info->next;
583 sock_info);
584 if (NULL != sock_info->read_task)
586 if (NULL != sock_info->timeout_task)
588 if (do_not_touch != sock_info->udp_sock)
589 {
591 if (NULL != sock_info->address)
592 GNUNET_free (sock_info->address);
594 "freeing sock_info %p\n",
595 sock_info);
596 GNUNET_free (sock_info);
597 }
598 }
599}
static struct GNUNET_UdpSocketInfo * sock_infos_tail
Definition: nat.c:48
static struct GNUNET_UdpSocketInfo * sock_infos_head
Definition: nat.c:46
struct GNUNET_UdpSocketInfo * next
This is a linked list.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task for this socket.
struct GNUNET_SCHEDULER_Task * read_task
The read task for retrieving a burst message for this socket.

References GNUNET_UdpSocketInfo::address, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), GNUNET_UdpSocketInfo::next, read_send_task, GNUNET_UdpSocketInfo::read_task, sock_infos_head, sock_infos_tail, GNUNET_UdpSocketInfo::timeout_task, and GNUNET_UdpSocketInfo::udp_sock.

Referenced by do_shutdown(), sock_read(), and start_burst().

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

◆ GNUNET_NAT_register()

struct GNUNET_NAT_Handle * GNUNET_NAT_register ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  config_section,
uint8_t  proto,
unsigned int  num_addrs,
const struct sockaddr **  addrs,
const socklen_t *  addrlens,
GNUNET_NAT_AddressCallback  address_callback,
GNUNET_NAT_ReversalCallback  reversal_callback,
void *  callback_cls 
)

Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on the local network.

Use addr to specify to which of the local host's addresses should the external port be mapped. The port is taken from the corresponding sockaddr_in[6] field. The NAT module should call the given address_callback for any 'plausible' external address.

Parameters
cfgconfiguration to use
config_sectionname of the configuration section for options
protoprotocol this is about, IPPROTO_TCP or IPPROTO_UDP
num_addrsnumber of addresses in addrs
addrslist of local addresses packets should be redirected to
addrlensactual lengths of the addresses in addrs
address_callbackfunction to call every time the public IP address changes
reversal_callbackfunction to call if someone wants connection reversal from us, NULL if connection reversal is not supported
callback_clsclosure for callbacks
Returns
NULL on error, otherwise handle that can be used to unregister

Definition at line 366 of file nat_api.c.

375{
376 struct GNUNET_NAT_Handle *nh;
378 size_t len;
379 size_t str_len;
380 char *off;
381
382 len = 0;
383 for (unsigned int i = 0; i < num_addrs; i++)
384 len += addrlens[i];
385 str_len = strlen (config_section) + 1;
386 len += str_len;
387 if ( (len > GNUNET_MAX_MESSAGE_SIZE - sizeof(*rm)) ||
388 (num_addrs > UINT16_MAX) ||
389 (str_len > UINT16_MAX) )
390 {
391 GNUNET_break (0);
392 return NULL;
393 }
394 rm = GNUNET_malloc (sizeof(*rm) + len);
395 rm->header.size = htons (sizeof(*rm) + len);
398 if (NULL != address_callback)
400 if (NULL != reversal_callback)
402 rm->proto = proto;
403 rm->str_len = htons (str_len);
404 rm->num_addrs = htons ((uint16_t) num_addrs);
405 off = (char *) &rm[1];
406 for (unsigned int i = 0; i < num_addrs; i++)
407 {
408 switch (addrs[i]->sa_family)
409 {
410 case AF_INET:
411 if (sizeof(struct sockaddr_in) != addrlens[i])
412 {
413 GNUNET_break (0);
414 GNUNET_free (rm);
415 return NULL;
416 }
417 break;
418
419 case AF_INET6:
420 if (sizeof(struct sockaddr_in6) != addrlens[i])
421 {
422 GNUNET_break (0);
423 GNUNET_free (rm);
424 return NULL;
425 }
426 break;
427
428#if AF_UNIX
429 case AF_UNIX:
430 if (sizeof(struct sockaddr_un) != addrlens[i])
431 {
432 GNUNET_break (0);
433 GNUNET_free (rm);
434 return NULL;
435 }
436 break;
437#endif
438 default:
439 GNUNET_break (0);
440 GNUNET_free (rm);
441 return NULL;
442 }
443 GNUNET_memcpy (off, addrs[i], addrlens[i]);
444 off += addrlens[i];
445 }
446 GNUNET_memcpy (off, config_section, str_len);
447
449 nh->reg = &rm->header;
450 nh->cfg = cfg;
451 nh->address_callback = address_callback;
453 nh->callback_cls = callback_cls;
454 do_connect (nh);
455 return nh;
456}
static void reversal_callback(void *cls, const struct sockaddr_in *ra)
We got a connection reversal request from another peer.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_NAT_REGISTER
Message to ask NAT service to register a client.
@ GNUNET_NAT_RF_ADDRESSES
This client wants to be informed about changes to our applicable addresses.
Definition: nat.h:82
@ GNUNET_NAT_RF_NONE
This client does not want any notifications.
Definition: nat.h:76
@ GNUNET_NAT_RF_REVERSAL
This client supports address reversal.
Definition: nat.h:87
static void do_connect(void *cls)
Task to connect to the NAT service.
Definition: nat_api.c:329
Handle for active NAT registrations.
Definition: nat_api.c:72
void * callback_cls
Closure for the various callbacks.
Definition: nat_api.c:111
struct GNUNET_MessageHeader * reg
Our registration message.
Definition: nat_api.c:86
GNUNET_NAT_ReversalCallback reversal_callback
Function to call when another peer requests connection reversal.
Definition: nat_api.c:106
GNUNET_NAT_AddressCallback address_callback
Function to call when our addresses change.
Definition: nat_api.c:101
Message sent by a client to register with its addresses.
Definition: nat.h:95
uint16_t num_addrs
Number of addresses that this service is bound to that follow.
Definition: nat.h:122
uint16_t str_len
Number of bytes in the string that follow which specifies a section name in the configuration.
Definition: nat.h:115
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_REGISTER.
Definition: nat.h:99
uint8_t flags
An enum GNUNET_NAT_RegisterFlags.
Definition: nat.h:104
uint8_t proto
Client's IPPROTO, e.g.
Definition: nat.h:109

References GNUNET_NAT_Handle::address_callback, GNUNET_NAT_Handle::callback_cls, cfg, GNUNET_NAT_Handle::cfg, do_connect(), GNUNET_NAT_RegisterMessage::flags, GNUNET_break, GNUNET_free, GNUNET_malloc, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_REGISTER, GNUNET_NAT_RF_ADDRESSES, GNUNET_NAT_RF_NONE, GNUNET_NAT_RF_REVERSAL, GNUNET_new, GNUNET_NAT_RegisterMessage::header, nh, GNUNET_NAT_RegisterMessage::num_addrs, proto, GNUNET_NAT_RegisterMessage::proto, GNUNET_NAT_Handle::reg, reversal_callback(), GNUNET_NAT_Handle::reversal_callback, GNUNET_MessageHeader::size, GNUNET_NAT_RegisterMessage::str_len, and GNUNET_MessageHeader::type.

Referenced by GNUNET_NAT_AUTO_test_start(), GNUNET_NAT_test_start(), nat_register(), run(), and try_anat().

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

◆ GNUNET_NAT_add_global_address()

void GNUNET_NAT_add_global_address ( struct GNUNET_NAT_Handle nh,
char *  addr,
unsigned int  address_length 
)

Add global address to the list of addresses and notify clients.

Parameters
nhthe handle returned by register
addrIP address to add.
address_lengthnumber of bytes in addr

Definition at line 460 of file nat_api.c.

463{
465 struct GNUNET_MQ_Envelope *env;
466 //char *address_without_port = get_address_without_port (addr);
467 //unsigned int address_len_without_port = strlen (address_without_port);
468 char *off;
469
471 "natting address %s length %u\n",
472 addr,
473 address_length);
474
476 address_length,
478 aam->address_length = htons (address_length);
479 off = (char *) &aam[1];
480 GNUNET_memcpy (off, addr, address_length);
482 env);
483 //GNUNET_free (address_without_port);
484}
#define GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS
Message to ask NAT service to notify all clients about a new global address.
Message sent by client to add a global address.
Definition: nat.h:225
unsigned int address_length
Length of the address following the struct, in NBO.
Definition: nat.h:234
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
Definition: nat_api.c:81

References GNUNET_NAT_AddGlobalAddressMessage::address_length, env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NAT_Handle::mq, and nh.

Referenced by handle_flow_control().

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

◆ GNUNET_NAT_test_address()

int GNUNET_NAT_test_address ( struct GNUNET_NAT_Handle nh,
const void *  addr,
socklen_t  addrlen 
)

Test if the given address is (currently) a plausible IP address for this peer.

Mostly a convenience function so that clients do not have to explicitly track all IPs that the GNUNET_NAT_AddressCallback has returned so far.

Parameters
nhthe handle returned by register
addrIP address to test (IPv4 or IPv6)
addrlennumber of bytes in addr
Returns
GNUNET_YES if the address is plausible, GNUNET_NO if the address is not plausible, GNUNET_SYSERR if the address is malformed

Definition at line 643 of file nat_api.c.

646{
647 struct AddrEntry *ae;
648
649 if ((addrlen != sizeof(struct sockaddr_in)) &&
650 (addrlen != sizeof(struct sockaddr_in6)))
651 {
652 GNUNET_break (0);
653 return GNUNET_SYSERR;
654 }
655 for (ae = nh->ae_head; NULL != ae; ae = ae->next)
656 if ((addrlen == ae->addrlen) && (0 == memcmp (addr, &ae[1], addrlen)))
657 return GNUNET_YES;
658 return GNUNET_NO;
659}
@ GNUNET_SYSERR
Entry in DLL of addresses of this peer.
Definition: nat_api.c:39
struct AddrEntry * next
DLL.
Definition: nat_api.c:43
socklen_t addrlen
Number of bytes that follow.
Definition: nat_api.c:64
struct AddrEntry * ae_head
Head of address DLL.
Definition: nat_api.c:91

References AddrEntry::addrlen, GNUNET_NAT_Handle::ae_head, GNUNET_break, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, AddrEntry::next, and nh.

◆ GNUNET_NAT_request_reversal()

int GNUNET_NAT_request_reversal ( struct GNUNET_NAT_Handle nh,
const struct sockaddr_in *  local_sa,
const struct sockaddr_in *  remote_sa 
)

We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP responses to cause that peer to connect to us (connection reversal).

Parameters
nhhandle (used for configuration)
local_saour local address of the peer (IPv4-only)
remote_sathe remote address of the peer (IPv4-only)
Returns
GNUNET_SYSERR on error, GNUNET_NO if connection reversal is unavailable, GNUNET_OK otherwise (presumably in progress)

Definition at line 675 of file nat_api.c.

678{
679 struct GNUNET_MQ_Envelope *env;
681 char *buf;
682
683 if (NULL == nh->mq)
684 return GNUNET_SYSERR;
685 GNUNET_break (AF_INET == local_sa->sin_family);
686 GNUNET_break (AF_INET == remote_sa->sin_family);
687 env =
689 2 * sizeof(struct sockaddr_in),
691 req->local_addr_size = htons (sizeof(struct sockaddr_in));
692 req->remote_addr_size = htons (sizeof(struct sockaddr_in));
693 buf = (char *) &req[1];
694 GNUNET_memcpy (buf, local_sa, sizeof(struct sockaddr_in));
695 buf += sizeof(struct sockaddr_in);
696 GNUNET_memcpy (buf, remote_sa, sizeof(struct sockaddr_in));
698 return GNUNET_OK;
699}
#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL
Message to ask NAT service to request connection reversal.
Client asking the service to initiate connection reversal.
Definition: nat.h:161
uint16_t local_addr_size
Size of the local address included, in NBO.
Definition: nat.h:170
uint16_t remote_addr_size
Size of the remote address included, in NBO.
Definition: nat.h:175

References env, GNUNET_break, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_NAT_RequestConnectionReversalMessage::local_addr_size, GNUNET_NAT_Handle::mq, nh, and GNUNET_NAT_RequestConnectionReversalMessage::remote_addr_size.

Referenced by mq_init(), run(), and try_anat().

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

◆ GNUNET_NAT_unregister()

void GNUNET_NAT_unregister ( struct GNUNET_NAT_Handle nh)

Stop port redirection and public IP address detection for the given handle.

This frees the handle, after having sent the needed commands to close open ports.

FIXME: No, the implementation of this API does not do anything beyond cleaning up the handle. This is a problem for applications that use GNUNET_NAT_AddressCallback and use the app_ctx to store objects, because the callback will never be called for cleanup on unregister.

Parameters
nhthe handle to unregister

Definition at line 703 of file nat_api.c.

704{
705 struct AddrEntry *ae;
706 struct AddrEntry *next;
707
708 if (NULL != nh->mq)
709 {
711 nh->mq = NULL;
712 }
713 if (NULL != nh->reconnect_task)
714 {
716 nh->reconnect_task = NULL;
717 }
718 next = nh->ae_head;
719 while (NULL != next)
720 {
721 ae = next;
722 next = next->next;
724 GNUNET_free (ae);
725 }
726 GNUNET_free (nh->reg);
727 GNUNET_free (nh);
728}
struct GNUNET_SCHEDULER_Task * reconnect_task
Task scheduled to reconnect to the service.
Definition: nat_api.c:116
struct AddrEntry * ae_tail
Tail of address DLL.
Definition: nat_api.c:96

References GNUNET_NAT_Handle::ae_head, GNUNET_NAT_Handle::ae_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_NAT_Handle::mq, AddrEntry::next, nh, GNUNET_NAT_Handle::reconnect_task, and GNUNET_NAT_Handle::reg.

Referenced by do_shutdown(), GNUNET_NAT_AUTO_test_stop(), GNUNET_NAT_test_stop(), and try_anat().

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

◆ GNUNET_NAT_stun_handle_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 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.

Parameters
nhhandle to the NAT service
sender_addraddress from which we got data
sender_addr_lennumber of bytes in sender_addr
datathe packet
data_sizenumber of bytes in data
Returns
GNUNET_OK on success GNUNET_NO if the packet is not a STUN packet GNUNET_SYSERR on internal error handling the packet

Definition at line 601 of file nat_api.c.

606{
607 struct GNUNET_MQ_Envelope *env;
609 char *buf;
610
612 return GNUNET_NO;
613 if (NULL == nh->mq)
614 return GNUNET_SYSERR;
616 data_size + sender_addr_len,
618 hsn->sender_addr_size = htons ((uint16_t) sender_addr_len);
619 hsn->payload_size = htons ((uint16_t) data_size);
620 buf = (char *) &hsn[1];
621 GNUNET_memcpy (buf, sender_addr, sender_addr_len);
622 buf += sender_addr_len;
625 return GNUNET_OK;
626}
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
#define GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN
Message to ask NAT service to handle a STUN packet.
static enum GNUNET_GenericReturnValue test_stun_packet(const void *data, size_t len)
Check if an incoming message is a STUN message.
Definition: nat_api.c:497
Client telling the service to (possibly) handle a STUN message.
Definition: nat.h:135
uint16_t payload_size
Number of bytes of payload included, in NBO.
Definition: nat.h:149
uint16_t sender_addr_size
Size of the sender address included, in NBO.
Definition: nat.h:144

References data, data_size, env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_NAT_Handle::mq, nh, GNUNET_NAT_HandleStunMessage::payload_size, GNUNET_NAT_HandleStunMessage::sender_addr_size, and test_stun_packet().

Referenced by do_udp_read(), and stun_read_task().

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

◆ GNUNET_NAT_stun_make_request()

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 
)

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.

Parameters
serverthe address of the stun server
portport of the stun server, in host byte order
sockthe socket used to send the request, must be a UDP socket
cbcallback in case of error
cb_clsclosure for cb
Returns
NULL on error

Sends a generic stun request to the server specified using the specified socket.

Parameters
serverthe address of the stun server
portport of the stun server, in host byte order
sockthe socket used to send the request
cbcallback in case of error
cb_clsclosure for cb
Returns
NULL on error

Definition at line 211 of file nat_api_stun.c.

216{
217 struct GNUNET_NAT_STUN_Handle *rh;
218
220 rh->sock = sock;
221 rh->cb = cb;
222 rh->cb_cls = cb_cls;
223 rh->stun_server = GNUNET_strdup (server);
224 rh->stun_port = port;
227 AF_INET,
228 TIMEOUT,
230 rh);
231 if (NULL == rh->dns_active)
232 {
234 return NULL;
235 }
236 return rh;
237}
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
void GNUNET_NAT_stun_make_request_cancel(struct GNUNET_NAT_STUN_Handle *rh)
Cancel active STUN request.
Definition: nat_api_stun.c:247
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:940
static void stun_dns_callback(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Try to establish a connection given the specified address.
Definition: nat_api_stun.c:135
#define TIMEOUT
Definition: nat_api_stun.c:48
Handle to a request given to the resolver.
Definition: nat_api_stun.c:57
int dns_success
Do we got a DNS resolution successfully?
Definition: nat_api_stun.c:86
GNUNET_NAT_TestCallback cb
Function to call when a error occurs.
Definition: nat_api_stun.c:76
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
Definition: nat_api_stun.c:61
void * cb_cls
Closure for cb.
Definition: nat_api_stun.c:81
char * stun_server
Stun server address.
Definition: nat_api_stun.c:71
uint16_t stun_port
STUN port.
Definition: nat_api_stun.c:91
struct GNUNET_NETWORK_Handle * sock
Handle to the listen socket.
Definition: nat_api_stun.c:66

References GNUNET_NAT_STUN_Handle::cb, GNUNET_NAT_STUN_Handle::cb_cls, GNUNET_NAT_STUN_Handle::dns_active, GNUNET_NAT_STUN_Handle::dns_success, GNUNET_NAT_stun_make_request_cancel(), GNUNET_new, GNUNET_NO, GNUNET_RESOLVER_ip_get(), GNUNET_strdup, port, GNUNET_NAT_STUN_Handle::sock, stun_dns_callback(), GNUNET_NAT_STUN_Handle::stun_port, GNUNET_NAT_STUN_Handle::stun_server, and TIMEOUT.

Referenced by test_stun().

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

◆ GNUNET_NAT_stun_make_request_cancel()

void GNUNET_NAT_stun_make_request_cancel ( struct GNUNET_NAT_STUN_Handle rh)

Cancel active STUN request.

Frees associated resources and ensures that the callback is no longer invoked.

Parameters
rhrequest to cancel

Definition at line 247 of file nat_api_stun.c.

248{
249 if (NULL != rh->dns_active)
250 {
252 rh->dns_active = NULL;
253 }
255 GNUNET_free (rh);
256}
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.

References GNUNET_NAT_STUN_Handle::dns_active, GNUNET_free, GNUNET_RESOLVER_request_cancel(), and GNUNET_NAT_STUN_Handle::stun_server.

Referenced by GNUNET_NAT_stun_make_request(), and stun_dns_callback().

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