#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet_protocols.h"
#include "../../service/nat-auto/nat-auto.h"
Go to the source code of this file.
Data Structures | |
struct | ClientData |
Information we track per client. More... | |
struct | TcpContext |
Closure for tcp_send. More... | |
Functions | |
static void | try_anat (uint32_t dst_ipv4, uint16_t dport, int is_tcp) |
Try contacting the peer using autonomous NAT traversal method. More... | |
static void | tcp_send (void *cls) |
Task called by the scheduler once we can do the TCP send (or once we failed to connect...). More... | |
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. More... | |
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. More... | |
static void | handle_test (void *cls, const struct GNUNET_NAT_AUTO_TestMessage *tm) |
We've received a request to probe a NAT traversal. More... | |
static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *srv) |
Main function that will be run. More... | |
static void | force_timeout (void *cls) |
Forcefully drops client after 1s. More... | |
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. More... | |
static void | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) |
Callback called when a client disconnected from the service. More... | |
GNUNET_SERVICE_MAIN ("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. More... | |
Variables | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Our configuration. More... | |
|
static |
Try contacting the peer using autonomous NAT traversal method.
dst_ipv4 | IPv4 address to send the fake ICMP message |
dport | destination port to include in ICMP message |
is_tcp | mark for TCP (GNUNET_YES) or UDP (GNUNET_NO) |
Definition at line 65 of file gnunet-nat-server.c.
References cfg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAT_register(), GNUNET_NAT_request_reversal(), GNUNET_NAT_unregister(), and h.
Referenced by handle_test().
|
static |
Task called by the scheduler once we can do the TCP send (or once we failed to connect...).
cls | the struct TcpContext |
Definition at line 133 of file gnunet-nat-server.c.
References ctx, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log_strerror, GNUNET_NETWORK_fdset_isset(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_send(), GNUNET_NETWORK_socket_shutdown(), GNUNET_SCHEDULER_get_task_context(), tc, and GNUNET_SCHEDULER_TaskContext::write_ready.
Referenced by try_send_tcp().
|
static |
Try to send data to the IP dst_ipv4' at port dport via TCP.
dst_ipv4 | target IP |
dport | target port |
data | data to send |
Definition at line 163 of file gnunet-nat-server.c.
References ctx, data, GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_connect(), GNUNET_NETWORK_socket_create(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_SECONDS, TcpContext::s, and tcp_send().
Referenced by handle_test().
|
static |
Try to send data to the IP dst_ipv4 at port dport via UDP.
dst_ipv4 | target IP |
dport | target port |
data | data to send |
Definition at line 221 of file gnunet-nat-server.c.
References data, GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), and GNUNET_NETWORK_socket_sendto().
Referenced by handle_test().
|
static |
We've received a request to probe a NAT traversal.
Do it.
cls | handle to client (we always close) |
tm | message with details about what to test |
Definition at line 268 of file gnunet-nat-server.c.
References ClientData::client, GNUNET_NAT_AUTO_TestMessage::data, GNUNET_NAT_AUTO_TestMessage::dport, GNUNET_NAT_AUTO_TestMessage::dst_ipv4, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SERVICE_client_drop(), GNUNET_YES, GNUNET_NAT_AUTO_TestMessage::is_tcp, try_anat(), try_send_tcp(), and try_send_udp().
|
static |
Main function that will be run.
cls | closure |
c | configuration |
srv | service handle |
Definition at line 301 of file gnunet-nat-server.c.
References cfg.
|
static |
Forcefully drops client after 1s.
cls | our struct ClientData of a client to drop |
Definition at line 315 of file gnunet-nat-server.c.
References ClientData::client, GNUNET_SERVICE_client_drop(), and ClientData::tt.
Referenced by client_connect_cb().
|
static |
Callback called when a client connects to the service.
cls | closure for the service |
c | the new client that connected to the service |
mq | the message queue used to send messages to the client |
struct ClientData
Definition at line 333 of file gnunet-nat-server.c.
References ClientData::client, force_timeout(), GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_SECONDS, and ClientData::tt.
|
static |
Callback called when a client disconnected from the service.
cls | closure for the service |
c | the client that disconnected |
internal_cls | our struct ClientData |
Definition at line 356 of file gnunet-nat-server.c.
References GNUNET_free, GNUNET_SCHEDULER_cancel(), and ClientData::tt.
GNUNET_SERVICE_MAIN | ( | "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 |
Our configuration.
Definition at line 54 of file gnunet-nat-server.c.
Referenced by run(), and try_anat().