GNUnet  0.11.x
Data Structures | Macros | Functions
tcp_server_legacy.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
Include dependency graph for tcp_server_legacy.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  HandlerList
 List of arrays of message handlers. More...
 
struct  NotifyList
 List of arrays of message handlers. More...
 
struct  GNUNET_SERVER_Handle
 handle for a server More...
 
struct  GNUNET_SERVER_TransmitHandle
 Handle server returns for aborting transmission to a client. More...
 
struct  GNUNET_SERVER_Client
 handle for a client of the server More...
 

Macros

#define LOG_STRERROR_FILE(kind, syscall, filename)
 

Functions

void * GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, size_t size)
 Return user context associated with the given client. More...
 
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. More...
 
static void process_listen_socket (void *cls)
 Scheduler says our listen socket is ready. More...
 
static struct GNUNET_NETWORK_Handleopen_listen_socket (const struct sockaddr *server_addr, socklen_t socklen)
 Create and initialize a listen socket for the server. More...
 
struct GNUNET_SERVER_HandleGNUNET_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. More...
 
struct GNUNET_SERVER_HandleGNUNET_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. More...
 
void GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client)
 Set the 'monitor' flag on this client. More...
 
static void do_destroy (void *cls)
 Helper function for test_monitor_clients() to trigger GNUNET_SERVER_destroy() after the stack has unwound. More...
 
static void test_monitor_clients (struct GNUNET_SERVER_Handle *server)
 Check if only 'monitor' clients are left. More...
 
void GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
 Suspend accepting connections from the listen socket temporarily. More...
 
void GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
 Resume accepting connections from the listen socket. More...
 
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. More...
 
void GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server)
 Free resources held by this server. More...
 
void GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, const struct GNUNET_SERVER_MessageHandler *handlers)
 Add additional handlers to an existing server. More...
 
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. More...
 
static void warn_no_receive_done (void *cls)
 Task run to warn about missing calls to GNUNET_SERVER_receive_done. More...
 
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. More...
 
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. More...
 
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. More...
 
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 schedule receiving more), or until some handler is not immediately done (then wait for restart_processing) or shutdown. More...
 
static void restart_processing (void *cls)
 Task run to start again receiving from the network and process requests. More...
 
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. More...
 
struct GNUNET_SERVER_ClientGNUNET_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. More...
 
void GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, struct GNUNET_TIME_Relative timeout)
 Change the timeout for a particular client. More...
 
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, increments the internal reference counter). More...
 
void GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
 Notify the server that the given client handle is no longer required. More...
 
int GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, void **addr, size_t *addrlen)
 Obtain the network address of the other party. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
 Ask the server to disconnect from the given client. More...
 
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 flush the buffer on transmission instead of potentially buffering multiple messages. More...
 
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 time for our connection. More...
 
struct GNUNET_SERVER_TransmitHandleGNUNET_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 client. More...
 
void GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th)
 Abort transmission request. More...
 
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 service it's connected to is actually dead. More...
 
void GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, int success)
 Resume receiving from this client, we are done processing the current request. More...
 

Macro Definition Documentation

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)
Value:
"util-server", \
syscall, \
#define GNUNET_log_from_strerror_file(level, component, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
static char * filename

Definition at line 31 of file tcp_server_legacy.c.

Function Documentation

◆ GNUNET_SERVER_client_get_user_context_()

void* GNUNET_SERVER_client_get_user_context_ ( struct GNUNET_SERVER_Client client,
size_t  size 
)

Return user context associated with the given client.

Note: you should probably use the macro (call without the underscore).

Parameters
clientclient to query
sizenumber of bytes in user context struct (for verification only)
Returns
pointer to user context

Definition at line 349 of file tcp_server_legacy.c.

References GNUNET_assert, GNUNET_SERVER_Client::user_context, and GNUNET_SERVER_Client::user_context_size.

351 {
352  if ((0 == client->user_context_size) &&
353  (NULL == client->user_context))
354  return NULL; /* never set */
355  GNUNET_assert (size == client->user_context_size);
356  return client->user_context;
357 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * user_context
User context value, manipulated using 'GNUNET_SERVER_client_{get/set}_user_context' functions...
size_t user_context_size
Last size given when user context was initialized; used for sanity check.
static unsigned int size
Size of the "table".
Definition: peer.c:67

◆ GNUNET_SERVER_client_set_user_context_()

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.

Note: you should probably use the macro (call without the underscore).

Parameters
clientclient to query
ptrpointer to user context
sizenumber of bytes in user context struct (for verification only)

Definition at line 369 of file tcp_server_legacy.c.

References size, GNUNET_SERVER_Client::user_context, and GNUNET_SERVER_Client::user_context_size.

372 {
373  if (NULL == ptr)
374  {
375  client->user_context_size = 0;
376  client->user_context = ptr;
377  return;
378  }
379  client->user_context_size = size;
380  client->user_context = ptr;
381 }
void * user_context
User context value, manipulated using 'GNUNET_SERVER_client_{get/set}_user_context' functions...
size_t user_context_size
Last size given when user context was initialized; used for sanity check.
static unsigned int size
Size of the "table".
Definition: peer.c:67

◆ process_listen_socket()

static void process_listen_socket ( void *  cls)
static

Scheduler says our listen socket is ready.

Process it!

Parameters
clshandle to our server for which we are processing the listen socket

Definition at line 391 of file tcp_server_legacy.c.

References GNUNET_SERVER_Handle::access_cb, GNUNET_SERVER_Handle::access_cb_cls, GNUNET_CONNECTION_create_from_accept(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NETWORK_fdset_isset(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SERVER_connect_socket(), GNUNET_SERVER_resume(), GNUNET_SERVER_Handle::listen_sockets, GNUNET_SERVER_Handle::listen_task, LOG, GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_CONNECTION_Handle::sock, and tc.

Referenced by GNUNET_SERVER_resume().

392 {
393  struct GNUNET_SERVER_Handle *server = cls;
394  const struct GNUNET_SCHEDULER_TaskContext *tc;
396  unsigned int i;
397 
398  server->listen_task = NULL;
400  for (i = 0; NULL != server->listen_sockets[i]; i++)
401  {
403  server->listen_sockets[i]))
404  {
405  sock =
407  server->access_cb_cls,
408  server->listen_sockets[i]);
409  if (NULL != sock)
410  {
412  "Server accepted incoming connection.\n");
413  (void) GNUNET_SERVER_connect_socket (server,
414  sock);
415  }
416  }
417  }
418  /* listen for more! */
419  GNUNET_SERVER_resume (server);
420 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
struct GNUNET_NETWORK_Handle * sock
Underlying OS's socket, set to NULL after fatal errors.
void * access_cb_cls
Closure for access_cb.
Context information passed to each scheduler task.
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
#define LOG(kind,...)
Definition: abd_api.c:38
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:418
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_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.
handle for a server
void GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
Resume accepting connections from the listen socket.
GNUNET_CONNECTION_AccessCheck access_cb
Function to call for access control.
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
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.
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.
Definition: network.c:1029
handle for a network connection
Here is the call graph for this function:
Here is the caller graph for this function:

◆ open_listen_socket()

static struct GNUNET_NETWORK_Handle* open_listen_socket ( const struct sockaddr *  server_addr,
socklen_t  socklen 
)
static

Create and initialize a listen socket for the server.

Parameters
server_addraddress to listen on
socklenlength of server_addr
Returns
NULL on error, otherwise the listen socket

Definition at line 431 of file tcp_server_legacy.c.

References _, GNUNET_a2s(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_listen(), GNUNET_OK, LOG, LOG_STRERROR, and port.

Referenced by GNUNET_SERVER_create().

433 {
434  struct GNUNET_NETWORK_Handle *sock;
435  uint16_t port;
436  int eno;
437 
438  switch (server_addr->sa_family)
439  {
440  case AF_INET:
441  port = ntohs (((const struct sockaddr_in *) server_addr)->sin_port);
442  break;
443 
444  case AF_INET6:
445  port = ntohs (((const struct sockaddr_in6 *) server_addr)->sin6_port);
446  break;
447 
448  case AF_UNIX:
449  port = 0;
450  break;
451 
452  default:
453  GNUNET_break (0);
454  port = 0;
455  break;
456  }
457  sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
458  if (NULL == sock)
459  {
461  errno = 0;
462  return NULL;
463  }
464  /* bind the socket */
465  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
466  {
467  eno = errno;
468  if (EADDRINUSE != errno)
469  {
470  /* we don't log 'EADDRINUSE' here since an IPv4 bind may
471  * fail if we already took the port on IPv6; if both IPv4 and
472  * IPv6 binds fail, then our caller will log using the
473  * errno preserved in 'eno' */
475  "bind");
476  if (0 != port)
478  _ ("`%s' failed for port %d (%s).\n"),
479  "bind",
480  port,
481  (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
482  eno = 0;
483  }
484  else
485  {
486  if (0 != port)
488  _ ("`%s' failed for port %d (%s): address already in use\n"),
489  "bind", port,
490  (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
491  else if (AF_UNIX == server_addr->sa_family)
492  {
494  _ ("`%s' failed for `%s': address already in use\n"),
495  "bind",
496  GNUNET_a2s (server_addr, socklen));
497  }
498  }
500  errno = eno;
501  return NULL;
502  }
503  if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
504  {
506  "listen");
508  errno = 0;
509  return NULL;
510  }
511  if (0 != port)
513  "Server starts to listen on port %u.\n",
514  port);
515  return sock;
516 }
int GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:708
#define LOG(kind,...)
Definition: abd_api.c:38
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.
Definition: network.c:485
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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)...
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
#define LOG_STRERROR(kind, syscall)
handle to a socket
Definition: network.c:52
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:912
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_create_with_sockets()

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.

Parameters
access_cbfunction for access control
access_cb_clsclosure for access_cb
lsocksNULL-terminated array of listen sockets
idle_timeoutafter how long should we timeout idle connections?
require_foundif GNUNET_YES, connections sending messages of unknown type will be closed
Returns
handle for the new server, NULL on error (typically, "port" already in use)

Definition at line 532 of file tcp_server_legacy.c.

References GNUNET_SERVER_Handle::access_cb, GNUNET_SERVER_Handle::access_cb_cls, GNUNET_new, GNUNET_SERVER_resume(), GNUNET_SERVER_Handle::idle_timeout, GNUNET_SERVER_Handle::listen_sockets, and GNUNET_SERVER_Handle::require_found.

Referenced by GNUNET_SERVER_create(), LEGACY_SERVICE_start(), libgnunet_plugin_transport_tcp_init(), and service_task().

537 {
538  struct GNUNET_SERVER_Handle *server;
539 
540  server = GNUNET_new (struct GNUNET_SERVER_Handle);
541  server->idle_timeout = idle_timeout;
542  server->listen_sockets = lsocks;
543  server->access_cb = access_cb;
544  server->access_cb_cls = access_cb_cls;
545  server->require_found = require_found;
546  if (NULL != lsocks)
547  GNUNET_SERVER_resume (server);
548  return server;
549 }
void * access_cb_cls
Closure for access_cb.
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
handle for a server
void GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
Resume accepting connections from the listen socket.
int require_found
Do we ignore messages of types that we do not understand or do we require that a handler is found (an...
GNUNET_CONNECTION_AccessCheck access_cb
Function to call for access control.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_create()

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.

Parameters
access_cbfunction for access control
access_cb_clsclosure for access_cb
server_addraddress to listen on (including port), NULL terminated array
socklenlength of server_addr
idle_timeoutafter how long should we timeout idle connections?
require_foundif YES, connections sending messages of unknown type will be closed
Returns
handle for the new server, NULL on error (typically, "port" already in use)

Definition at line 566 of file tcp_server_legacy.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_malloc, GNUNET_SERVER_create_with_sockets(), LOG_STRERROR, and open_listen_socket().

Referenced by LEGACY_SERVICE_start(), and service_task().

572 {
573  struct GNUNET_NETWORK_Handle **lsocks;
574  unsigned int i;
575  unsigned int j;
576  unsigned int k;
577  int seen;
578 
579  i = 0;
580  while (NULL != server_addr[i])
581  i++;
582  if (i > 0)
583  {
584  lsocks = GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1));
585  i = 0;
586  j = 0;
587  while (NULL != server_addr[i])
588  {
589  seen = 0;
590  for (k = 0; k < i; k++)
591  if ((socklen[k] == socklen[i]) &&
592  (0 == memcmp (server_addr[k], server_addr[i], socklen[i])))
593  {
594  seen = 1;
595  break;
596  }
597  if (0 != seen)
598  {
599  /* duplicate address, skip */
600  i++;
601  continue;
602  }
603  lsocks[j] = open_listen_socket (server_addr[i], socklen[i]);
604  if (NULL != lsocks[j])
605  j++;
606  i++;
607  }
608  if (0 == j)
609  {
610  if (0 != errno)
612  GNUNET_free (lsocks);
613  lsocks = NULL;
614  }
615  }
616  else
617  {
618  lsocks = NULL;
619  }
620  return GNUNET_SERVER_create_with_sockets (access_cb,
621  access_cb_cls,
622  lsocks,
623  idle_timeout,
624  require_found);
625 }
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.
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.
#define LOG_STRERROR(kind, syscall)
handle to a socket
Definition: network.c:52
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_mark_monitor()

void GNUNET_SERVER_client_mark_monitor ( struct GNUNET_SERVER_Client client)

Set the 'monitor' flag on this client.

Clients which have been marked as 'monitors' won't prevent the server from shutting down once 'GNUNET_SERVER_stop_listening()' has been invoked. The idea is that for "normal" clients we likely want to allow them to process their requests; however, monitor-clients are likely to 'never' disconnect during shutdown and thus will not be considered when determining if the server should continue to exist after GNUNET_SERVER_destroy() has been called.

Parameters
clientthe client to set the 'monitor' flag on

Definition at line 641 of file tcp_server_legacy.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, and GNUNET_SERVER_Client::is_monitor.

642 {
644  "Marking client as monitor!\n");
645  client->is_monitor = GNUNET_YES;
646 }
int is_monitor
Is this client a &#39;monitor&#39; client that should not be counted when deciding on destroying the server d...
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77

◆ do_destroy()

static void do_destroy ( void *  cls)
static

Helper function for test_monitor_clients() to trigger GNUNET_SERVER_destroy() after the stack has unwound.

Parameters
clsthe struct GNUNET_SERVER_Handle * to destroy

Definition at line 656 of file tcp_server_legacy.c.

References GNUNET_SERVER_destroy().

Referenced by test_monitor_clients().

657 {
658  struct GNUNET_SERVER_Handle *server = cls;
659 
660  GNUNET_SERVER_destroy (server);
661 }
void GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server)
Free resources held by this server.
handle for a server
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_monitor_clients()

static void test_monitor_clients ( struct GNUNET_SERVER_Handle server)
static

Check if only 'monitor' clients are left.

If so, destroy the server completely.

Parameters
serverserver to test for full shutdown

Definition at line 671 of file tcp_server_legacy.c.

References GNUNET_SERVER_Handle::clients_head, do_destroy(), GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SYSERR, GNUNET_YES, GNUNET_SERVER_Handle::in_soft_shutdown, GNUNET_SERVER_Client::is_monitor, and GNUNET_SERVER_Client::next.

Referenced by GNUNET_SERVER_client_disconnect(), and GNUNET_SERVER_stop_listening().

