40 #define LOG(kind, ...) GNUNET_log_from (kind, "util-service", __VA_ARGS__)
42 #define LOG_STRERROR(kind, syscall) \
43 GNUNET_log_from_strerror (kind, "util-service", syscall)
45 #define LOG_STRERROR_FILE(kind, syscall, filename) \
46 GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename)
364 client = client->next)
366 if (client->is_monitor)
387 sh->suspend_state |= sr;
388 for (slc =
sh->slc_head; NULL != slc; slc = slc->
next)
441 const struct in_addr *
add)
448 while ((0 !=
list[i].network.s_addr) || (0 !=
list[i].netmask.s_addr))
450 if ((
add->s_addr &
list[i].netmask.s_addr) ==
451 (
list[i].network.s_addr &
list[i].netmask.s_addr))
468 const struct in6_addr *ip)
478 for (
unsigned int j = 0; j <
sizeof(
struct in6_addr) / sizeof(
int); j++)
479 if (((((
int *) ip)[j] & ((
int *) &
list[i].netmask)[j])) !=
480 (((
int *) &
list[i].network)[j] & ((
int *) &
list[i].netmask)[j]))
506 "service: sending message with type %u\n",
509 buf = (
const char *) client->
msg;
523 if ((EAGAIN == errno) || (EINTR == errno))
533 "socket send returned with error code %i",
544 if (left > (
size_t)
ret)
578 "Sending message of type %u and size %u to client\n",
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));
757 client->
sock = csock;
766 if (NULL !=
sh->connect_cb)
793 const struct sockaddr_in *v4;
794 const struct sockaddr_in6 *v6;
795 struct sockaddr_storage sa;
799 addrlen =
sizeof(sa);
801 (
struct sockaddr *) &sa,
807 else if (EAGAIN != errno)
811 switch (sa.ss_family)
815 v4 = (
const struct sockaddr_in *) &sa;
816 ok = (((NULL ==
sh->v4_allowed) ||
818 ((NULL ==
sh->v4_denied) ||
824 v6 = (
const struct sockaddr_in6 *) &sa;
825 ok = (((NULL ==
sh->v6_allowed) ||
827 ((NULL ==
sh->v6_denied) ||
837 _ (
"Unknown address family %d\n"),
844 "Service rejected incoming connection from %s due to policy.\n",
845 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
850 "Service accepted incoming connection from %s.\n",
851 GNUNET_a2s ((
const struct sockaddr *) &sa, addrlen));
854 if (0 !=
sh->suspend_state)
877 sh->suspend_state -= sr;
880 for (slc =
sh->slc_head; NULL != slc; slc = slc->
next)
909 if (-1 !=
sh->ready_confirm_fd)
913 sh->ready_confirm_fd = -1;
916 if (NULL !=
sh->service_init_cb)
917 sh->service_init_cb (
sh->cb_cls,
sh->cfg,
sh);
950 _ (
"Could not parse IPv4 network specification `%s' for `%s:%s'\n"),
991 _ (
"Could not parse IPv6 network specification `%s' for `%s:%s'\n"),
1013 socklen_t *saddrlens,
1014 const char *unixpath)
1017 struct sockaddr_un *un;
1020 un->sun_family = AF_UNIX;
1022 #if HAVE_SOCKADDR_UN_SUN_LEN
1023 un->sun_len = (u_char)
sizeof(
struct sockaddr_un);
1025 *saddrs = (
struct sockaddr *) un;
1026 *saddrlens =
sizeof(
struct sockaddr_un);
1058 struct sockaddr ***addrs,
1059 socklen_t **addr_lens)
1063 unsigned long long port;
1065 struct addrinfo hints;
1066 struct addrinfo *
res;
1067 struct addrinfo *pos;
1068 struct addrinfo *next;
1072 struct sockaddr **saddrs;
1073 socklen_t *saddrlens;
1094 _ (
"Require valid port number for service `%s' in configuration!\n"),
1100 _ (
"Require valid port number for service `%s' in configuration!\n"),
1125 (0 < strlen (unixpath)))
1128 struct sockaddr_un s_un;
1130 if (strlen (unixpath) >=
sizeof(s_un.sun_path))
1133 _ (
"UNIXPATH `%s' too long, maximum length is %llu\n"),
1135 (
unsigned long long)
sizeof(s_un.sun_path));
1142 if (NULL != unixpath)
1147 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1157 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1171 if ((0 ==
port) && (NULL == unixpath))
1175 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1188 *addr_lens = saddrlens;
1195 "Resolving `%s' since that is where `%s' will bind to.\n",
1198 memset (&hints, 0,
sizeof(
struct addrinfo));
1200 hints.ai_family = AF_INET;
1201 hints.ai_protocol = IPPROTO_TCP;
1206 _ (
"Failed to resolve `%s': %s\n"),
1208 gai_strerror (
ret));
1215 while (NULL != (pos = next))
1217 next = pos->ai_next;
1218 if ((disablev6) && (pos->ai_family == AF_INET6))
1225 _ (
"Failed to find %saddress for `%s'.\n"),
1226 disablev6 ?
"IPv4 " :
"",
1234 if (NULL != unixpath)
1239 if (NULL != unixpath)
1245 while (NULL != (pos = next))
1247 next = pos->ai_next;
1248 if ((disablev6) && (AF_INET6 == pos->ai_family))
1250 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1252 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1255 "Service `%s' will bind to `%s'\n",
1258 if (AF_INET == pos->ai_family)
1260 GNUNET_assert (
sizeof(
struct sockaddr_in) == pos->ai_addrlen);
1261 saddrlens[i] = pos->ai_addrlen;
1264 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1269 GNUNET_assert (
sizeof(
struct sockaddr_in6) == pos->ai_addrlen);
1270 saddrlens[i] = pos->ai_addrlen;
1273 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1288 if (NULL != unixpath)
1293 if (NULL != unixpath)
1298 saddrlens[i] =
sizeof(
struct sockaddr_in);
1300 #if HAVE_SOCKADDR_IN_SIN_LEN
1301 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
1303 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1304 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1310 if (NULL != unixpath)
1315 if (NULL != unixpath)
1320 saddrlens[i] =
sizeof(
struct sockaddr_in6);
1322 #if HAVE_SOCKADDR_IN_SIN_LEN
1323 ((
struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
1325 ((
struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
1326 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
1328 saddrlens[i] =
sizeof(
struct sockaddr_in);
1330 #if HAVE_SOCKADDR_IN_SIN_LEN
1331 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
1333 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
1334 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
1339 *addr_lens = saddrlens;
1359 switch (server_addr->sa_family)
1362 port = ntohs (((
const struct sockaddr_in *) server_addr)->sin_port);
1365 port = ntohs (((
const struct sockaddr_in6 *) server_addr)->sin6_port);
1392 if (EADDRINUSE != errno)
1400 _ (
"`%s' failed for port %d (%s).\n"),
1403 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1412 _ (
"`%s' failed for port %d (%s): address already in use\n"),
1415 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
1416 else if (AF_UNIX == server_addr->sa_family)
1419 _ (
"`%s' failed for `%s': address already in use\n"),
1437 "Server starts to listen on port %u.\n",
1480 _ (
"Specified value for `%s' of service `%s' is invalid\n"),
1491 if ((NULL != (nfds =
getenv (
"LISTEN_FDS"))) &&
1492 (1 == sscanf (nfds,
"%u%1s", &cnt,
dummy)) && (cnt > 0) &&
1493 (cnt < FD_SETSIZE) && (cnt + 4 < FD_SETSIZE))
1498 flags = fcntl (3 + cnt, F_GETFD);
1499 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1504 "Could not access pre-bound socket %u, will try to bind myself\n"),
1505 (
unsigned int) 3 + cnt);
1507 while (NULL != lsocks[cnt])
1515 unsetenv (
"LISTEN_FDS");
1540 struct sockaddr **addrs;
1541 socklen_t *addrlens;
1548 for (
int i = 0; i < num; i++)
1566 if ((0 != num) && (NULL ==
sh->slc_head))
1572 "Could not bind to any of the ports I was supposed to, refusing to run!\n"));
1637 pws = getpwnam (user);
1641 _ (
"Cannot obtain information about user `%s': %s\n"),
1643 errno == 0 ?
_ (
"No such user") : strerror (errno));
1647 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) ||
1649 (0 != initgroups (user, pws->pw_gid)) ||
1651 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid)))
1653 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1654 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1657 _ (
"Cannot change user/group to `%s': %s\n"),
1703 if (0 != unlink (pif))
1722 if (0 != pipe (filedes))
1740 if (1 != read (filedes[0], &c,
sizeof(
char)))
1750 _ (
"Service process failed to initialize\n"));
1755 _ (
"Service process could not initialize server function\n"));
1760 _ (
"Service process failed to report status\n"));
1768 nullfd = open (
"/dev/null", O_RDWR | O_APPEND);
1772 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0))
1775 (void) close (nullfd);
1778 (void) close (nullfd);
1783 sh->ready_confirm_fd = filedes[1];
1804 while (NULL != (slc =
sh->slc_head))
1983 char *opt_cfg_filename;
1988 unsigned long long skew_offset;
1989 unsigned long long skew_variance;
1990 long long clock_offset;
2000 "do daemonize (detach from terminal)"),
2010 memset (&
sh, 0,
sizeof(
sh));
2011 xdg =
getenv (
"XDG_CONFIG_HOME");
2020 sh.ready_confirm_fd = -1;
2023 sh.service_init_cb = service_init_cb;
2035 opt_cfg_filename = NULL;
2040 setlocale (LC_ALL,
"");
2070 if (NULL != opt_cfg_filename)
2076 _ (
"Malformed configuration file `%s', exit ...\n"),
2088 _ (
"Malformed configuration file `%s', exit ...\n"),
2098 _ (
"Malformed configuration, exit ...\n"));
2113 "Service `%s' runs with configuration from `%s'\n",
2115 (NULL != opt_cfg_filename) ? opt_cfg_filename :
cfg_filename);
2125 clock_offset = skew_offset - skew_variance;
2128 "Skewing clock by %lld ms\n",
2129 (
long long) clock_offset);
2137 if (1 == do_daemonize)
2141 if (-1 !=
sh.ready_confirm_fd)
2143 if (1 != write (
sh.ready_confirm_fd, err ?
"I" :
"S", 1))
2159 struct mallinfo2 mi;
2334 "Client dropped: %p (MQ: %p)\n",
2339 void *backtrace_array[MAX_TRACE_DEPTH];
2340 int num_backtrace_strings = backtrace (backtrace_array, MAX_TRACE_DEPTH);
2341 char **backtrace_strings =
2342 backtrace_symbols (backtrace_array,
t->num_backtrace_strings);
2343 for (
unsigned int i = 0; i < num_backtrace_strings; i++)
2345 "client drop trace %u: %s\n",
2347 backtrace_strings[i]);
2359 if (NULL !=
sh->disconnect_cb)
2360 sh->disconnect_cb (
sh->cb_cls,
2394 while (NULL != (client =
sh->clients_head))
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
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 const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static int ret
Return value of the commandline.
static int list
Set if we should print a list of currently running services.
static struct SolverHandle * sh
static char * cfg_filename
Name of the configuration file.
static uint16_t port
Port number.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static int add
Desired action is to add a record.
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
static int ok
Return value from 'main' (0 == success)
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 char * hostname
Our hostname; we give this to all the peers we start.
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.
#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_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.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
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 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)
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#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.
#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...
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_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.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
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.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
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.
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_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!
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
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.
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.
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...
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.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_box_native(int fd)
Box a native socket (and check that it is a socket).
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_get(void)
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,...
@ 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.
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
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_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_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...
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_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
int 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...
int 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_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
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_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_ConnectHandler)(void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
Callback to be called when a client connects to the service.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
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.
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_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_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...
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.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
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 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 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 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.
#define LOG_STRERROR_FILE(kind, syscall, filename)
static char * get_user_name(struct GNUNET_SERVICE_Handle *sh)
Get the name of the user that'll be used to provide the service.
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.
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.
#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.
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition of a command line option.
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.
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.