GNUnet  0.11.x
Data Structures | Functions
messenger_api_room.c File Reference

messenger api: client implementation of GNUnet MESSENGER service More...

#include "messenger_api_room.h"
#include "messenger_api_handle.h"
Include dependency graph for messenger_api_room.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_MESSENGER_MemberCall
 
struct  GNUNET_MESSENGER_MemberFind
 

Functions

struct GNUNET_MESSENGER_Roomcreate_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Creates and allocates a new room for a handle with a given key for the client API. More...
 
static int iterate_destroy_message (void *cls, const struct GNUNET_HashCode *key, void *value)
 
void destroy_room (struct GNUNET_MESSENGER_Room *room)
 Destroys a room and frees its memory fully from the client API. More...
 
const struct GNUNET_MESSENGER_Messageget_room_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Returns a message locally stored from a map for a given hash in a room. More...
 
struct GNUNET_MESSENGER_Contactget_room_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Returns a messages sender locally stored from a map for a given hash in a room. More...
 
static struct GNUNET_MESSENGER_Contacthandle_join_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_leave_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_name_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_key_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_id_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_miss_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_delete_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
struct GNUNET_MESSENGER_Contacthandle_room_message (struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Handles a message with a given hash in a room for the client API to update members and its information. More...
 
static int iterate_local_members (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
int iterate_room_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, void *cls)
 Iterates through all members of a given room to forward each of them to a selected callback with a custom closure. More...
 
static int iterate_find_member (void *cls, const struct GNUNET_ShortHashCode *key, void *value)
 
int find_room_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
 Checks through all members of a given room if a specific contact is found and returns a result depending on that. More...
 

Detailed Description

messenger api: client implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_room.c.

Function Documentation

◆ create_room()

struct GNUNET_MESSENGER_Room* create_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Creates and allocates a new room for a handle with a given key for the client API.

Parameters

Definition at line 31 of file messenger_api_room.c.

References GNUNET_MESSENGER_Room::contact_id, GNUNET_MESSENGER_Room::entries, GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multishortmap_create(), GNUNET_memcpy, GNUNET_new, GNUNET_NO, handle, GNUNET_MESSENGER_Room::handle, init_list_tunnels(), GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::members, GNUNET_MESSENGER_Room::messages, and GNUNET_MESSENGER_Room::opened.

32 {
33  GNUNET_assert((handle) && (key));
34 
36 
37  room->handle = handle;
38  GNUNET_memcpy(&(room->key), key, sizeof(*key));
39 
40  room->opened = GNUNET_NO;
41  room->contact_id = NULL;
42 
43  init_list_tunnels (&(room->entries));
44 
47 
48  return room;
49 }
struct GNUNET_HashCode key
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * members
#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.
struct GNUNET_CONTAINER_MultiHashMap * messages
struct GNUNET_MESSENGER_ListTunnels entries
struct GNUNET_ShortHashCode * contact_id
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiShortmap * GNUNET_CONTAINER_multishortmap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
struct GNUNET_MESSENGER_Handle * handle
void init_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Initializes list of tunnels peer identities as empty list.
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:

◆ iterate_destroy_message()

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

Definition at line 52 of file messenger_api_room.c.

References destroy_message(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_RoomMessageEntry::message, and value.

Referenced by destroy_room().

53 {
55 
56  destroy_message (entry->message);
57  GNUNET_free(entry);
58 
59  return GNUNET_YES;
60 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
static char * value
Value of the record to add/remove.
struct GNUNET_MESSENGER_Message * message
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_room()

void destroy_room ( struct GNUNET_MESSENGER_Room room)

Destroys a room and frees its memory fully from the client API.

Parameters

Definition at line 63 of file messenger_api_room.c.

References clear_list_tunnels(), GNUNET_MESSENGER_Room::contact_id, GNUNET_MESSENGER_Room::entries, GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multishortmap_destroy(), GNUNET_free, iterate_destroy_message(), GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_Room::messages.

64 {
65  GNUNET_assert(room);
66 
67  clear_list_tunnels (&(room->entries));
68 
69  if (room->messages)
70  {
72 
74  }
75 
76  if (room->members)
78 
79  if (room->contact_id)
80  GNUNET_free(room->contact_id);
81 
82  GNUNET_free(room);
83 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_CONTAINER_MultiHashMap * messages
struct GNUNET_MESSENGER_ListTunnels entries
struct GNUNET_ShortHashCode * contact_id
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void clear_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Clears the list of tunnels peer identities.
void GNUNET_CONTAINER_multishortmap_destroy(struct GNUNET_CONTAINER_MultiShortmap *map)
Destroy a hash map.
static int iterate_destroy_message(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.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ get_room_message()

const struct GNUNET_MESSENGER_Message* get_room_message ( const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_HashCode hash 
)

Returns a message locally stored from a map for a given hash in a room.

If no matching message is found, NULL gets returned.

Parameters
[in]roomRoom
[in]hashHash of message
Returns
Message or NULL

Definition at line 86 of file messenger_api_room.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_MESSENGER_RoomMessageEntry::message, and GNUNET_MESSENGER_Room::messages.

Referenced by GNUNET_MESSENGER_get_message().

87 {
88  GNUNET_assert((room) && (hash));
89 
91  room->messages, hash
92  );
93 
94  return (entry? entry->message : NULL);
95 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * 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.
struct GNUNET_MESSENGER_Message * message
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_room_sender()

struct GNUNET_MESSENGER_Contact* get_room_sender ( const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_HashCode hash 
)

Returns a messages sender locally stored from a map for a given hash in a room.

If no matching message is found, NULL gets returned.

Parameters
[in]roomRoom
[in]hashHash of message
Returns
Contact of sender or NULL

Definition at line 98 of file messenger_api_room.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_MESSENGER_Room::messages, and GNUNET_MESSENGER_RoomMessageEntry::sender.

Referenced by GNUNET_MESSENGER_get_sender().

99 {
100  GNUNET_assert((room) && (hash));
101 
103  room->messages, hash
104  );
105 
106  return (entry? entry->sender : NULL);
107 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiHashMap * 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.
struct GNUNET_MESSENGER_Contact * sender
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_join_message()

static struct GNUNET_MESSENGER_Contact* handle_join_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 110 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, get_context_from_member(), get_handle_contact_store(), get_store_contact(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_contains_value(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Message::header, increase_contact_rc(), GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_room_message().

112 {
113  if (!sender)
114  {
116  struct GNUNET_HashCode context;
117 
118  get_context_from_member(&(room->key), &(message->header.sender_id), &context);
119 
120  sender = get_store_contact(store, &context, &(message->body.join.key));
121  }
122 
126  increase_contact_rc(sender);
127 
128  return sender;
129 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_HashCode key
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_CONTAINER_MultiShortmap * members
static pa_context * context
Pulseaudio context.
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_MESSENGER_MessageBody body
Body.
void increase_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Increases the reference counter of a given contact which is zero as default.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
A 512-bit hashcode.
struct GNUNET_MESSENGER_Contact * get_store_contact(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact using a specific public key.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
Allow multiple values with the same key.
struct GNUNET_MESSENGER_MessageJoin join
int GNUNET_CONTAINER_multishortmap_contains_value(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Check if the map contains the given value under the given key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_leave_message()

static void handle_leave_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 132 of file messenger_api_room.c.

References decrease_contact_rc(), get_context_from_member(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_room_message().

134 {
135  if ((!sender) ||
137  return;
138 
139  struct GNUNET_HashCode context;
140  get_context_from_member(&(room->key), &(message->header.sender_id), &context);
141 
142  if (GNUNET_YES == decrease_contact_rc(sender))
143  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "A contact does not share any room with you anymore!\n");
144 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
int decrease_contact_rc(struct GNUNET_MESSENGER_Contact *contact)
Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNE...
struct GNUNET_HashCode key
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_CONTAINER_MultiShortmap * members
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
static pa_context * context
Pulseaudio context.
A 512-bit hashcode.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_name_message()

static void handle_name_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 147 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, and set_contact_name().

Referenced by handle_room_message().

149 {
150  if (!sender)
151  return;
152 
153  set_contact_name (sender, message->body.name.name);
154 }
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageName name
char * name
The new name which replaces the current senders name.
void set_contact_name(struct GNUNET_MESSENGER_Contact *contact, const char *name)
Changes the current name of a given contact by copying it from the parameter name.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_key_message()

static void handle_key_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 157 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, get_context_from_member(), get_handle_contact_store(), GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_MessageHeader::sender_id, and update_store_contact().

Referenced by handle_room_message().

159 {
160  if (!sender)
161  return;
162 
163  struct GNUNET_HashCode context;
164  get_context_from_member(&(room->key), &(message->header.sender_id), &context);
165 
167 
168  update_store_contact(store, sender, &context, &context, &(message->body.key.key));
169 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_HashCode key
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_MESSENGER_MessageKey key
void update_store_contact(struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Moves a contact from the store to another location matching a given public key and member context...
static pa_context * context
Pulseaudio context.
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_MESSENGER_MessageBody body
Body.
A 512-bit hashcode.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_id_message()

static void handle_id_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 172 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, get_contact_key(), get_context_from_member(), get_handle_contact_store(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Room::members, GNUNET_MESSENGER_MessageHeader::sender_id, and update_store_contact().

Referenced by handle_room_message().

174 {
175  if ((!sender) ||
176  (GNUNET_YES != GNUNET_CONTAINER_multishortmap_remove(room->members, &(message->header.sender_id), sender)) ||
177  (GNUNET_OK != GNUNET_CONTAINER_multishortmap_put(room->members, &(message->body.id.id), sender,
179  return;
180 
181  struct GNUNET_HashCode context, next_context;
182  get_context_from_member(&(room->key), &(message->header.sender_id), &context);
183  get_context_from_member(&(room->key), &(message->body.id.id), &next_context);
184 
186 
187  update_store_contact(store, sender, &context, &next_context, get_contact_key(sender));
188 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_HashCode key
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
void update_store_contact(struct GNUNET_MESSENGER_ContactStore *store, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *next_context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Moves a contact from the store to another location matching a given public key and member context...
static pa_context * context
Pulseaudio context.
struct GNUNET_MESSENGER_MessageBody body
Body.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
A 512-bit hashcode.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
Allow multiple values with the same key.
struct GNUNET_MESSENGER_MessageId id
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_miss_message()

static void handle_miss_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 191 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_Room::contact_id, GNUNET_MESSENGER_Room::entries, find_list_tunnels(), GNUNET_memcmp, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageBody::miss, GNUNET_MESSENGER_MessageMiss::peer, remove_from_list_tunnels(), and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_room_message().

193 {
194  if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id)))
195  {
196  struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels (&(room->entries), &(message->body.miss.peer), NULL);
197 
198  if (match)
199  remove_from_list_tunnels (&(room->entries), match);
200  }
201 }
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_MESSENGER_ListTunnels entries
struct GNUNET_ShortHashCode * contact_id
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessageBody body
Body.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_MESSENGER_ListTunnel * find_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, size_t *index)
Searches linearly through the list of tunnels peer identities for matching a specific peer identity a...
struct GNUNET_MESSENGER_ListTunnel * remove_from_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, struct GNUNET_MESSENGER_ListTunnel *element)
Removes a specific element from the list of tunnels peer identities and returns the next element in t...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_delete_message()

static void handle_delete_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 204 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_MESSENGER_MessageBody::deletion, destroy_message(), get_handle_contact(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_YES, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_MessageDelete::hash, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_RoomMessageEntry::message, GNUNET_MESSENGER_Room::messages, and GNUNET_MESSENGER_RoomMessageEntry::sender.

Referenced by handle_room_message().

206 {
208  room->messages, &(message->body.deletion.hash)
209  );
210 
211  if ((entry) && ((entry->sender == sender) || (get_handle_contact (room->handle, &(room->key)) == sender)) &&
213  {
214  destroy_message (entry->message);
215  GNUNET_free(entry);
216  }
217 }
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_HashCode key
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_CONTAINER_MultiHashMap * 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.
struct GNUNET_MESSENGER_MessageDelete deletion
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_MessageBody body
Body.
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.
struct GNUNET_MESSENGER_Contact * sender
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_Contact * get_handle_contact(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Returns the contact of a given handle in a room identified by a given key.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_room_message()

struct GNUNET_MESSENGER_Contact* handle_room_message ( struct GNUNET_MESSENGER_Room room,
struct GNUNET_MESSENGER_Contact sender,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)

Handles a message with a given hash in a room for the client API to update members and its information.

The function also stores the message in map locally for access afterwards.

The contact of the message's sender could be updated or even created. It may not be freed or destroyed though! (The contact may still be in use for old messages...)

Parameters

Definition at line 220 of file messenger_api_room.c.

References copy_message(), destroy_message(), GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_free, GNUNET_MESSENGER_KIND_DELETE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_new, GNUNET_NO, GNUNET_OK, handle_delete_message(), handle_id_message(), handle_join_message(), handle_key_message(), handle_leave_message(), handle_miss_message(), handle_name_message(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_RoomMessageEntry::message, GNUNET_MESSENGER_Room::messages, and GNUNET_MESSENGER_RoomMessageEntry::sender.

Referenced by handle_recv_message().

222 {
224  return sender;
225 
226  switch (message->header.kind)
227  {
229  sender = handle_join_message (room, sender, message, hash);
230  break;
232  handle_leave_message (room, sender, message, hash);
233  break;
235  handle_name_message (room, sender, message, hash);
236  break;
238  handle_key_message (room, sender, message, hash);
239  break;
241  handle_id_message (room, sender, message, hash);
242  break;
244  handle_miss_message (room, sender, message, hash);
245  break;
247  handle_delete_message (room, sender, message, hash);
248  break;
249  default:
250  break;
251  }
252 
254 
255  if (!entry)
256  return sender;
257 
258  entry->sender = sender;
259  entry->message = copy_message (message);
260 
261  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, entry,
263  {
264  destroy_message (entry->message);
265  GNUNET_free(entry);
266  }
267 
268  return sender;
269 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
static void handle_miss_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
static void handle_key_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
#define GNUNET_new(type)
Allocate a struct or union of the given type.
int GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL)...
struct GNUNET_CONTAINER_MultiHashMap * messages
static void handle_id_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
static void handle_leave_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_MESSENGER_Message * message
static void handle_name_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
struct GNUNET_MESSENGER_Contact * sender
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
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.
static struct GNUNET_MESSENGER_Contact * handle_join_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
static void handle_delete_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
#define GNUNET_free(ptr)
Wrapper around free.
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:

◆ iterate_local_members()

static int iterate_local_members ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 279 of file messenger_api_room.c.

References call, GNUNET_MESSENGER_MemberCall::callback, GNUNET_MESSENGER_MemberCall::cls, GNUNET_MESSENGER_MemberCall::room, and value.

Referenced by iterate_room_members().

280 {
282  struct GNUNET_MESSENGER_Contact *contact = value;
283 
284  return call->callback(call->cls, call->room, contact);
285 }
struct GNUNET_MESSENGER_Room * room
GNUNET_MESSENGER_MemberCallback callback
static char * value
Value of the record to add/remove.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
Here is the caller graph for this function:

◆ iterate_room_members()

int iterate_room_members ( struct GNUNET_MESSENGER_Room room,
GNUNET_MESSENGER_MemberCallback  callback,
void *  cls 
)

Iterates through all members of a given room to forward each of them to a selected callback with a custom closure.

Parameters

Definition at line 288 of file messenger_api_room.c.

References GNUNET_MESSENGER_MemberCall::callback, GNUNET_MESSENGER_MemberCall::cls, GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), iterate_local_members(), GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MemberCall::room.

Referenced by GNUNET_MESSENGER_iterate_members().

290 {
291  GNUNET_assert(room);
292 
293  if (!callback)
294  return GNUNET_CONTAINER_multishortmap_iterate(room->members, NULL, NULL);
295 
297 
298  call.room = room;
299  call.callback = callback;
300  call.cls = cls;
301 
303 
305 }
static int iterate_local_members(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_Room * room
GNUNET_MESSENGER_MemberCallback callback
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_CONVERSATION_Call * call
Call handle (for active outgoing call).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_find_member()

static int iterate_find_member ( void *  cls,
const struct GNUNET_ShortHashCode key,
void *  value 
)
static

Definition at line 314 of file messenger_api_room.c.

References GNUNET_MESSENGER_MemberCall::cls, GNUNET_MESSENGER_MemberFind::contact, GNUNET_NO, GNUNET_YES, GNUNET_MESSENGER_MemberFind::result, and value.

Referenced by find_room_member().

315 {
316  struct GNUNET_MESSENGER_MemberFind *find = cls;
317  struct GNUNET_MESSENGER_Contact *contact = value;
318 
319  if (contact == find->contact)
320  {
321  find->result = GNUNET_YES;
322  return GNUNET_NO;
323  }
324 
325  return GNUNET_YES;
326 }
const struct GNUNET_MESSENGER_Contact * contact
static char * value
Value of the record to add/remove.
Here is the caller graph for this function:

◆ find_room_member()

int find_room_member ( const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Contact contact 
)

Checks through all members of a given room if a specific contact is found and returns a result depending on that.

Parameters
[in]roomRoom
[in]contact
Returns
GNUNET_YES if found, otherwise GNUNET_NO

Definition at line 329 of file messenger_api_room.c.

References GNUNET_MESSENGER_MemberFind::contact, GNUNET_assert, GNUNET_CONTAINER_multishortmap_iterate(), GNUNET_NO, iterate_find_member(), GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MemberFind::result.

Referenced by iterate_find_room().

330 {
331  GNUNET_assert(room);
332 
333  struct GNUNET_MESSENGER_MemberFind find;
334 
335  find.contact = contact;
336  find.result = GNUNET_NO;
337 
339 
340  return find.result;
341 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_CONTAINER_MultiShortmap * members
const struct GNUNET_MESSENGER_Contact * contact
int GNUNET_CONTAINER_multishortmap_iterate(struct GNUNET_CONTAINER_MultiShortmap *map, GNUNET_CONTAINER_ShortmapIterator it, void *it_cls)
Iterate over all entries in the map.
static int iterate_find_member(void *cls, const struct GNUNET_ShortHashCode *key, void *value)
Here is the call graph for this function:
Here is the caller graph for this function: