41#define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
43#define LOG_STRERROR(kind, syscall) \
44 GNUNET_log_from_strerror (kind, "util-service", syscall)
46#define LOG_STRERROR_FILE(kind, syscall, filename) \
47 GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
365 client = client->next)
367 if (client->is_monitor)
388 sh->suspend_state |= sr;
389 for (slc =
sh->slc_head; NULL != slc; slc = slc->
next)
442 const struct in_addr *
add)
449 while ((0 !=
list[i].network.s_addr) || (0 !=
list[i].netmask.s_addr))
451 if ((
add->s_addr &
list[i].netmask.s_addr) ==
452 (
list[i].network.s_addr &
list[i].netmask.s_addr))
469 const struct in6_addr *ip)
479 for (
unsigned int j = 0; j <
sizeof(
struct in6_addr) / sizeof(
int); j++)
480 if (((((
int *) ip)[j] & ((
int *) &
list[i].netmask)[j])) !=
481 (((
int *) &
list[i].network)[j] & ((
int *) &
list[i].netmask)[j]))
507 "service: sending message with type %u\n",
510 buf = (
const char *) client->
msg;
524 if ((EAGAIN == errno) || (EINTR == errno))
534 "socket send returned with error code %i",
545 if (left > (
size_t)
ret)
579 "Sending message of type %u and size %u to client\n",
626 "No handler for message of type %u found\n",
654 "Processing code for message of type %u did not call `GNUNET_SERVICE_client_continue' after %s\n"),
680 "Received message of type %u and size %u from client\n",
681 ntohs (message->
type),
682 ntohs (message->
size));
758 client->
sock = csock;
767 if (NULL !=
sh->connect_cb)
794 const struct sockaddr_in *v4;
795 const struct sockaddr_in6 *v6;
796 struct sockaddr_storage sa;
800 addrlen =
sizeof(sa);
802 (
struct sockaddr *) &sa,
808 else if (EAGAIN != errno)
812 switch (sa.ss_family)
816 v4 = (
const struct sockaddr_in *) &sa;
817 ok = (((NULL ==
sh->v4_allowed) ||
819 ((NULL ==
sh->v4_denied) ||
825 v6 = (
const struct sockaddr_in6 *) &sa;
826 ok = (((NULL ==
sh->v6_allowed) ||
828 ((NULL ==
sh->v6_denied) ||
838 _ (
"Unknown address family %d\n"),
845 "Service rejected incoming connection from %s due to policy.\n",
846 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
851 "Service accepted incoming connection from %s.\n",
852 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
855 if (0 !=
sh->suspend_state)
878 sh->suspend_state -= sr;
881 for (slc =
sh->slc_head; NULL != slc; slc = slc->
next)
910 if (-1 !=
sh->ready_confirm_fd)
914 sh->ready_confirm_fd = -1;
917 if (NULL !=
sh->service_init_cb)
951 _ (
"Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
992 _ (
"Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
1014 socklen_t *saddrlens,
1015 const char *unixpath)
1018 struct sockaddr_un *un;
1021 un->sun_family = AF_UNIX;
1023#if HAVE_SOCKADDR_UN_SUN_LEN
1024 un->sun_len = (u_char)
sizeof(
struct sockaddr_un);
1026 *saddrs = (
struct sockaddr *) un;
1027 *saddrlens =
sizeof(
struct sockaddr_un);
1059 struct sockaddr ***addrs,
1060 socklen_t **addr_lens)
1064 unsigned long long port;
1066 struct addrinfo hints;
1067 struct addrinfo *
res;
1068 struct addrinfo *pos;
1069 struct addrinfo *next;
1073 struct sockaddr **saddrs;
1074 socklen_t *saddrlens;
1095 _ (
"Require valid port number for service `%s' in configuration!\n"),
1101 _ (
"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));
1143 if (NULL != unixpath)
1148 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1158 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1172 if ((0 ==
port) && (NULL == unixpath))
1176 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1189 *addr_lens = saddrlens;
1193 if (NULL != hostname)
1196 "Resolving `%s' since that is where `%s' will bind to.\n",
1199 memset (&hints, 0,
sizeof(
struct addrinfo));
1201 hints.ai_family = AF_INET;
1202 hints.ai_protocol = IPPROTO_TCP;
1203 if ((0 != (
ret = getaddrinfo (hostname, NULL, &hints, &
res))) ||
1207 _ (
"Failed to resolve `%s': %s\n"),
1209 gai_strerror (
ret));
1216 while (NULL != (pos = next))
1218 next = pos->ai_next;
1219 if ((disablev6) && (pos->ai_family == AF_INET6))
1226 _ (
"Failed to find %saddress for `%s'.\n"),
1227 disablev6 ?
"IPv4 " :
"",
1235 if (NULL != unixpath)
1240 if (NULL != unixpath)
1246 while (NULL != (pos = next))
1248 next = pos->ai_next;
1249 if ((disablev6) && (AF_INET6 == pos->ai_family))
1251 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1253 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1256 "Service `%s' will bind to `%s'\n",
1259 if (AF_INET == pos->ai_family)
1261 GNUNET_assert (
sizeof(
struct sockaddr_in) == pos->ai_addrlen);
1262 saddrlens[i] = pos->ai_addrlen;
1265 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1270 GNUNET_assert (
sizeof(
struct sockaddr_in6) == pos->ai_addrlen);
1271 saddrlens[i] = pos->ai_addrlen;
1274 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1289 if (NULL != unixpath)
1294 if (NULL != unixpath)
1299 saddrlens[i] =
sizeof(
struct sockaddr_in);
1301#if HAVE_SOCKADDR_IN_SIN_LEN
1302 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1304 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1305 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1311 if (NULL != unixpath)
1316 if (NULL != unixpath)
1321 saddrlens[i] =
sizeof(
struct sockaddr_in6);
1323#if HAVE_SOCKADDR_IN_SIN_LEN
1324 ((
struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1326 ((
struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1327 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1329 saddrlens[i] =
sizeof(
struct sockaddr_in);
1331#if HAVE_SOCKADDR_IN_SIN_LEN
1332 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1334 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1335 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1340 *addr_lens = saddrlens;
1360 switch (server_addr->sa_family)
1363 port = ntohs (((
const struct sockaddr_in *) server_addr)->sin_port);
1366 port = ntohs (((
const struct sockaddr_in6 *) server_addr)->sin6_port);
1393 if (EADDRINUSE != errno)
1401 _ (
"`%s' failed for port %d (%s).\n"),
1404 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1413 _ (
"`%s' failed for port %d (%s): address already in use\n"),
1416 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1417 else if (AF_UNIX == server_addr->sa_family)
1420 _ (
"`%s' failed for `%s': address already in use\n"),
1438 "Server starts to listen on port %u.\n",
1481 _ (
"Specified value for `%s' of service `%s' is invalid\n"),
1492 if ((NULL != (nfds =
getenv (
"LISTEN_FDS"))) &&
1493 (1 == sscanf (nfds,
"%u%1s", &cnt,
dummy)) && (cnt > 0) &&
1494 (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
1499 flags = fcntl (3 + cnt, F_GETFD);
1500 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1505 "Could not access pre-bound socket %u, will try to bind myself\n"),
1506 (
unsigned int) 3 + cnt);
1508 while (NULL != lsocks[cnt])
1516 unsetenv (
"LISTEN_FDS");
1541 struct sockaddr **addrs;
1542 socklen_t *addrlens;
1549 for (
int i = 0; i < num; i++)
1567 if ((0 != num) && (NULL ==
sh->slc_head))
1573 "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
1638 pws = getpwnam (user);
1642 _ (
"Cannot obtain information about user `%s': %s\n"),
1644 errno == 0 ?
_ (
"No such user") : strerror (errno));
1648 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1650 (0 != initgroups (user, pws->pw_gid)) ||
1652 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1654 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1655 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1658 _ (
"Cannot change user/group to `%s': %s\n"),
1704 if (0 != unlink (pif))
1723 if (0 != pipe (filedes))
1741 if (1 != read (filedes[0], &c,
sizeof(
char)))
1751 _ (
"Service process failed to initialize\n"));
1756 _ (
"Service process could not initialize server function\n"));
1761 _ (
"Service process failed to report status\n"));
1769 nullfd = open (
"/dev/null", O_RDWR | O_APPEND);
1773 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1776 (void) close (nullfd);
1779 (void) close (nullfd);
1784 sh->ready_confirm_fd = filedes[1];
1805 while (NULL != (slc =
sh->slc_head))
1943 char *opt_cfg_filename;
1948 unsigned long long skew_offset;
1949 unsigned long long skew_variance;
1950 long long clock_offset;
1960 "do daemonize (detach from terminal)"),
1970 memset (&
sh, 0,
sizeof(
sh));
1971 xdg =
getenv (
"XDG_CONFIG_HOME");
1980 sh.ready_confirm_fd = -1;
1983 sh.service_init_cb = service_init_cb;
1995 opt_cfg_filename = NULL;
2000 setlocale (LC_ALL,
"");
2030 if (NULL != opt_cfg_filename)
2036 _ (
"Malformed configuration file `%s', exit ...\n"),
2048 _ (
"Malformed configuration file `%s', exit ...\n"),
2058 _ (
"Malformed configuration, exit ...\n"));
2073 "Service `%s' runs with configuration from `%s'\n",
2075 (NULL != opt_cfg_filename) ? opt_cfg_filename :
cfg_filename);
2085 clock_offset = skew_offset - skew_variance;
2088 "Skewing clock by %lld ms\n",
2089 (
long long) clock_offset);
2097 if (1 == do_daemonize)
2101 if (-1 !=
sh.ready_confirm_fd)
2103 if (1 != write (
sh.ready_confirm_fd, err ?
"I" :
"S", 1))
2119 struct mallinfo2 mi;
2174 sh->ready_confirm_fd = -1;
2176 sh->service_init_cb = service_init_cb;
2203 if (-1 !=
sh->ready_confirm_fd)
2205 if (1 != write (
sh->ready_confirm_fd,
"S", 1))
2241 char *opt_cfg_filename;
2255 "do daemonize (detach from terminal)"),
2263 xdg =
getenv (
"XDG_CONFIG_HOME");
2292 if (NULL != opt_cfg_filename)
2298 _ (
"Malformed configuration file `%s', exit ...\n"),
2310 _ (
"Malformed configuration file `%s', exit ...\n"),
2321 _ (
"Malformed configuration, exit ...\n"));
2494 "Client dropped: %p (MQ: %p)\n",
2499 void *backtrace_array[MAX_TRACE_DEPTH];
2500 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2501 char **backtrace_strings =
2502 backtrace_symbols (backtrace_array,
t->num_backtrace_strings);
2503 for (
unsigned int i = 0; i < num_backtrace_strings; i++)
2505 "client drop trace %u: %s\n",
2507 backtrace_strings[i]);
2519 if (NULL !=
sh->disconnect_cb)
2554 while (NULL != (client =
sh->clients_head))
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 GAUGER(category, counter, value, unit)
#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.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_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/)
#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.
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_main(int argc, char *const *argv)
Run the mainloop in a monolithic libgnunet.
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 int detach_terminal(struct GNUNET_SERVICE_Handle *sh)
Detach from terminal.
static void return_agpl(void *cls, const struct GNUNET_MessageHeader *msg)
Function to return link to AGPL source upon request.
static int process_acl4(struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, struct GNUNET_SERVICE_Handle *sh, const char *option)
Parse an IPv4 access control list.
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 int process_acl6(struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, struct GNUNET_SERVICE_Handle *sh, const char *option)
Parse an IPv6 access control list.
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 int set_user_id(struct GNUNET_SERVICE_Handle *sh)
Set user ID.
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 int have_non_monitor_clients(struct GNUNET_SERVICE_Handle *sh)
Check if any of the clients we have left are unrelated to monitoring.
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 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 int 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 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 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 int setup_service(struct GNUNET_SERVICE_Handle *sh)
Setup service handle.
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 int 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.
#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.
char * gettext_path
Gettext directory, e.g.
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.
char * gettext_domain
Gettext domain for localisation, e.g.
const char * version
String identifying the current project version.
char * agpl_url
URL pointing to the source code of the application.
Entry in list of pending tasks.
Handle to a client that is connected to a service.
int needs_continue
Are we waiting for the application to call GNUNET_SERVICE_client_continue()?
size_t msg_pos
Current position in msg at which we are transmitting.
int is_monitor
Is this client a 'monitor' client that should not be counted when deciding on destroying the server d...
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.
int persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
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.
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.
int ret
Overall success/failure of the service start.
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.
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.
int require_found
If GNUNET_YES, consider unknown message types an error where the client is disconnected.
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.
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.