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.

30 {
32 
33  init_list_messages (&(state->last_messages));
34 }
enum State state
current state of profiling
void init_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Initializes list of message hashes as empty list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References GNUNET_assert, init_list_messages(), and state.

Referenced by create_room(), and create_tunnel().

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.

38 {
40 
41  clear_list_messages (&(state->last_messages));
42 }
void clear_list_messages(struct GNUNET_MESSENGER_ListMessages *messages)
Clears the list of message hashes.

References clear_list_messages(), GNUNET_assert, and state.

Referenced by destroy_room(), and destroy_tunnel().

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.

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 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.

References GNUNET_assert, GNUNET_memcpy, and state.

Referenced by pack_room_message().

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.

58 {
60 
61  if (state->last_messages.head == state->last_messages.tail)
62  return NULL;
63 
64  return &(state->last_messages.tail->hash);
65 }

References GNUNET_assert, and state.

Referenced by idle_request_room_messages(), and merge_room_last_messages().

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.

72 {
73  GNUNET_assert((state) && (message) && (hash));
74 
75  if ((GNUNET_YES == requested) ||
76  (GNUNET_MESSENGER_KIND_INFO == message->header.kind) ||
78  return;
79 
80  if (GNUNET_MESSENGER_KIND_MERGE == message->header.kind)
81  remove_from_list_messages(&(state->last_messages), &(message->body.merge.previous));
82  remove_from_list_messages(&(state->last_messages), &(message->header.previous));
83 
84  add_to_list_messages (&(state->last_messages), hash);
85 }
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.
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.
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.

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_MessageBody::merge, GNUNET_MESSENGER_MessageMerge::previous, GNUNET_MESSENGER_MessageHeader::previous, remove_from_list_messages(), and state.

Referenced by update_room_message(), and update_tunnel_last_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 88 of file gnunet-service-messenger_message_state.c.

90 {
91  GNUNET_assert((state) && (path));
92 
93  char *last_messages_file;
94  GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list");
95 
96  load_list_messages(&(state->last_messages), last_messages_file);
97  GNUNET_free(last_messages_file);
98 }
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.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_asprintf(), GNUNET_assert, GNUNET_free, load_list_messages(), and state.

Referenced by load_room().

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 101 of file gnunet-service-messenger_message_state.c.

103 {
104  GNUNET_assert((state) && (path));
105 
106  char *last_messages_file;
107  GNUNET_asprintf (&last_messages_file, "%s%s", path, "last_messages.list");
108 
109  save_list_messages(&(state->last_messages), last_messages_file);
110  GNUNET_free(last_messages_file);
111 }
void save_list_messages(const struct GNUNET_MESSENGER_ListMessages *messages, const char *path)
Saves the list of message hashes to a file under a given path.

References GNUNET_asprintf(), GNUNET_assert, GNUNET_free, save_list_messages(), and state.

Referenced by save_room().

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