672 {
673  struct GNUNET_SERVER_Client *client;
674 
675  if (GNUNET_YES != server->in_soft_shutdown)
676  return;
677  for (client = server->clients_head; NULL != client; client = client->next)
678  if (GNUNET_NO == client->is_monitor)
679  return;
680  /* not done yet */
682  (void) GNUNET_SCHEDULER_add_now (&do_destroy, server);
683 }
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_SERVER_Client * next
This is a doubly linked list.
int is_monitor
Is this client a &#39;monitor&#39; client that should not be counted when deciding on destroying the server d...
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.
Definition: scheduler.c:1280
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static void do_destroy(void *cls)
Helper function for test_monitor_clients() to trigger GNUNET_SERVER_destroy() after the stack has unw...
int in_soft_shutdown
Set to GNUNET_YES once we are in &#39;soft&#39; shutdown where we wait for all non-monitor clients to disconn...
#define GNUNET_YES
Definition: gnunet_common.h:77
handle for a client of the server
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_suspend()

void GNUNET_SERVER_suspend ( struct GNUNET_SERVER_Handle server)

Suspend accepting connections from the listen socket temporarily.

Parameters
serverserver to stop accepting connections.

Definition at line 692 of file tcp_server_legacy.c.

References GNUNET_SCHEDULER_cancel(), and GNUNET_SERVER_Handle::listen_task.

Referenced by connect_notify().

693 {
694  if (NULL != server->listen_task)
695  {
697  server->listen_task = NULL;
698  }
699 }
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_resume()

void GNUNET_SERVER_resume ( struct GNUNET_SERVER_Handle server)

Resume accepting connections from the listen socket.

Parameters
serverserver to stop accepting connections.

Definition at line 708 of file tcp_server_legacy.c.

References GNUNET_NETWORK_fdset_create(), GNUNET_NETWORK_fdset_destroy(), GNUNET_NETWORK_fdset_set(), GNUNET_SCHEDULER_add_read_net_with_priority(), GNUNET_SCHEDULER_add_select(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_SERVER_Handle::listen_sockets, GNUNET_SERVER_Handle::listen_task, and process_listen_socket().

Referenced by disconnect_notify(), GNUNET_SERVER_create_with_sockets(), and process_listen_socket().

709 {
710  struct GNUNET_NETWORK_FDSet *r;
711  unsigned int i;
712 
713  if (NULL == server->listen_sockets)
714  return;
715  if (NULL == server->listen_sockets[0])
716  return; /* nothing to do, no listen sockets! */
717  if (NULL == server->listen_sockets[1])
718  {
719  /* simplified method: no fd set needed; this is then much simpler
720  and much more efficient */
721  server->listen_task =
724  server->listen_sockets[0],
726  server);
727  return;
728  }
730  i = 0;
731  while (NULL != server->listen_sockets[i])
732  GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
733  server->listen_task =
736  &process_listen_socket, server);
738 }
Run with high priority (important requests).
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
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...
Definition: scheduler.c:1520
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1266
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1250
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...
Definition: scheduler.c:1810
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void process_listen_socket(void *cls)
Scheduler says our listen socket is ready.
void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Add a socket to the FD set.
Definition: network.c:1011
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_stop_listening()

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.

Parameters
serverserver to stop listening on

Definition at line 748 of file tcp_server_legacy.c.

References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, GNUNET_SERVER_Handle::in_soft_shutdown, GNUNET_SERVER_Handle::listen_sockets, GNUNET_SERVER_Handle::listen_task, LOG, and test_monitor_clients().

Referenced by shutdown_task().

749 {
750  unsigned int i;
751 
753  "Server in soft shutdown\n");
754  if (NULL != server->listen_task)
755  {
757  server->listen_task = NULL;
758  }
759  if (NULL != server->listen_sockets)
760  {
761  i = 0;
762  while (NULL != server->listen_sockets[i])
765  GNUNET_free (server->listen_sockets);
766  server->listen_sockets = NULL;
767  }
768  if (GNUNET_NO == server->in_soft_shutdown)
769  server->in_soft_shutdown = GNUNET_YES;
770  test_monitor_clients (server);
771 }
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
int in_soft_shutdown
Set to GNUNET_YES once we are in &#39;soft&#39; shutdown where we wait for all non-monitor clients to disconn...
#define GNUNET_YES
Definition: gnunet_common.h:77
static void test_monitor_clients(struct GNUNET_SERVER_Handle *server)
Check if only &#39;monitor&#39; clients are left.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_destroy()

void GNUNET_SERVER_destroy ( struct GNUNET_SERVER_Handle server)

Free resources held by this server.

Parameters
serverserver to destroy

Definition at line 780 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::connect_notify_list_head, GNUNET_SERVER_Handle::connect_notify_list_tail, GNUNET_SERVER_Handle::disconnect_notify_list_head, GNUNET_SERVER_Handle::disconnect_notify_list_tail, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NETWORK_socket_close(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_Handle::handlers, GNUNET_SERVER_Handle::listen_sockets, GNUNET_SERVER_Handle::listen_task, LOG, and HandlerList::next.

Referenced by do_destroy(), LEGACY_SERVICE_stop(), libgnunet_plugin_transport_tcp_done(), and shutdown_task().

781 {
782  struct HandlerList *hpos;
783  struct NotifyList *npos;
784  unsigned int i;
785 
787  "Server shutting down.\n");
788  if (NULL != server->listen_task)
789  {
791  server->listen_task = NULL;
792  }
793  if (NULL != server->listen_sockets)
794  {
795  i = 0;
796  while (NULL != server->listen_sockets[i])
799  GNUNET_free (server->listen_sockets);
800  server->listen_sockets = NULL;
801  }
802  while (NULL != server->clients_head)
804  while (NULL != (hpos = server->handlers))
805  {
806  server->handlers = hpos->next;
807  GNUNET_free (hpos);
808  }
809  while (NULL != (npos = server->disconnect_notify_list_head))
810  {
811  npos->callback (npos->callback_cls,
812  NULL);
815  npos);
816  GNUNET_free (npos);
817  }
818  while (NULL != (npos = server->connect_notify_list_head))
819  {
820  npos->callback (npos->callback_cls,
821  NULL);
823  server->connect_notify_list_tail,
824  npos);
825  GNUNET_free (npos);
826  }
827  GNUNET_free (server);
828 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
List of arrays of message handlers.
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
List of arrays of message handlers.
struct GNUNET_NETWORK_Handle ** listen_sockets
NULL-terminated array of sockets used to listen for new connections.
#define LOG(kind,...)
Definition: abd_api.c:38
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void * callback_cls
Closure for callback.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct HandlerList * handlers
List of handlers for incoming messages.
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
struct GNUNET_SCHEDULER_Task * listen_task
Task scheduled to do the listening.
struct NotifyList * disconnect_notify_list_tail
Tail of linked list of functions to call on disconnects by clients.
struct NotifyList * connect_notify_list_tail
Tail of linked list of functions to call on connects by clients.
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
struct HandlerList * next
This is a linked list.
int GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:560
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_add_handlers()

void GNUNET_SERVER_add_handlers ( struct GNUNET_SERVER_Handle server,
const struct GNUNET_SERVER_MessageHandler handlers 
)

Add additional handlers to an existing server.

Parameters
serverthe server to add handlers to
handlersarray of message handlers for incoming messages; the last entry must have "NULL" for the "callback"; multiple entries for the same type are allowed, they will be called in order of occurence. These handlers can be removed later; the handlers array must exist until removed (or server is destroyed).

Definition at line 845 of file tcp_server_legacy.c.

References GNUNET_new, HandlerList::handlers, GNUNET_SERVER_Handle::handlers, HandlerList::next, and p.

Referenced by LEGACY_SERVICE_start(), libgnunet_plugin_transport_tcp_init(), and service_task().

847 {
848  struct HandlerList *p;
849 
850  p = GNUNET_new (struct HandlerList);
851  p->handlers = handlers;
852  p->next = server->handlers;
853  server->handlers = p;
854 }
List of arrays of message handlers.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct HandlerList * handlers
List of handlers for incoming messages.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
const struct GNUNET_SERVER_MessageHandler * handlers
NULL-terminated array of handlers.
struct HandlerList * next
This is a linked list.
Here is the caller graph for this function:

◆ GNUNET_SERVER_set_callbacks()

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.

(very rarely used).

Parameters
serverserver to modify
createnew tokenizer initialization function
destroynew tokenizer destruction function
receivenew tokenizer receive function
clsclosure for create, receive, destroy

Definition at line 868 of file tcp_server_legacy.c.

References destroy(), GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_create, GNUNET_SERVER_Handle::mst_destroy, and GNUNET_SERVER_Handle::mst_receive.

873 {
874  server->mst_create = create;
875  server->mst_destroy = destroy;
876  server->mst_receive = receive;
877  server->mst_cls = cls;
878 }
GNUNET_SERVER_MstReceiveCallback mst_receive
Alternative function to give data to a MST instance.
GNUNET_SERVER_MstDestroyCallback mst_destroy
Alternative function to destroy a MST instance.
GNUNET_SERVER_MstCreateCallback mst_create
Alternative function to create a MST instance.
static void destroy(void *cls)
void * mst_cls
Closure for &#39;mst_&#39;-callbacks.
Here is the call graph for this function:

◆ warn_no_receive_done()

static void warn_no_receive_done ( void *  cls)
static

Task run to warn about missing calls to GNUNET_SERVER_receive_done.

Parameters
clsour struct GNUNET_SERVER_Client * to process more requests from

Definition at line 887 of file tcp_server_legacy.c.

References _, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, LOG, GNUNET_SERVER_Client::warn_start, GNUNET_SERVER_Client::warn_task, and GNUNET_SERVER_Client::warn_type.

Referenced by GNUNET_SERVER_inject().

888 {
889  struct GNUNET_SERVER_Client *client = cls;
890 
891  GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
892  client->warn_task =
894  &warn_no_receive_done, client);
896  _ (
897  "Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
898  (unsigned int) client->warn_type,
901  GNUNET_YES));
902 }
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define LOG(kind,...)
Definition: abd_api.c:38
static void warn_no_receive_done(void *cls)
Task run to warn about missing calls to GNUNET_SERVER_receive_done.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
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.
Definition: scheduler.c:1253
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
uint16_t warn_type
Type of last message processed (for warn_no_receive_done).
struct GNUNET_TIME_Absolute warn_start
Time when the warn task was started.
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...
Definition: time.c:375
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVER_receive_done.
#define GNUNET_YES
Definition: gnunet_common.h:77
handle for a client of the server
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_disable_receive_done_warning()

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.

Use this call if a client is intentionally delayed for a while. Only applies to the current message.

Parameters
clientclient for which to disable the warning

Definition at line 913 of file tcp_server_legacy.c.

References GNUNET_SCHEDULER_cancel(), and GNUNET_SERVER_Client::warn_task.

Referenced by handle_tcp_data().

914 {
915  if (NULL != client->warn_task)
916  {
918  client->warn_task = NULL;
919  }
920 }
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVER_receive_done.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_inject()

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.

Delivery of the message will happen instantly (if a handler is installed; otherwise the call does nothing).

Parameters
serverthe server receiving the message
senderthe "pretended" sender of the message can be NULL!
messagemessage to transmit
Returns
GNUNET_OK if the message was OK and the connection can stay open GNUNET_SYSERR if the connection to the client should be shut down

Definition at line 939 of file tcp_server_legacy.c.

References buf, GNUNET_SERVER_MessageHandler::callback, GNUNET_SERVER_MessageHandler::callback_cls, GNUNET_SERVER_MessageHandler::expected_size, GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_MESSAGE_TYPE_ALL, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, HandlerList::handlers, GNUNET_SERVER_Handle::handlers, LOG, mh, HandlerList::next, process_incoming(), GNUNET_SERVER_Handle::require_found, size, GNUNET_MessageHeader::size, GNUNET_SERVER_Client::suspended, type, GNUNET_SERVER_MessageHandler::type, GNUNET_MessageHeader::type, warn_no_receive_done(), GNUNET_SERVER_Client::warn_start, GNUNET_SERVER_Client::warn_task, and GNUNET_SERVER_Client::warn_type.

Referenced by client_message_tokenizer_callback().

942 {
943  struct HandlerList *pos;
944  const struct GNUNET_SERVER_MessageHandler *mh;
945  unsigned int i;
946  uint16_t type;
947  uint16_t size;
948  int found;
949 
950  type = ntohs (message->type);
951  size = ntohs (message->size);
953  "Received message of type %u and size %u from client\n",
954  type, size);
955  found = GNUNET_NO;
956  for (pos = server->handlers; NULL != pos; pos = pos->next)
957  {
958  i = 0;
959  while (pos->handlers[i].callback != NULL)
960  {
961  mh = &pos->handlers[i];
962  if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
963  {
964  if ((0 != mh->expected_size) && (mh->expected_size != size))
965  {
966 #if GNUNET8_NETWORK_IS_DEAD
968  "Expected %u bytes for message of type %u, got %u\n",
969  mh->expected_size, mh->type, size);
970  GNUNET_break_op (0);
971 #else
973  "Expected %u bytes for message of type %u, got %u\n",
974  mh->expected_size, mh->type, size);
975 #endif
976  return GNUNET_SYSERR;
977  }
978  if (NULL != sender)
979  {
980  if ((0 == sender->suspended) &&
981  (NULL == sender->warn_task))
982  {
983  GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */
985  sender->warn_task =
988  sender);
989  sender->warn_type = type;
990  }
991  sender->suspended++;
992  }
993  mh->callback (mh->callback_cls, sender, message);
994  found = GNUNET_YES;
995  }
996  i++;
997  }
998  }
999  if (GNUNET_NO == found)
1000  {
1002  "Received message of unknown type %d\n", type);
1003  if (GNUNET_YES == server->require_found)
1004  return GNUNET_SYSERR;
1005  }
1006  return GNUNET_OK;
1007 }
List of arrays of message handlers.
GNUNET_SERVER_MessageCallback callback
Function to call for messages of "type".
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define LOG(kind,...)
Definition: abd_api.c:38
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
static void warn_no_receive_done(void *cls)
Task run to warn about missing calls to GNUNET_SERVER_receive_done.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct HandlerList * handlers
List of handlers for incoming messages.
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.
Definition: scheduler.c:1253
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint16_t expected_size
Expected size of messages of this type.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
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.
uint16_t warn_type
Type of last message processed (for warn_no_receive_done).
struct GNUNET_TIME_Absolute warn_start
Time when the warn task was started.
#define GNUNET_MESSAGE_TYPE_ALL
Next available: 1500.
const struct GNUNET_SERVER_MessageHandler * handlers
NULL-terminated array of handlers.
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVER_receive_done.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:77
struct HandlerList * next
This is a linked list.
void * callback_cls
Closure argument for callback.
unsigned int suspended
Was processing if incoming messages suspended while we were still processing data already received...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_incoming()

static void process_incoming ( void *  cls,
const void *  buf,
size_t  available,
const struct sockaddr *  addr,
socklen_t  addrlen,
int  errCode 
)
static

We are receiving an incoming message.

Process it.

Parameters
clsour closure (handle for the client)
bufbuffer with data received from network
availablenumber of bytes available in buf
addraddress of the sender
addrlenlength of addr
errCodecode indicating errors receiving, 0 for success

Definition at line 1104 of file tcp_server_legacy.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_SERVER_Client::connection, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CONNECTION_check(), GNUNET_CONNECTION_receive(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_client_drop(), GNUNET_SERVER_client_keep(), GNUNET_SERVER_mst_receive(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GNUNET_SERVER_Client::idle_timeout, GNUNET_SERVER_Client::last_activity, LOG, GNUNET_SERVER_Client::mst, GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_receive, process_mst(), GNUNET_SERVER_Client::receive_pending, ret, GNUNET_SERVER_Client::server, and GNUNET_SERVER_Client::shutdown_now.

Referenced by GNUNET_SERVER_connect_socket(), GNUNET_SERVER_inject(), process_mst(), and restart_processing().

1110 {
1111  struct GNUNET_SERVER_Client *client = cls;
1112  struct GNUNET_SERVER_Handle *server = client->server;
1113  struct GNUNET_TIME_Absolute end;
1114  struct GNUNET_TIME_Absolute now;
1115  int ret;
1116 
1118  client->receive_pending = GNUNET_NO;
1119  now = GNUNET_TIME_absolute_get ();
1121  client->idle_timeout);
1122 
1123  if ((NULL == buf) &&
1124  (0 == available) &&
1125  (NULL == addr) &&
1126  (0 == errCode) &&
1127  (GNUNET_YES != client->shutdown_now) &&
1128  (NULL != server) &&
1130  (end.abs_value_us > now.abs_value_us))
1131  {
1132  /* wait longer, timeout changed (i.e. due to us sending) */
1134  "Receive time out, but no disconnect due to sending (%p)\n",
1135  client);
1136  client->receive_pending = GNUNET_YES;
1141  client);
1142  return;
1143  }
1144  if ((NULL == buf) ||
1145  (0 == available) ||
1146  (0 != errCode) ||
1147  (NULL == server) ||
1148  (GNUNET_YES == client->shutdown_now) ||
1150  {
1151  /* other side closed connection, error connecting, etc. */
1153  "Failed to connect or other side closed connection (%p)\n",
1154  client);
1156  return;
1157  }
1159  "Server receives %u bytes from `%s'.\n",
1160  (unsigned int) available,
1161  GNUNET_a2s (addr, addrlen));
1162  GNUNET_SERVER_client_keep (client);
1163  client->last_activity = now;
1164 
1165  if (NULL != server->mst_receive)
1166  {
1167  ret = client->server->mst_receive (client->server->mst_cls,
1168  client->mst,
1169  client,
1170  buf,
1171  available,
1172  GNUNET_NO,
1173  GNUNET_YES);
1174  }
1175  else if (NULL != client->mst)
1176  {
1177  ret =
1178  GNUNET_SERVER_mst_receive (client->mst,
1179  client,
1180  buf,
1181  available,
1182  GNUNET_NO,
1183  GNUNET_YES);
1184  }
1185  else
1186  {
1187  GNUNET_break (0);
1188  return;
1189  }
1190  process_mst (client,
1191  ret);
1192  GNUNET_SERVER_client_drop (client);
1193 }
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
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...
GNUNET_SERVER_MstReceiveCallback mst_receive
Alternative function to give data to a MST instance.
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute last_activity
Last activity on this socket (used to time it out if reference_count == 0).
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
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.
Definition: time.c:395
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).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
static char buf[2048]
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.
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.
handle for a server
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)...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
int shutdown_now
We&#39;re about to close down this client.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
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.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
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?
Definition: time.c:331
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
handle for a client of the server
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
void * mst_cls
Closure for &#39;mst_&#39;-callbacks.
void * mst
Processing of incoming data.
static void process_mst(struct GNUNET_SERVER_Client *client, int ret)
Process messages from the client&#39;s message tokenizer until either the tokenizer is empty (and then sc...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_mst()

static void process_mst ( struct GNUNET_SERVER_Client client,
int  ret 
)
static

Process messages from the client's message tokenizer until either the tokenizer is empty (and then schedule receiving more), or until some handler is not immediately done (then wait for restart_processing) or shutdown.

Parameters
clientthe client to process, RC must have already been increased using GNUNET_SERVER_client_keep and will be decreased by one in this function
retGNUNET_NO to start processing from the buffer, GNUNET_OK if the mst buffer is drained and we should instantly go back to receiving GNUNET_SYSERR if we should instantly abort due to error in a previous step

Definition at line 1043 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::connection, GNUNET_CONNECTION_receive(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_OK, GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_mst_receive(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_YES, GNUNET_SERVER_Client::idle_timeout, LOG, GNUNET_SERVER_Client::mst, GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_receive, process_incoming(), GNUNET_SERVER_Client::receive_pending, GNUNET_SERVER_Client::server, GNUNET_SERVER_Client::shutdown_now, and GNUNET_SERVER_Client::suspended.

Referenced by process_incoming(), and restart_processing().

1045 {
1046  while ((GNUNET_SYSERR != ret) && (NULL != client->server) &&
1047  (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
1048  {
1049  if (GNUNET_OK == ret)
1050  {
1052  "Server re-enters receive loop, timeout: %s.\n",
1054  GNUNET_YES));
1055  client->receive_pending = GNUNET_YES;
1056  if (GNUNET_OK !=
1059  client->idle_timeout,
1061  client))
1062  return;
1063  break;
1064  }
1066  "Server processes additional messages instantly.\n");
1067  if (NULL != client->server->mst_receive)
1068  ret =
1069  client->server->mst_receive (client->server->mst_cls, client->mst,
1070  client, NULL, 0, GNUNET_NO, GNUNET_YES);
1071  else
1072  ret =
1073  GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
1074  GNUNET_YES);
1075  }
1077  "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
1078  ret, client->server,
1079  client->shutdown_now,
1080  client->suspended);
1081  if (GNUNET_NO == ret)
1082  {
1084  "Server has more data pending but is suspended.\n");
1085  client->receive_pending = GNUNET_SYSERR; /* data pending */
1086  }
1087  if ((GNUNET_SYSERR == ret) ||
1088  (GNUNET_YES == client->shutdown_now))
1090 }
GNUNET_SERVER_MstReceiveCallback mst_receive
Alternative function to give data to a MST instance.
#define LOG(kind,...)
Definition: abd_api.c:38
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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).
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
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 GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
int shutdown_now
We&#39;re about to close down this client.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
void * mst_cls
Closure for &#39;mst_&#39;-callbacks.
void * mst
Processing of incoming data.
unsigned int suspended
Was processing if incoming messages suspended while we were still processing data already received...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ restart_processing()

static void restart_processing ( void *  cls)
static

Task run to start again receiving from the network and process requests.

Parameters
clsour struct GNUNET_SERVER_Client * to process more requests from

Definition at line 1203 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::connection, GNUNET_assert, GNUNET_CONNECTION_receive(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_SERVER_client_drop(), GNUNET_SERVER_client_keep(), GNUNET_YES, GNUNET_SERVER_Client::idle_timeout, LOG, process_incoming(), process_mst(), GNUNET_SERVER_Client::receive_pending, GNUNET_SERVER_Client::restart_task, and GNUNET_SERVER_Client::shutdown_now.

Referenced by GNUNET_SERVER_receive_done().

1204 {
1205  struct GNUNET_SERVER_Client *client = cls;
1206 
1207  GNUNET_assert (GNUNET_YES != client->shutdown_now);
1208  client->restart_task = NULL;
1209  if (GNUNET_NO == client->receive_pending)
1210  {
1211  LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
1212  client->receive_pending = GNUNET_YES;
1215  client->idle_timeout,
1217  client);
1218  return;
1219  }
1221  "Server continues processing messages still in the buffer.\n");
1222  GNUNET_SERVER_client_keep (client);
1223  client->receive_pending = GNUNET_NO;
1224  process_mst (client,
1225  GNUNET_NO);
1226  GNUNET_SERVER_client_drop (client);
1227 }
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...
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
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).
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
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.
void GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client)
Notify the server that the given client handle is no longer required.
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
int shutdown_now
We&#39;re about to close down this client.
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.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_YES
Definition: gnunet_common.h:77
handle for a client of the server
static void process_mst(struct GNUNET_SERVER_Client *client, int ret)
Process messages from the client&#39;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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_message_tokenizer_callback()

static int client_message_tokenizer_callback ( void *  cls,
void *  client,
const struct GNUNET_MessageHeader message 
)
static

This function is called whenever our inbound message tokenizer has received a complete message.

