GNUnet  0.11.x
Functions
gnunet-service-messenger_operation_store.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_operation_store.h"
#include "gnunet-service-messenger_operation.h"
#include "gnunet-service-messenger_room.h"
Include dependency graph for gnunet-service-messenger_operation_store.c:

Go to the source code of this file.

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...
 
static int iterate_destroy_operations (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void clear_operation_store (struct GNUNET_MESSENGER_OperationStore *store)
 Clears an operation store, stops all operations and deallocates its memory. More...
 
static int callback_scan_for_operations (void *cls, const char *filename)
 
void load_operation_store (struct GNUNET_MESSENGER_OperationStore *store, const char *directory)
 Loads operations from a directory into an operation store. More...
 
static int iterate_save_operations (void *cls, const struct GNUNET_HashCode *key, void *value)
 
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...
 
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)
 
void callback_store_operation (struct GNUNET_MESSENGER_OperationStore *store, enum GNUNET_MESSENGER_OperationType type, const struct GNUNET_HashCode *hash)
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_operation_store.c.

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
[in/out]room Room

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

34 {
35  GNUNET_assert((store) && (room));
36 
37  store->room = room;
39 }
@ GNUNET_NO
Definition: gnunet_common.h:94
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * operations

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

Referenced by create_room().

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

◆ iterate_destroy_operations()

static int iterate_destroy_operations ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

45 {
47 
49 
50  return GNUNET_YES;
51 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static char * value
Value of the record to add/remove.
void destroy_operation(struct GNUNET_MESSENGER_Operation *op)
Destroys an operation and frees its memory fully.
@ GNUNET_YES
Definition: gnunet_common.h:97

References destroy_operation(), GNUNET_YES, op, and value.

Referenced by clear_operation_store().

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
[in/out]store Operation store

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

55 {
56  GNUNET_assert(store);
57 
60 }
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.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.

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

Referenced by destroy_room().

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

◆ callback_scan_for_operations()

static int callback_scan_for_operations ( void *  cls,
const char *  filename 
)
static

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

65 {
66  struct GNUNET_MESSENGER_OperationStore *store = cls;
67 
69  return GNUNET_OK;
70 
71  if ((strlen(filename) <= 4) || (0 != strcmp(filename + strlen(filename) - 4, ".cfg")))
72  return GNUNET_OK;
73 
75 
78  &(op->hash), op,
80  {
82  }
83 
84  return GNUNET_OK;
85 }
static char * filename
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 fo...
@ GNUNET_OK
Definition: gnunet_common.h:95
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
struct GNUNET_MESSENGER_OperationStore * store

References destroy_operation(), filename, GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_DISK_file_test(), GNUNET_OK, GNUNET_YES, load_operation(), op, GNUNET_MESSENGER_OperationStore::operations, and GNUNET_MESSENGER_Operation::store.

Referenced by load_operation_store().

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 88 of file gnunet-service-messenger_operation_store.c.

90 {
91  GNUNET_assert ((store) && (directory));
92 
93  char* load_dir;
94  GNUNET_asprintf (&load_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR);
95 
98 
99  GNUNET_free(load_dir);
100 }
static int callback_scan_for_operations(void *cls, const char *filename)
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
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
#define DIR_SEPARATOR
Definition: platform.h:164

References callback_scan_for_operations(), DIR_SEPARATOR, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_directory_scan(), GNUNET_DISK_directory_test(), GNUNET_free, GNUNET_OK, GNUNET_YES, and GNUNET_MESSENGER_Operation::store.

Referenced by load_room().

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

◆ iterate_save_operations()

static int iterate_save_operations ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

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

106 {
107  const char *save_dir = cls;
108 
110 
111  if (!op)
112  return GNUNET_YES;
113 
114  char *op_dir;
115  GNUNET_asprintf (&op_dir, "%s%s.cfg", save_dir, GNUNET_h2s(key));
116  save_operation(op, op_dir);
117 
118  GNUNET_free(op_dir);
119  return GNUNET_YES;
120 }
struct GNUNET_HashCode key
The key used in the DHT.
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 restor...
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).

References GNUNET_asprintf(), GNUNET_free, GNUNET_h2s(), GNUNET_YES, key, op, save_operation(), and value.

Referenced by get_store_operation_type().

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 123 of file gnunet-service-messenger_operation_store.c.

125 {
126  GNUNET_assert ((store) && (directory));
127 
128  char* save_dir;
129  GNUNET_asprintf (&save_dir, "%s%s%c", directory, "operations", DIR_SEPARATOR);
130 
131  if ((GNUNET_YES == GNUNET_DISK_directory_test (save_dir, GNUNET_NO)) ||
132  (GNUNET_OK == GNUNET_DISK_directory_create (save_dir)))
134 
135  GNUNET_free(save_dir);
136 }
static int iterate_save_operations(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496

Referenced by save_room().

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 123 of file gnunet-service-messenger_operation_store.c.

141 {
142  GNUNET_assert((store) && (hash));
143 
145 
146  if (!op)
148 
149  return op->type;
150 }
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.

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(), GNUNET_MESSENGER_OperationStore::operations, and GNUNET_MESSENGER_Operation::store.

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

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
[in/out]store Operation store
[in]hashHash of message
[in]typeOperation type
[in]delayDelay
Returns
GNUNET_OK on success, otherwise GNUNET_SYSERR

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

157 {
158  GNUNET_assert((store) && (hash));
159 
161 
162  if (op)
163  goto use_op;
164 
166 
168  {
170 
171  return GNUNET_SYSERR;
172  }
173 
174 use_op:
175  if ((op->type != GNUNET_MESSENGER_OP_UNKNOWN) &&
177  stop_operation (op);
178 
179  return start_operation(op, type, store, delay);
180 }
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
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.
int stop_operation(struct GNUNET_MESSENGER_Operation *op)
Stops an active operation and resets its type to be GNUNET_MESSENGER_OP_UNKNOWN.
struct GNUNET_MESSENGER_Operation * create_operation(const struct GNUNET_HashCode *hash)
Creates and allocates a new operation under a given hash.
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References create_operation(), delay, 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, GNUNET_MESSENGER_Operation::hash, op, GNUNET_MESSENGER_OperationStore::operations, start_operation(), stop_operation(), GNUNET_MESSENGER_Operation::store, and type.

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

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
[in/out]store Operation store
[in]hashHash of message

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

185 {
186  GNUNET_assert((store) && (hash));
187 
189 
190  if (!op)
191  return;
192 
194 
196  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Canceled operation could not be removed: %s\n",
197  GNUNET_h2s(hash));
198 
200 }
#define GNUNET_log(kind,...)
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.
@ GNUNET_ERROR_TYPE_WARNING

References 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, stop_operation(), and GNUNET_MESSENGER_Operation::store.

Referenced by callback_store_operation(), and update_room_message().

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 
)

Definition at line 643 of file gnunet-service-messenger_room.c.

645 {
647  {
648  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Deletion of message failed! (%s)\n", GNUNET_h2s(hash));
649  return;
650  }
651 }
int delete_store_message(struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Deletes a message in the message store.
struct GNUNET_MESSENGER_MessageStore * get_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.

References delete_store_message(), get_room_message_store(), GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, and GNUNET_OK.

Referenced by callback_store_operation().

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

◆ callback_room_merge()

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

Definition at line 654 of file gnunet-service-messenger_room.c.

656 {
657  if (!room->host)
658  return;
659 
660  send_room_message (room, room->host, create_message_merge (hash));
661 }
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...
int send_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.
struct GNUNET_MESSENGER_SrvHandle * host

References create_message_merge(), GNUNET_MESSENGER_SrvRoom::host, and send_room_message().

Referenced by callback_store_operation().

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

◆ callback_store_operation()

void callback_store_operation ( struct GNUNET_MESSENGER_OperationStore store,
enum GNUNET_MESSENGER_OperationType  type,
const struct GNUNET_HashCode hash 
)

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

214 {
215  GNUNET_assert((store) && (hash));
216 
217  struct GNUNET_HashCode op_hash;
218  GNUNET_memcpy(&op_hash, hash, sizeof(op_hash));
219  cancel_store_operation (store, &op_hash);
220 
221  struct GNUNET_MESSENGER_SrvRoom *room = store->room;
222 
223  switch (type)
224  {
226  break;
228  callback_room_deletion (room, &op_hash);
229  break;
231  callback_room_merge (room, &op_hash);
232  break;
233  default:
234  break;
235  }
236 }
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.
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)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
A 512-bit hashcode.

References callback_room_deletion(), callback_room_merge(), cancel_store_operation(), GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_OP_DELETE, GNUNET_MESSENGER_OP_MERGE, GNUNET_MESSENGER_OP_REQUEST, GNUNET_MESSENGER_Operation::hash, GNUNET_MESSENGER_OperationStore::room, GNUNET_MESSENGER_Operation::store, and type.

Referenced by callback_operation().

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