GNUnet  0.11.x
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.

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...
 
static void handle_join_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_leave_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_name_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_key_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_id_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
static void handle_miss_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 
void handle_room_message (struct GNUNET_MESSENGER_Room *room, 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...
 

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
handleHandle
keyKey of room
Returns
New room

Definition at line 31 of file messenger_api_room.c.

References GNUNET_MESSENGER_Room::contact_id, GNUNET_MESSENGER_Room::entries, 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 {
34 
35  room->handle = handle;
36  GNUNET_memcpy(&(room->key), key, sizeof(*key));
37 
38  room->opened = GNUNET_NO;
39  room->contact_id = NULL;
40 
42 
43  init_list_tunnels (&(room->entries));
44 
46 
47  return room;
48 }
struct GNUNET_HashCode key
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 51 of file messenger_api_room.c.

References destroy_message(), GNUNET_YES, and value.

Referenced by destroy_room().

52 {
53  struct GNUNET_MESSENGER_Message *message = value;
54 
55  destroy_message (message);
56 
57  return GNUNET_YES;
58 }
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.
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
roomRoom

Definition at line 61 of file messenger_api_room.c.

References clear_list_tunnels(), GNUNET_MESSENGER_Room::contact_id, GNUNET_MESSENGER_Room::entries, 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.

62 {
63  if (room->members)
65 
66  clear_list_tunnels (&(room->entries));
67 
68  if (room->messages)
69  {
71 
73  }
74 
75  if (room->contact_id)
76  GNUNET_free(room->contact_id);
77 
78  GNUNET_free(room);
79 }
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
roomRoom
hashHash of message
Returns
Message or NULL

Definition at line 82 of file messenger_api_room.c.

References GNUNET_CONTAINER_multihashmap_get(), and GNUNET_MESSENGER_Room::messages.

83 {
84  return GNUNET_CONTAINER_multihashmap_get (room->messages, hash);
85 }
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.
Here is the call graph for this function:

◆ handle_join_message()

static void handle_join_message ( struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 88 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, get_handle_contact_by_pubkey(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_put(), GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageBody::join, GNUNET_MESSENGER_MessageJoin::key, GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_room_message().

90 {
91  struct GNUNET_MESSENGER_Contact *contact = get_handle_contact_by_pubkey (room->handle, &(message->body.join.key));
92 
93  if (contact)
94  GNUNET_CONTAINER_multishortmap_put (room->members, &(message->header.sender_id), contact,
96 }
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_CONTAINER_MultiShortmap * members
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_IDENTITY_PublicKey key
The senders public key to verify its signatures.
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.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_Contact * get_handle_contact_by_pubkey(const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact known to a handle identified by a given public key.
struct GNUNET_MESSENGER_MessageJoin join
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,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 99 of file messenger_api_room.c.

References GNUNET_CONTAINER_multishortmap_remove_all(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_room_message().

101 {
103 }
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_CONTAINER_MultiShortmap * members
int GNUNET_CONTAINER_multishortmap_remove_all(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Remove all entries for the given key from the map.
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,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 106 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_CONTAINER_multishortmap_get(), GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_Room::members, GNUNET_MESSENGER_MessageName::name, GNUNET_MESSENGER_MessageBody::name, GNUNET_MESSENGER_MessageHeader::sender_id, and set_contact_name().

Referenced by handle_room_message().

108 {
110  &(message->header.sender_id));
111 
112  if (contact)
113  set_contact_name (contact, message->body.name.name);
114 }
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_CONTAINER_MultiShortmap * members
void set_contact_name(struct GNUNET_MESSENGER_SrvContact *contact, const char *name)
Changes the current name of a given contact by copying it from the parameter name.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageName name
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
char * name
The new name which replaces the current senders 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,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 117 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_CONTAINER_multishortmap_get(), GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageKey::key, GNUNET_MESSENGER_MessageBody::key, GNUNET_MESSENGER_Room::members, GNUNET_MESSENGER_MessageHeader::sender_id, and swap_handle_contact_by_pubkey().

Referenced by handle_room_message().

119 {
121  &(message->header.sender_id));
122 
123  if (contact)
124  swap_handle_contact_by_pubkey (room->handle, contact, &(message->body.key.key));
125 }
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_CONTAINER_MultiShortmap * members
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_Handle * handle
void swap_handle_contact_by_pubkey(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Contact *contact, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Changes the public key for a contact known to a handle to a specific public key and updates local map...
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
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,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 128 of file messenger_api_room.c.

References GNUNET_MESSENGER_Message::body, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_OK, GNUNET_MESSENGER_Message::header, GNUNET_MESSENGER_MessageId::id, GNUNET_MESSENGER_MessageBody::id, GNUNET_MESSENGER_Room::members, and GNUNET_MESSENGER_MessageHeader::sender_id.

Referenced by handle_room_message().

130 {
132  &(message->header.sender_id));
133 
134  if ((contact) && (GNUNET_OK
135  == GNUNET_CONTAINER_multishortmap_put (room->members, &(message->body.id.id), contact,
137  GNUNET_CONTAINER_multishortmap_remove (room->members, &(message->header.sender_id), contact);
138 }
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_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.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the 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,
const struct GNUNET_MESSENGER_Message message,
const struct GNUNET_HashCode hash 
)
static

Definition at line 141 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().

143 {
144  if ((room->contact_id) && (0 == GNUNET_memcmp(&(message->header.sender_id), room->contact_id)))
145  {
146  struct GNUNET_MESSENGER_ListTunnel *match = find_list_tunnels (&(room->entries), &(message->body.miss.peer), NULL);
147 
148  if (match)
149  remove_from_list_tunnels (&(room->entries), match);
150  }
151 }
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_room_message()

void handle_room_message ( struct GNUNET_MESSENGER_Room room,
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.

Parameters
roomRoom
messageMessage
hashHash of message

Definition at line 154 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_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_NO, GNUNET_OK, 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, and GNUNET_MESSENGER_Room::messages.

Referenced by handle_recv_message().

156 {
158  return;
159 
160  switch (message->header.kind)
161  {
163  handle_join_message (room, message, hash);
164  break;
166  handle_leave_message (room, message, hash);
167  break;
169  handle_name_message (room, message, hash);
170  break;
172  handle_key_message (room, message, hash);
173  break;
175  handle_id_message (room, message, hash);
176  break;
178  handle_miss_message (room, message, hash);
179  break;
180  default:
181  break;
182  }
183 
184  struct GNUNET_MESSENGER_Message *clone = copy_message (message);
185 
186  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (room->messages, hash, clone,
188  destroy_message (clone);
189 }
struct GNUNET_MESSENGER_MessageHeader header
Header.
static void handle_name_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
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_leave_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
static void handle_id_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
static void handle_miss_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
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 void handle_join_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
static void handle_key_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
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: