GNUnet 0.21.1
messenger_api_handle.c File Reference
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_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 enum GNUNET_GenericReturnValue 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_CRYPTO_PrivateKey *key)
 Sets the keypair of a given handle to the keypair of a specific private key. More...
 
const struct GNUNET_CRYPTO_PrivateKeyget_handle_key (const struct GNUNET_MESSENGER_Handle *handle)
 Returns the private key of a given handle. More...
 
const struct GNUNET_CRYPTO_PublicKeyget_handle_pubkey (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...
 
struct GNUNET_MESSENGER_Roomget_handle_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Returns the room known to a handle identified by a given key. More...
 

Function Documentation

◆ create_handle()

struct GNUNET_MESSENGER_Handle * create_handle ( const struct GNUNET_CONFIGURATION_Handle cfg,
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_clsClosure
Returns
New handle

Definition at line 32 of file messenger_api_handle.c.

35{
37
40
41 handle->cfg = cfg;
42 handle->mq = NULL;
43
44 handle->msg_callback = msg_callback;
45 handle->msg_cls = msg_cls;
46
47 handle->name = NULL;
48 handle->key = NULL;
49 handle->pubkey = NULL;
50
51 handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
52 handle->reconnect_task = NULL;
53
55
57
58 return handle;
59}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
@ GNUNET_NO
#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:133
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.
GNUNET_MESSENGER_MessageCallback msg_callback
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44

References cfg, GNUNET_VPN_Handle::cfg, get_handle_contact_store(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_new, GNUNET_NO, GNUNET_TIME_relative_get_zero_(), handle, init_contact_store(), GNUNET_VPN_Handle::mq, GNUNET_MESSENGER_Handle::msg_callback, and GNUNET_MESSENGER_Handle::msg_cls.

Referenced by GNUNET_MESSENGER_connect().

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

◆ iterate_destroy_room()

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

Definition at line 63 of file messenger_api_handle.c.

66{
67 struct GNUNET_MESSENGER_Room *room = value;
68
69 destroy_room (room);
70
71 return GNUNET_YES;
72}
static char * value
Value of the record to add/remove.
@ GNUNET_YES
void destroy_room(struct GNUNET_MESSENGER_Room *room)
Destroys a room and frees its memory fully from the client API.

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]handleHandle

Definition at line 76 of file messenger_api_handle.c.

77{
79
80 if (handle->reconnect_task)
81 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
82
83 if (handle->mq)
85
86 if (handle->name)
87 GNUNET_free (handle->name);
88
89 if (handle->key)
90 GNUNET_free (handle->key);
91
92 if (handle->pubkey)
93 GNUNET_free (handle->pubkey);
94
95 if (handle->rooms)
96 {
98 NULL);
99
101 }
102
104
106}
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback 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:683
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
void clear_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Clears a contact store, wipes its content and deallocates its memory.
static enum GNUNET_GenericReturnValue 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(), and GNUNET_VPN_Handle::mq.

Referenced by GNUNET_MESSENGER_connect(), and GNUNET_MESSENGER_disconnect().

Here is the call graph for this function:
Here is the caller 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]handleHandle
[in]nameNew name

Definition at line 110 of file messenger_api_handle.c.

112{
114
115 if (handle->name)
116 GNUNET_free (handle->name);
117
118 handle->name = name ? GNUNET_strdup (name) : NULL;
119}
static char * name
Name (label) of the records to list.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

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

Referenced by GNUNET_MESSENGER_connect(), and GNUNET_MESSENGER_set_name().

Here is the caller graph for this function:

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

124{
126
127 return handle->name;
128}

References GNUNET_assert, and handle.

Referenced by GNUNET_MESSENGER_get_name(), handle_name_message(), iterate_send_name_to_room(), and send_message_to_room_with_key().

Here is the caller graph for this function:

◆ set_handle_key()

void set_handle_key ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_CRYPTO_PrivateKey key 
)

Sets the keypair of a given handle to the keypair of a specific private key.

Parameters
[in,out]handleHandle
[in]keyPrivate key or NULL

Definition at line 132 of file messenger_api_handle.c.

134{
136
137 if (! key)
138 {
139 if (handle->key)
140 GNUNET_free (handle->key);
141
142 if (handle->pubkey)
143 GNUNET_free (handle->pubkey);
144
145 handle->key = NULL;
146 handle->pubkey = NULL;
147 return;
148 }
149
150 if (! handle->key)
152
153 if (! handle->pubkey)
154 handle->pubkey = GNUNET_new (struct GNUNET_CRYPTO_PublicKey);
155
156 GNUNET_memcpy (handle->key, key, sizeof(*key));
158}
struct GNUNET_HashCode key
The key used in the DHT.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:602
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.

References GNUNET_assert, GNUNET_CRYPTO_key_get_public(), GNUNET_free, GNUNET_memcpy, GNUNET_new, handle, and key.

Referenced by GNUNET_MESSENGER_connect(), and GNUNET_MESSENGER_set_key().

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

◆ get_handle_key()

const struct GNUNET_CRYPTO_PrivateKey * get_handle_key ( const struct GNUNET_MESSENGER_Handle handle)

Returns the private key of a given handle.

Parameters
[in]handleHandle
Returns
Private key of the handle

Definition at line 162 of file messenger_api_handle.c.

163{
165
166 if (handle->key)
167 return handle->key;
168
170}
const struct GNUNET_CRYPTO_PrivateKey * get_anonymous_private_key()
Returns the private identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it ever...

References get_anonymous_private_key(), GNUNET_assert, and handle.

Referenced by enqueue_message_to_room(), handle_member_id(), and handle_private_message().

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

◆ get_handle_pubkey()

const struct GNUNET_CRYPTO_PublicKey * get_handle_pubkey ( 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 174 of file messenger_api_handle.c.

175{
177
178 if (handle->pubkey)
179 return handle->pubkey;
180
181 return get_anonymous_public_key ();
182}
const struct GNUNET_CRYPTO_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(), GNUNET_MESSENGER_get_key(), GNUNET_MESSENGER_send_ticket(), send_enter_room(), send_message_to_room_with_key(), and send_open_room().

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]handleHandle
Returns
Contact store

Definition at line 186 of file messenger_api_handle.c.

187{
189
190 return &(handle->contact_store);
191}

References GNUNET_assert, and handle.

Referenced by create_handle(), destroy_handle(), get_handle_contact(), handle_id_message(), handle_join_message(), handle_key_message(), handle_transcript_message(), process_message_control(), and task_message_control().

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]handleHandle
[in]keyKey of room
Returns
Contact

Definition at line 195 of file messenger_api_handle.c.

197{
198 GNUNET_assert ((handle) && (key));
199
201 handle->rooms, key);
202
203 if (! room)
204 return NULL;
205
206 const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room);
207
208 if (! contact_id)
209 return NULL;
210
212 get_context_from_member (key, contact_id, &context);
213
216}
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_CRYPTO_PublicKey *pubkey)
Returns a contact using a specific public key.
const struct GNUNET_CRYPTO_PublicKey * get_handle_pubkey(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
const struct GNUNET_ShortHashCode * get_room_sender_id(const struct GNUNET_MESSENGER_Room *room)
Returns the member id of the room's sender.
A 512-bit hashcode.
A 256-bit hashcode.

References context, get_context_from_member(), get_handle_contact_store(), get_handle_pubkey(), get_room_sender_id(), get_store_contact(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), handle, and key.

Referenced by handle_delete_message(), handle_private_message(), and handle_transcript_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]handleHandle
[in]keyKey of room

Definition at line 220 of file messenger_api_handle.c.

222{
223 GNUNET_assert ((handle) && (key));
224
226 handle->rooms, key);
227
228 if (room)
229 room->opened = GNUNET_YES;
230}
enum GNUNET_GenericReturnValue opened

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

Referenced by handle_room_open().

Here is the call graph for this function:
Here is the caller 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]handleHandle
[in]doorPeer identity
[in]keyKey of room

Definition at line 234 of file messenger_api_handle.c.

237{
238 GNUNET_assert ((handle) && (door) && (key));
239
241 handle->rooms, key);
242
243 if (room)
244 add_to_list_tunnels (&(room->entries), door, NULL);
245}
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HashCode *hash)
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]handleHandle
[in]keyKey of room

Definition at line 249 of file messenger_api_handle.c.

251{
252 GNUNET_assert ((handle) && (key));
253
255 handle->rooms, key);
256
258 handle->rooms, key, room)))
259 destroy_room (room);
260}
enum GNUNET_GenericReturnValue 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.

Referenced by handle_room_close().

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

◆ get_handle_room()

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

Returns the room known to a handle identified by a given key.

Parameters
[in,out]handlehandle Handle
[in]keyKey of room
Returns
Room or NULL

Definition at line 264 of file messenger_api_handle.c.

266{
267 GNUNET_assert ((handle) && (key));
268
270}

References GNUNET_assert, GNUNET_CONTAINER_multihashmap_get(), handle, and key.

Referenced by handle_member_id(), handle_miss_message(), handle_recv_message(), handle_room_close(), handle_room_entry(), handle_room_open(), and handle_room_sync().

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