GNUnet  0.10.x
Typedefs | Functions
Helper library

Dealing with SUID helper processes. More...

Typedefs

typedef void(* GNUNET_HELPER_ExceptionCallback) (void *cls)
 Callback that will be called when the helper process dies. More...
 
typedef void(* GNUNET_HELPER_Continuation) (void *cls, int result)
 Continuation function. More...
 

Functions

struct GNUNET_HELPER_HandleGNUNET_HELPER_start (int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
 Starts a helper and begins reading from it. More...
 
int GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h, int soft_kill)
 Sends termination signal to the helper process. More...
 
int GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
 Reap the helper process. More...
 
void GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
 Free's the resources occupied by the helper handle. More...
 
void GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h, int soft_kill)
 Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process. More...
 
struct GNUNET_HELPER_SendHandleGNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
 Send an message to the helper. More...
 
void GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh)
 Cancel a GNUNET_HELPER_send operation. More...
 

Detailed Description

Dealing with SUID helper processes.

Provides an API for dealing with (SUID) helper processes that communicate via GNUNET_MessageHeaders on STDIN/STDOUT.

Typedef Documentation

◆ GNUNET_HELPER_ExceptionCallback

typedef void(* GNUNET_HELPER_ExceptionCallback) (void *cls)

Callback that will be called when the helper process dies.

This is not called when the helper process is stoped using GNUNET_HELPER_stop()

Parameters
clsthe closure from GNUNET_HELPER_start()

Definition at line 57 of file gnunet_helper_lib.h.

◆ GNUNET_HELPER_Continuation

typedef void(* GNUNET_HELPER_Continuation) (void *cls, int result)

Continuation function.

Parameters
clsclosure
resultGNUNET_OK on success, GNUNET_NO if helper process died GNUNET_SYSERR during GNUNET_HELPER_destroy

Definition at line 139 of file gnunet_helper_lib.h.

Function Documentation

◆ GNUNET_HELPER_start()

struct GNUNET_HELPER_Handle* GNUNET_HELPER_start ( int  with_control_pipe,
const char *  binary_name,
char *const  binary_argv[],
GNUNET_MessageTokenizerCallback  cb,
GNUNET_HELPER_ExceptionCallback  exp_cb,
void *  cb_cls 
)

Starts a helper and begins reading from it.

The helper process is restarted when it dies except when it is stopped using GNUNET_HELPER_stop() or when the exp_cb callback is not NULL.

Parameters
with_control_pipedoes the helper support the use of a control pipe for signalling?
binary_namename of the binary to run
binary_argvNULL-terminated list of arguments to give when starting the binary (this argument must not be modified by the client for the lifetime of the helper handle)
cbfunction to call if we get messages from the helper
exp_cbthe exception callback to call. Set this to NULL if the helper process has to be restarted automatically when it dies/crashes
cb_clsclosure for the above callbacks
Returns
the new Handle, NULL on error

The helper process is restarted when it dies except when it is stopped using GNUNET_HELPER_stop() or when the exp_cb callback is not NULL.

Parameters
with_control_pipedoes the helper support the use of a control pipe for signalling?
binary_namename of the binary to run
binary_argvNULL-terminated list of arguments to give when starting the binary (this argument must not be modified by the client for the lifetime of the helper handle)
cbfunction to call if we get messages from the helper
exp_cbthe exception callback to call. Set this to NULL if the helper process has to be restarted automatically when it dies/crashes
cb_clsclosure for the above callback
Returns
the new Handle, NULL on error

Definition at line 491 of file helper.c.

References GNUNET_HELPER_Handle::binary_argv, GNUNET_HELPER_Handle::binary_name, GNUNET_HELPER_Handle::cb_cls, GNUNET_HELPER_Handle::exp_cb, GNUNET_malloc, GNUNET_MST_create(), GNUNET_new, GNUNET_OS_get_libexec_binary_path(), GNUNET_strdup, GNUNET_HELPER_SendHandle::h, GNUNET_HELPER_Handle::mst, GNUNET_HELPER_Handle::retry_back_off, start_helper(), and GNUNET_HELPER_Handle::with_control_pipe.

Referenced by enable(), GNUNET_FS_directory_scan_start(), GNUNET_TESTBED_controller_start(), LIBGNUNET_PLUGIN_TRANSPORT_INIT(), and run().

497 {
498  struct GNUNET_HELPER_Handle *h;
499  unsigned int c;
500 
501  h = GNUNET_new (struct GNUNET_HELPER_Handle);
503  /* Lookup in libexec path only if we are starting gnunet helpers */
504  if (NULL != strstr (binary_name, "gnunet"))
506  else
508  for (c = 0; NULL != binary_argv[c]; c++);
509  h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1));
510  for (c = 0; NULL != binary_argv[c]; c++)
512  h->binary_argv[c] = NULL;
513  h->cb_cls = cb_cls;
514  if (NULL != cb)
515  h->mst = GNUNET_MST_create (cb,
516  h->cb_cls);
517  h->exp_cb = exp_cb;
518  h->retry_back_off = 0;
519  start_helper (h);
520  return h;
521 }
The handle to a helper process.
Definition: helper.c:80
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int with_control_pipe
Does the helper support the use of a control pipe for signalling?
Definition: helper.c:161
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
unsigned int retry_back_off
Count start attempts to increase linear back off.
Definition: helper.c:166
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:87
char * binary_name
Binary to run.
Definition: helper.c:136
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
Definition: helper.c:116
char ** binary_argv
NULL-terminated list of command-line arguments.
Definition: helper.c:141
void * cb_cls
The closure for callbacks.
Definition: helper.c:121
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:111
static void start_helper(struct GNUNET_HELPER_Handle *h)
Start the helper process.
Definition: helper.c:410
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELPER_kill()

int GNUNET_HELPER_kill ( struct GNUNET_HELPER_Handle h,
int  soft_kill 
)

Sends termination signal to the helper process.

The helper process is not reaped; call GNUNET_HELPER_wait() for reaping the dead helper process.

Parameters
hthe helper handle
soft_killif GNUNET_YES, signals termination by closing the helper's stdin; GNUNET_NO to signal termination by sending SIGTERM to helper
Returns
GNUNET_OK on success; GNUNET_SYSERR on error

The helper process is not reaped; call GNUNET_HELPER_wait() for reaping the dead helper process.

Parameters
hthe helper handle
soft_killif GNUNET_YES, signals termination by closing the helper's stdin; GNUNET_NO to signal termination by sending SIGTERM to helper
Returns
GNUNET_OK on success; GNUNET_SYSERR on error

Definition at line 180 of file helper.c.

References GNUNET_HELPER_SendHandle::cont, GNUNET_HELPER_SendHandle::cont_cls, GNUNET_HELPER_Handle::fh_to_helper, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_OS_process_kill(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TERM_SIG, GNUNET_YES, GNUNET_HELPER_Handle::helper_in, GNUNET_HELPER_Handle::helper_proc, GNUNET_HELPER_Handle::read_task, GNUNET_HELPER_Handle::restart_task, ret, sh, GNUNET_HELPER_Handle::sh_head, and GNUNET_HELPER_Handle::sh_tail.

Referenced by cleanup(), disable(), GNUNET_TESTBED_controller_kill_(), and stop_helper().

182 {
184  int ret;
185 
186  while (NULL != (sh = h->sh_head))
187  {
189  h->sh_tail,
190  sh);
191  if (NULL != sh->cont)
192  sh->cont (sh->cont_cls, GNUNET_NO);
193  GNUNET_free (sh);
194  }
195  if (NULL != h->restart_task)
196  {
198  h->restart_task = NULL;
199  }
200  if (NULL != h->read_task)
201  {
203  h->read_task = NULL;
204  }
205  if (NULL == h->helper_proc)
206  return GNUNET_SYSERR;
207  if (GNUNET_YES == soft_kill)
208  {
209  /* soft-kill only possible with pipes */
210  GNUNET_assert (NULL != h->helper_in);
212  h->helper_in = NULL;
213  h->fh_to_helper = NULL;
214  return ret;
215  }
217  return GNUNET_SYSERR;
218  return GNUNET_OK;
219 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const struct GNUNET_DISK_FileHandle * fh_to_helper
FileHandle to send data to the helper.
Definition: helper.c:101
struct GNUNET_SCHEDULER_Task * restart_task
Restart task.
Definition: helper.c:156
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:131
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:146
static struct SolverHandle * sh
struct GNUNET_DISK_PipeHandle * helper_in
PipeHandle to receive data from the helper.
Definition: helper.c:86
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:126
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
struct GNUNET_OS_Process * helper_proc
The process id of the helper.
Definition: helper.c:106
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:282
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:62
void * cont_cls
Closure to 'cont'.
Definition: helper.c:67
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:251
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELPER_wait()

int GNUNET_HELPER_wait ( struct GNUNET_HELPER_Handle h)

Reap the helper process.

This call is blocking (!). The helper process should either be sent a termination signal before or should be dead before calling this function

Parameters
hthe helper handle
Returns
GNUNET_OK on success; GNUNET_SYSERR on error

This call is blocking(!). The helper process should either be sent a termination signal before or should be dead before calling this function

Parameters
hthe helper handle
Returns
GNUNET_OK on success; GNUNET_SYSERR on error

Definition at line 231 of file helper.c.

References GNUNET_HELPER_SendHandle::cont, GNUNET_HELPER_SendHandle::cont_cls, GNUNET_HELPER_Handle::fh_from_helper, GNUNET_HELPER_Handle::fh_to_helper, GNUNET_CONTAINER_DLL_remove, GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_OS_process_destroy(), GNUNET_OS_process_wait(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_YES, GNUNET_HELPER_Handle::helper_in, GNUNET_HELPER_Handle::helper_out, GNUNET_HELPER_Handle::helper_proc, GNUNET_HELPER_Handle::mst, GNUNET_HELPER_Handle::read_task, ret, sh, GNUNET_HELPER_Handle::sh_head, GNUNET_HELPER_Handle::sh_tail, and GNUNET_HELPER_Handle::write_task.

Referenced by cleanup(), GNUNET_TESTBED_controller_destroy_(), and stop_helper().

232 {
234  int ret;
235 
236  ret = GNUNET_SYSERR;
237  if (NULL != h->helper_proc)
238  {
241  h->helper_proc = NULL;
242  }
243  if (NULL != h->read_task)
244  {
246  h->read_task = NULL;
247  }
248  if (NULL != h->write_task)
249  {
251  h->write_task = NULL;
252  }
253  if (NULL != h->helper_in)
254  {
256  h->helper_in = NULL;
257  h->fh_to_helper = NULL;
258  }
259  if (NULL != h->helper_out)
260  {
262  h->helper_out = NULL;
263  h->fh_from_helper = NULL;
264  }
265  while (NULL != (sh = h->sh_head))
266  {
268  h->sh_tail,
269  sh);
270  if (NULL != sh->cont)
271  sh->cont (sh->cont_cls, GNUNET_NO);
272  GNUNET_free (sh);
273  }
274  /* purge MST buffer */
275  if (NULL != h->mst)
276  (void) GNUNET_MST_from_buffer (h->mst,
277  NULL, 0,
278  GNUNET_YES,
279  GNUNET_NO);
280  return ret;
281 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const struct GNUNET_DISK_FileHandle * fh_to_helper
FileHandle to send data to the helper.
Definition: helper.c:101
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:364
struct GNUNET_DISK_PipeHandle * helper_out
PipeHandle to send data to the helper.
Definition: helper.c:91
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:131
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:146
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:151
static struct SolverHandle * sh
struct GNUNET_DISK_PipeHandle * helper_in
PipeHandle to receive data from the helper.
Definition: helper.c:86
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, 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.
Definition: mst.c:116
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:126
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:111
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:2603
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1762
struct GNUNET_OS_Process * helper_proc
The process id of the helper.
Definition: helper.c:106
#define GNUNET_YES
Definition: gnunet_common.h:80
const struct GNUNET_DISK_FileHandle * fh_from_helper
FileHandle to receive data from the helper.
Definition: helper.c:96
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:62
void * cont_cls
Closure to 'cont'.
Definition: helper.c:67
#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:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELPER_destroy()

void GNUNET_HELPER_destroy ( struct GNUNET_HELPER_Handle h)

Free's the resources occupied by the helper handle.

Parameters
hthe helper handle to free

Definition at line 530 of file helper.c.

References GNUNET_HELPER_Handle::binary_argv, GNUNET_HELPER_Handle::binary_name, GNUNET_HELPER_SendHandle::cont, GNUNET_HELPER_SendHandle::cont_cls, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MST_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_HELPER_Handle::mst, GNUNET_HELPER_Handle::read_task, GNUNET_HELPER_Handle::restart_task, sh, GNUNET_HELPER_Handle::sh_head, GNUNET_HELPER_Handle::sh_tail, and GNUNET_HELPER_Handle::write_task.

Referenced by disable(), GNUNET_HELPER_stop(), and GNUNET_TESTBED_controller_destroy_().

531 {
532  unsigned int c;
534 
535  if (NULL != h->write_task)
536  {
538  h->write_task = NULL;
539  }
540  GNUNET_assert (NULL == h->read_task);
541  GNUNET_assert (NULL == h->restart_task);
542  while (NULL != (sh = h->sh_head))
543  {
545  h->sh_tail,
546  sh);
547  if (NULL != sh->cont)
548  sh->cont (sh->cont_cls, GNUNET_SYSERR);
549  GNUNET_free (sh);
550  }
551  if (NULL != h->mst)
552  GNUNET_MST_destroy (h->mst);
554  for (c = 0; h->binary_argv[c] != NULL; c++)
555  GNUNET_free (h->binary_argv[c]);
557  GNUNET_free (h);
558 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_SCHEDULER_Task * restart_task
Restart task.
Definition: helper.c:156
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:131
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:146
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:151
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
static struct SolverHandle * sh
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:126
char * binary_name
Binary to run.
Definition: helper.c:136
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
char ** binary_argv
NULL-terminated list of command-line arguments.
Definition: helper.c:141
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:111
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:62
void * cont_cls
Closure to 'cont'.
Definition: helper.c:67
#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:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELPER_stop()

void GNUNET_HELPER_stop ( struct GNUNET_HELPER_Handle h,
int  soft_kill 
)

Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process.

Parameters
hhandle to helper to stop
soft_killif GNUNET_YES, signals termination by closing the helper's stdin; GNUNET_NO to signal termination by sending SIGTERM to helper

Kills the helper, closes the pipe, frees the handle and calls wait() on the helper process.

Parameters
hhandle to helper to stop
soft_killif GNUNET_YES, signals termination by closing the helper's stdin; GNUNET_NO to signal termination by sending SIGTERM to helper

Definition at line 569 of file helper.c.

References GNUNET_HELPER_Handle::exp_cb, GNUNET_HELPER_destroy(), and stop_helper().

Referenced by cleanup(), cleanup_task(), do_stop_task(), finish_scan(), GNUNET_FS_directory_scan_abort(), helper_read(), helper_write(), and LIBGNUNET_PLUGIN_TRANSPORT_DONE().

571 {
572  h->exp_cb = NULL;
573  stop_helper (h, soft_kill);
575 }
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
Definition: helper.c:116
static void stop_helper(struct GNUNET_HELPER_Handle *h, int soft_kill)
Stop the helper process, we're closing down or had an error.
Definition: helper.c:292
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:530
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELPER_send()

struct GNUNET_HELPER_SendHandle* GNUNET_HELPER_send ( struct GNUNET_HELPER_Handle h,
const struct GNUNET_MessageHeader msg,
int  can_drop,
GNUNET_HELPER_Continuation  cont,
void *  cont_cls 
)

Send an message to the helper.

Parameters
hhelper to send message to
msgmessage to send
can_dropcan the message be dropped if there is already one in the queue?
contcontinuation to run once the message is out (GNUNET_OK on succees, GNUNET_NO if the helper process died, GNUNET_SYSERR during GNUNET_HELPER_destroy).
cont_clsclosure for cont
Returns
NULL if the message was dropped, otherwise handle to cancel cont (actual transmission may not be abortable)
Parameters
hhelper to send message to
msgmessage to send
can_dropcan the message be dropped if there is already one in the queue?
contcontinuation to run once the message is out (GNUNET_OK on succees, GNUNET_NO if the helper process died, GNUNET_SYSERR during GNUNET_HELPER_destroy).
cont_clsclosure for cont
Returns
NULL if the message was dropped, otherwise handle to cancel cont (actual transmission may not be abortable)

Definition at line 660 of file helper.c.

References GNUNET_HELPER_SendHandle::cont, GNUNET_HELPER_SendHandle::cont_cls, GNUNET_HELPER_Handle::fh_to_helper, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_malloc, GNUNET_memcpy, GNUNET_SCHEDULER_add_write_file(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GNUNET_HELPER_SendHandle::h, helper_write(), GNUNET_HELPER_SendHandle::msg, sh, GNUNET_HELPER_Handle::sh_head, GNUNET_HELPER_Handle::sh_tail, GNUNET_MessageHeader::size, and GNUNET_HELPER_Handle::write_task.

Referenced by GNUNET_TESTBED_controller_start(), handle_icmp_back(), handle_tcp_back(), handle_udp_back(), play(), request_done(), send_ack(), send_hello_beacon(), send_icmp_packet_via_tun(), send_tcp_packet_via_tun(), send_udp_packet_via_tun(), and transmit_fragment().

665 {
667  uint16_t mlen;
668 
669  if (NULL == h->fh_to_helper)
670  return NULL;
671  if ( (GNUNET_YES == can_drop) &&
672  (NULL != h->sh_head) )
673  return NULL;
674  mlen = ntohs (msg->size);
675  sh = GNUNET_malloc (sizeof (struct GNUNET_HELPER_SendHandle) + mlen);
676  sh->msg = (const struct GNUNET_MessageHeader*) &sh[1];
677  GNUNET_memcpy (&sh[1], msg, mlen);
678  sh->h = h;
679  sh->cont = cont;
680  sh->cont_cls = cont_cls;
682  h->sh_tail,
683  sh);
684  if (NULL == h->write_task)
686  h->fh_to_helper,
687  &helper_write,
688  h);
689 
690  return sh;
691 }
const struct GNUNET_DISK_FileHandle * fh_to_helper
FileHandle to send data to the helper.
Definition: helper.c:101
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1675
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:131
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:151
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
Definition: helper.c:57
#define GNUNET_memcpy(dst, src, n)
static struct SolverHandle * sh
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:126
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_malloc(size)
Wrapper around malloc.
const struct GNUNET_MessageHeader * msg
Message to transmit (allocated at the end of this struct)
Definition: helper.c:52
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:62
static void helper_write(void *cls)
Write to the helper-process.
Definition: helper.c:584
void * cont_cls
Closure to 'cont'.
Definition: helper.c:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_HELPER_send_cancel()

void GNUNET_HELPER_send_cancel ( struct GNUNET_HELPER_SendHandle sh)

Cancel a GNUNET_HELPER_send operation.

If possible, transmitting the message is also aborted, but at least 'cont' won't be called.

Parameters
shoperation to cancel

Definition at line 701 of file helper.c.

References GNUNET_HELPER_SendHandle::cont, GNUNET_HELPER_SendHandle::cont_cls, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_HELPER_SendHandle::h, GNUNET_HELPER_Handle::sh_head, GNUNET_HELPER_Handle::sh_tail, GNUNET_HELPER_SendHandle::wpos, and GNUNET_HELPER_Handle::write_task.

Referenced by free_fragment_message(), and GNUNET_TESTBED_controller_kill_().

702 {
703  struct GNUNET_HELPER_Handle *h = sh->h;
704 
705  sh->cont = NULL;
706  sh->cont_cls = NULL;
707  if (0 == sh->wpos)
708  {
710  GNUNET_free (sh);
711  if (NULL == h->sh_head)
712  {
714  h->write_task = NULL;
715  }
716  }
717 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
The handle to a helper process.
Definition: helper.c:80
unsigned int wpos
Current write position.
Definition: helper.c:72
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:131
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:151
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
Definition: helper.c:57
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:126
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:62
void * cont_cls
Closure to 'cont'.
Definition: helper.c:67
#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:965
Here is the call graph for this function:
Here is the caller graph for this function: