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

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_container_lib.h"
#include "gnunet_disk_lib.h"
Include dependency graph for gnunet-service-messenger_list_messages.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_ListMessage
 
struct  GNUNET_MESSENGER_ListMessages
 

Functions

void init_list_messages (struct GNUNET_MESSENGER_ListMessages *messages)
 Initializes list of message hashes as empty list. More...
 
void clear_list_messages (struct GNUNET_MESSENGER_ListMessages *messages)
 Clears the list of message hashes. More...
 
void add_to_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
 Adds a specific hash from a message to the end of the list. More...
 
void copy_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_MESSENGER_ListMessages *origin)
 Copies all message hashes from an origin to another list. More...
 
void remove_from_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
 Removes the first entry with a matching hash from the list. More...
 
void load_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
 Loads the list of message hashes from a file under a given path. More...
 
void save_list_messages (struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
 Saves the list of message hashes to a file under a given path. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_list_messages.h.

Function Documentation

◆ init_list_messages()

void init_list_messages ( struct GNUNET_MESSENGER_ListMessages messages)

Initializes list of message hashes as empty list.

Parameters
[out]messagesList of hashes

Definition at line 29 of file gnunet-service-messenger_list_messages.c.

References GNUNET_assert, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by check_member_session_completion(), create_member_session(), create_room(), init_message_state(), and switch_member_session().

30 {
31  GNUNET_assert(messages);
32 
33  messages->head = NULL;
34  messages->tail = NULL;
35 }
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessage * tail
Here is the caller graph for this function:

◆ clear_list_messages()

void clear_list_messages ( struct GNUNET_MESSENGER_ListMessages messages)

Clears the list of message hashes.

Parameters

Definition at line 38 of file gnunet-service-messenger_list_messages.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by check_member_session_completion(), clear_message_state(), destroy_member_session(), and reset_member_session().

39 {
40  GNUNET_assert(messages);
41 
42  while (messages->head)
43  {
44  struct GNUNET_MESSENGER_ListMessage *element = messages->head;
45 
46  GNUNET_CONTAINER_DLL_remove(messages->head, messages->tail, element);
47  GNUNET_free(element);
48  }
49 
50  messages->head = NULL;
51  messages->tail = NULL;
52 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessage * tail
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ add_to_list_messages()

void add_to_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const struct GNUNET_HashCode hash 
)

Adds a specific hash from a message to the end of the list.

Parameters

Definition at line 55 of file gnunet-service-messenger_list_messages.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_memcpy, GNUNET_new, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by callback_room_handle_message(), check_member_session_completion(), copy_list_messages(), load_list_messages(), reset_member_session(), update_member_session_history(), and update_message_state().

56 {
57  GNUNET_assert((messages) && (hash));
58 
60 
61  GNUNET_memcpy(&(element->hash), hash, sizeof(struct GNUNET_HashCode));
62 
63  GNUNET_CONTAINER_DLL_insert_tail(messages->head, messages->tail, element);
64 }
struct GNUNET_MESSENGER_ListMessage * head
#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.
A 512-bit hashcode.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct GNUNET_MESSENGER_ListMessage * tail
Here is the caller graph for this function:

◆ copy_list_messages()

void copy_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const struct GNUNET_MESSENGER_ListMessages origin 
)

Copies all message hashes from an origin to another list.

Parameters

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

References add_to_list_messages(), GNUNET_assert, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessage::next.

Referenced by check_member_session_completion(), and switch_member_session().

68 {
69  GNUNET_assert((messages) && (origin));
70 
71  struct GNUNET_MESSENGER_ListMessage *element;
72 
73  for (element = origin->head; element; element = element->next)
74  add_to_list_messages (messages, &(element->hash));
75 }
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_from_list_messages()

void remove_from_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const struct GNUNET_HashCode hash 
)

Removes the first entry with a matching hash from the list.

Parameters

Definition at line 78 of file gnunet-service-messenger_list_messages.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CRYPTO_hash_cmp(), GNUNET_free, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_ListMessage::next, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by update_message_state().

79 {
80  GNUNET_assert((messages) && (hash));
81 
82  struct GNUNET_MESSENGER_ListMessage *element;
83 
84  for (element = messages->head; element; element = element->next)
85  if (0 == GNUNET_CRYPTO_hash_cmp (&(element->hash), hash))
86  {
87  GNUNET_CONTAINER_DLL_remove(messages->head, messages->tail, element);
88  GNUNET_free(element);
89  break;
90  }
91 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessage * tail
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:201
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_list_messages()

void load_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const char *  path 
)

Loads the list of message hashes from a file under a given path.

Parameters
[out]messagesList of hashes
[in]pathPath of file

Definition at line 94 of file gnunet-service-messenger_list_messages.c.

References add_to_list_messages(), GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_test(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, GNUNET_YES, handle, and len.

Referenced by load_member_session(), and load_message_state().

95 {
96  GNUNET_assert((messages) && (path));
97 
98  if (GNUNET_YES != GNUNET_DISK_file_test (path))
99  return;
100 
102 
104  path, GNUNET_DISK_OPEN_READ, permission
105  );
106 
107  if (!handle)
108  return;
109 
111 
112  struct GNUNET_HashCode hash;
113  ssize_t len;
114 
115  do {
116  len = GNUNET_DISK_file_read(handle, &hash, sizeof(hash));
117 
118  if (len != sizeof(hash))
119  break;
120 
121  add_to_list_messages(messages, &hash);
122  } while (len == sizeof(hash));
123 
124  GNUNET_DISK_file_close(handle);
125 }
Open the file for reading.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:602
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
void add_to_list_messages(struct GNUNET_MESSENGER_ListMessages *messages, const struct GNUNET_HashCode *hash)
Adds a specific hash from a message to the end of the list.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
A 512-bit hashcode.
Seek an absolute position (from the start of the file).
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1055
Handle used to access files (and pipes).
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:437
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_list_messages()

void save_list_messages ( struct GNUNET_MESSENGER_ListMessages messages,
const char *  path 
)

Saves the list of message hashes to a file under a given path.

Parameters
[in]messagesList of hashes
[in]pathPath of file

Definition at line 128 of file gnunet-service-messenger_list_messages.c.

References GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_seek(), GNUNET_DISK_file_sync(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_DISK_SEEK_SET, handle, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_ListMessage::next.

Referenced by save_member_session(), and save_message_state().

129 {
130  GNUNET_assert((messages) && (path));
131 
133 
136  );
137 
138  if (!handle)
139  return;
140 
142 
143  struct GNUNET_MESSENGER_ListMessage *element;
144 
145  for (element = messages->head; element; element = element->next)
146  GNUNET_DISK_file_write(handle, &(element->hash), sizeof(element->hash));
147 
148  GNUNET_DISK_file_sync(handle);
149  GNUNET_DISK_file_close(handle);
150 }
Create file if it doesn't exist.
struct GNUNET_MESSENGER_ListMessage * next
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1126
off_t GNUNET_DISK_file_seek(const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence)
Move the read/write pointer in a file.
Definition: disk.c:206
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:666
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
GNUNET_DISK_AccessPermissions
File access permissions, UNIX-style.
Open the file for writing.
Seek an absolute position (from the start of the file).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync(const struct GNUNET_DISK_FileHandle *h)
Write file changes to disk.
Definition: disk.c:1245
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1055
Handle used to access files (and pipes).
Here is the call graph for this function:
Here is the caller graph for this function: