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

GNUnet MESSENGER service. More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "messenger_api_message.h"
#include "gnunet-service-messenger_list_messages.h"
Include dependency graph for gnunet-service-messenger_message_state.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_MessageState
 

Functions

void init_message_state (struct GNUNET_MESSENGER_MessageState *state)
 
void clear_message_state (struct GNUNET_MESSENGER_MessageState *state)
 
void get_message_state_chain_hash (const struct GNUNET_MESSENGER_MessageState *state, struct GNUNET_HashCode *hash)
 
const struct GNUNET_HashCodeget_message_state_merge_hash (const struct GNUNET_MESSENGER_MessageState *state)
 
void update_message_state (struct GNUNET_MESSENGER_MessageState *state, int requested, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
void load_message_state (struct GNUNET_MESSENGER_MessageState *state, const char *path)
 
void save_message_state (const struct GNUNET_MESSENGER_MessageState *state, const char *path)
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_message_state.h.

Function Documentation

◆ init_message_state()

void init_message_state ( struct GNUNET_MESSENGER_MessageState state)

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

References GNUNET_assert, init_list_messages(), and GNUNET_MESSENGER_MessageState::last_messages.

Referenced by create_room(), and create_tunnel().

30 {
31  GNUNET_assert(state);
32 
34 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
struct GNUNET_MESSENGER_ListMessages last_messages
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear_message_state()

void clear_message_state ( struct GNUNET_MESSENGER_MessageState state)

Definition at line 37 of file gnunet-service-messenger_message_state.c.

References clear_list_messages(), GNUNET_assert, and GNUNET_MESSENGER_MessageState::last_messages.

Referenced by destroy_room(), and destroy_tunnel().

38 {
39  GNUNET_assert(state);
40 
42 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessages last_messages
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_message_state_chain_hash()

void get_message_state_chain_hash ( const struct GNUNET_MESSENGER_MessageState state,
struct GNUNET_HashCode hash 
)

Definition at line 45 of file gnunet-service-messenger_message_state.c.

References GNUNET_assert, GNUNET_memcpy, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, and GNUNET_MESSENGER_MessageState::last_messages.

Referenced by pack_room_message().

47 {
48  GNUNET_assert((state) && (hash));
49 
50  if (state->last_messages.head)
51  GNUNET_memcpy(hash, &(state->last_messages.head->hash), sizeof(*hash));
52  else
53  memset (hash, 0, sizeof(*hash));
54 }
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.
struct GNUNET_MESSENGER_ListMessages last_messages
Here is the caller graph for this function:

◆ get_message_state_merge_hash()

const struct GNUNET_HashCode* get_message_state_merge_hash ( const struct GNUNET_MESSENGER_MessageState state)

Definition at line 57 of file gnunet-service-messenger_message_state.c.

References GNUNET_assert, GNUNET_MESSENGER_ListMessage::hash, GNUNET_MESSENGER_ListMessages::head, GNUNET_MESSENGER_MessageState::last_messages, and GNUNET_MESSENGER_ListMessages::tail.

Referenced by idle_request_room_messages(), and merge_room_last_messages().

58 {
59  GNUNET_assert(state);
60 
61  if (state->last_messages.head == state->last_messages.tail)
62  return NULL;
63 
64  return &(state->last_messages.tail->hash);
65 }
struct GNUNET_MESSENGER_ListMessage * head
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_MESSENGER_ListMessage * tail
Here is the caller graph for this function:

◆ update_message_state()

void update_message_state ( struct GNUNET_MESSENGER_MessageState state,
int  requested,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Definition at line 68 of file gnunet-service-messenger_message_state.c.

References add_to_list_messages(), GNUNET_MESSENGER_Message::body, GNUNET_assert, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_REQUEST, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_MessageState::last_messages, GNUNET_MESSENGER_MessageBody::merge, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageHeader::previous, and remove_from_list_messages().

Referenced by update_room_message(), and update_tunnel_last_message().

70 {
71  GNUNET_assert((state) && (message) && (hash));
72 
73  if ((GNUNET_YES == requested) ||
74  (GNUNET_MESSENGER_KIND_INFO == message->header.kind) ||
76  return;
77 
78  if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind)
81 
82  add_to_list_messages (&(state->last_messages), hash);
83 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_HashCode previous
The hash of a second previous message.
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.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_ListMessages last_messages
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
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.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_message_state()

void load_message_state ( struct GNUNET_MESSENGER_MessageState state,
const char *  path 
)

Definition at line 86 of file gnunet-service-messenger_message_state.c.

References GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_MESSENGER_MessageState::last_messages, and load_list_messages().

Referenced by load_room().

87 {
88  GNUNET_assert((state) && (path));
89 
90  char *last_messages_file;
91  GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list");
92 
93  load_list_messages(&(state->last_messages), last_messages_file);
94  GNUNET_free(last_messages_file);
95 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
struct GNUNET_MESSENGER_ListMessages last_messages
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_message_state()

void save_message_state ( const struct GNUNET_MESSENGER_MessageState state,
const char *  path 
)

Definition at line 98 of file gnunet-service-messenger_message_state.c.

References GNUNET_asprintf(), GNUNET_assert, GNUNET_free, GNUNET_MESSENGER_MessageState::last_messages, and save_list_messages().

Referenced by save_room().

99 {
100  GNUNET_assert((state) && (path));
101 
102  char *last_messages_file;
103  GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list");
104 
105  save_list_messages(&(state->last_messages), last_messages_file);
106  GNUNET_free(last_messages_file);
107 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ListMessages last_messages
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function: