GNUnet  0.11.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 489 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().

495 {
496  struct GNUNET_HELPER_Handle *h;
497  unsigned int c;
498 
499  h = GNUNET_new (struct GNUNET_HELPER_Handle);
501  /* Lookup in libexec path only if we are starting gnunet helpers */
502  if (NULL != strstr (binary_name, "gnunet"))
504  else
506  for (c = 0; NULL != binary_argv[c]; c++)
507  ;
508  h->binary_argv = GNUNET_malloc (sizeof(char *) * (c + 1));
509  for (c = 0; NULL != binary_argv[c]; c++)
511  h->binary_argv[c] = NULL;
512  h->cb_cls = cb_cls;
513  if (NULL != cb)
514  h->mst = GNUNET_MST_create (cb, h->cb_cls);
515  h->exp_cb = exp_cb;
516  h->retry_back_off = 0;
517  start_helper (h);
518  return h;
519 }
The handle to a helper process.
Definition: helper.c:78
#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:158
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
unsigned int retry_back_off
Count start attempts to increase linear back off.
Definition: helper.c:163
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:85
char * binary_name
Binary to run.
Definition: helper.c:133
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
Definition: helper.c:113
char ** binary_argv
NULL-terminated list of command-line arguments.
Definition: helper.c:138
void * cb_cls
The closure for callbacks.
Definition: helper.c:118
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:108
static void start_helper(struct GNUNET_HELPER_Handle *h)
Start the helper process.
Definition: helper.c:401
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 177 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().

178 {
180  int ret;
181 
182  while (NULL != (sh = h->sh_head))
183  {
185  if (NULL != sh->cont)
186  sh->cont (sh->cont_cls, GNUNET_NO);
187  GNUNET_free (sh);
188  }
189  if (NULL != h->restart_task)
190  {
192  h->restart_task = NULL;
193  }
194  if (NULL != h->read_task)
195  {
197  h->read_task = NULL;
198  }
199  if (NULL == h->helper_proc)
200  return GNUNET_SYSERR;
201  if (GNUNET_YES == soft_kill)
202  {
203  /* soft-kill only possible with pipes */
204  GNUNET_assert (NULL != h->helper_in);
206  h->helper_in = NULL;
207  h->fh_to_helper = NULL;
208  return ret;
209  }
211  return GNUNET_SYSERR;
212  return GNUNET_OK;
213 }
#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:98
struct GNUNET_SCHEDULER_Task * restart_task
Restart task.
Definition: helper.c:153
#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
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
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:128
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:143
static struct SolverHandle * sh
struct GNUNET_DISK_PipeHandle * helper_in
PipeHandle to receive data from the helper.
Definition: helper.c:83
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:123
#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:1715
struct GNUNET_OS_Process * helper_proc
The process id of the helper.
Definition: helper.c:103
#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:61
void * cont_cls
Closure to 'cont'.
Definition: helper.c:66
#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:225
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_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 225 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().

226 {
228  int ret;
229 
230  ret = GNUNET_SYSERR;
231  if (NULL != h->helper_proc)
232  {
235  h->helper_proc = NULL;
236  }
237  if (NULL != h->read_task)
238  {
240  h->read_task = NULL;
241  }
242  if (NULL != h->write_task)
243  {
245  h->write_task = NULL;
246  }
247  if (NULL != h->helper_in)
248  {
250  h->helper_in = NULL;
251  h->fh_to_helper = NULL;
252  }
253  if (NULL != h->helper_out)
254  {
256  h->helper_out = NULL;
257  h->fh_from_helper = NULL;
258  }
259  while (NULL != (sh = h->sh_head))
260  {
262  if (NULL != sh->cont)
263  sh->cont (sh->cont_cls, GNUNET_NO);
264  GNUNET_free (sh);
265  }
266  /* purge MST buffer */
267  if (NULL != h->mst)
268  (void) GNUNET_MST_from_buffer (h->mst, NULL, 0, GNUNET_YES, GNUNET_NO);
269  return ret;
270 }
#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:98
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:287
struct GNUNET_DISK_PipeHandle * helper_out
PipeHandle to send data to the helper.
Definition: helper.c:88
Entry in the queue of messages we need to transmit to the helper.
Definition: helper.c:36
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:128
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:143
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:148
static struct SolverHandle * sh
struct GNUNET_DISK_PipeHandle * helper_in
PipeHandle to receive data from the helper.
Definition: helper.c:83
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:114
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:123
#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:108
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1715
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:103
#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:93
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:61
void * cont_cls
Closure to 'cont'.
Definition: helper.c:66
#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_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 528 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_().

529 {
530  unsigned int c;
532 
533  if (NULL != h->write_task)
534  {
536  h->write_task = NULL;
537  }
538  GNUNET_assert (NULL == h->read_task);
539  GNUNET_assert (NULL == h->restart_task);
540  while (NULL != (sh = h->sh_head))
541  {
543  if (NULL != sh->cont)
544  sh->cont (sh->cont_cls, GNUNET_SYSERR);
545  GNUNET_free (sh);
546  }
547  if (NULL != h->mst)
548  GNUNET_MST_destroy (h->mst);
550  for (c = 0; h->binary_argv[c] != NULL; c++)
551  GNUNET_free (h->binary_argv[c]);
553  GNUNET_free (h);
554 }
#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:153
#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:128
struct GNUNET_SCHEDULER_Task * read_task
Task to read from the helper.
Definition: helper.c:143
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:148
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
static struct SolverHandle * sh
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:123
char * binary_name
Binary to run.
Definition: helper.c:133
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
char ** binary_argv
NULL-terminated list of command-line arguments.
Definition: helper.c:138
struct GNUNET_MessageStreamTokenizer * mst
The Message-Tokenizer that tokenizes the messages comming from the helper.
Definition: helper.c:108
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:61
void * cont_cls
Closure to 'cont'.
Definition: helper.c:66
#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_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 565 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().

566 {
567  h->exp_cb = NULL;
568  stop_helper (h, soft_kill);
570 }
GNUNET_HELPER_ExceptionCallback exp_cb
The exception callback.
Definition: helper.c:113
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:281
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:528
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 655 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().

660 {
662  uint16_t mlen;
663 
664  if (NULL == h->fh_to_helper)
665  return NULL;
666  if ((GNUNET_YES == can_drop) && (NULL != h->sh_head))
667  return NULL;
668  mlen = ntohs (msg->size);
669  sh = GNUNET_malloc (sizeof(struct GNUNET_HELPER_SendHandle) + mlen);
670  sh->msg = (const struct GNUNET_MessageHeader *) &sh[1];
671  GNUNET_memcpy (&sh[1], msg, mlen);
672  sh->h = h;
673  sh->cont = cont;
674  sh->cont_cls = cont_cls;
676  if (NULL == h->write_task)
677  h->write_task =
679  h->fh_to_helper,
680  &helper_write,
681  h);
682 
683  return sh;
684 }
const struct GNUNET_DISK_FileHandle * fh_to_helper
FileHandle to send data to the helper.
Definition: helper.c:98
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:1669
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:128
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:99
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:148
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
Definition: helper.c:56
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:123
#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:51
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:61
static void helper_write(void *cls)
Write to the helper-process.
Definition: helper.c:579
void * cont_cls
Closure to 'cont'.
Definition: helper.c:66
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 695 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_().

696 {
697  struct GNUNET_HELPER_Handle *h = sh->h;
698 
699  sh->cont = NULL;
700  sh->cont_cls = NULL;
701  if (0 == sh->wpos)
702  {
704  GNUNET_free (sh);
705  if (NULL == h->sh_head)
706  {
708  h->write_task = NULL;
709  }
710  }
711 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
The handle to a helper process.
Definition: helper.c:78
unsigned int wpos
Current write position.
Definition: helper.c:71
struct GNUNET_HELPER_SendHandle * sh_tail
Last message queued for transmission to helper.
Definition: helper.c:128
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_SCHEDULER_Task * write_task
Task to read from the helper.
Definition: helper.c:148
struct GNUNET_HELPER_Handle * h
The handle to a helper process.
Definition: helper.c:56
struct GNUNET_HELPER_SendHandle * sh_head
First message queued for transmission to helper.
Definition: helper.c:123
GNUNET_HELPER_Continuation cont
Function to call upon completion.
Definition: helper.c:61
void * cont_cls
Closure to 'cont'.
Definition: helper.c:66
#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: