31#include "../../service/nat-auto/nat-auto.h"
70 struct sockaddr_in lsa;
71 struct sockaddr_in rsa;
72 const struct sockaddr *sa;
76 "Asking for connection reversal with %x and code %u\n",
77 (
unsigned int) dst_ipv4,
78 (
unsigned int) dport);
79 memset (&lsa, 0,
sizeof(lsa));
80 lsa.sin_family = AF_INET;
81#if HAVE_SOCKADDR_IN_SIN_LEN
82 lsa.sin_len =
sizeof(sa);
84 lsa.sin_addr.s_addr = 0;
85 lsa.sin_port = htons (dport);
86 memset (&rsa, 0,
sizeof(rsa));
87 rsa.sin_family = AF_INET;
88#if HAVE_SOCKADDR_IN_SIN_LEN
89 rsa.sin_len =
sizeof(sa);
91 rsa.sin_addr.s_addr = dst_ipv4;
92 rsa.sin_port = htons (dport);
94 sa = (
const struct sockaddr *) &lsa;
97 is_tcp ? IPPROTO_TCP : IPPROTO_UDP,
168 struct sockaddr_in sa;
180 memset (&sa, 0,
sizeof(sa));
181 sa.sin_family = AF_INET;
182#if HAVE_SOCKADDR_IN_SIN_LEN
183 sa.sin_len =
sizeof(sa);
185 sa.sin_addr.s_addr = dst_ipv4;
186 sa.sin_port = htons (dport);
188 "Sending TCP message to `%s'\n",
193 (
const struct sockaddr *) &sa,
195 (errno != EINPROGRESS))
226 struct sockaddr_in sa;
237 memset (&sa, 0,
sizeof(sa));
238 sa.sin_family = AF_INET;
239#if HAVE_SOCKADDR_IN_SIN_LEN
240 sa.sin_len =
sizeof(sa);
242 sa.sin_addr.s_addr = dst_ipv4;
243 sa.sin_port = htons (dport);
245 "Sending UDP packet to `%s'\n",
252 (
const struct sockaddr *) &sa,
275 "Received test request\n");
276 dport = ntohs (tm->
dport);
280 (
int) ntohl (tm->
is_tcp));
386#if defined(__linux__) && defined(__GLIBC__)
390GNUNET_NATS_memory_init (
void);
396GNUNET_NATS_memory_init ()
398 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
399 mallopt (M_TOP_PAD, 1 * 1024);
struct GNUNET_MQ_Handle * mq
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static char * data
The data to insert into the dht.
static struct GNUNET_FS_Handle * ctx
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *srv)
Main function that will be run.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void handle_test(void *cls, const struct GNUNET_NAT_AUTO_TestMessage *tm)
We've received a request to probe a NAT traversal.
GNUNET_SERVICE_MAIN(GNUNET_OS_project_data_gnunet(), "nat-server", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(test, GNUNET_MESSAGE_TYPE_NAT_TEST, struct GNUNET_NAT_AUTO_TestMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static void force_timeout(void *cls)
Forcefully drops client after 1s.
static void try_send_tcp(uint32_t dst_ipv4, uint16_t dport, uint16_t data)
Try to send data to the IP dst_ipv4' at port dport via TCP.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback called when a client connects to the service.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback called when a client disconnected from the service.
static void try_send_udp(uint32_t dst_ipv4, uint16_t dport, uint16_t data)
Try to send data to the IP dst_ipv4 at port dport via UDP.
static void try_anat(uint32_t dst_ipv4, uint16_t dport, int is_tcp)
Try contacting the peer using autonomous NAT traversal method.
static void tcp_send(void *cls)
Task called by the scheduler once we can do the TCP send (or once we failed to connect....
struct GNUNET_PQ_ResultSpec __attribute__
Constants for network protocols.
#define GNUNET_log(kind,...)
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).
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
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...
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.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_connect(const struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Connect a socket to some remote address.
ssize_t GNUNET_NETWORK_socket_send(const struct GNUNET_NETWORK_Handle *desc, const void *buffer, size_t length)
Send data (always non-blocking).
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_shutdown(struct GNUNET_NETWORK_Handle *desc, int how)
Shut down socket operations.
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).
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_NAT_TEST
Message to ask NAT server to perform traversal test.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, 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...
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
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.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
#define GNUNET_TIME_UNIT_SECONDS
One second.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Information we track per client.
struct GNUNET_SCHEDULER_Task * tt
Timeout task.
struct GNUNET_SERVICE_Client * client
Client handle.
Handle to a message queue.
Request to test NAT traversal, sent to the gnunet-nat-server (not the service!).
uint32_t dst_ipv4
IPv4 target IP address.
uint16_t dport
Port to use, 0 to send dummy ICMP response.
int32_t is_tcp
GNUNET_YES for TCP, GNUNET_NO for UDP.
uint16_t data
Data to send OR advertised-port (in NBO) to use for dummy ICMP.
Handle for active NAT registrations.
Context information passed to each scheduler task.
const struct GNUNET_NETWORK_FDSet * write_ready
Set of file descriptors ready for writing; note that additional bits may be set that were not in the ...
Entry in list of pending tasks.
Handle to a client that is connected to a service.
struct GNUNET_NETWORK_Handle * s
TCP socket.
uint16_t data
Data to transmit.