GNUnet  0.11.x
Data Structures | Functions
messenger_api_handle.h File Reference

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

#include "platform.h"
#include "gnunet_cadet_service.h"
#include "gnunet_container_lib.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_identity_service.h"
#include "gnunet_peer_lib.h"
#include "gnunet_messenger_service.h"
#include "messenger_api_contact_store.h"
#include "messenger_api_room.h"
Include dependency graph for messenger_api_handle.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_Handle
 

Functions

struct GNUNET_MESSENGER_Handlecreate_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
 Creates and allocates a new handle using a given configuration and a custom message callback with a given closure for the client API. More...
 
void destroy_handle (struct GNUNET_MESSENGER_Handle *handle)
 Destroys a handle and frees its memory fully from the client API. More...
 
void set_handle_name (struct GNUNET_MESSENGER_Handle *handle, const char *name)
 Sets the name of a handle to a specific name. More...
 
const char * get_handle_name (const struct GNUNET_MESSENGER_Handle *handle)
 Returns the current name of a given handle or NULL if no valid name was assigned yet. More...
 
void set_handle_key (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey)
 Sets the public key of a given handle to a specific public key. More...
 
const struct GNUNET_IDENTITY_PublicKeyget_handle_key (const struct GNUNET_MESSENGER_Handle *handle)
 Returns the public key of a given handle. More...
 
struct GNUNET_MESSENGER_ContactStoreget_handle_contact_store (struct GNUNET_MESSENGER_Handle *handle)
 Returns the used contact store of a given handle. More...
 
struct GNUNET_MESSENGER_Contactget_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. More...
 
void open_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Marks a room known to a handle identified by a given key as open. More...
 
void entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections. More...
 
void close_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Destroys and so implicitly closes a room known to a handle identified by a given key. More...
 

Detailed Description

messenger api: client implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_handle.h.

Function Documentation

◆ create_handle()

struct GNUNET_MESSENGER_Handle* create_handle ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_MESSENGER_IdentityCallback  identity_callback,
void *  identity_cls,
GNUNET_MESSENGER_MessageCallback  msg_callback,
void *  msg_cls 
)

Creates and allocates a new handle using a given configuration and a custom message callback with a given closure for the client API.

Parameters
[in]cfgConfiguration
[in]msg_callbackMessage callback

Definition at line 31 of file messenger_api_handle.c.

References cfg, GNUNET_MESSENGER_Handle::cfg, get_handle_contact_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_new, GNUNET_NO, GNUNET_TIME_relative_get_zero_(), handle, GNUNET_MESSENGER_Handle::identity_callback, GNUNET_MESSENGER_Handle::identity_cls, init_contact_store(), GNUNET_MESSENGER_Handle::mq, GNUNET_MESSENGER_Handle::msg_callback, GNUNET_MESSENGER_Handle::msg_cls, GNUNET_MESSENGER_Handle::name, GNUNET_MESSENGER_Handle::pubkey, GNUNET_MESSENGER_Handle::reconnect_task, GNUNET_MESSENGER_Handle::reconnect_time, and GNUNET_MESSENGER_Handle::rooms.

33 {
34  GNUNET_assert(cfg);
35 
37 
38  handle->cfg = cfg;
39  handle->mq = NULL;
40 
42  handle->identity_cls = identity_cls;
43 
44  handle->msg_callback = msg_callback;
45  handle->msg_cls = msg_cls;
46 
47  handle->name = NULL;
48  handle->pubkey = NULL;
49 
51  handle->reconnect_task = NULL;
52 
54 
56 
57  return handle;
58 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
void init_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Initializes a contact store as fully empty.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * reconnect_task
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MQ_Handle * mq
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition: time.c:100
GNUNET_MESSENGER_MessageCallback msg_callback
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
struct GNUNET_TIME_Relative reconnect_time
const struct GNUNET_CONFIGURATION_Handle * cfg
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
struct GNUNET_IDENTITY_PublicKey * pubkey
GNUNET_MESSENGER_IdentityCallback identity_callback
Here is the call graph for this function:

◆ destroy_handle()

void destroy_handle ( struct GNUNET_MESSENGER_Handle handle)

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

Parameters

Definition at line 71 of file messenger_api_handle.c.

References clear_contact_store(), get_handle_contact_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), iterate_destroy_room(), GNUNET_MESSENGER_Handle::mq, GNUNET_MESSENGER_Handle::name, GNUNET_MESSENGER_Handle::pubkey, GNUNET_MESSENGER_Handle::reconnect_task, and GNUNET_MESSENGER_Handle::rooms.

72 {
73  GNUNET_assert(handle);
74 
75  if (handle->reconnect_task)
77 
78  if (handle->mq)
79  GNUNET_MQ_destroy (handle->mq);
80 
81  if (handle->name)
82  GNUNET_free(handle->name);
83 
84  if (handle->pubkey)
85  GNUNET_free(handle->pubkey);
86 
87  if (handle->rooms)
88  {
90 
92  }
93 
95 
96  GNUNET_free(handle->name);
97 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * reconnect_task
struct GNUNET_MQ_Handle * mq
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * rooms
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
struct GNUNET_IDENTITY_PublicKey * pubkey
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
static int iterate_destroy_room(void *cls, const struct GNUNET_HashCode *key, void *value)
void clear_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Clears a contact store, wipes its content and deallocates its memory.
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:

◆ set_handle_name()

void set_handle_name ( struct GNUNET_MESSENGER_Handle handle,
const char *  name 
)

Sets the name of a handle to a specific name.

Parameters

Definition at line 100 of file messenger_api_handle.c.

References GNUNET_assert, GNUNET_free, GNUNET_strdup, and GNUNET_MESSENGER_Handle::name.

101 {
102  GNUNET_assert(handle);
103 
104  if (handle->name)
105  GNUNET_free(handle->name);
106 
107  handle->name = name ? GNUNET_strdup(name) : NULL;
108 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const char * name
#define GNUNET_free(ptr)
Wrapper around free.

◆ get_handle_name()

const char* get_handle_name ( const struct GNUNET_MESSENGER_Handle handle)

Returns the current name of a given handle or NULL if no valid name was assigned yet.

Parameters
[in]handleHandle
Returns
Name of the handle or NULL

Definition at line 111 of file messenger_api_handle.c.

References GNUNET_assert, and GNUNET_MESSENGER_Handle::name.

Referenced by GNUNET_MESSENGER_get_name(), and GNUNET_MESSENGER_update().

112 {
113  GNUNET_assert(handle);
114 
115  return handle->name;
116 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ set_handle_key()

void set_handle_key ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_IDENTITY_PublicKey pubkey 
)

Sets the public key of a given handle to a specific public key.

Parameters

Definition at line 119 of file messenger_api_handle.c.

References GNUNET_assert, GNUNET_memcpy, GNUNET_new, and GNUNET_MESSENGER_Handle::pubkey.

Referenced by handle_get_key().

120 {
121  GNUNET_assert(handle);
122 
123  if (!handle->pubkey)
124  handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey);
125 
126  GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey));
127 }
#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.
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PublicKey * pubkey
Here is the caller graph for this function:

◆ get_handle_key()

const struct GNUNET_IDENTITY_PublicKey* get_handle_key ( const struct GNUNET_MESSENGER_Handle handle)

Returns the public key of a given handle.

Parameters
[in]handleHandle
Returns
Public key of the handle

Definition at line 130 of file messenger_api_handle.c.

References get_anonymous_public_key(), GNUNET_assert, and GNUNET_MESSENGER_Handle::pubkey.

Referenced by get_handle_contact(), and GNUNET_MESSENGER_get_key().

131 {
132  GNUNET_assert(handle);
133 
134  if (handle->pubkey)
135  return handle->pubkey;
136 
137  return get_anonymous_public_key ();
138 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_IDENTITY_PublicKey * pubkey
const struct GNUNET_IDENTITY_PublicKey * get_anonymous_public_key()
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_handle_contact_store()

struct GNUNET_MESSENGER_ContactStore* get_handle_contact_store ( struct GNUNET_MESSENGER_Handle handle)

Returns the used contact store of a given handle.

Parameters

Definition at line 141 of file messenger_api_handle.c.

References GNUNET_MESSENGER_Handle::contact_store, and GNUNET_assert.

Referenced by create_handle(), destroy_handle(), get_handle_contact(), handle_id_message(), handle_join_message(), handle_key_message(), and handle_recv_message().

142 {
143  GNUNET_assert(handle);
144 
145  return &(handle->contact_store);
146 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MESSENGER_ContactStore contact_store
Here is the caller graph for this function:

◆ get_handle_contact()

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.

Parameters

Definition at line 149 of file messenger_api_handle.c.

References GNUNET_MESSENGER_Room::contact_id, get_context_from_member(), get_handle_contact_store(), get_handle_key(), get_store_contact(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), and GNUNET_MESSENGER_Handle::rooms.

Referenced by handle_delete_message().

150 {
151  GNUNET_assert((handle) && (key));
152 
153  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
154 
155  if ((!room) || (!(room->contact_id)))
156  return NULL;
157 
158  struct GNUNET_HashCode context;
160 
162 }
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static pa_context * context
Pulseaudio context.
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_ShortHashCode * contact_id
struct GNUNET_CONTAINER_MultiHashMap * rooms
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_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:

◆ open_handle_room()

void open_handle_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Marks a room known to a handle identified by a given key as open.

Parameters

Definition at line 165 of file messenger_api_handle.c.

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_YES, GNUNET_MESSENGER_Room::opened, and GNUNET_MESSENGER_Handle::rooms.

166 {
167  GNUNET_assert((handle) && (key));
168 
169  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
170 
171  if (room)
172  room->opened = GNUNET_YES;
173 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_CONTAINER_MultiHashMap * rooms
Here is the call graph for this function:

◆ entry_handle_room_at()

void entry_handle_room_at ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_PeerIdentity door,
const struct GNUNET_HashCode key 
)

Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections.

Parameters

Definition at line 176 of file messenger_api_handle.c.

References add_to_list_tunnels(), GNUNET_MESSENGER_Room::entries, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), and GNUNET_MESSENGER_Handle::rooms.

Referenced by handle_room_entry().

178 {
179  GNUNET_assert((handle) && (door) && (key));
180 
181  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
182 
183  if (room)
184  add_to_list_tunnels (&(room->entries), door);
185 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Adds a specific peer from a tunnel to the end of the list.
struct GNUNET_MESSENGER_ListTunnels entries
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_CONTAINER_MultiHashMap * rooms
Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_handle_room()

void close_handle_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Destroys and so implicitly closes a room known to a handle identified by a given key.

Parameters

Definition at line 188 of file messenger_api_handle.c.

References destroy_room(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, and GNUNET_MESSENGER_Handle::rooms.

189 {
190  GNUNET_assert((handle) && (key));
191 
192  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
193 
194  if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room)))
195  destroy_room (room);
196 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
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_CONTAINER_MultiHashMap * rooms
Here is the call graph for this function: