31 #define LOG_STRERROR_FILE(kind, syscall, \ 32 filename) GNUNET_log_from_strerror_file (kind, \ 412 "Server accepted incoming connection.\n");
438 switch (server_addr->sa_family)
441 port = ntohs (((
const struct sockaddr_in *) server_addr)->sin_port);
445 port = ntohs (((
const struct sockaddr_in6 *) server_addr)->sin6_port);
468 if (EADDRINUSE != errno)
478 _ (
"`%s' failed for port %d (%s).\n"),
481 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
488 _ (
"`%s' failed for port %d (%s): address already in use\n"),
490 (AF_INET == server_addr->sa_family) ?
"IPv4" :
"IPv6");
491 else if (AF_UNIX == server_addr->sa_family)
494 _ (
"`%s' failed for `%s': address already in use\n"),
513 "Server starts to listen on port %u.\n",
568 struct sockaddr *
const *server_addr,
569 const socklen_t *socklen,
580 while (NULL != server_addr[i])
587 while (NULL != server_addr[i])
590 for (k = 0; k < i; k++)
591 if ((socklen[k] == socklen[i]) &&
592 (0 == memcmp (server_addr[k], server_addr[i], socklen[i])))
604 if (NULL != lsocks[j])
644 "Marking client as monitor!\n");
753 "Server in soft shutdown\n");
787 "Server shutting down.\n");
804 while (NULL != (hpos = server->
handlers))
897 "Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
950 type = ntohs (message->
type);
951 size = ntohs (message->
size);
953 "Received message of type %u and size %u from client\n",
956 for (pos = server->
handlers; NULL != pos; pos = pos->
next)
966 #if GNUNET8_NETWORK_IS_DEAD 968 "Expected %u bytes for message of type %u, got %u\n",
973 "Expected %u bytes for message of type %u, got %u\n",
1002 "Received message of unknown type %d\n", type);
1024 const struct sockaddr *addr,
1052 "Server re-enters receive loop, timeout: %s.\n",
1066 "Server processes additional messages instantly.\n");
1077 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
1084 "Server has more data pending but is suspended.\n");
1107 const struct sockaddr *addr,
1123 if ((NULL == buf) &&
1134 "Receive time out, but no disconnect due to sending (%p)\n",
1144 if ((NULL == buf) ||
1153 "Failed to connect or other side closed connection (%p)\n",
1159 "Server receives %u bytes from `%s'.\n",
1160 (
unsigned int) available,
1175 else if (NULL != client->
mst)
1221 "Server continues processing messages still in the buffer.\n");
1250 "Tokenizer gives server message of type %u and size %u from client\n",
1251 ntohs (message->
type), ntohs (message->
size));
1370 void **addr,
size_t *addrlen)
1430 callback (callback_cls, client);
1508 "Client is being disconnected from the server.\n");
1526 if ((NULL != client->
mst) &&
1546 "RC of %p still positive, not destroying everything.\n",
1554 "Still processing inputs of %p, not destroying everything.\n",
1559 "RC of %p now zero, destroying everything.\n",
1563 if (NULL != client->
th.
cth)
1615 client->
th.
cth = NULL;
1711 "GNUNET_SERVER_receive_done called with failure indication\n");
1721 "GNUNET_SERVER_receive_done called, but more clients pending\n");
1732 "GNUNET_SERVER_receive_done called while still in processing loop\n");
1741 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
void GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server)
Free resources held by this server.
Handle server returns for aborting transmission to a client.
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
struct GNUNET_NETWORK_Handle * sock
Underlying OS's socket, set to NULL after fatal errors.
void GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server, const struct GNUNET_SERVER_MessageHandler *handlers)
Add additional handlers to an existing server.
void * access_cb_cls
Closure for access_cb.
int(* GNUNET_SERVER_MstReceiveCallback)(void *cls, void *mst, struct GNUNET_SERVER_Client *client, const char *buf, size_t size, int purge, int one_shot)
Signature of a function to receive data for a custom tokenizer.
Run with high priority (important requests).
void GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection)
Set the persist option on this connection handle.
List of arrays of message handlers.
void * GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, size_t size)
Return user context associated with the given client.
int in_process_client_buffer
Are we currently in the "process_client_buffer" function (and will hence restart the receive job on e...
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client)
Notify the server that the given client handle should be kept (keeps the connection up if possible...
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
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.
GNUNET_SERVER_MessageCallback callback
Function to call for messages of "type".
List of arrays of message handlers.
struct GNUNET_SERVER_Client * clients_tail
Head of list of our current clients.
Context information passed to each scheduler task.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
GNUNET_SERVER_MstReceiveCallback mst_receive
Alternative function to give data to a MST instance.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
struct GNUNET_TIME_Absolute last_activity
Last activity on this socket (used to time it out if reference_count == 0).
static void warn_no_receive_done(void *cls)
Task run to warn about missing calls to GNUNET_SERVER_receive_done.
int GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
struct GNUNET_SERVER_Handle * GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb, void *access_cb_cls, struct sockaddr *const *server_addr, const socklen_t *socklen, struct GNUNET_TIME_Relative idle_timeout, int require_found)
Create a new server.
GNUNET_SERVER_MstDestroyCallback mst_destroy
Alternative function to destroy a MST instance.
void * user_context
User context value, manipulated using 'GNUNET_SERVER_client_{get/set}_user_context' functions...
GNUNET_SERVER_DisconnectCallback callback
Function to call.
static int ret
Return value of the commandline.
void * GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection)
Cancel receive job on the given connection.
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
void GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst)
Destroys a tokenizer.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_CONNECTION_notify_transmit_ready_cancel(struct GNUNET_CONNECTION_TransmitHandle *th)
Cancel the specified transmission-ready notification.
int GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client)
Disable the "CORK" feature for communication with the given client, forcing the OS to immediately flu...
struct GNUNET_SERVER_Client * next
This is a doubly linked list.
int GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, void *client_identity, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
int receive_pending
Are we currently trying to receive? (GNUNET_YES if we are, GNUNET_NO if we are not, GNUNET_SYSERR if data is already available in MST).
void * callback_cls
Closure for callback.
int GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server, struct GNUNET_SERVER_Client *sender, const struct GNUNET_MessageHeader *message)
Inject a message into the server, pretend it came from the specified client.
struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb, void *access_cb_cls, struct GNUNET_NETWORK_Handle *lsock)
Create a connection handle by accepting on a listen socket.
struct NotifyList * next
This is a doubly linked list.
uint64_t abs_value_us
The actual value.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority and to be run after the specified delay or wh...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SERVER_Handle * GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb, void *access_cb_cls, struct GNUNET_NETWORK_Handle **lsocks, struct GNUNET_TIME_Relative idle_timeout, int require_found)
Create a new server.
size_t(* GNUNET_CONNECTION_TransmitReadyNotify)(void *cls, size_t size, void *buf)
Function called to notify a client about the connection begin ready to queue more data...
void GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_DisconnectCallback callback, void *callback_cls)
Ask the server to stop notifying us whenever a client connects.
struct NotifyList * prev
This is a doubly linked list.
void GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_ConnectCallback callback, void *callback_cls)
Ask the server to stop notifying us whenever a client disconnects.
void GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, void *ptr, size_t size)
Set user context to be associated with the given client.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
struct HandlerList * handlers
List of handlers for incoming messages.
int GNUNET_CONNECTION_disable_corking(struct GNUNET_CONNECTION_Handle *connection)
Disable the "CORK" feature for communication with the given connection, forcing the OS to immediately...
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.
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
struct GNUNET_CONNECTION_TransmitHandle * cth
Active connection transmission handle.
struct GNUNET_SERVER_TransmitHandle th
Transmission handle we return for this client from GNUNET_SERVER_notify_transmit_ready.
int is_monitor
Is this client a 'monitor' client that should not be counted when deciding on destroying the server d...
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
static struct GNUNET_OS_Process * p
Helper process we started.
void GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th)
Abort transmission request.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
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.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
collection of IO descriptors
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
void GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_MstCreateCallback create, GNUNET_SERVER_MstDestroyCallback destroy, GNUNET_SERVER_MstReceiveCallback receive, void *cls)
Change functions used by the server to tokenize the message stream.
int GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection, size_t max, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_Receiver receiver, void *receiver_cls)
Receive data from the given connection.
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
int GNUNET_CONNECTION_check(struct GNUNET_CONNECTION_Handle *connection)
Check if connection is valid (no fatal errors have happened so far).
void GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client)
Notify the server that the given client handle is no longer required.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
GNUNET_SERVER_MstCreateCallback mst_create
Alternative function to create a MST instance.
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
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)...
void GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, struct GNUNET_TIME_Relative timeout)
Change the timeout for a particular client.
void GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_DisconnectCallback callback, void *callback_cls)
Ask the server to notify us whenever a client disconnects.
struct GNUNET_SERVER_Client * prev
This is a doubly linked list.
uint16_t expected_size
Expected size of messages of this type.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
void(* GNUNET_SERVER_DisconnectCallback)(void *cls, struct GNUNET_SERVER_Client *client)
Functions with this signature are called whenever a client is disconnected on the network level...
int shutdown_now
We're about to close down this client.
void GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
Resume accepting connections from the listen socket.
unsigned int reference_count
Number of external entities with a reference to this client object.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
static void restart_processing(void *cls)
Task run to start again receiving from the network and process requests.
static void process_incoming(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
We are receiving an incoming message.
size_t user_context_size
Last size given when user context was initialized; used for sanity check.
static int client_message_tokenizer_callback(void *cls, void *client, const struct GNUNET_MessageHeader *message)
This function is called whenever our inbound message tokenizer has received a complete message...
static unsigned int size
Size of the "table".
int require_found
Do we ignore messages of types that we do not understand or do we require that a handler is found (an...
uint16_t type
Type of the message this handler covers.
int GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection, void **addr, size_t *addrlen)
Obtain the network address of the other party.
static void process_listen_socket(void *cls)
Scheduler says our listen socket is ready.
void GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
Close the connection and free associated resources.
uint16_t warn_type
Type of last message processed (for warn_no_receive_done).
static void do_destroy(void *cls)
Helper function for test_monitor_clients() to trigger GNUNET_SERVER_destroy() after the stack has unw...
int GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client, void **addr, size_t *addrlen)
Obtain the network address of the other party.
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
void *(* GNUNET_SERVER_MstCreateCallback)(void *cls, struct GNUNET_SERVER_Client *client)
Signature of a function to create a custom tokenizer.
GNUNET_CONNECTION_AccessCheck access_cb
Function to call for access control.
struct GNUNET_TIME_Absolute warn_start
Time when the warn task was started.
void GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client)
Set the 'monitor' flag on this client.
GNUNET_CONNECTION_TransmitReadyNotify callback
Function to call to get the message.
int(* GNUNET_CONNECTION_AccessCheck)(void *cls, const struct GNUNET_CONNECTION_Credentials *ucred, const struct sockaddr *addr, socklen_t addrlen)
Function to call for access control checks.
#define GNUNET_MESSAGE_TYPE_ALL
Type used to match 'all' message types.
void(* GNUNET_SERVER_MstDestroyCallback)(void *cls, void *mst)
Signature of a function to destroy a custom tokenizer.
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
int persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
struct NotifyList * disconnect_notify_list_tail
Tail of linked list of functions to call on disconnects by clients.
void GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server, GNUNET_SERVER_ConnectCallback callback, void *callback_cls)
Ask the server to notify us whenever a client connects.
static uint16_t port
Port number.
struct GNUNET_CONNECTION_TransmitHandle * GNUNET_CONNECTION_notify_transmit_ready(struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify notify, void *notify_cls)
Ask the connection to call us once the specified number of bytes are free in the transmission buffer...
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...
void * callback_cls
Closure for callback.
const struct GNUNET_SERVER_MessageHandler * handlers
NULL-terminated array of handlers.
#define LOG_STRERROR(kind, syscall)
#define GNUNET_log(kind,...)
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVER_receive_done.
Entry in list of pending tasks.
void GNUNET_SERVER_receive_done(struct GNUNET_SERVER_Client *client, int success)
Resume receiving from this client, we are done processing the current request.
void GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server)
Suspend accepting connections from the listen socket temporarily.
struct NotifyList * connect_notify_list_tail
Tail of linked list of functions to call on connects by clients.
struct GNUNET_SERVER_TransmitHandle * GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify callback, void *callback_cls)
Notify us when the server has enough space to transmit a message of the given size to the given clien...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
struct GNUNET_SERVER_Client * GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, struct GNUNET_CONNECTION_Handle *connection)
Add a TCP socket-based connection to the set of handles managed by this server.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
int in_soft_shutdown
Set to GNUNET_YES once we are in 'soft' shutdown where we wait for all non-monitor clients to disconn...
void GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client)
Set the persistent flag on this client, used to setup client connection to only be killed when the se...
Time for absolute times used by GNUnet, in microseconds.
handle for a client of the server
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
static void destroy(void *cls)
static void test_monitor_clients(struct GNUNET_SERVER_Handle *server)
Check if only 'monitor' clients are left.
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
struct HandlerList * next
This is a linked list.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
handle for a network connection
void * mst_cls
Closure for 'mst_'-callbacks.
void * mst
Processing of incoming data.
void * callback_cls
Closure argument for callback.
void GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server)
Stop the listen socket and get ready to shutdown the server once only 'monitor' clients are left...
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
static void process_mst(struct GNUNET_SERVER_Client *client, int ret)
Process messages from the client's message tokenizer until either the tokenizer is empty (and then sc...
struct GNUNET_SCHEDULER_Task * restart_task
ID of task used to restart processing.
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_SERVER_MessageStreamTokenizer * GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
void GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client)
Disable the warning the server issues if a message is not acknowledged in a timely fashion...
void(* GNUNET_SERVER_ConnectCallback)(void *cls, struct GNUNET_SERVER_Client *client)
Functions with this signature are called whenever a client is connected on the network level...
static size_t transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
Wrapper for transmission notification that calls the original callback and update the last activity t...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
unsigned int suspended
Was processing if incoming messages suspended while we were still processing data already received...