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)
359 client = client->next)
361 if (NULL != client->drop_task)
363 if (client->is_monitor)
383 sh->suspend_state |= sr;
388 if (NULL != slc->listen_task)
391 slc->listen_task = NULL;
439 const struct in_addr *
add)
441 for (
unsigned int i = 0;
442 0 !=
list[i].network.s_addr;
445 if ( (
add->s_addr &
list[i].netmask.s_addr) ==
446 (
list[i].network.s_addr &
list[i].netmask.s_addr) )
462 const struct in6_addr *ip)
464 for (
unsigned int i = 0;
470 for (
unsigned int j = 0; j <
sizeof(
struct in6_addr) / sizeof(
int); j++)
471 if (((((
int *) ip)[j] & ((
int *) &
list[i].netmask)[j])) !=
472 (((
int *) &
list[i].network)[j] & ((
int *) &
list[i].netmask)[j]))
499 "service: sending message with type %u\n",
502 buf = (
const char *) client->
msg;
516 if ((EAGAIN == errno) || (EINTR == errno))
526 "socket send returned with error code %i",
537 if (left > (
size_t)
ret)
571 "Sending message of type %u and size %u to client\n",
618 (!
sh->require_found) )
621 "No handler for message of type %u found\n",
649 "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
675 "Received message of type %u and size %u from client\n",
676 ntohs (message->
type),
677 ntohs (message->
size));
755 client->
sock = csock;
764 if (NULL !=
sh->connect_cb)
791 const struct sockaddr_in *v4;
792 const struct sockaddr_in6 *v6;
793 struct sockaddr_storage sa;
797 addrlen =
sizeof(sa);
799 (
struct sockaddr *) &sa,
805 else if (EAGAIN != errno)
810 switch (sa.ss_family)
814 v4 = (
const struct sockaddr_in *) &sa;
815 ok = (((NULL ==
sh->v4_allowed) ||
818 ((NULL ==
sh->v4_denied) ||
825 v6 = (
const struct sockaddr_in6 *) &sa;
826 ok = (((NULL ==
sh->v6_allowed) ||
829 ((NULL ==
sh->v6_denied) ||
840 _ (
"Unknown address family %d\n"),
847 "Service rejected incoming connection from %s due to policy.\n",
848 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
853 "Service accepted incoming connection from %s.\n",
854 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
858 if (0 !=
sh->suspend_state)
880 sh->suspend_state -= sr;
914 if (-1 !=
sh->ready_confirm_fd)
918 sh->ready_confirm_fd = -1;
921 if (NULL !=
sh->service_init_cb)
955 _ (
"Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
996 _ (
"Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
1018 socklen_t *saddrlens,
1019 const char *unixpath)
1022 struct sockaddr_un *un;
1025 un->sun_family = AF_UNIX;
1027#if HAVE_SOCKADDR_UN_SUN_LEN
1028 un->sun_len = (u_char)
sizeof(
struct sockaddr_un);
1030 *saddrs = (
struct sockaddr *) un;
1031 *saddrlens =
sizeof(
struct sockaddr_un);
1063 struct sockaddr ***addrs,
1064 socklen_t **addr_lens)
1068 unsigned long long port;
1070 struct addrinfo hints;
1071 struct addrinfo *
res;
1072 struct addrinfo *pos;
1073 struct addrinfo *next;
1077 struct sockaddr **saddrs;
1078 socklen_t *saddrlens;
1101 _ (
"Require valid port number for service `%s' in configuration!\n"),
1107 _ (
"Require valid port number for service `%s' in configuration!\n"),
1126 (0 < strlen (unixpath)) )
1129 struct sockaddr_un s_un;
1131 if (strlen (unixpath) >=
sizeof(s_un.sun_path))
1134 "UNIXPATH `%s' too long, maximum length is %llu\n",
1136 (
unsigned long long)
sizeof(s_un.sun_path));
1139 _ (
"Using `%s' instead\n"),
1148 if (NULL != unixpath)
1155 if ((ENOBUFS == errno) ||
1156 (ENOMEM == errno) ||
1157 (ENFILE == errno) ||
1167 "Failed to create UNIX domain socket for service %s: %s\n",
1183 (NULL == unixpath) )
1186 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n",
1199 *addr_lens = saddrlens;
1203 if (NULL != hostname)
1206 "Resolving `%s' since that is where `%s' will bind to.\n",
1209 memset (&hints, 0,
sizeof(
struct addrinfo));
1211 hints.ai_family = AF_INET;
1212 hints.ai_protocol = IPPROTO_TCP;
1213 if ((0 != (
ret = getaddrinfo (hostname, NULL, &hints, &
res))) ||
1217 _ (
"Failed to resolve `%s': %s\n"),
1219 gai_strerror (
ret));
1226 while (NULL != (pos = next))
1228 next = pos->ai_next;
1229 if ((disablev6) && (pos->ai_family == AF_INET6))
1236 _ (
"Failed to find %saddress for `%s'.\n"),
1237 disablev6 ?
"IPv4 " :
"",
1245 if (NULL != unixpath)
1250 if (NULL != unixpath)
1256 while (NULL != (pos = next))
1258 next = pos->ai_next;
1259 if ((disablev6) && (AF_INET6 == pos->ai_family))
1261 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1263 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1266 "Service `%s' will bind to `%s'\n",
1269 if (AF_INET == pos->ai_family)
1271 GNUNET_assert (
sizeof(
struct sockaddr_in) == pos->ai_addrlen);
1272 saddrlens[i] = pos->ai_addrlen;
1275 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1280 GNUNET_assert (
sizeof(
struct sockaddr_in6) == pos->ai_addrlen);
1281 saddrlens[i] = pos->ai_addrlen;
1284 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1299 if (NULL != unixpath)
1304 if (NULL != unixpath)
1309 saddrlens[i] =
sizeof(
struct sockaddr_in);
1311#if HAVE_SOCKADDR_IN_SIN_LEN
1312 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1314 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1315 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1321 if (NULL != unixpath)
1326 if (NULL != unixpath)
1331 saddrlens[i] =
sizeof(
struct sockaddr_in6);
1333#if HAVE_SOCKADDR_IN_SIN_LEN
1334 ((
struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1336 ((
struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1337 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1339 saddrlens[i] =
sizeof(
struct sockaddr_in);
1341#if HAVE_SOCKADDR_IN_SIN_LEN
1342 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1344 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1345 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1350 *addr_lens = saddrlens;
1370 switch (server_addr->sa_family)
1373 port = ntohs (((
const struct sockaddr_in *) server_addr)->sin_port);
1376 port = ntohs (((
const struct sockaddr_in6 *) server_addr)->sin6_port);
1403 if (EADDRINUSE != errno)
1411 _ (
"`%s' failed for port %d (%s).\n"),
1414 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1423 _ (
"`%s' failed for port %d (%s): address already in use\n"),
1426 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1427 else if (AF_UNIX == server_addr->sa_family)
1430 _ (
"`%s' failed for `%s': address already in use\n"),
1448 "Server starts to listen on port %u.\n",
1491 _ (
"Specified value for `%s' of service `%s' is invalid\n"),
1502 if ( (NULL != (nfds =
getenv (
"LISTEN_FDS"))) &&
1503 (1 == sscanf (nfds,
"%u%1s", &cnt,
dummy)) && (cnt > 0) &&
1504 (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
1509 flags = fcntl (3 + cnt, F_GETFD);
1510 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1515 "Could not access pre-bound socket %u, will try to bind myself\n"),
1516 (
unsigned int) 3 + cnt);
1518 while (NULL != lsocks[cnt])
1526 unsetenv (
"LISTEN_FDS");
1553 struct sockaddr **addrs;
1554 socklen_t *addrlens;
1564 for (
int i = 0; i < num; i++)
1585 if ((0 != num) && (NULL ==
sh->slc_head))
1591 "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
1655 pws = getpwnam (user);
1659 _ (
"Cannot obtain information about user `%s': %s\n"),
1661 errno == 0 ?
_ (
"No such user") : strerror (errno));
1665 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1667 (0 != initgroups (user, pws->pw_gid)) ||
1669 (0 != setuid (pws->pw_uid)) ||
1670 (0 != seteuid (pws->pw_uid)))
1672 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1673 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1676 _ (
"Cannot change user/group to `%s': %s\n"),
1723 if (0 != unlink (pif))
1744 if (0 != pipe (filedes))
1764 if (1 != read (filedes[0], &c,
sizeof(
char)))
1775 _ (
"Service process failed to initialize\n"));
1780 _ (
"Service process could not initialize server function\n"));
1785 _ (
"Service process failed to report status\n"));
1793 nullfd = open (
"/dev/null", O_RDWR | O_APPEND);
1797 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1800 (void) close (nullfd);
1803 (void) close (nullfd);
1809 sh->ready_confirm_fd = filedes[1];
1830 while (NULL != (slc =
sh->slc_head))
1981 char *opt_cfg_filename;
1986 unsigned long long skew_offset;
1987 unsigned long long skew_variance;
1988 long long clock_offset;
1998 "do daemonize (detach from terminal)"),
2008 memset (&
sh, 0,
sizeof(
sh));
2009 xdg =
getenv (
"XDG_CONFIG_HOME");
2018 sh.ready_confirm_fd = -1;
2021 sh.service_init_cb = service_init_cb;
2032 opt_cfg_filename = NULL;
2037 setlocale (LC_ALL,
"");
2067 if (NULL != opt_cfg_filename)
2073 _ (
"Malformed configuration file `%s', exit ...\n"),
2088 _ (
"Malformed configuration file `%s', exit ...\n"),
2100 _ (
"Malformed configuration, exit ...\n"));
2107 if ( (1 == do_daemonize) &&
2116 "Service `%s' runs with configuration from `%s'\n",
2118 (NULL != opt_cfg_filename) ? opt_cfg_filename :
cfg_filename);
2130 clock_offset = skew_offset - skew_variance;
2133 "Skewing clock by %lld ms\n",
2134 (
long long) clock_offset);
2142 if (1 == do_daemonize)
2146 if (-1 !=
sh.ready_confirm_fd)
2148 if (1 != write (
sh.ready_confirm_fd, err ?
"I" :
"S", 1))
2201 sh->ready_confirm_fd = -1;
2203 sh->service_init_cb = service_init_cb;
2232 if (-1 !=
sh->ready_confirm_fd)
2234 if (1 != write (
sh->ready_confirm_fd,
"S", 1))
2238 close (
sh->ready_confirm_fd));
2276 "Entering GNUNET_SERVICE_main\n");
2382 "Client dropped: %p (MQ: %p)\n",
2387 void *backtrace_array[MAX_TRACE_DEPTH];
2388 int num_backtrace_strings = backtrace (backtrace_array,
2390 char **backtrace_strings =
2391 backtrace_symbols (backtrace_array,
2392 t->num_backtrace_strings);
2393 for (
unsigned int i = 0; i < num_backtrace_strings; i++)
2395 "client drop trace %u: %s\n",
2397 backtrace_strings[i]);
2401 if (NULL !=
sh->disconnect_cb)
2433 client = client->next)
2435 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) ...
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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
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 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(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_conf_and_options(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.
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.
void GNUNET_SERVICE_main(int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_GenericReturnValue with_scheduler)
Run the mainloop in a monolithic libgnunet.
struct GNUNET_SERVICE_Handle * GNUNET_SERVICE_start(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_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.
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_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.
int GNUNET_SERVICE_register_(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.
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.
int GNUNET_SERVICE_run_(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_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 enum GNUNET_GenericReturnValue setup_service(struct GNUNET_SERVICE_Handle *sh)
Setup service handle.
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 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?
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.
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.