39#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
41#define LOG_STRERROR(kind, syscall) \
42 GNUNET_log_from_strerror (kind, "util-service", syscall)
44#define LOG_STRERROR_FILE(kind, syscall, filename) \
45 GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
363 client = client->next)
365 if (NULL != client->drop_task)
367 if (client->is_monitor)
387 sh->suspend_state |= sr;
392 if (NULL != slc->listen_task)
395 slc->listen_task = NULL;
443 const struct in_addr *
add)
445 for (
unsigned int i = 0;
446 0 !=
list[i].network.s_addr;
449 if ( (
add->s_addr &
list[i].netmask.s_addr) ==
450 (
list[i].network.s_addr &
list[i].netmask.s_addr) )
466 const struct in6_addr *ip)
468 for (
unsigned int i = 0;
474 for (
unsigned int j = 0; j <
sizeof(
struct in6_addr) / sizeof(
int); j++)
475 if (((((
int *) ip)[j] & ((
int *) &
list[i].netmask)[j])) !=
476 (((
int *) &
list[i].network)[j] & ((
int *) &
list[i].netmask)[j]))
503 "service: sending message with type %u\n",
506 buf = (
const char *) client->
msg;
520 if ((EAGAIN == errno) || (EINTR == errno))
530 "socket send returned with error code %i",
541 if (left > (
size_t)
ret)
575 "Sending message of type %u and size %u to client\n",
622 (!
sh->require_found) )
625 "No handler for message of type %u found\n",
653 "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
679 "Received message of type %u and size %u from client\n",
680 ntohs (message->
type),
681 ntohs (message->
size));
759 client->
sock = csock;
768 if (NULL !=
sh->connect_cb)
795 const struct sockaddr_in *v4;
796 const struct sockaddr_in6 *v6;
797 struct sockaddr_storage sa;
801 addrlen =
sizeof(sa);
803 (
struct sockaddr *) &sa,
809 else if (EAGAIN != errno)
814 switch (sa.ss_family)
818 v4 = (
const struct sockaddr_in *) &sa;
819 ok = (((NULL ==
sh->v4_allowed) ||
822 ((NULL ==
sh->v4_denied) ||
829 v6 = (
const struct sockaddr_in6 *) &sa;
830 ok = (((NULL ==
sh->v6_allowed) ||
833 ((NULL ==
sh->v6_denied) ||
844 _ (
"Unknown address family %d\n"),
851 "Service rejected incoming connection from %s due to policy.\n",
852 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
857 "Service accepted incoming connection from %s.\n",
858 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
862 if (0 !=
sh->suspend_state)
884 sh->suspend_state -= sr;
918 if (-1 !=
sh->ready_confirm_fd)
922 sh->ready_confirm_fd = -1;
925 if (NULL !=
sh->service_init_cb)
959 _ (
"Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
1000 _ (
"Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
1022 socklen_t *saddrlens,
1023 const char *unixpath)
1026 struct sockaddr_un *un;
1029 un->sun_family = AF_UNIX;
1031#if HAVE_SOCKADDR_UN_SUN_LEN
1032 un->sun_len = (u_char)
sizeof(
struct sockaddr_un);
1034 *saddrs = (
struct sockaddr *) un;
1035 *saddrlens =
sizeof(
struct sockaddr_un);
1067 struct sockaddr ***addrs,
1068 socklen_t **addr_lens)
1072 unsigned long long port;
1074 struct addrinfo hints;
1075 struct addrinfo *
res;
1076 struct addrinfo *pos;
1077 struct addrinfo *next;
1081 struct sockaddr **saddrs;
1082 socklen_t *saddrlens;
1105 _ (
"Require valid port number for service `%s' in configuration!\n"),
1111 _ (
"Require valid port number for service `%s' in configuration!\n"),
1130 (0 < strlen (unixpath)) )
1133 struct sockaddr_un s_un;
1135 if (strlen (unixpath) >=
sizeof(s_un.sun_path))
1138 "UNIXPATH `%s' too long, maximum length is %llu\n",
1140 (
unsigned long long)
sizeof(s_un.sun_path));
1143 _ (
"Using `%s' instead\n"),
1152 if (NULL != unixpath)
1159 if ((ENOBUFS == errno) ||
1160 (ENOMEM == errno) ||
1161 (ENFILE == errno) ||
1171 "Failed to create UNIX domain socket for service %s: %s\n",
1187 (NULL == unixpath) )
1190 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n",
1203 *addr_lens = saddrlens;
1207 if (NULL != hostname)
1210 "Resolving `%s' since that is where `%s' will bind to.\n",
1213 memset (&hints, 0,
sizeof(
struct addrinfo));
1215 hints.ai_family = AF_INET;
1216 hints.ai_protocol = IPPROTO_TCP;
1217 if ((0 != (
ret = getaddrinfo (hostname, NULL, &hints, &
res))) ||
1221 _ (
"Failed to resolve `%s': %s\n"),
1223 gai_strerror (
ret));
1230 while (NULL != (pos = next))
1232 next = pos->ai_next;
1233 if ((disablev6) && (pos->ai_family == AF_INET6))
1240 _ (
"Failed to find %saddress for `%s'.\n"),
1241 disablev6 ?
"IPv4 " :
"",
1249 if (NULL != unixpath)
1254 if (NULL != unixpath)
1260 while (NULL != (pos = next))
1262 next = pos->ai_next;
1263 if ((disablev6) && (AF_INET6 == pos->ai_family))
1265 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1267 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1270 "Service `%s' will bind to `%s'\n",
1273 if (AF_INET == pos->ai_family)
1275 GNUNET_assert (
sizeof(
struct sockaddr_in) == pos->ai_addrlen);
1276 saddrlens[i] = pos->ai_addrlen;
1279 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1284 GNUNET_assert (
sizeof(
struct sockaddr_in6) == pos->ai_addrlen);
1285 saddrlens[i] = pos->ai_addrlen;
1288 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1303 if (NULL != unixpath)
1308 if (NULL != unixpath)
1313 saddrlens[i] =
sizeof(
struct sockaddr_in);
1315#if HAVE_SOCKADDR_IN_SIN_LEN
1316 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1318 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1319 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1325 if (NULL != unixpath)
1330 if (NULL != unixpath)
1335 saddrlens[i] =
sizeof(
struct sockaddr_in6);
1337#if HAVE_SOCKADDR_IN_SIN_LEN
1338 ((
struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1340 ((
struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1341 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1343 saddrlens[i] =
sizeof(
struct sockaddr_in);
1345#if HAVE_SOCKADDR_IN_SIN_LEN
1346 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1348 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1349 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1354 *addr_lens = saddrlens;
1374 switch (server_addr->sa_family)
1377 port = ntohs (((
const struct sockaddr_in *) server_addr)->sin_port);
1380 port = ntohs (((
const struct sockaddr_in6 *) server_addr)->sin6_port);
1407 if (EADDRINUSE != errno)
1415 _ (
"`%s' failed for port %d (%s).\n"),
1418 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1427 _ (
"`%s' failed for port %d (%s): address already in use\n"),
1430 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1431 else if (AF_UNIX == server_addr->sa_family)
1434 _ (
"`%s' failed for `%s': address already in use\n"),
1452 "Server starts to listen on port %u.\n",
1497 _ (
"Specified value for `%s' of service `%s' is invalid\n"),
1508 if ( (NULL != (nfds =
getenv (
"LISTEN_FDS"))) &&
1509 (1 == sscanf (nfds,
"%u%1s", &cnt,
dummy)) && (cnt > 0) &&
1510 (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
1515 flags = fcntl (3 + cnt, F_GETFD);
1516 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1521 "Could not access pre-bound socket %u, will try to bind myself\n"),
1522 (
unsigned int) 3 + cnt);
1524 while (NULL != lsocks[cnt])
1532 unsetenv (
"LISTEN_FDS");
1559 struct sockaddr **addrs;
1560 socklen_t *addrlens;
1570 for (
int i = 0; i < num; i++)
1591 if ((0 != num) && (NULL ==
sh->slc_head))
1597 "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
1661 pws = getpwnam (user);
1665 _ (
"Cannot obtain information about user `%s': %s\n"),
1667 errno == 0 ?
_ (
"No such user") : strerror (errno));
1671 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1673 (0 != initgroups (user, pws->pw_gid)) ||
1675 (0 != setuid (pws->pw_uid)) ||
1676 (0 != seteuid (pws->pw_uid)))
1678 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1679 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1682 _ (
"Cannot change user/group to `%s': %s\n"),
1729 if (0 != unlink (pif))
1750 if (0 != pipe (filedes))
1770 if (1 != read (filedes[0], &c,
sizeof(
char)))
1781 _ (
"Service process failed to initialize\n"));
1786 _ (
"Service process could not initialize server function\n"));
1791 _ (
"Service process failed to report status\n"));
1799 nullfd = open (
"/dev/null", O_RDWR | O_APPEND);
1803 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1806 (void) close (nullfd);
1809 (void) close (nullfd);
1815 sh->ready_confirm_fd = filedes[1];
1836 while (NULL != (slc =
sh->slc_head))
1994 char *opt_cfg_filename;
1999 unsigned long long skew_offset;
2000 unsigned long long skew_variance;
2001 long long clock_offset;
2010 "do daemonize (detach from terminal)"),
2021 memset (&
sh, 0,
sizeof(
sh));
2022 xdg =
getenv (
"XDG_CONFIG_HOME");
2032 sh.ready_confirm_fd = -1;
2035 sh.service_init_cb = service_init_cb;
2048 opt_cfg_filename = NULL;
2053 setlocale (LC_ALL,
"");
2084 if (NULL != opt_cfg_filename)
2090 _ (
"Malformed configuration file `%s', exit ...\n"),
2105 _ (
"Malformed configuration file `%s', exit ...\n"),
2117 _ (
"Malformed configuration, exit ...\n"));
2126 if ( (1 == do_daemonize) &&
2136 "Service `%s' runs with configuration from `%s'\n",
2138 (NULL != opt_cfg_filename) ? opt_cfg_filename :
cfg_filename);
2150 clock_offset = skew_offset - skew_variance;
2153 "Skewing clock by %lld ms\n",
2154 (
long long) clock_offset);
2162 if (1 == do_daemonize)
2166 if (-1 !=
sh.ready_confirm_fd)
2168 if (1 != write (
sh.ready_confirm_fd, err ?
"I" :
"S", 1))
2222 sh->ready_confirm_fd = -1;
2253 if (-1 !=
sh->ready_confirm_fd)
2255 if (1 != write (
sh->ready_confirm_fd,
"S", 1))
2259 close (
sh->ready_confirm_fd));
2315 "Entering GNUNET_SERVICE_main\n");
2423 "Client dropped: %p (MQ: %p)\n",
2428 void *backtrace_array[MAX_TRACE_DEPTH];
2429 int num_backtrace_strings = backtrace (backtrace_array,
2431 char **backtrace_strings =
2432 backtrace_symbols (backtrace_array,
2433 t->num_backtrace_strings);
2434 for (
unsigned int i = 0; i < num_backtrace_strings; i++)
2436 "client drop trace %u: %s\n",
2438 backtrace_strings[i]);
2442 if (NULL !=
sh->disconnect_cb)
2474 client = client->next)
2476 if (NULL == client->drop_task)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
#define gettext_noop(String)
#define textdomain(Domainname)
#define bindtextdomain(Domainname, Dirname)
static int list
Set if we should print a list of currently running services.
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * cfg_filename
Name of the configuration file.
static uint16_t port
Port number.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
static char * res
Currently read line or NULL on EOF.
static int add
Desired action is to add a record.
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
static void disconnect_cb(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called by cadet when a client disconnects.
static void * connect_cb(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator)
Functions of this type are called upon new cadet connection from other peers.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static char * service_name
Option -s: service name (hash to get service descriptor)
static struct GNUNET_SCHEDULER_Task * t
Main task.
Constants for network protocols.
Functions related to doing DNS lookups.
#define GNUNET_AGPL_URL
NOTE: You MUST adjust this URL to point to the location of a publicly accessible repository (or TGZ) ...
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
#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.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const struct GNUNET_OS_ProjectData *pd, const char *about)
Defining the option to print the command line help text (-h option).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.
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_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
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...
#define GNUNET_log_strerror_file(level, cmd, filename)
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_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_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_inject_error(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_Error error)
Call the error handler of a message queue with the given error code.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
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_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers2(const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_MessageCallback agpl_handler, void *agpl_cls)
Copy an array of handlers, appending AGPL handler.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
void GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
Call the send notification for the current message, but do not try to send the next message until #gn...
void GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
Change the closure argument in all of the handlers of the mq.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
@ GNUNET_MQ_ERROR_NO_MATCH
We received a message for which we have no matching handler.
@ GNUNET_MQ_ERROR_WRITE
FIXME: document!
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
char * GNUNET_NETWORK_shorten_unixpath(char *unixpath)
Given a unixpath that is too long (larger than UNIX_PATH_MAX), shorten it to an acceptable length whi...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
void GNUNET_NETWORK_socket_free_memory_only_(struct GNUNET_NETWORK_Handle *desc)
Only free memory of a socket, keep the file descriptor untouched.
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_test_pf(int pf)
Test if the given protocol family is supported by this system.
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.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_conf_and_options(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg)
Create configuration handle from options and configuration file.
#define GNUNET_MESSAGE_TYPE_RESPONSE_AGPL
Source code link.
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
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_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
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...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
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.
enum GNUNET_GenericReturnValue GNUNET_MST_next(struct GNUNET_MessageStreamTokenizer *mst, int one_shot)
Obtain the next message from the mst, assuming that there are more unprocessed messages in the intern...
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
enum GNUNET_GenericReturnValue GNUNET_MST_read(struct GNUNET_MessageStreamTokenizer *mst, struct GNUNET_NETWORK_Handle *sock, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
void GNUNET_SERVICE_suspend(struct GNUNET_SERVICE_Handle *sh)
Suspend accepting connections from the listen socket temporarily.
void GNUNET_SERVICE_stop(struct GNUNET_SERVICE_Handle *srv)
Stops a service that was started with GNUNET_SERVICE_start().
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
int GNUNET_SERVICE_run_(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *service_name, enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_InitCallback service_init_cb, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
Creates the "main" function for a GNUnet service.
GNUNET_SERVICE_Options
Options for the service (bitmask).
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
int GNUNET_SERVICE_register_(const struct GNUNET_OS_ProjectData *pd, const char *service_name, enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_InitCallback service_init_cb, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
Registers the GNUnet service to be scheduled as part of a monilithic libgnunet.
void(* GNUNET_SERVICE_DisconnectHandler)(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback to be called when a client disconnected from the service.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
struct GNUNET_SERVICE_Handle * GNUNET_SERVICE_start(const struct GNUNET_OS_ProjectData *pd, const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
Low-level function to start a service if the scheduler is already running.
void GNUNET_SERVICE_client_persist(struct GNUNET_SERVICE_Client *c)
Set the persist option on this client.
void GNUNET_SERVICE_client_disable_continue_warning(struct GNUNET_SERVICE_Client *c)
Disable the warning the server issues if a message is not acknowledged in a timely fashion.
void GNUNET_SERVICE_main(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_GenericReturnValue with_scheduler)
Run the mainloop in a monolithic libgnunet.
void(* GNUNET_SERVICE_InitCallback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *sh)
Callback to initialize a service, called exactly once when the service is run.
void *(* GNUNET_SERVICE_ConnectHandler)(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback to be called when a client connects to the service.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
void GNUNET_SERVICE_resume(struct GNUNET_SERVICE_Handle *sh)
Resume accepting connections from the listen socket.
@ GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN
Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server ...
@ GNUNET_SERVICE_OPTION_SHUTDOWN_BITMASK
Bitmask over the shutdown options.
@ GNUNET_SERVICE_OPTION_CLOSE_LSOCKS
Instead of listening on lsocks passed by the parent, close them after opening our own listen socket(s...
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
@ GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN
Trigger a SOFT server shutdown on signals, allowing active non-monitor clients to complete their tran...
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
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_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
static void do_registered_services_shutdown(void *cls)
static char * get_pid_file_name(struct GNUNET_SERVICE_Handle *sh)
Get the name of the file where we will write the PID of the service.
static void do_resume(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Resume accepting connections from the listen socket.
static bool check_ipv6_listed(const struct GNUNET_STRINGS_IPv6NetworkPolicy *list, const struct in6_addr *ip)
Check if the given IP address is in the list of IP addresses.
static void return_agpl(void *cls, const struct GNUNET_MessageHeader *msg)
Function to return link to AGPL source upon request.
static void teardown_service(struct GNUNET_SERVICE_Handle *sh)
Tear down the service, closing the listen sockets and freeing the ACLs.
static void service_client_recv(void *cls)
A client sent us data.
static void service_mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void service_shutdown(void *cls)
Shutdown task triggered when a service should be terminated.
static void resume_client_receive(void *cls)
Task run to resume receiving data from the client after the client called GNUNET_SERVICE_client_conti...
static enum GNUNET_GenericReturnValue detach_terminal(struct GNUNET_SERVICE_Handle *sh)
Detach from terminal.
static void launch_registered_services(void *cls)
static struct ServiceHandleList * hll_head
static void service_mq_send(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue.
static char * get_user_name(struct GNUNET_SERVICE_Handle *sh)
Get the name of the user that'll be used to provide the service.
#define LOG_STRERROR_FILE(kind, syscall, filename)
static void start_client(struct GNUNET_SERVICE_Handle *sh, struct GNUNET_NETWORK_Handle *csock)
We have successfully accepted a connection from a client.
static void do_send(void *cls)
Task run when we are ready to transmit data to the client.
static enum GNUNET_GenericReturnValue process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, struct GNUNET_SERVICE_Handle *sh, const char *option)
Parse an IPv4 access control list.
static enum GNUNET_GenericReturnValue setup_service(const struct GNUNET_OS_ProjectData *pd, struct GNUNET_SERVICE_Handle *sh)
Setup service handle.
static void finish_client_drop(void *cls)
Asynchronously finish dropping the client.
static int service_client_mst_cb(void *cls, const struct GNUNET_MessageHeader *message)
Functions with this signature are called whenever a complete message is received by the tokenizer for...
static bool check_ipv4_listed(const struct GNUNET_STRINGS_IPv4NetworkPolicy *list, const struct in_addr *add)
Check if the given IP address is in the list of IP addresses.
static void pid_file_delete(struct GNUNET_SERVICE_Handle *sh)
Delete the PID file that was created by our parent.
static int get_server_addresses(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg, struct sockaddr ***addrs, socklen_t **addr_lens)
Get the list of addresses that a server for the given service should bind to.
static void do_suspend(struct GNUNET_SERVICE_Handle *sh, enum SuspendReason sr)
Suspend accepting connections from the listen socket temporarily.
static void warn_no_client_continue(void *cls)
Task run to warn about missing calls to GNUNET_SERVICE_client_continue().
static enum GNUNET_GenericReturnValue set_user_id(struct GNUNET_SERVICE_Handle *sh)
Set user ID.
static void service_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void add_unixpath(struct sockaddr **saddrs, socklen_t *saddrlens, const char *unixpath)
Add the given UNIX domain path as an address to the list (as the first entry).
static void service_main(void *cls)
First task run by any service.
static enum GNUNET_GenericReturnValue process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, struct GNUNET_SERVICE_Handle *sh, const char *option)
Parse an IPv6 access control list.
static enum GNUNET_GenericReturnValue have_non_monitor_clients(struct GNUNET_SERVICE_Handle *sh)
Check if any of the clients we have left are unrelated to monitoring.
#define LOG_STRERROR(kind, syscall)
static void accept_client(void *cls)
We have a client.
SuspendReason
Reasons why we might be suspended.
@ SUSPEND_STATE_SHUTDOWN
Suspension because service was permanently shutdown.
@ SUSPEND_STATE_APP
Application requested it.
@ SUSPEND_STATE_NONE
We are running normally.
@ SUSPEND_STATE_APP_AND_EMFILE
Both reasons, APP and EMFILE apply.
@ SUSPEND_STATE_EMFILE
OS ran out of file descriptors.
static struct ServiceHandleList * hll_tail
static struct GNUNET_NETWORK_Handle * open_listen_socket(const struct sockaddr *server_addr, socklen_t socklen)
Create and initialize a listen socket for the server.
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition of a command line option.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
void * cb_cls
Closure for cb.
Handle to a message queue.
Message handler for a specific message type.
Handle to a message stream tokenizer.
Project-specific data used to help the OS subsystem find installation paths.
const char * gettext_path
Gettext directory, e.g.
const char * gettext_domain
Gettext domain for localisation, e.g.
const char * agpl_url
URL pointing to the source code of the application.
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
const char * version
String identifying the current project version.
Entry in list of pending tasks.
Handle to a client that is connected to a service.
bool persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
size_t msg_pos
Current position in msg at which we are transmitting.
struct GNUNET_SCHEDULER_Task * send_task
Task that transmit data to the client.
struct GNUNET_SCHEDULER_Task * drop_task
Task run to finish dropping the client after the stack has properly unwound.
struct GNUNET_TIME_Absolute warn_start
Time when we last gave a message from this client to the application.
struct GNUNET_NETWORK_Handle * sock
Socket of this client.
uint16_t warn_type
Type of last message processed (for warn_no_receive_done).
const struct GNUNET_MessageHeader * msg
Pointer to the message to be transmitted by send_task.
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVICE_client_continue().
struct GNUNET_SCHEDULER_Task * recv_task
Task that receives data from the client to pass it to the handlers.
struct GNUNET_SERVICE_Handle * sh
Service that this client belongs to.
struct GNUNET_SERVICE_Client * next
Kept in a DLL.
void * user_context
User context value, value returned from the connect callback.
bool needs_continue
Are we waiting for the application to call GNUNET_SERVICE_client_continue()?
bool is_monitor
Is this client a 'monitor' client that should not be counted when deciding on destroying the server d...
struct GNUNET_SERVICE_Client * prev
Kept in a DLL.
struct GNUNET_MQ_Handle * mq
Message queue for the client.
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer we use for processing incoming data.
void * task_cls
Closure for task.
struct GNUNET_STRINGS_IPv6NetworkPolicy * v6_denied
IPv6 addresses that are not allowed to connect.
GNUNET_SERVICE_ConnectHandler connect_cb
Function to call when clients connect.
GNUNET_SERVICE_InitCallback service_init_cb
Main service-specific task to run.
int ready_confirm_fd
If we are daemonizing, this FD is set to the pipe to the parent.
struct GNUNET_SERVICE_Client * clients_tail
Our clients, kept in a DLL.
struct GNUNET_MQ_MessageHandler * handlers
Message handlers to use for all clients.
void * cb_cls
Closure for service_init_cb, connect_cb, disconnect_cb.
struct GNUNET_STRINGS_IPv4NetworkPolicy * v4_denied
IPv4 addresses that are not allowed to connect.
struct GNUNET_STRINGS_IPv6NetworkPolicy * v6_allowed
IPv6 addresses that are allowed to connect (if not set, all are allowed).
const char * service_name
Name of our service.
struct GNUNET_SERVICE_Client * clients_head
Our clients, kept in a DLL.
bool require_found
If true, consider unknown message types an error where the client is disconnected.
GNUNET_SERVICE_DisconnectHandler disconnect_cb
Function to call when clients disconnect / are disconnected.
enum GNUNET_SERVICE_Options options
Our options.
int match_uid
Do we require a matching UID for UNIX domain socket connections? GNUNET_NO means that the UID does no...
int match_gid
Do we require a matching GID for UNIX domain socket connections? Ignored if match_uid is GNUNET_YES.
struct ServiceListenContext * slc_head
DLL of listen sockets used to accept new connections.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
enum SuspendReason suspend_state
Are we suspended, and if so, why?
const struct GNUNET_OS_ProjectData * pd
Project data of this service.
struct ServiceListenContext * slc_tail
DLL of listen sockets used to accept new connections.
struct GNUNET_STRINGS_IPv4NetworkPolicy * v4_allowed
IPv4 addresses that are allowed to connect (if not set, all are allowed).
IPV4 network in CIDR notation.
network in CIDR notation for IPV6.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_CONFIGURATION_Handle * cfg
const struct GNUNET_OS_ProjectData * pd
A list of service to be launched when GNUNET_SERVICE_main() is called.
struct GNUNET_SERVICE_Handle * sh
struct ServiceHandleList * next
struct ServiceHandleList * prev
Information the service tracks per listen operation.
struct ServiceListenContext * next
Kept in a DLL.
struct ServiceListenContext * prev
Kept in a DLL.
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
struct GNUNET_NETWORK_Handle * listen_socket
Socket we are listening on.
struct GNUNET_SERVICE_Handle * sh
Service this listen context belongs to.