156 (
const struct sockaddr *) &ae[1],
178 if (ntohs (crm->
header.
size) !=
sizeof(*crm) +
sizeof(
struct sockaddr_in))
201 (
const struct sockaddr *) &crm[1],
202 sizeof(
struct sockaddr_in));
218 size_t alen = ntohs (acn->
header.
size) -
sizeof(*acn);
222 case sizeof(
struct sockaddr_in): {
223 const struct sockaddr_in *s4 = (
const struct sockaddr_in *) &acn[1];
224 if (AF_INET != s4->sin_family)
232 case sizeof(
struct sockaddr_in6): {
233 const struct sockaddr_in6 *s6 = (
const struct sockaddr_in6 *) &acn[1];
234 if (AF_INET6 != s6->sin6_family)
262 size_t alen = ntohs (acn->
header.
size) -
sizeof(*acn);
263 const struct sockaddr *sa = (
const struct sockaddr *) &acn[1];
268 "Received address change notification\n");
287 if ((ae->
addrlen == alen) && (0 == memcmp (&ae[1], sa, alen)))
334 connection_reversal_request,
339 address_change_notification,
367 const char *config_section,
369 unsigned int num_addrs,
370 const struct sockaddr **addrs,
371 const socklen_t *addrlens,
383 for (
unsigned int i = 0; i <
num_addrs; i++)
385 str_len = strlen (config_section) + 1;
398 if (NULL != address_callback)
405 off = (
char *) &rm[1];
406 for (
unsigned int i = 0; i <
num_addrs; i++)
408 switch (addrs[i]->sa_family)
411 if (
sizeof(
struct sockaddr_in) != addrlens[i])
420 if (
sizeof(
struct sockaddr_in6) != addrlens[i])
430 if (
sizeof(
struct sockaddr_un) != addrlens[i])
462 unsigned int address_length)
471 "natting address %s length %u\n",
479 off = (
char *) &aam[1];
501 uint32_t advertised_message_size;
502 uint32_t message_magic_cookie;
511 "STUN packet too short (only %d, wanting at least %d)\n",
522 advertised_message_size = ntohs (hdr->
msglen);
524 message_magic_cookie = ntohl (hdr->
magic);
532 if (advertised_message_size > len)
535 "Scrambled STUN packet length (got %d, expecting %d)\n",
536 advertised_message_size,
540 len = advertised_message_size;
546 "Attribute too short in STUN packet (got %d, expecting %d)\n",
554 advertised_message_size = ntohs (
attr->len) +
sizeof(
struct stun_attr);
557 if (advertised_message_size >
len)
561 "Inconsistent Attribute (length %d exceeds remaining msg len %d)\n",
562 advertised_message_size,
566 data += advertised_message_size;
567 len -= advertised_message_size;
570 "STUN Packet, msg %04x, length: %d\n",
572 advertised_message_size);
602 const struct sockaddr *sender_addr,
603 size_t sender_addr_len,
620 buf = (
char *) &hsn[1];
622 buf += sender_addr_len;
649 if ((
addrlen !=
sizeof(
struct sockaddr_in)) &&
650 (
addrlen !=
sizeof(
struct sockaddr_in6)))
676 const struct sockaddr_in *local_sa,
677 const struct sockaddr_in *remote_sa)
689 2 *
sizeof(
struct sockaddr_in),
693 buf = (
char *) &req[1];
695 buf +=
sizeof(
struct sockaddr_in);
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MQ_Envelope * env
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
static uint8_t proto
Protocol to use.
static void reversal_callback(void *cls, const struct sockaddr_in *ra)
We got a connection reversal request from another peer.
struct GNUNET_NAT_Handle * nh
Handle for connect to the NAT service.
#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.
#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.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#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
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#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)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
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 respons...
void(* GNUNET_NAT_ReversalCallback)(void *cls, const struct sockaddr *remote_addr, socklen_t remote_addrlen)
Signature of the callback passed to 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...
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
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.
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 ...
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.
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
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.
#define GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS
Message to ask NAT service to notify all clients about a new global address.
#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE
Message to from NAT service notifying us that one of our addresses changed.
#define GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED
Message to from NAT service notifying us that connection reversal was requested by another peer.
#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL
Message to ask NAT service to request connection reversal.
#define GNUNET_MESSAGE_TYPE_NAT_REGISTER
Message to ask NAT service to register a client.
#define GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN
Message to ask NAT service to handle a STUN packet.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
@ GNUNET_NAT_RF_ADDRESSES
This client wants to be informed about changes to our applicable addresses.
@ GNUNET_NAT_RF_NONE
This client does not want any notifications.
@ GNUNET_NAT_RF_REVERSAL
This client supports address reversal.
static int check_connection_reversal_request(void *cls, const struct GNUNET_NAT_ConnectionReversalRequestedMessage *crm)
Check connection reversal request.
static enum GNUNET_GenericReturnValue test_stun_packet(const void *data, size_t len)
Check if an incoming message is a STUN message.
static void handle_address_change_notification(void *cls, const struct GNUNET_NAT_AddressChangeNotificationMessage *acn)
Handle connection reversal request.
static void do_connect(void *cls)
Task to connect to the NAT service.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handle queue errors by reconnecting to NAT.
static void reconnect(struct GNUNET_NAT_Handle *nh)
Task to connect to the NAT service.
static int check_address_change_notification(void *cls, const struct GNUNET_NAT_AddressChangeNotificationMessage *acn)
Check address change notification.
static void handle_connection_reversal_request(void *cls, const struct GNUNET_NAT_ConnectionReversalRequestedMessage *crm)
Handle connection reversal request.
Message types for STUN server resolution.
#define STUN_MAGIC_COOKIE
Entry in DLL of addresses of this peer.
struct AddrEntry * next
DLL.
struct AddrEntry * prev
DLL.
enum GNUNET_NAT_AddressClass ac
Address class of the address.
void * app_ctx
Place where the application can store data (on add, and retrieve on remove).
socklen_t addrlen
Number of bytes that follow.
Handle to a message queue.
Message handler for a specific message type.
Message sent by client to add a global address.
unsigned int address_length
Length of the address following the struct, in NBO.
Service notifying the client about changes in the set of addresses it has.
int32_t add_remove
GNUNET_YES to add, GNUNET_NO to remove the address from the list.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE.
uint32_t addr_class
Type of the address, an enum GNUNET_NAT_AddressClass in NBO.
Service telling a client that connection reversal was requested.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED.
Client telling the service to (possibly) handle a STUN message.
uint16_t payload_size
Number of bytes of payload included, in NBO.
uint16_t sender_addr_size
Size of the sender address included, in NBO.
Handle for active NAT registrations.
struct GNUNET_TIME_Relative reconnect_delay
How long to wait until we reconnect.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
void * callback_cls
Closure for the various callbacks.
struct AddrEntry * ae_head
Head of address DLL.
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task scheduled to reconnect to the service.
struct GNUNET_MessageHeader * reg
Our registration message.
struct AddrEntry * ae_tail
Tail of address DLL.
GNUNET_NAT_ReversalCallback reversal_callback
Function to call when another peer requests connection reversal.
GNUNET_NAT_AddressCallback address_callback
Function to call when our addresses change.
Message sent by a client to register with its addresses.
uint16_t num_addrs
Number of addresses that this service is bound to that follow.
uint16_t str_len
Number of bytes in the string that follow which specifies a section name in the configuration.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_REGISTER.
uint8_t flags
An enum GNUNET_NAT_RegisterFlags.
uint8_t proto
Client's IPPROTO, e.g.
Client asking the service to initiate connection reversal.
uint16_t local_addr_size
Size of the local address included, in NBO.
uint16_t remote_addr_size
Size of the remote address included, in NBO.
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.