Parameters
clsclosure (struct GNUNET_SERVER_Handle)
clientidentification of the client (struct GNUNET_SERVER_Client *)
messagethe actual message
Returns
GNUNET_OK on success, GNUNET_SYSERR to stop further processing

Definition at line 1241 of file tcp_server_legacy.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_OK, GNUNET_SERVER_client_disconnect(), GNUNET_SERVER_inject(), GNUNET_SYSERR, GNUNET_YES, GNUNET_SERVER_Client::in_process_client_buffer, LOG, ret, GNUNET_SERVER_Client::shutdown_now, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GNUNET_SERVER_connect_socket().

1244 {
1245  struct GNUNET_SERVER_Handle *server = cls;
1246  struct GNUNET_SERVER_Client *sender = client;
1247  int ret;
1248 
1250  "Tokenizer gives server message of type %u and size %u from client\n",
1251  ntohs (message->type), ntohs (message->size));
1253  ret = GNUNET_SERVER_inject (server, sender, message);
1255  if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now))
1256  {
1258  return GNUNET_SYSERR;
1259  }
1260  return GNUNET_OK;
1261 }
int in_process_client_buffer
Are we currently in the "process_client_buffer" function (and will hence restart the receive job on e...
#define LOG(kind,...)
Definition: abd_api.c:38
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
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.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
handle for a server
int shutdown_now
We&#39;re about to close down this client.
void GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
Ask the server to disconnect from the given client.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_YES
Definition: gnunet_common.h:77
handle for a client of the server
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_connect_socket()

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.

Use this function for outgoing (P2P) connections that we initiated (and where this server should process incoming messages).

Parameters
serverthe server to use
connectionthe connection to manage (client must stop using this connection from now on)
Returns
the client handle

Definition at line 1276 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, client_message_tokenizer_callback(), GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::clients_tail, GNUNET_SERVER_Handle::connect_notify_list_head, GNUNET_SERVER_Client::connection, GNUNET_assert, GNUNET_CONNECTION_receive(), GNUNET_CONTAINER_DLL_insert, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_SERVER_mst_create(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_YES, GNUNET_SERVER_Handle::idle_timeout, GNUNET_SERVER_Client::idle_timeout, GNUNET_SERVER_Client::last_activity, GNUNET_SERVER_Client::mst, GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_create, NotifyList::next, process_incoming(), GNUNET_SERVER_Client::receive_pending, and GNUNET_SERVER_Client::server.

Referenced by notify_send_probe(), process_listen_socket(), and tcp_plugin_get_session().

1278 {
1279  struct GNUNET_SERVER_Client *client;
1280  struct NotifyList *n;
1281 
1282  client = GNUNET_new (struct GNUNET_SERVER_Client);
1283  client->connection = connection;
1284  client->server = server;
1286  client->idle_timeout = server->idle_timeout;
1288  server->clients_tail,
1289  client);
1290  if (NULL != server->mst_create)
1291  client->mst =
1292  server->mst_create (server->mst_cls, client);
1293  else
1294  client->mst =
1296  server);
1297  GNUNET_assert (NULL != client->mst);
1298  for (n = server->connect_notify_list_head; NULL != n; n = n->next)
1299  n->callback (n->callback_cls, client);
1300  client->receive_pending = GNUNET_YES;
1301  if (GNUNET_SYSERR ==
1304  client->idle_timeout,
1306  client))
1307  return NULL;
1308  return client;
1309 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
List of arrays of message handlers.
struct GNUNET_SERVER_Client * clients_tail
Head of list of our current clients.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute last_activity
Last activity on this socket (used to time it out if reference_count == 0).
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
struct NotifyList * next
This is a doubly linked list.
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).
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.
GNUNET_SERVER_MstCreateCallback mst_create
Alternative function to create a MST instance.
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
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.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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...
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
#define GNUNET_YES
Definition: gnunet_common.h:77
handle for a client of the server
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
void * mst_cls
Closure for &#39;mst_&#39;-callbacks.
void * mst
Processing of incoming data.
struct GNUNET_SERVER_MessageStreamTokenizer * GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_set_timeout()

void GNUNET_SERVER_client_set_timeout ( struct GNUNET_SERVER_Client client,
struct GNUNET_TIME_Relative  timeout 
)

Change the timeout for a particular client.

Decreasing the timeout may not go into effect immediately (only after the previous timeout times out or activity happens on the socket).

Parameters
clientthe client to update
timeoutnew timeout for activities on the socket

Definition at line 1321 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::idle_timeout, and timeout.

Referenced by handle_tcp_welcome(), and tcp_plugin_send().

1323 {
1324  client->idle_timeout = timeout;
1325 }
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
struct GNUNET_TIME_Relative idle_timeout
After how long should an idle connection time out (on write).
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_keep()

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, increments the internal reference counter).

Parameters
clientthe client to keep

Definition at line 1336 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::reference_count.

Referenced by process_incoming(), and restart_processing().

1337 {
1338  client->reference_count++;
1339 }
unsigned int reference_count
Number of external entities with a reference to this client object.
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_drop()

void GNUNET_SERVER_client_drop ( struct GNUNET_SERVER_Client client)

Notify the server that the given client handle is no longer required.

Decrements the reference counter. If that counter reaches zero an inactive connection maybe closed.

Parameters
clientthe client to drop

Definition at line 1351 of file tcp_server_legacy.c.

References GNUNET_assert, GNUNET_SERVER_client_disconnect(), GNUNET_YES, GNUNET_SERVER_Client::reference_count, and GNUNET_SERVER_Client::shutdown_now.

Referenced by process_incoming(), and restart_processing().

1352 {
1353  GNUNET_assert (client->reference_count > 0);
1354  client->reference_count--;
1355  if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count))
1357 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int shutdown_now
We&#39;re about to close down this client.
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.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_get_address()

int GNUNET_SERVER_client_get_address ( struct GNUNET_SERVER_Client client,
void **  addr,
size_t *  addrlen 
)

Obtain the network address of the other party.

Parameters
clientthe client to get the address for
addrwhere to store the address
addrlenwhere to store the length of the addr
Returns
GNUNET_OK on success

Definition at line 1369 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::connection, and GNUNET_CONNECTION_get_address().

Referenced by handle_tcp_data(), handle_tcp_nat_probe(), and handle_tcp_welcome().

1371 {
1372  return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
1373 }
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
int GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection, void **addr, size_t *addrlen)
Obtain the network address of the other party.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_disconnect_notify()

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.

This function is called whenever the actual network connection is closed; the reference count may be zero or larger than zero at this point.

Parameters
serverthe server manageing the clients
callbackfunction to call on disconnect
callback_clsclosure for callback

Definition at line 1387 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::disconnect_notify_list_head, GNUNET_SERVER_Handle::disconnect_notify_list_tail, GNUNET_CONTAINER_DLL_insert, and GNUNET_new.

Referenced by libgnunet_plugin_transport_tcp_init().

1390 {
1391  struct NotifyList *n;
1392 
1393  n = GNUNET_new (struct NotifyList);
1394  n->callback = callback;
1398  n);
1399 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
List of arrays of message handlers.
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void * callback_cls
Closure for callback.
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
struct NotifyList * disconnect_notify_list_tail
Tail of linked list of functions to call on disconnects by clients.
Here is the caller graph for this function:

◆ GNUNET_SERVER_connect_notify()

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.

