GNUnet  0.11.x
Macros | Functions | Variables
gnunet-service-testbed-logger.c File Reference

service for collecting messages and writing to a file More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-service-testbed-logger.c:

Go to the source code of this file.

Macros

#define LOG(type, ...)   GNUNET_log (type, __VA_ARGS__)
 Generic logging shorthand. More...
 
#define LOG_DEBUG(...)   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 Debug logging shorthand. More...
 

Functions

static int check_log_msg (void *cls, const struct GNUNET_MessageHeader *msg)
 Check GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages. More...
 
static void handle_log_msg (void *cls, const struct GNUNET_MessageHeader *msg)
 Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages. More...
 
static void shutdown_task (void *cls)
 Task to clean up and shutdown nicely. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
 Callback called when a client connects to the service. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
 Callback called when a client disconnected from the service. More...
 
static void logger_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
 Testbed setup. More...
 
 GNUNET_SERVICE_MAIN ("testbed-logger", GNUNET_SERVICE_OPTION_NONE, &logger_run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(log_msg, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

struct GNUNET_BIO_WriteHandlebio
 Handle for buffered writing. More...
 
static unsigned int nconn
 The number of connections we have. More...
 
static int in_shutdown
 Are we shutting down? More...
 

Detailed Description

service for collecting messages and writing to a file

Author
Sree Harsha Totakura

Definition in file gnunet-service-testbed-logger.c.

Macro Definition Documentation

◆ LOG

#define LOG (   type,
  ... 
)    GNUNET_log (type, __VA_ARGS__)

Generic logging shorthand.

Definition at line 33 of file gnunet-service-testbed-logger.c.

Referenced by logger_run().

◆ LOG_DEBUG

#define LOG_DEBUG (   ...)    LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)

Debug logging shorthand.

Definition at line 39 of file gnunet-service-testbed-logger.c.

Referenced by logger_run().

Function Documentation

◆ check_log_msg()

static int check_log_msg ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Check GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages.

Parameters
clsclient identification of the client
msgthe actual message
Returns
GNUNET_OK (they are all always OK)

Definition at line 66 of file gnunet-service-testbed-logger.c.

References GNUNET_OK.

68 {
69  return GNUNET_OK;
70 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75

◆ handle_log_msg()

static void handle_log_msg ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Message handler for GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages.

Parameters
clsclient identification of the client
msgthe actual message

Definition at line 80 of file gnunet-service-testbed-logger.c.

References GNUNET_BIO_write(), GNUNET_SERVICE_client_continue(), and GNUNET_MessageHeader::size.

82 {
83  struct GNUNET_SERVICE_Client *client = cls;
84  uint16_t ms;
85 
86  ms = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader);
88  &msg[1],
89  ms);
91 }
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Handle to a client that is connected to a service.
Definition: service.c:250
struct GNUNET_BIO_WriteHandle * bio
Handle for buffered writing.
Header for all communications.
int GNUNET_BIO_write(struct GNUNET_BIO_WriteHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: bio.c:483
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
Here is the call graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task to clean up and shutdown nicely.

Parameters
clsNULL

Definition at line 100 of file gnunet-service-testbed-logger.c.

References GNUNET_BIO_write_close(), GNUNET_break, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_YES, in_shutdown, and nconn.

Referenced by logger_run().

101 {
103  if (0 != nconn)
104  {
105  /* Delay shutdown if there are active connections */
107  NULL);
108  return;
109  }
112 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void shutdown_task(void *cls)
Task to clean up and shutdown nicely.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_BIO_WriteHandle * bio
Handle for buffered writing.
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:438
#define GNUNET_YES
Definition: gnunet_common.h:77
static int in_shutdown
Are we shutting down?
static unsigned int nconn
The number of connections we have.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
struct GNUNET_MQ_Handle mq 
)
static

Callback called when a client connects to the service.

Parameters
clsclosure for the service
cthe new client that connected to the service
mqthe message queue used to send messages to the client
Returns
c

Definition at line 124 of file gnunet-service-testbed-logger.c.

References GNUNET_SERVICE_client_persist(), and nconn.

Referenced by logger_run().

127 {
128  /* FIXME: is this really what we want here? */
130  nconn++;
131  return c;
132 }
void GNUNET_SERVICE_client_persist(struct GNUNET_SERVICE_Client *c)
Set the persist option on this client.
Definition: service.c:2424
static unsigned int nconn
The number of connections we have.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
void *  internal_cls 
)
static

Callback called when a client disconnected from the service.

Parameters
clsclosure for the service
cthe client that disconnected
internal_clsshould be equal to c

Definition at line 143 of file gnunet-service-testbed-logger.c.

References GNUNET_assert, GNUNET_SCHEDULER_shutdown(), GNUNET_YES, in_shutdown, and nconn.

Referenced by logger_run().

146 {
147  nconn--;
148  if (GNUNET_YES == in_shutdown)
150  GNUNET_assert (c == internal_cls);
151 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
#define GNUNET_YES
Definition: gnunet_common.h:77
static int in_shutdown
Are we shutting down?
static unsigned int nconn
The number of connections we have.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ logger_run()

static void logger_run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg,
struct GNUNET_SERVICE_Handle service 
)
static

Testbed setup.

Parameters
clsclosure
cfgconfiguration to use
servicethe initialized service

Definition at line 162 of file gnunet-service-testbed-logger.c.

References client_connect_cb(), client_disconnect_cb(), dir, fn, GNUNET_asprintf(), GNUNET_BIO_write_open(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log_config_missing(), GNUNET_malloc, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_OK, GNUNET_OS_get_hostname_max_length, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, LOG, LOG_DEBUG, pid, and shutdown_task().

165 {
166  char *dir;
167  char *fn;
168  char *hname;
169  size_t hname_len;
170  pid_t pid;
171 
172  if (GNUNET_OK !=
174  "TESTBED-LOGGER",
175  "DIR",
176  &dir))
177  {
179  "TESTBED-LOGGER",
180  "DIR");
182  return;
183  }
184  pid = getpid ();
185  hname_len = GNUNET_OS_get_hostname_max_length ();
186  hname = GNUNET_malloc (hname_len);
187  if (0 != gethostname (hname,
188  hname_len))
189  {
191  "Cannot get hostname. Exiting\n");
192  GNUNET_free (hname);
193  GNUNET_free (dir);
195  return;
196  }
197  GNUNET_asprintf (&fn,
198  "%s/%.*s_%jd.dat",
199  dir,
200  hname_len,
201  hname,
202  (intmax_t) pid);
203  GNUNET_free (hname);
204  GNUNET_free (dir);
205  if (NULL == (bio = GNUNET_BIO_write_open (fn)))
206  {
207  GNUNET_free (fn);
209  return;
210  }
211  GNUNET_free (fn);
213  NULL);
214  LOG_DEBUG ("TESTBED-LOGGER startup complete\n");
215 }
static char * dir
Set to the directory where runtime files are stored.
Definition: gnunet-arm.c:89
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
#define LOG_DEBUG(...)
Debug logging shorthand.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void shutdown_task(void *cls)
Task to clean up and shutdown nicely.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_OS_get_hostname_max_length()
Get maximum string length returned by gethostname()
static char * fn
Filename of the unique file.
#define LOG(type,...)
Generic logging shorthand.
struct GNUNET_BIO_WriteHandle * bio
Handle for buffered writing.
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:410
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( "testbed-logger"  ,
GNUNET_SERVICE_OPTION_NONE  ,
logger_run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_var_size(log_msg, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, struct GNUNET_MessageHeader, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Referenced by logger_run().

Here is the caller graph for this function:

Variable Documentation

◆ bio

Handle for buffered writing.

Definition at line 45 of file gnunet-service-testbed-logger.c.

◆ nconn

unsigned int nconn
static

The number of connections we have.

Definition at line 50 of file gnunet-service-testbed-logger.c.

Referenced by client_connect_cb(), client_disconnect_cb(), and shutdown_task().

◆ in_shutdown

int in_shutdown
static

Are we shutting down?

Definition at line 55 of file gnunet-service-testbed-logger.c.

Referenced by client_disconnect_cb(), and shutdown_task().