GNUnet  0.11.x
Functions
messenger_api_handle.c File Reference

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

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

Go to the source code of this file.

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...
 
static int iterate_destroy_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
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.c.

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
[in/out]msg_cls Closure
Returns
New handle

Definition at line 31 of file messenger_api_handle.c.

36 {
38 
40 
41  handle->cfg = cfg;
42  handle->mq = NULL;
43 
44  handle->identity_callback = identity_callback;
45  handle->identity_cls = identity_cls;
46 
47  handle->msg_callback = msg_callback;
48  handle->msg_cls = msg_cls;
49 
50  handle->name = NULL;
51  handle->pubkey = NULL;
52 
53  handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
54  handle->reconnect_task = NULL;
55 
57 
59 
60  return handle;
61 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
@ GNUNET_NO
Definition: gnunet_common.h:94
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition: time.c:100
void init_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Initializes a contact store as fully empty.
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
GNUNET_MESSENGER_MessageCallback msg_callback
GNUNET_MESSENGER_IdentityCallback identity_callback

References cfg, GNUNET_DNS_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_DNS_Handle::mq, GNUNET_MESSENGER_Handle::msg_callback, GNUNET_MESSENGER_Handle::msg_cls, and GNUNET_DNS_Handle::reconnect_task.

Here is the call graph for this function:

◆ iterate_destroy_room()

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

Definition at line 64 of file messenger_api_handle.c.

67 {
68  struct GNUNET_MESSENGER_Room *room = value;
69 
70  destroy_room (room);
71 
72  return GNUNET_YES;
73 }
static char * value
Value of the record to add/remove.
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
@ GNUNET_YES
Definition: gnunet_common.h:97

References destroy_room(), GNUNET_YES, and value.

Referenced by destroy_handle().

Here is the call graph for this function:
Here is the caller 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
[in/out]handle Handle

Definition at line 76 of file messenger_api_handle.c.

77 {
79 
82 
83  if (handle->mq)
85 
86  if (handle->name)
87  GNUNET_free(handle->name);
88 
89  if (handle->pubkey)
90  GNUNET_free(handle->pubkey);
91 
92  if (handle->rooms)
93  {
95 
97  }
98 
100 
101  GNUNET_free(handle->name);
102 }
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
void clear_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Clears a contact store, wipes its content and deallocates its memory.
static int iterate_destroy_room(void *cls, const struct GNUNET_HashCode *key, void *value)

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(), handle, iterate_destroy_room(), GNUNET_DNS_Handle::mq, and GNUNET_DNS_Handle::reconnect_task.

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
[in/out]handle Handle
[in]nameNew name

Definition at line 105 of file messenger_api_handle.c.

107 {
109 
110  if (handle->name)
111  GNUNET_free(handle->name);
112 
113  handle->name = name ? GNUNET_strdup(name) : NULL;
114 }
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
const char * name

References GNUNET_assert, GNUNET_free, GNUNET_strdup, handle, and name.

◆ 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 117 of file messenger_api_handle.c.

118 {
120 
121  return handle->name;
122 }

References GNUNET_assert, and handle.

Referenced by GNUNET_MESSENGER_get_name(), and GNUNET_MESSENGER_update().

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
[in/out]handle Handle
[in]pubkeyPublic key

Definition at line 125 of file messenger_api_handle.c.

127 {
129 
130  if (!handle->pubkey)
131  handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey);
132 
133  GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey));
134 }
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
An identity key as per LSD0001.

References GNUNET_assert, GNUNET_memcpy, GNUNET_new, handle, and pubkey.

Referenced by handle_get_key().

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 137 of file messenger_api_handle.c.

138 {
140 
141  if (handle->pubkey)
142  return handle->pubkey;
143 
144  return get_anonymous_public_key ();
145 }
const struct GNUNET_IDENTITY_PublicKey * get_anonymous_public_key()
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...

References get_anonymous_public_key(), GNUNET_assert, and handle.

Referenced by get_handle_contact(), and GNUNET_MESSENGER_get_key().

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
[in/out]handle Handle
Returns
Contact store

Definition at line 148 of file messenger_api_handle.c.

149 {
151 
152  return &(handle->contact_store);
153 }

References GNUNET_assert, and handle.

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

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
[in/out]handle Handle
[in]keyKey of room
Returns
Contact

Definition at line 156 of file messenger_api_handle.c.

158 {
159  GNUNET_assert((handle) && (key));
160 
162 
163  if ((!room) || (!(room->contact_id)))
164  return NULL;
165 
166  struct GNUNET_HashCode context;
168 
170 }
struct GNUNET_HashCode key
The key used in the DHT.
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.
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_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.
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
A 512-bit hashcode.
struct GNUNET_ShortHashCode * contact_id

References GNUNET_MESSENGER_Room::contact_id, context, get_context_from_member(), get_handle_contact_store(), get_handle_key(), get_store_contact(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), handle, and key.

Referenced by handle_delete_message().

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
[in/out]handle Handle
[in]keyKey of room

Definition at line 173 of file messenger_api_handle.c.

175 {
176  GNUNET_assert((handle) && (key));
177 
179 
180  if (room)
181  room->opened = GNUNET_YES;
182 }

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_YES, handle, key, and GNUNET_MESSENGER_Room::opened.

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
[in/out]handle Handle
[in]doorPeer identity
[in]keyKey of room

Definition at line 185 of file messenger_api_handle.c.

188 {
189  GNUNET_assert((handle) && (door) && (key));
190 
192 
193  if (room)
194  add_to_list_tunnels (&(room->entries), door);
195 }
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

References add_to_list_tunnels(), GNUNET_MESSENGER_Room::entries, GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), handle, and key.

Referenced by handle_room_entry().

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
[in/out]handle Handle
[in]keyKey of room

Definition at line 198 of file messenger_api_handle.c.

200 {
201  GNUNET_assert((handle) && (key));
202 
204 
205  if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room)))
206  destroy_room (room);
207 }
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.

References destroy_room(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_YES, handle, and key.

Here is the call graph for this function: