functions for interaction with miniupnp; tested with miniupnpc 1.5 More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet-service-nat_mini.h"
#include "nat.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_NAT_ExternalHandle |
Opaque handle to cancel "GNUNET_NAT_mini_get_external_ipv4" operation. More... | |
struct | GNUNET_NAT_MiniHandle |
Handle to a mapping created with upnpc. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__) |
#define | MAP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
How long do we give upnpc to create a mapping? More... | |
#define | UNMAP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
How long do we give upnpc to remove a mapping? More... | |
#define | MAP_REFRESH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
How often do we check for changes in the mapping? More... | |
Functions | |
static void | read_external_ipv4 (void *cls) |
Read the output of external-ip into buf . More... | |
static void | signal_external_ip_error (void *cls) |
(Asynchronously) signal error invoking external-ip to client. More... | |
struct GNUNET_NAT_ExternalHandle * | GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb, void *cb_cls) |
Try to get the external IPv4 address of this peer. More... | |
void | GNUNET_NAT_mini_get_external_ipv4_cancel_ (struct GNUNET_NAT_ExternalHandle *eh) |
Cancel operation. More... | |
static void | do_refresh (void *cls) |
Run "upnpc -l" to find out if our mapping changed. More... | |
static void | process_map_output (void *cls, const char *line) |
Process the output from the "upnpc -r" command. More... | |
static void | run_upnpc_r (struct GNUNET_NAT_MiniHandle *mini) |
Run "upnpc -r" to map our internal port. More... | |
static void | process_refresh_output (void *cls, const char *line) |
Process the output from "upnpc -l" to see if our external mapping changed. More... | |
struct GNUNET_NAT_MiniHandle * | GNUNET_NAT_mini_map_start (uint16_t port, int is_tcp, GNUNET_NAT_MiniAddressCallback ac, void *ac_cls) |
Start mapping the given port using (mini)upnpc. More... | |
static void | process_unmap_output (void *cls, const char *line) |
Process output from our 'unmap' command. More... | |
void | GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini) |
Remove a mapping created with (mini)upnpc. More... | |
functions for interaction with miniupnp; tested with miniupnpc 1.5
Definition in file gnunet-service-nat_mini.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "nat", __VA_ARGS__) |
Definition at line 32 of file gnunet-service-nat_mini.c.
#define MAP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
How long do we give upnpc to create a mapping?
Definition at line 37 of file gnunet-service-nat_mini.c.
#define UNMAP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) |
How long do we give upnpc to remove a mapping?
Definition at line 42 of file gnunet-service-nat_mini.c.
#define MAP_REFRESH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
How often do we check for changes in the mapping?
Definition at line 48 of file gnunet-service-nat_mini.c.
|
static |
Read the output of external-ip
into buf
.
When complete, parse the address and call our callback.
cls | the struct GNUNET_NAT_ExternalHandle |
Definition at line 113 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_ExternalHandle::buf, GNUNET_NAT_ExternalHandle::cb, GNUNET_NAT_ExternalHandle::cb_cls, GNUNET_DISK_file_read(), GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_mini_get_external_ipv4_cancel_(), GNUNET_SCHEDULER_add_read_file(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_NAT_ExternalHandle::off, GNUNET_NAT_ExternalHandle::r, read_external_ipv4(), ret, GNUNET_NAT_ExternalHandle::ret, and GNUNET_NAT_ExternalHandle::task.
Referenced by GNUNET_NAT_mini_get_external_ipv4_(), and read_external_ipv4().
|
static |
(Asynchronously) signal error invoking external-ip
to client.
cls | the struct GNUNET_NAT_ExternalHandle (freed) |
Definition at line 159 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_ExternalHandle::cb, GNUNET_NAT_ExternalHandle::cb_cls, GNUNET_free, GNUNET_NAT_ExternalHandle::ret, and GNUNET_NAT_ExternalHandle::task.
Referenced by GNUNET_NAT_mini_get_external_ipv4_().
struct GNUNET_NAT_ExternalHandle * GNUNET_NAT_mini_get_external_ipv4_ | ( | GNUNET_NAT_IPCallback | cb, |
void * | cb_cls | ||
) |
Try to get the external IPv4 address of this peer.
cb | function to call with result |
cb_cls | closure for cb |
Definition at line 177 of file gnunet-service-nat_mini.c.
References _, GNUNET_NAT_ExternalHandle::cb, GNUNET_NAT_ExternalHandle::cb_cls, GNUNET_NAT_ExternalHandle::eip, GNUNET_DISK_PF_BLOCKING_RW, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_DISK_pipe_close_end(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_PIPE_END_WRITE, GNUNET_DISK_pipe_handle(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, GNUNET_NAT_ERROR_IPC_FAILURE, GNUNET_NAT_ERROR_SUCCESS, GNUNET_new, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_OS_INHERIT_STD_NONE, GNUNET_OS_start_process(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, LOG, GNUNET_NAT_ExternalHandle::opipe, GNUNET_NAT_ExternalHandle::r, read_external_ipv4(), GNUNET_NAT_ExternalHandle::ret, signal_external_ip_error(), and GNUNET_NAT_ExternalHandle::task.
Referenced by run_external_ip().
void GNUNET_NAT_mini_get_external_ipv4_cancel_ | ( | struct GNUNET_NAT_ExternalHandle * | eh | ) |
Cancel operation.
eh | operation to cancel |
Definition at line 232 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_ExternalHandle::eip, GNUNET_break, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_process_kill(), GNUNET_OS_process_wait(), GNUNET_SCHEDULER_cancel(), GNUNET_NAT_ExternalHandle::opipe, and GNUNET_NAT_ExternalHandle::task.
Referenced by GN_nat_status_changed(), read_external_ipv4(), and run_external_ip().
|
static |
Run "upnpc -l" to find out if our mapping changed.
cls | the struct GNUNET_NAT_MiniHandle |
Definition at line 475 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, do_refresh(), GNUNET_NAT_MiniHandle::found, GNUNET_ERROR_TYPE_DEBUG, GNUNET_NAT_ERROR_UPNPC_TIMEOUT, GNUNET_NO, GNUNET_OS_command_run(), GNUNET_OS_command_stop(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_YES, LOG, GNUNET_NAT_MiniHandle::map_cmd, MAP_REFRESH_FREQ, MAP_TIMEOUT, process_refresh_output(), GNUNET_NAT_MiniHandle::refresh_cmd, and GNUNET_NAT_MiniHandle::refresh_task.
Referenced by do_refresh(), GNUNET_NAT_mini_map_start(), and process_map_output().
|
static |
Process the output from the "upnpc -r" command.
Process the output from the 'upnpc -r' command.
cls | the struct GNUNET_NAT_MiniHandle |
line | line of output, NULL at the end |
Definition at line 523 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, GNUNET_NAT_MiniHandle::current_addr, GNUNET_NAT_MiniHandle::did_map, do_refresh(), GNUNET_free, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, GNUNET_OS_command_stop(), GNUNET_SCHEDULER_add_delayed(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, line, GNUNET_NAT_MiniHandle::map_cmd, MAP_REFRESH_FREQ, port, and GNUNET_NAT_MiniHandle::refresh_task.
Referenced by run_upnpc_r().
|
static |
Run "upnpc -r" to map our internal port.
mini | our handle |
Definition at line 345 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, GNUNET_NAT_ERROR_UPNPC_FAILED, GNUNET_OS_command_run(), GNUNET_snprintf(), GNUNET_SYSERR, GNUNET_NAT_MiniHandle::is_tcp, GNUNET_NAT_MiniHandle::map_cmd, MAP_TIMEOUT, GNUNET_NAT_MiniHandle::port, and process_map_output().
Referenced by GNUNET_NAT_mini_map_start(), and process_refresh_output().
|
static |
Process the output from "upnpc -l" to see if our external mapping changed.
If so, do the notifications.
cls | the struct GNUNET_NAT_MiniHandle |
line | line of output, NULL at the end |
Definition at line 379 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, GNUNET_NAT_MiniHandle::current_addr, GNUNET_NAT_MiniHandle::did_map, GNUNET_NAT_MiniHandle::found, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NO, GNUNET_OS_command_stop(), GNUNET_snprintf(), GNUNET_YES, GNUNET_NAT_MiniHandle::is_tcp, line, GNUNET_NAT_MiniHandle::port, GNUNET_NAT_MiniHandle::refresh_cmd, and run_upnpc_r().
Referenced by do_refresh().
struct GNUNET_NAT_MiniHandle * GNUNET_NAT_mini_map_start | ( | uint16_t | port, |
int | is_tcp, | ||
GNUNET_NAT_MiniAddressCallback | ac, | ||
void * | ac_cls | ||
) |
Start mapping the given port using (mini)upnpc.
This function should typically not be used directly (it is used within the general-purpose GNUNET_NAT_register() code). However, it can be used if specifically UPnP-based NAT traversal is to be used or tested.
port | port to map |
is_tcp | GNUNET_YES to map TCP, GNUNET_NO for UDP |
ac | function to call with mapping result |
ac_cls | closure for ac |
Definition at line 593 of file gnunet-service-nat_mini.c.
References _, GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, do_refresh(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, GNUNET_new, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_NAT_MiniHandle::is_tcp, LOG, MAP_REFRESH_FREQ, port, ret, and run_upnpc_r().
Referenced by handle_register().
|
static |
Process output from our 'unmap' command.
cls | the struct GNUNET_NAT_MiniHandle |
line | line of output, NULL at the end |
Definition at line 626 of file gnunet-service-nat_mini.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_OS_command_stop(), line, LOG, and GNUNET_NAT_MiniHandle::unmap_cmd.
Referenced by GNUNET_NAT_mini_map_stop().
void GNUNET_NAT_mini_map_stop | ( | struct GNUNET_NAT_MiniHandle * | mini | ) |
Remove a mapping created with (mini)upnpc.
Calling this function will give 'upnpc' 1s to remove the mapping, so while this function is non-blocking, a task will be left with the scheduler for up to 1s past this call.
mini | the handle |
Definition at line 643 of file gnunet-service-nat_mini.c.
References GNUNET_NAT_MiniHandle::ac, GNUNET_NAT_MiniHandle::ac_cls, GNUNET_NAT_MiniHandle::current_addr, GNUNET_NAT_MiniHandle::did_map, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NO, GNUNET_OS_command_run(), GNUNET_OS_command_stop(), GNUNET_SCHEDULER_cancel(), GNUNET_snprintf(), GNUNET_NAT_MiniHandle::is_tcp, LOG, GNUNET_NAT_MiniHandle::map_cmd, process_unmap_output(), GNUNET_NAT_MiniHandle::refresh_cmd, GNUNET_NAT_MiniHandle::refresh_task, GNUNET_NAT_MiniHandle::unmap_cmd, and UNMAP_TIMEOUT.
Referenced by client_disconnect_cb().