This function is called whenever the actual network connection is opened. If the server is destroyed before this notification is explicitly cancelled, the 'callback' will once be called with a 'client' argument of NULL to indicate that the server itself is now gone (and that the callback won't be called anymore and also can no longer be cancelled).

Parameters
serverthe server manageing the clients
callbackfunction to call on sconnect
callback_clsclosure for callback

Definition at line 1416 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::connect_notify_list_head, GNUNET_SERVER_Handle::connect_notify_list_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_new, and GNUNET_SERVER_Client::next.

Referenced by libgnunet_plugin_transport_tcp_init().

1419 {
1420  struct NotifyList *n;
1421  struct GNUNET_SERVER_Client *client;
1422 
1423  n = GNUNET_new (struct NotifyList);
1424  n->callback = callback;
1425  n->callback_cls = callback_cls;
1427  server->connect_notify_list_tail,
1428  n);
1429  for (client = server->clients_head; NULL != client; client = client->next)
1430  callback (callback_cls, client);
1431 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
List of arrays of message handlers.
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_SERVER_Client * next
This is a doubly linked list.
void * callback_cls
Closure for callback.
struct NotifyList * connect_notify_list_tail
Tail of linked list of functions to call on connects by clients.
handle for a client of the server
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
Here is the caller graph for this function:

◆ GNUNET_SERVER_disconnect_notify_cancel()

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.

Parameters
serverthe server manageing the clients
callbackfunction to call on connect
callback_clsclosure for callback

Definition at line 1442 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::disconnect_notify_list_head, GNUNET_SERVER_Handle::disconnect_notify_list_tail, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, and NotifyList::next.

1446 {
1447  struct NotifyList *pos;
1448 
1449  for (pos = server->disconnect_notify_list_head; NULL != pos; pos = pos->next)
1450  if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1451  break;
1452  if (NULL == pos)
1453  {
1454  GNUNET_break (0);
1455  return;
1456  }
1459  pos);
1460  GNUNET_free (pos);
1461 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
List of arrays of message handlers.
GNUNET_SERVER_DisconnectCallback callback
Function to call.
void * callback_cls
Closure for callback.
struct NotifyList * next
This is a doubly linked list.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
struct NotifyList * disconnect_notify_list_tail
Tail of linked list of functions to call on disconnects by clients.
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_SERVER_connect_notify_cancel()

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.

Parameters
serverthe server manageing the clients
callbackfunction to call on disconnect
callback_clsclosure for callback

Definition at line 1472 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::connect_notify_list_head, GNUNET_SERVER_Handle::connect_notify_list_tail, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_free, and NotifyList::next.

1475 {
1476  struct NotifyList *pos;
1477 
1478  for (pos = server->connect_notify_list_head; NULL != pos; pos = pos->next)
1479  if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1480  break;
1481  if (NULL == pos)
1482  {
1483  GNUNET_break (0);
1484  return;
1485  }
1487  server->connect_notify_list_tail,
1488  pos);
1489  GNUNET_free (pos);
1490 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct NotifyList * connect_notify_list_head
Head of linked list of functions to call on connects by clients.
List of arrays of message handlers.
GNUNET_SERVER_DisconnectCallback callback
Function to call.
void * callback_cls
Closure for callback.
struct NotifyList * next
This is a doubly linked list.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct NotifyList * connect_notify_list_tail
Tail of linked list of functions to call on connects by clients.
#define GNUNET_free(ptr)
Wrapper around free.

◆ GNUNET_SERVER_client_disconnect()

void GNUNET_SERVER_client_disconnect ( struct GNUNET_SERVER_Client client)

Ask the server to disconnect from the given client.

This is the same as returning GNUNET_SYSERR from a message handler, except that it allows dropping of a client even when not handling a message from that client.

Parameters
clientthe client to disconnect from

Definition at line 1502 of file tcp_server_legacy.c.

References NotifyList::callback, NotifyList::callback_cls, GNUNET_SERVER_Handle::clients_head, GNUNET_SERVER_Handle::clients_tail, GNUNET_SERVER_Client::connection, GNUNET_SERVER_TransmitHandle::cth, GNUNET_SERVER_Handle::disconnect_notify_list_head, GNUNET_CONNECTION_destroy(), GNUNET_CONNECTION_persist_(), GNUNET_CONNECTION_receive_cancel(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_mst_destroy(), GNUNET_SERVER_notify_transmit_ready_cancel(), GNUNET_YES, GNUNET_SERVER_Client::in_process_client_buffer, LOG, GNUNET_SERVER_Client::mst, GNUNET_SERVER_Handle::mst_cls, GNUNET_SERVER_Handle::mst_destroy, NotifyList::next, GNUNET_SERVER_Client::persist, GNUNET_SERVER_Client::receive_pending, GNUNET_SERVER_Client::reference_count, GNUNET_SERVER_Client::restart_task, GNUNET_SERVER_Client::server, GNUNET_SERVER_Client::shutdown_now, test_monitor_clients(), GNUNET_SERVER_Client::th, and GNUNET_SERVER_Client::warn_task.

Referenced by client_message_tokenizer_callback(), GNUNET_SERVER_client_drop(), GNUNET_SERVER_destroy(), GNUNET_SERVER_receive_done(), process_incoming(), process_mst(), and tcp_plugin_disconnect_session().

1503 {
1504  struct GNUNET_SERVER_Handle *server = client->server;
1505  struct NotifyList *n;
1506 
1508  "Client is being disconnected from the server.\n");
1509  if (NULL != client->restart_task)
1510  {
1512  client->restart_task = NULL;
1513  }
1514  if (NULL != client->warn_task)
1515  {
1517  client->warn_task = NULL;
1518  }
1519  if (GNUNET_YES == client->receive_pending)
1520  {
1522  client->receive_pending = GNUNET_NO;
1523  }
1524  client->shutdown_now = GNUNET_YES;
1525  client->reference_count++; /* make sure nobody else clean up client... */
1526  if ((NULL != client->mst) &&
1527  (NULL != server))
1528  {
1530  server->clients_tail,
1531  client);
1532  if (NULL != server->mst_destroy)
1533  server->mst_destroy (server->mst_cls,
1534  client->mst);
1535  else
1536  GNUNET_SERVER_mst_destroy (client->mst);
1537  client->mst = NULL;
1538  for (n = server->disconnect_notify_list_head; NULL != n; n = n->next)
1539  n->callback (n->callback_cls,
1540  client);
1541  }
1542  client->reference_count--;
1543  if (client->reference_count > 0)
1544  {
1546  "RC of %p still positive, not destroying everything.\n",
1547  client);
1548  client->server = NULL;
1549  return;
1550  }
1551  if (GNUNET_YES == client->in_process_client_buffer)
1552  {
1554  "Still processing inputs of %p, not destroying everything.\n",
1555  client);
1556  return;
1557  }
1559  "RC of %p now zero, destroying everything.\n",
1560  client);
1561  if (GNUNET_YES == client->persist)
1563  if (NULL != client->th.cth)
1566  /* need to cancel again, as it might have been re-added
1567  in the meantime (i.e. during callbacks) */
1568  if (NULL != client->warn_task)
1569  {
1571  client->warn_task = NULL;
1572  }
1573  if (GNUNET_YES == client->receive_pending)
1574  {
1576  client->receive_pending = GNUNET_NO;
1577  }
1578  GNUNET_free (client);
1579  /* we might be in soft-shutdown, test if we're done */
1580  if (NULL != server)
1581  test_monitor_clients (server);
1582 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection)
Set the persist option on this connection handle.
int in_process_client_buffer
Are we currently in the "process_client_buffer" function (and will hence restart the receive job on e...
List of arrays of message handlers.
struct GNUNET_SERVER_Client * clients_tail
Head of list of our current clients.
#define LOG(kind,...)
Definition: abd_api.c:38
GNUNET_SERVER_MstDestroyCallback mst_destroy
Alternative function to destroy a MST instance.
GNUNET_SERVER_DisconnectCallback callback
Function to call.
#define GNUNET_NO
Definition: gnunet_common.h:78
void * GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection)
Cancel receive job on the given connection.
void GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst)
Destroys a tokenizer.
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.
struct NotifyList * next
This is a doubly linked list.
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.
void GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th)
Abort transmission request.
struct NotifyList * disconnect_notify_list_head
Head of linked list of functions to call on disconnects by clients.
handle for a server
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
int shutdown_now
We&#39;re about to close down this client.
unsigned int reference_count
Number of external entities with a reference to this client object.
void GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
Close the connection and free associated resources.
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_SERVER_receive_done.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_SERVER_Client * clients_head
Head of list of our current clients.
static void test_monitor_clients(struct GNUNET_SERVER_Handle *server)
Check if only &#39;monitor&#39; clients are left.
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
void * mst_cls
Closure for &#39;mst_&#39;-callbacks.
void * mst
Processing of incoming data.
struct GNUNET_SCHEDULER_Task * restart_task
ID of task used to restart processing.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_disable_corking()

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 flush the buffer on transmission instead of potentially buffering multiple messages.

Parameters
clienthandle to the client
Returns
GNUNET_OK on success

Definition at line 1594 of file tcp_server_legacy.c.

References GNUNET_SERVER_Client::connection, and GNUNET_CONNECTION_disable_corking().

1595 {
1597 }
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_CONNECTION_Handle * connection
Client closure for callbacks.
Here is the call graph for this function:

◆ transmit_ready_callback_wrapper()

static size_t transmit_ready_callback_wrapper ( void *  cls,
size_t  size,
void *  buf 
)
static

Wrapper for transmission notification that calls the original callback and update the last activity time for our connection.

Parameters
clsthe struct GNUNET_SERVER_Client *
sizenumber of bytes we can transmit
bufwhere to copy the message
Returns
number of bytes actually transmitted

Definition at line 1610 of file tcp_server_legacy.c.

References GNUNET_SERVER_TransmitHandle::callback, GNUNET_SERVER_TransmitHandle::callback_cls, GNUNET_SERVER_TransmitHandle::cth, GNUNET_TIME_absolute_get(), GNUNET_SERVER_Client::last_activity, and GNUNET_SERVER_Client::th.

Referenced by GNUNET_SERVER_notify_transmit_ready().

1611 {
1612  struct GNUNET_SERVER_Client *client = cls;
1614 
1615  client->th.cth = NULL;
1616  callback = client->th.callback;
1617  client->th.callback = NULL;
1619  return callback (client->th.callback_cls, size, buf);
1620 }
struct GNUNET_TIME_Absolute last_activity
Last activity on this socket (used to time it out if reference_count == 0).
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...
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.
static char buf[2048]
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_CONNECTION_TransmitReadyNotify callback
Function to call to get the message.
void * callback_cls
Closure for callback.
handle for a client of the server
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_notify_transmit_ready()

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 client.

Parameters
clientclient to transmit message to
sizerequested amount of buffer space
timeoutafter how long should we give up (and call notify with buf NULL and size 0)?
callbackfunction to call when space is available
callback_clsclosure for callback
Returns
non-NULL if the notify callback was queued; can be used to cancel the request using GNUNET_SERVER_notify_transmit_ready_cancel(). NULL if we are already going to notify someone else (busy)

Definition at line 1639 of file tcp_server_legacy.c.

References GNUNET_SERVER_TransmitHandle::callback, GNUNET_SERVER_TransmitHandle::callback_cls, GNUNET_SERVER_Client::connection, GNUNET_SERVER_TransmitHandle::cth, GNUNET_CONNECTION_notify_transmit_ready(), GNUNET_SERVER_Client::th, and transmit_ready_callback_wrapper().

Referenced by handle_test(), and process_pending_messages().

1645 {
1646  if (NULL != client->th.callback)
1647  return NULL;
1648  client->th.callback_cls = callback_cls;
1649  client->th.callback = callback;
1651  size,
1652  timeout,
1653  &
1655  client);
1656  return &client->th;
1657 }
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.
struct GNUNET_CONNECTION_Handle * connection
Client closure for callbacks.
static unsigned int size
Size of the "table".
Definition: peer.c:67
GNUNET_CONNECTION_TransmitReadyNotify callback
Function to call to get the message.
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...
void * callback_cls
Closure for callback.
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...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_notify_transmit_ready_cancel()

void GNUNET_SERVER_notify_transmit_ready_cancel ( struct GNUNET_SERVER_TransmitHandle th)

Abort transmission request.

Parameters
threquest to abort

Definition at line 1666 of file tcp_server_legacy.c.

References GNUNET_SERVER_TransmitHandle::callback, GNUNET_SERVER_TransmitHandle::cth, and GNUNET_CONNECTION_notify_transmit_ready_cancel().

Referenced by GNUNET_SERVER_client_disconnect(), and tcp_plugin_disconnect_session().

1668 {
1670  th->cth = NULL;
1671  th->callback = NULL;
1672 }
void GNUNET_CONNECTION_notify_transmit_ready_cancel(struct GNUNET_CONNECTION_TransmitHandle *th)
Cancel the specified transmission-ready notification.
struct GNUNET_CONNECTION_TransmitHandle * cth
Active connection transmission handle.
GNUNET_CONNECTION_TransmitReadyNotify callback
Function to call to get the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_SERVER_client_persist_()

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 service it's connected to is actually dead.

Parameters
clientthe client to set the persistent flag on

Definition at line 1682 of file tcp_server_legacy.c.

References GNUNET_YES, and GNUNET_SERVER_Client::persist.

1683 {
1684  client->persist = GNUNET_YES;
1685 }
int persist
Persist the file handle for this client no matter what happens, force the OS to close once the proces...
#define GNUNET_YES
Definition: gnunet_common.h:77

◆ GNUNET_SERVER_receive_done()

void GNUNET_SERVER_receive_done ( struct GNUNET_SERVER_Client client,
int  success 
)

Resume receiving from this client, we are done processing the current request.

This function must be called from within each GNUNET_SERVER_MessageCallback (or its respective continuations).

Parameters
clientclient we were processing a message of
successGNUNET_OK to keep the connection open and continue to receive GNUNET_NO to close the connection (normal behavior) GNUNET_SYSERR to close the connection (signal serious error)

Definition at line 1701 of file tcp_server_legacy.c.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_SERVER_client_disconnect(), GNUNET_YES, GNUNET_SERVER_Client::in_process_client_buffer, LOG, GNUNET_SERVER_Client::reference_count, restart_processing(), GNUNET_SERVER_Client::restart_task, GNUNET_SERVER_Client::server, GNUNET_SERVER_Client::shutdown_now, GNUNET_SERVER_Client::suspended, and GNUNET_SERVER_Client::warn_task.

Referenced by delayed_done(), handle_tcp_data(), handle_tcp_nat_probe(), handle_tcp_welcome(), handle_test(), and write_test().

1703 {
1704  if (NULL == client)
1705  return;
1706  GNUNET_assert (client->suspended > 0);
1707  client->suspended--;
1708  if (GNUNET_OK != success)
1709  {
1711  "GNUNET_SERVER_receive_done called with failure indication\n");
1712  if ((client->reference_count > 0) || (client->suspended > 0))
1713  client->shutdown_now = GNUNET_YES;
1714  else
1716  return;
1717  }
1718  if (client->suspended > 0)
1719  {
1721  "GNUNET_SERVER_receive_done called, but more clients pending\n");
1722  return;
1723  }
1724  if (NULL != client->warn_task)
1725  {
1727  client->warn_task = NULL;
1728  }
1729  if (GNUNET_YES == client->in_process_client_buffer)
1730  {
1732  "GNUNET_SERVER_receive_done called while still in processing loop\n");
1733  return;
1734  }
1735  if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now))
1736  {
1738  return;
1739  }
1741  "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1742  GNUNET_assert (NULL == client->restart_task);
1744  client);
1745 }
int in_process_client_buffer
Are we currently in the "process_client_buffer" function (and will hence restart the receive job on e...
#define LOG(kind,...)
Definition: abd_api.c:38
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
Definition: scheduler.c:1280
int shutdown_now
We&#39;re about to close down this client.
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.
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns about missing calls to GNUNET_SERVER_receive_done.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_SERVER_Handle * server
Server that this client belongs to.
struct GNUNET_SCHEDULER_Task * restart_task
ID of task used to restart processing.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
unsigned int suspended
Was processing if incoming messages suspended while we were still processing data already received...
Here is the call graph for this function:
Here is the caller graph for this function: