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

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_container_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_scheduler_lib.h"
#include "gnunet_time_lib.h"
Include dependency graph for gnunet-service-messenger_operation_store.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_OperationStore
 

Functions

void init_operation_store (struct GNUNET_MESSENGER_OperationStore *store, struct GNUNET_MESSENGER_SrvRoom *room)
 Initializes an operation store as fully empty with a given room. More...
 
void clear_operation_store (struct GNUNET_MESSENGER_OperationStore *store)
 Clears an operation store, stops all operations and deallocates its memory. More...
 
void load_operation_store (struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
 Loads operations from a directory into an operation store. More...
 
void save_operation_store (const struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
 Saves operations from an operation store into a directory. More...
 
enum GNUNET_MESSENGER_OperationType get_store_operation_type (const struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash)
 Returns the type of the active operation under a given hash in a specific operation store. More...
 
int use_store_operation (struct GNUNET_MESSENGER_OperationStore *store, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_OperationType type, struct GNUNET_TIME_Relative delay)
 Tries to use an operation under a given hash in a specific operation store. More...
 
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. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_operation_store.h.

Function Documentation

◆ init_operation_store()

void init_operation_store ( struct GNUNET_MESSENGER_OperationStore store,
struct GNUNET_MESSENGER_SrvRoom room 
)

Initializes an operation store as fully empty with a given room.

Parameters
[out]storeOperation store

Definition at line 32 of file gnunet-service-messenger_operation_store.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_NO, GNUNET_MESSENGER_OperationStore::operations, and GNUNET_MESSENGER_OperationStore::room.

Referenced by create_room().

33 {
34  GNUNET_assert((store) && (room));
35 
36  store->room = room;
38 }
struct GNUNET_CONTAINER_MultiHashMap * operations
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_operation_store()

void clear_operation_store ( struct GNUNET_MESSENGER_OperationStore store)

Clears an operation store, stops all operations and deallocates its memory.

Parameters

Definition at line 51 of file gnunet-service-messenger_operation_store.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), iterate_destroy_operations(), and GNUNET_MESSENGER_OperationStore::operations.

Referenced by destroy_room().

52 {
53  GNUNET_assert(store);
54 
57 }
struct GNUNET_CONTAINER_MultiHashMap * operations
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static int iterate_destroy_operations(void *cls, const struct GNUNET_HashCode *key, void *value)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_operation_store()

void load_operation_store ( struct GNUNET_MESSENGER_OperationStore store,
const char *  directory 
)

Loads operations from a directory into an operation store.

Parameters
[out]storeOperation store
[in]directoryPath to a directory

Definition at line 87 of file gnunet-service-messenger_operation_store.c.

References callback_scan_for_operations(), GNUNET_assert, GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_OK, and GNUNET_YES.

Referenced by load_room().

89 {
90  GNUNET_assert ((store) && (directory));
91 
94 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:794
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
static int callback_scan_for_operations(void *cls, const char *filename)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_operation_store()

void save_operation_store ( const struct GNUNET_MESSENGER_OperationStore store,
const char *  directory 
)

Saves operations from an operation store into a directory.

Parameters
[in]storeOperation store
[in]directoryPath to a directory

Definition at line 115 of file gnunet-service-messenger_operation_store.c.

References DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_DISK_directory_create(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_YES, iterate_save_operations(), and GNUNET_MESSENGER_OperationStore::operations.

Referenced by save_room().

117 {
118  GNUNET_assert ((store) && (directory));
119 
120  char* save_dir;
121  GNUNET_asprintf (&save_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR);
122 
123  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
124  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
126 
127  GNUNET_free(save_dir);
128 }
struct GNUNET_CONTAINER_MultiHashMap * operations
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:476
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR
Definition: platform.h:164
static int iterate_save_operations(void *cls, const struct GNUNET_HashCode *key, void *value)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test(const char *fil, int is_readable)
Test if fil is a directory and listable.
Definition: disk.c:404
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_store_operation_type()

enum GNUNET_MESSENGER_OperationType get_store_operation_type ( const struct GNUNET_MESSENGER_OperationStore store,
const struct GNUNET_HashCode hash 
)

Returns the type of the active operation under a given hash in a specific operation store.

If there is no active operation under the given hash, GNUNET_MESSENGER_OP_UNKNOWN gets returned instead.

Parameters
[in]storeOperation store
[in]hashHash of message
Returns
Type of operation or GNUNET_MESSENGER_OP_UNKNOWN

Definition at line 131 of file gnunet-service-messenger_operation_store.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_MESSENGER_OP_UNKNOWN, op, GNUNET_MESSENGER_OperationStore::operations, and GNUNET_MESSENGER_Operation::type.

Referenced by idle_request_room_messages(), update_room_message(), and update_tunnel_last_message().

133 {
134  GNUNET_assert((store) && (hash));
135 
137 
138  if (!op)
140 
141  return op->type;
142 }
enum GNUNET_MESSENGER_OperationType type
struct GNUNET_CONTAINER_MultiHashMap * operations
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
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:

◆ use_store_operation()

int use_store_operation ( struct GNUNET_MESSENGER_OperationStore store,
const struct GNUNET_HashCode hash,
enum GNUNET_MESSENGER_OperationType  type,
struct GNUNET_TIME_Relative  delay 
)

Tries to use an operation under a given hash in a specific operation store.

The operation will use the selected type if successful. The operation will be delayed by a given delay.

If the selected type is GNUNET_MESSENGER_OP_DELETE any active operation under the given hash will be stopped and replaced.

If the new operation could be started successfully the method returns GNUNET_OK, otherwise GNUNET_SYSERR.

Parameters

Definition at line 145 of file gnunet-service-messenger_operation_store.c.

References create_operation(), destroy_operation(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_MESSENGER_OP_DELETE, GNUNET_MESSENGER_OP_UNKNOWN, GNUNET_OK, GNUNET_SYSERR, op, GNUNET_MESSENGER_OperationStore::operations, start_operation(), stop_operation(), and GNUNET_MESSENGER_Operation::type.

Referenced by callback_found_message(), delete_room_message(), idle_request_room_messages(), and send_message_request().

149 {
150  GNUNET_assert((store) && (hash));
151 
153 
154  if (op)
155  goto use_op;
156 
157  op = create_operation(hash);
158 
160  {
161  destroy_operation(op);
162 
163  return GNUNET_SYSERR;
164  }
165 
166 use_op:
167  if ((op->type != GNUNET_MESSENGER_OP_UNKNOWN) &&
169  stop_operation (op);
170 
171  return start_operation(op, type, store, delay);
172 }
enum GNUNET_MESSENGER_OperationType type
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.
struct GNUNET_CONTAINER_MultiHashMap * operations
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void destroy_operation(struct GNUNET_MESSENGER_Operation *op)
Destroys an operation and frees its memory fully.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
struct GNUNET_MESSENGER_Operation * create_operation(const struct GNUNET_HashCode *hash)
Creates and allocates a new operation under a given hash.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
int stop_operation(struct GNUNET_MESSENGER_Operation *op)
Stops an active operation and resets its type to be GNUNET_MESSENGER_OP_UNKNOWN.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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:

◆ cancel_store_operation()

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.

Beware that calling this method will also implicitly free the memory of any active operation under the given hash!

Parameters

Definition at line 175 of file gnunet-service-messenger_operation_store.c.

References callback_room_deletion(), callback_room_merge(), destroy_operation(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_YES, GNUNET_MESSENGER_Operation::hash, op, GNUNET_MESSENGER_OperationStore::operations, and stop_operation().

Referenced by callback_store_operation(), and update_room_message().

177 {
178  GNUNET_assert((store) && (hash));
179 
181 
182  if (!op)
183  return;
184 
185  stop_operation(op);
186 
188  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Canceled operation could not be removed: %s\n",
189  GNUNET_h2s(hash));
190 
191  destroy_operation(op);
192 }
struct GNUNET_CONTAINER_MultiHashMap * operations
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void destroy_operation(struct GNUNET_MESSENGER_Operation *op)
Destroys an operation and frees its memory fully.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
int stop_operation(struct GNUNET_MESSENGER_Operation *op)
Stops an active operation and resets its type to be GNUNET_MESSENGER_OP_UNKNOWN.
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_log(kind,...)
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: