GNUnet 0.22.2
gnunet-service-messenger_operation.c File Reference
Include dependency graph for gnunet-service-messenger_operation.c:

Go to the source code of this file.

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...
 
static void callback_operation (void *cls)
 
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...
 
void callback_room_deletion (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
 
void callback_room_merge (struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *hash)
 
enum GNUNET_GenericReturnValue 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...
 
enum GNUNET_GenericReturnValue stop_operation (struct GNUNET_MESSENGER_Operation *op)
 Stops an active operation and resets its type to be GNUNET_MESSENGER_OP_UNKNOWN. More...
 

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 33 of file gnunet-service-messenger_operation.c.

34{
36
38
40
42 GNUNET_memcpy (&(op->hash), hash, sizeof(*hash));
43 op->timestamp = GNUNET_TIME_absolute_get_zero_ ();
44 op->store = NULL;
45 op->task = NULL;
46
47 return op;
48}
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:143
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_(void)
Return absolute time of 0ms.
Definition: time.c:142

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_new, GNUNET_TIME_absolute_get_zero_(), GNUNET_MESSENGER_Operation::hash, and op.

Referenced by load_operation(), and use_store_operation().

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
[in,out]opOperation

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

53{
55
56 if (op->task)
58
60}
#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:980

References GNUNET_assert, GNUNET_free, GNUNET_SCHEDULER_cancel(), and op.

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_operation()

static void callback_operation ( void *  cls)
static

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

207{
210 struct GNUNET_MESSENGER_SrvRoom *room;
212 struct GNUNET_HashCode hash;
213
214 GNUNET_assert (cls);
215
216 op = cls;
217 op->task = NULL;
218
219 GNUNET_assert ((op->store) && (op->store->room));
220
221 store = op->store;
222 room = store->room;
223 type = op->type;
224
225 GNUNET_memcpy (&hash, &(op->hash), sizeof(hash));
226
227 cancel_store_operation (store, &hash);
228
229 switch (type)
230 {
232 break;
234 {
236 &hash))
237 {
239 "Deletion of message failed! (%s)\n",
240 GNUNET_h2s (&hash));
241 break;
242 }
243
244 break;
245 }
247 {
248 if (! room->host)
249 break;
250
251 send_srv_room_message (room, room->host, create_message_merge (&hash));
252 break;
253 }
254 default:
255 break;
256 }
257}
static uint32_t type
Type string converted to DNS type value.
struct GNUNET_MESSENGER_Message * create_message_merge(const struct GNUNET_HashCode *previous)
Creates and allocates a new merge message containing the hash of a second previous message besides th...
enum GNUNET_GenericReturnValue delete_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Deletes a message in the message store.
void cancel_store_operation(struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
Stops any active operation under a given hash in a specific operation store.
struct GNUNET_MESSENGER_MessageStore * get_srv_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
enum GNUNET_GenericReturnValue send_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
#define GNUNET_log(kind,...)
@ GNUNET_OK
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
A 512-bit hashcode.
struct GNUNET_MESSENGER_SrvHandle * host

References cancel_store_operation(), create_message_merge(), delete_store_message(), get_srv_room_message_store(), GNUNET_assert, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSENGER_OP_DELETE, GNUNET_MESSENGER_OP_MERGE, GNUNET_MESSENGER_OP_REQUEST, GNUNET_OK, GNUNET_MESSENGER_SrvRoom::host, op, GNUNET_MESSENGER_OperationStore::room, send_srv_room_message(), and type.

Referenced by load_operation(), and start_operation().

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
[in,out]storeOperation store
[in]pathPath of a configuration file

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

69{
72
73 GNUNET_assert ((store) && (path));
74
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Load operation configuration: %s\n",
76 path);
77
79
80 if (! cfg)
81 return NULL;
82
83 op = NULL;
84
86 goto destroy_config;
87
88 {
89 struct GNUNET_HashCode hash;
90
91 if (GNUNET_OK != GNUNET_CONFIGURATION_get_data (cfg, "operation", "hash",
92 &hash, sizeof(hash)))
93 goto destroy_config;
94
95 op = create_operation (&hash);
96 }
97
98 {
99 unsigned long long type_number;
101 "type", &type_number
102 ))
103 switch (type_number)
104 {
107 break;
110 break;
113 break;
114 default:
115 break;
116 }
117 }
118
119 if ((GNUNET_MESSENGER_OP_UNKNOWN == op->type) ||
121 "timestamp",
122 &(op->timestamp),
123 sizeof(op->timestamp))))
124 {
126 op = NULL;
127 goto destroy_config;
128 }
129
130 {
131 struct GNUNET_TIME_Relative delay;
132 delay = GNUNET_TIME_absolute_get_remaining (op->timestamp);
133
135 delay,
138 op
139 );
140 }
141
142 op->store = store;
143
144destroy_config:
146
147 return op;
148}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_MESSENGER_Operation * create_operation(const struct GNUNET_HashCode *hash)
Creates and allocates a new operation under a given hash.
static void callback_operation(void *cls)
void destroy_operation(struct GNUNET_MESSENGER_Operation *op)
Destroys an operation and frees its memory fully.
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_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
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 GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
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.
@ GNUNET_SCHEDULER_PRIORITY_BACKGROUND
Run as background job (higher than idle, lower than default).
@ GNUNET_ERROR_TYPE_DEBUG
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
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:1207
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:406
struct GNUNET_MESSENGER_OperationStore * store
Time for relative time used by GNUnet, in microseconds.

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_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSENGER_OP_DELETE, GNUNET_MESSENGER_OP_MERGE, GNUNET_MESSENGER_OP_REQUEST, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_BACKGROUND, GNUNET_TIME_absolute_get_remaining(), op, and GNUNET_MESSENGER_Operation::store.

Referenced by callback_scan_for_operations().

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 152 of file gnunet-service-messenger_operation.c.

154{
156 char *hash_data;
157 char *timestamp_data;
158
159 GNUNET_assert ((path) && (op));
160
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Save operation configuration: %s\n",
162 path);
163
165
166 if (! cfg)
167 return;
168
169 hash_data = GNUNET_STRINGS_data_to_string_alloc (&(op->hash),
170 sizeof(op->hash));
171
172 if (hash_data)
173 {
174 GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "hash", hash_data);
175
176 GNUNET_free (hash_data);
177 }
178
179 GNUNET_CONFIGURATION_set_value_number (cfg, "operation", "type", op->type);
180
181 timestamp_data = GNUNET_STRINGS_data_to_string_alloc (&(op->timestamp),
182 sizeof(op->timestamp));
183
184 if (timestamp_data)
185 {
186 GNUNET_CONFIGURATION_set_value_string (cfg, "operation", "timestamp",
187 timestamp_data);
188
189 GNUNET_free (timestamp_data);
190 }
191
194}
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.
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.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:787

References cfg, GNUNET_assert, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_CONFIGURATION_write(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_OS_project_data_gnunet(), GNUNET_STRINGS_data_to_string_alloc(), and op.

Referenced by iterate_save_operations().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_room_deletion()

void callback_room_deletion ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_HashCode hash 
)

◆ callback_room_merge()

void callback_room_merge ( struct GNUNET_MESSENGER_SrvRoom room,
const struct GNUNET_HashCode hash 
)

◆ start_operation()

enum GNUNET_GenericReturnValue 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
[in,out]opOperation
[in]typeType of operation
[in,out]storeOperation store
[in]delayDelay
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

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

265{
267
268 GNUNET_assert ((op) && (store));
269
270 if (op->task)
271 return GNUNET_SYSERR;
272
274
276 delay,
279 op
280 );
281
282 op->type = type;
283 op->timestamp = timestamp;
284 op->store = store;
285
286 return GNUNET_OK;
287}
static uint64_t timestamp(void)
Get current timestamp.
@ GNUNET_SYSERR
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
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:452
Time for absolute times used by GNUnet, in microseconds.

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(), op, timestamp(), and type.

Referenced by use_store_operation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_operation()

enum GNUNET_GenericReturnValue 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 291 of file gnunet-service-messenger_operation.c.

292{
294
295 if (! op->task)
296 return GNUNET_SYSERR;
297
299 op->task = NULL;
300
302 op->timestamp = GNUNET_TIME_absolute_get_zero_ ();
303 op->store = NULL;
304
305 return GNUNET_OK;
306}

References GNUNET_assert, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_zero_(), and op.

Referenced by cancel_store_operation(), and use_store_operation().

Here is the call graph for this function:
Here is the caller graph for this function: