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 487 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().

493 {
494  struct GNUNET_HELPER_Handle *h;
495  unsigned int c;
496 
497  h = GNUNET_new(struct GNUNET_HELPER_Handle);
499  /* Lookup in libexec path only if we are starting gnunet helpers */
500  if (NULL != strstr(binary_name, "gnunet"))
502  else
504  for (c = 0; NULL != binary_argv[c]; c++)
505  ;
506  h->binary_argv = GNUNET_malloc(sizeof(char *) * (c + 1));
507  for (c = 0; NULL != binary_argv[c]; c++)
509  h->binary_argv[c] = NULL;
510  h->cb_cls = cb_cls;
511  if (NULL != cb)
512  h->mst = GNUNET_MST_create(cb, h->cb_cls);
513  h->exp_cb = exp_cb;
514  h->retry_back_off = 0;
515  start_helper(h);
516  return h;
517 }
The handle to a helper process.
Definition: helper.c:77
#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:156
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:161
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:84
char * binary_name
Binary to run.
Definition: helper.c:131
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
Definition: helper.c:111
char ** binary_argv
NULL-terminated list of command-line arguments.
Definition: helper.c:136
void * cb_cls
The closure for callbacks.
Definition: helper.c:116
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:106
static void start_helper(struct GNUNET_HELPER_Handle *h)
Start the helper process.
Definition: helper.c:399
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 175 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().

176 {
178  int ret;
179 
180  while (NULL != (sh = h->sh_head))
181  {
183  if (NULL != sh->cont)
184  sh->cont(sh->cont_cls, GNUNET_NO);
185  GNUNET_free(sh);
186  }
187  if (NULL != h->restart_task)
188  {
190  h->restart_task = NULL;
191  }
192  if (NULL != h->read_task)
193  {
195  h->read_task = NULL;
196  }
197  if (NULL == h->helper_proc)
198  return GNUNET_SYSERR;
199  if (GNUNET_YES == soft_kill)
200  {
201  /* soft-kill only possible with pipes */
202  GNUNET_assert(NULL != h->helper_in);
204  h->helper_in = NULL;
205  h->fh_to_helper = NULL;
206  return ret;
207  }
209  return GNUNET_SYSERR;
210  return GNUNET_OK;
211 }
#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:96
struct GNUNET_SCHEDULER_Task * restart_task
Restart task.
Definition: helper.c:151
#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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:126
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:141
static struct SolverHandle * sh
struct GNUNET_DISK_PipeHandle * helper_in
PipeHandle to receive data from the helper.
Definition: helper.c:81
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:121
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1706
struct GNUNET_OS_Process * helper_proc
The process id of the helper.
Definition: helper.c:101
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:242
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:60
void * cont_cls
Closure to 'cont'.
Definition: helper.c:65
#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:224
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 223 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().

224 {
226  int ret;
227 
228  ret = GNUNET_SYSERR;
229  if (NULL != h->helper_proc)
230  {
233  h->helper_proc = NULL;
234  }
235  if (NULL != h->read_task)
236  {
238  h->read_task = NULL;
239  }
240  if (NULL != h->write_task)
241  {
243  h->write_task = NULL;
244  }
245  if (NULL != h->helper_in)
246  {
248  h->helper_in = NULL;
249  h->fh_to_helper = NULL;
250  }
251  if (NULL != h->helper_out)
252  {
254  h->helper_out = NULL;
255  h->fh_from_helper = NULL;
256  }
257  while (NULL != (sh = h->sh_head))
258  {
260  if (NULL != sh->cont)
261  sh->cont(sh->cont_cls, GNUNET_NO);
262  GNUNET_free(sh);
263  }
264  /* purge MST buffer */
265  if (NULL != h->mst)
266  (void)GNUNET_MST_from_buffer(h->mst, NULL, 0, GNUNET_YES, GNUNET_NO);
267  return ret;
268 }
#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:96
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:286
struct GNUNET_DISK_PipeHandle * helper_out
PipeHandle to send data to the helper.
Definition: helper.c:86
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:126
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:141
struct GNUNET_SCHEDULER_Task * write_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:81
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:113
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:121
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:106
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1706
int GNUNET_OS_process_wait(struct GNUNET_OS_Process *proc)
Wait for a process to terminate.
Definition: os_priority.c:1000
struct GNUNET_OS_Process * helper_proc
The process id of the helper.
Definition: helper.c:101
#define GNUNET_YES
Definition: gnunet_common.h:77
const struct GNUNET_DISK_FileHandle * fh_from_helper
FileHandle to receive data from the helper.
Definition: helper.c:91
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:60
void * cont_cls
Closure to 'cont'.
Definition: helper.c:65
#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:956
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 526 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_().

527 {
528  unsigned int c;
530 
531  if (NULL != h->write_task)
532  {
534  h->write_task = NULL;
535  }
536  GNUNET_assert(NULL == h->read_task);
537  GNUNET_assert(NULL == h->restart_task);
538  while (NULL != (sh = h->sh_head))
539  {
541  if (NULL != sh->cont)
542  sh->cont(sh->cont_cls, GNUNET_SYSERR);
543  GNUNET_free(sh);
544  }
545  if (NULL != h->mst)
548  for (c = 0; h->binary_argv[c] != NULL; c++)
549  GNUNET_free(h->binary_argv[c]);
551  GNUNET_free(h);
552 }
#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:151
#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:126
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:141
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:146
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:410
static struct SolverHandle * sh
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:121
char * binary_name
Binary to run.
Definition: helper.c:131
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
char ** binary_argv
NULL-terminated list of command-line arguments.
Definition: helper.c:136
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:106
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:60
void * cont_cls
Closure to 'cont'.
Definition: helper.c:65
#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:956
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 563 of file helper.c.

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

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

564 {
565  h->exp_cb = NULL;
566  stop_helper(h, soft_kill);
568 }
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
Definition: helper.c:111
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:279
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:526
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 653 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().

658 {
660  uint16_t mlen;
661 
662  if (NULL == h->fh_to_helper)
663  return NULL;
664  if ((GNUNET_YES == can_drop) && (NULL != h->sh_head))
665  return NULL;
666  mlen = ntohs(msg->size);
667  sh = GNUNET_malloc(sizeof(struct GNUNET_HELPER_SendHandle) + mlen);
668  sh->msg = (const struct GNUNET_MessageHeader *)&sh[1];
669  GNUNET_memcpy(&sh[1], msg, mlen);
670  sh->h = h;
671  sh->cont = cont;
672  sh->cont_cls = cont_cls;
674  if (NULL == h->write_task)
675  h->write_task =
677  h->fh_to_helper,
678  &helper_write,
679  h);
680 
681  return sh;
682 }
const struct GNUNET_DISK_FileHandle * fh_to_helper
FileHandle to send data to the helper.
Definition: helper.c:96
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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:1647
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:126
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:146
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
Definition: helper.c:55
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:121
#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:77
#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:50
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:60
static void helper_write(void *cls)
Write to the helper-process.
Definition: helper.c:577
void * cont_cls
Closure to 'cont'.
Definition: helper.c:65
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 692 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_().

693 {
694  struct GNUNET_HELPER_Handle *h = sh->h;
695 
696  sh->cont = NULL;
697  sh->cont_cls = NULL;
698  if (0 == sh->wpos)
699  {
701  GNUNET_free(sh);
702  if (NULL == h->sh_head)
703  {
705  h->write_task = NULL;
706  }
707  }
708 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
The handle to a helper process.
Definition: helper.c:77
unsigned int wpos
Current write position.
Definition: helper.c:70
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:126
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:146
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
Definition: helper.c:55
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:121
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:60
void * cont_cls
Closure to 'cont'.
Definition: helper.c:65
#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:956
Here is the call graph for this function:
Here is the caller graph for this function: