GNUnet  0.11.x
Data Structures | Enumerations | Functions
gnunet-service-messenger_operation.h File Reference

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_configuration_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_scheduler_lib.h"
#include "gnunet_strings_lib.h"
#include "gnunet_time_lib.h"
Include dependency graph for gnunet-service-messenger_operation.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_Operation
 

Enumerations

enum  GNUNET_MESSENGER_OperationType { GNUNET_MESSENGER_OP_REQUEST = 1, GNUNET_MESSENGER_OP_DELETE = 2, GNUNET_MESSENGER_OP_MERGE = 3, GNUNET_MESSENGER_OP_UNKNOWN = 0 }
 

Functions

struct GNUNET_MESSENGER_Operationcreate_operation (const struct GNUNET_HashCode *hash)
 Creates and allocates a new operation under a given hash. More...
 
void destroy_operation (struct GNUNET_MESSENGER_Operation *op)
 Destroys an operation and frees its memory fully. More...
 
struct GNUNET_MESSENGER_Operationload_operation (struct GNUNET_MESSENGER_OperationStore *store, const char *path)
 Loads data from a configuration file at a selected path into a new allocated and created operation for a specific operation store if the required information could be read successfully. More...
 
void save_operation (const struct GNUNET_MESSENGER_Operation *op, const char *path)
 Saves data from an operation into a configuration file at a selected path which can be load to restore the operation completely and continue its process. More...
 
int start_operation (struct GNUNET_MESSENGER_Operation *op, enum GNUNET_MESSENGER_OperationType type, struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_TIME_Relative delay)
 Starts an inactive operation with a given delay in a specific operation store. More...
 
int stop_operation (struct GNUNET_MESSENGER_Operation *op)
 Stops an active operation and resets its type to be GNUNET_MESSENGER_OP_UNKNOWN. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_operation.h.

Enumeration Type Documentation

◆ GNUNET_MESSENGER_OperationType

Enumerator
GNUNET_MESSENGER_OP_REQUEST 
GNUNET_MESSENGER_OP_DELETE 
GNUNET_MESSENGER_OP_MERGE 
GNUNET_MESSENGER_OP_UNKNOWN 

Definition at line 36 of file gnunet-service-messenger_operation.h.

Function Documentation

◆ create_operation()

struct GNUNET_MESSENGER_Operation* create_operation ( const struct GNUNET_HashCode hash)

Creates and allocates a new operation under a given hash.

Parameters
[in]hashHash of message

Definition at line 31 of file gnunet-service-messenger_operation.c.

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_new, GNUNET_TIME_absolute_get_zero_(), GNUNET_MESSENGER_Operation::hash, op, GNUNET_MESSENGER_Operation::store, GNUNET_MESSENGER_Operation::task, GNUNET_MESSENGER_Operation::timestamp, and GNUNET_MESSENGER_Operation::type.

Referenced by load_operation(), and use_store_operation().

32 {
33  GNUNET_assert(hash);
34 
36 
38  GNUNET_memcpy(&(op->hash), hash, sizeof(*hash));
40  op->store = NULL;
41  op->task = NULL;
42 
43  return op;
44 }
enum GNUNET_MESSENGER_OperationType type
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MESSENGER_OperationStore * store
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:109
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_operation()

void destroy_operation ( struct GNUNET_MESSENGER_Operation op)

Destroys an operation and frees its memory fully.

Parameters

Definition at line 47 of file gnunet-service-messenger_operation.c.

References callback_operation(), GNUNET_assert, GNUNET_free, GNUNET_SCHEDULER_cancel(), and GNUNET_MESSENGER_Operation::task.

Referenced by callback_scan_for_operations(), cancel_store_operation(), iterate_destroy_operations(), load_operation(), and use_store_operation().

48 {
49  GNUNET_assert(op);
50 
51  if (op->task)
53 
54  GNUNET_free(op);
55 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#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:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_operation()

struct GNUNET_MESSENGER_Operation* load_operation ( struct GNUNET_MESSENGER_OperationStore store,
const char *  path 
)

Loads data from a configuration file at a selected path into a new allocated and created operation for a specific operation store if the required information could be read successfully.

The method will return the new operation and it will be started automatically to match its timestamp of execution.

If the method fails to restore any valid operation from the file, NULL gets returned instead.

Parameters

Definition at line 61 of file gnunet-service-messenger_operation.c.

References callback_operation(), cfg, create_operation(), destroy_operation(), GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_data(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_parse(), GNUNET_MESSENGER_OP_DELETE, GNUNET_MESSENGER_OP_MERGE, GNUNET_MESSENGER_OP_REQUEST, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_OK, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_TIME_absolute_get_remaining(), op, GNUNET_MESSENGER_Operation::store, GNUNET_MESSENGER_Operation::task, GNUNET_MESSENGER_Operation::timestamp, and GNUNET_MESSENGER_Operation::type.

Referenced by callback_scan_for_operations().

62 {
63  GNUNET_assert((store) && (path));
64 
66  struct GNUNET_MESSENGER_Operation* op = NULL;
67 
68  if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, path))
69  goto destroy_config;
70 
71  struct GNUNET_HashCode hash;
72 
73  if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "hash", &hash, sizeof(hash)))
74  goto destroy_config;
75 
76  op = create_operation(&hash);
77 
78  unsigned long long type_number;
79  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, "operation", "type", &type_number))
80  switch (type_number)
81  {
84  break;
87  break;
90  break;
91  default:
92  break;
93  }
94 
95  if ((GNUNET_MESSENGER_OP_UNKNOWN == op->type) ||
96  (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "timestamp", &(op->timestamp), sizeof(op->timestamp))))
97  {
99  op = NULL;
100  goto destroy_config;
101  }
102 
104 
106  delay,
109  op
110  );
111 
112  op->store = store;
113 
114 destroy_config:
116 
117  return op;
118 }
enum GNUNET_MESSENGER_OperationType type
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1199
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void destroy_operation(struct GNUNET_MESSENGER_Operation *op)
Destroys an operation and frees its memory fully.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
Run as background job (higher than idle, lower than default).
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, void *buf, size_t buf_size)
Get Crockford32-encoded fixed-size binary data from a configuration.
struct GNUNET_MESSENGER_Operation * create_operation(const struct GNUNET_HashCode *hash)
Creates and allocates a new operation under a given hash.
struct GNUNET_MESSENGER_OperationStore * store
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
A 512-bit hashcode.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
configuration data
Definition: configuration.c:84
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:232
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static void callback_operation(void *cls)
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_operation()

void save_operation ( const struct GNUNET_MESSENGER_Operation op,
const char *  path 
)

Saves data from an operation into a configuration file at a selected path which can be load to restore the operation completely and continue its process.

Parameters
[in]opOperation
[in]pathPath of a configuration file

Definition at line 121 of file gnunet-service-messenger_operation.c.

References callback_store_operation(), cfg, GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_free, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_MESSENGER_Operation::hash, GNUNET_MESSENGER_Operation::timestamp, type, and GNUNET_MESSENGER_Operation::type.

Referenced by iterate_save_operations().

122 {
123  GNUNET_assert((path) && (op));
124 
126 
127  char *hash_data;
128  hash_data = GNUNET_STRINGS_data_to_string_alloc (&(op->hash), sizeof(op->hash));
129 
130  if (hash_data)
131  {
132  GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "hash", hash_data);
133 
134  GNUNET_free(hash_data);
135  }
136 
137  GNUNET_CONFIGURATION_set_value_number(cfg, "operation", "type", op->type);
138 
139  char *timestamp_data;
140  timestamp_data = GNUNET_STRINGS_data_to_string_alloc (&(op->timestamp), sizeof(op->timestamp));
141 
142  if (timestamp_data)
143  {
144  GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "timestamp", timestamp_data);
145 
146  GNUNET_free(timestamp_data);
147  }
148 
149  GNUNET_CONFIGURATION_write (cfg, path);
151 }
enum GNUNET_MESSENGER_OperationType type
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
configuration data
Definition: configuration.c:84
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:937
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_operation()

int start_operation ( struct GNUNET_MESSENGER_Operation op,
enum GNUNET_MESSENGER_OperationType  type,
struct GNUNET_MESSENGER_OperationStore store,
struct GNUNET_TIME_Relative  delay 
)

Starts an inactive operation with a given delay in a specific operation store.

The method will replace the operations type to process it correctly. An operation can't be started twice, it has to be stopped or fully processed first.

Parameters

Definition at line 169 of file gnunet-service-messenger_operation.c.

References callback_operation(), GNUNET_assert, GNUNET_OK, GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_SYSERR, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_MESSENGER_Operation::store, GNUNET_MESSENGER_Operation::task, GNUNET_MESSENGER_Operation::timestamp, type, and GNUNET_MESSENGER_Operation::type.

Referenced by use_store_operation().

173 {
174  GNUNET_assert((op) && (store));
175 
176  if (op->task)
177  return GNUNET_SYSERR;
178 
179  const struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_add(
181  delay
182  );
183 
185  delay,
188  op
189  );
190 
191  op->type = type;
192  op->timestamp = timestamp;
193  op->store = store;
194 
195  return GNUNET_OK;
196 }
enum GNUNET_MESSENGER_OperationType type
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1199
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:277
Run as background job (higher than idle, lower than default).
struct GNUNET_MESSENGER_OperationStore * store
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:86
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
static void callback_operation(void *cls)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_operation()

int stop_operation ( struct GNUNET_MESSENGER_Operation op)

Stops an active operation and resets its type to be GNUNET_MESSENGER_OP_UNKNOWN.

Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

Definition at line 199 of file gnunet-service-messenger_operation.c.

References GNUNET_assert, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_zero_(), GNUNET_MESSENGER_Operation::store, GNUNET_MESSENGER_Operation::task, GNUNET_MESSENGER_Operation::timestamp, and GNUNET_MESSENGER_Operation::type.

Referenced by cancel_store_operation(), and use_store_operation().

200 {
201  GNUNET_assert(op);
202 
203  if (!op->task)
204  return GNUNET_SYSERR;
205 
207  op->task = NULL;
208 
211  op->store = NULL;
212 
213  return GNUNET_OK;
214 }
enum GNUNET_MESSENGER_OperationType type
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_OperationStore * store
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:109
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function: