31#define LOG(kind, ...) GNUNET_log_from (kind, "util-nat", __VA_ARGS__)
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 10)
36#define TIMEOUT_DELAY \
37 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100)
44 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 150)
102 "other sync ready %u, other rtt %lu and rtt %lu rel1 %lu rel2 %lu\n",
114 "other sync ready 1\n");
118 "other sync ready 2\n");
125 "other sync ready 3\n");
135 "other sync ready 6\n");
154 struct sockaddr_storage sa;
155 socklen_t salen =
sizeof(sa);
156 char buf[UINT16_MAX];
162 "Reading from socket\n");
168 (
struct sockaddr *) &sa,
172 struct sockaddr *addr = (
struct sockaddr*) &sa;
177 "Failed to recv from %s family %d failed sock %p\n",
187 (
unsigned long long) rcvd);
192 "Read 0 bytes from UDP socket\n");
201 "Received a burst message from remote port %u to local port %u!\n",
205 sock_info->
nus (sock_info);
211 "Received a non burst message on local port %u %lu!\n",
225static struct sockaddr *
235 colon = strrchr (cp,
':');
241 if (1 == sscanf (colon,
"%u%1s", &
port,
dummy))
244 if (
port > UINT16_MAX)
247 "BINDTO specification `%s' invalid: value too large for port\n",
257 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
270 struct sockaddr_in v4;
272 memset (&v4, 0,
sizeof(v4));
273 if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
275 v4.sin_family = AF_INET;
276 v4.sin_port = htons ((uint16_t)
port);
277#if HAVE_SOCKADDR_IN_SIN_LEN
278 v4.sin_len =
sizeof(
struct sockaddr_in);
281 *sock_len =
sizeof(
struct sockaddr_in);
288 struct sockaddr_in6 v6;
291 memset (&v6, 0,
sizeof(v6));
293 if ((
'[' == *cp) && (
']' == cp[strlen (cp) - 1]))
296 cp[strlen (cp) - 1] =
'\0';
298 if (1 == inet_pton (AF_INET6,
start, &v6.sin6_addr))
300 v6.sin6_family = AF_INET6;
301 v6.sin6_port = htons ((uint16_t)
port);
302#if HAVE_SOCKADDR_IN_SIN_LEN
303 v6.sin6_len =
sizeof(
struct sockaddr_in6);
306 *sock_len =
sizeof(v6);
329 "timeout nr_open_sockets %u\n",
336 "freeing sock_info %p\n",
353 struct sockaddr *bind_in;
354 socklen_t bind_in_len;
367 "Trying again in %s",
379 "3 sock %p addr %s addr %s %u\n",
388 "Failed to setup UDP socket address with path `%s'\n",
399 "4 sock addr %s addr %s\n",
406 "Failed to setup UDP socket bind address with path `%s'\n",
420 "Failed to create socket for %s family %d\n",
428 "Trying again in %s, because of EMFILE\n",
448 "Failed to bind socket for %s family %d sock %p\n",
477 memcpy (dgram, &bm,
sizeof(bm));
485 "Sending burst to %s family %d failed sock %p\n",
524 "2 sock addr %s addr %s rtt %s %u\n",
532 memcpy (dgram, &bm,
sizeof(bm));
540 "Sending burst to %s family %d failed sock %p\n",
550 sock_info->
nus = nus;
580 pos = sock_info->
next;
588 if (do_not_touch != sock_info->
udp_sock)
591 if (NULL != sock_info->
address)
594 "freeing sock_info %p\n",
static int start
Set if we are to start default services (including ARM).
static uint16_t port
Port number.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static char * address
GNS address for this phone.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
#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.
#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.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
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.
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.
struct GNUNET_BurstSync * GNUNET_get_burst_sync_msg(struct GNUNET_TIME_Relative rtt_average, enum GNUNET_GenericReturnValue sync_ready)
Create GNUNET_BurstSync message.
void GNUNET_stop_burst(struct GNUNET_NETWORK_Handle *do_not_touch)
Method to stop all sockets we established to the other peer.
void(* GNUNET_NotifyUdpSocket)(struct GNUNET_UdpSocketInfo *sock_info)
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
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.
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).
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...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
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.
const char * GNUNET_TIME_relative2s(struct GNUNET_TIME_Relative delta, bool do_round)
Give relative time in human-readable fancy format.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
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.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Subtract relative timestamp from the other.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
static void timeout_task_cb(void *cls)
#define RTT_DIFF
Difference of the average RTT for the DistanceVector calculate by us and the target we are willing to...
static void read_send(void *cls)
static void sock_read(void *cls)
Socket read task.
static struct GNUNET_SCHEDULER_Task * read_send_task
static struct sockaddr * udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
Convert UDP bind specification to a struct sockaddr *
static struct GNUNET_UdpSocketInfo * sock_infos_tail
static struct GNUNET_UdpSocketInfo * sock_infos_head
unsigned int nr_open_sockets
Maximum of open sockets.
Message send during burst mode.
unsigned int local_port
The local port the message was send from.
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.
Entry in list of pending tasks.
Struct wrapping information we use for starting the burst.
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.
Struct with the socket we like to use to send messages to another peer.
const char * bind_address
Our address without port.
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 port
The port we are bound to.
struct GNUNET_UdpSocketInfo * next
This is a linked list.
unsigned int std_port
Default local port we are bound to.
struct sockaddr * actual_address
The address of the other peer we received a burst message from.
struct GNUNET_SCHEDULER_Task * timeout_task
Timeout task for this socket.
struct GNUNET_NETWORK_Handle * udp_sock
struct GNUNET_SCHEDULER_Task * read_task
The read task for retrieving a burst message for this socket.