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 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)
 
static int iterate_destroy_contact (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_Contactget_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. More...
 
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 entries to access the contact by its updated 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
cfgConfiguration
msg_callbackMessage callback
msg_clsClosure
Returns
New handle

Definition at line 29 of file messenger_api_handle.c.

References cfg, GNUNET_MESSENGER_Handle::cfg, GNUNET_MESSENGER_Handle::contacts, GNUNET_CONTAINER_multihashmap_create(), GNUNET_new, GNUNET_NO, GNUNET_TIME_relative_get_zero_(), handle, GNUNET_MESSENGER_Handle::identity_callback, GNUNET_MESSENGER_Handle::identity_cls, 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.

31 {
33 
34  handle->cfg = cfg;
35  handle->mq = NULL;
36 
38  handle->identity_cls = identity_cls;
39 
40  handle->msg_callback = msg_callback;
41  handle->msg_cls = msg_cls;
42 
43  handle->name = NULL;
44  handle->pubkey = NULL;
45 
47  handle->reconnect_task = NULL;
48 
51 
52  return handle;
53 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_CONTAINER_MultiHashMap * contacts
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:135
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_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:

◆ iterate_destroy_room()

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

Definition at line 56 of file messenger_api_handle.c.

References destroy_room(), GNUNET_YES, and value.

Referenced by destroy_handle().

57 {
58  struct GNUNET_MESSENGER_Room *room = value;
59 
60  destroy_room (room);
61 
62  return GNUNET_YES;
63 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room 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:

◆ iterate_destroy_contact()

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

Definition at line 66 of file messenger_api_handle.c.

References destroy_contact(), GNUNET_YES, and value.

Referenced by destroy_handle().

67 {
68  struct GNUNET_MESSENGER_Contact *contact = value;
69 
70  destroy_contact (contact);
71 
72  return GNUNET_YES;
73 }
void destroy_contact(struct GNUNET_MESSENGER_SrvContact *contact)
Destroys a contact 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_handle()

void destroy_handle ( struct GNUNET_MESSENGER_Handle handle)

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

Parameters
handleHandle

Definition at line 76 of file messenger_api_handle.c.

References GNUNET_MESSENGER_Handle::contacts, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), iterate_destroy_contact(), 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.

77 {
78  if (handle->reconnect_task)
80 
81  if (handle->mq)
82  GNUNET_MQ_destroy (handle->mq);
83 
84  if (handle->name)
85  GNUNET_free(handle->name);
86 
87  if (handle->pubkey)
88  GNUNET_free(handle->pubkey);
89 
90  if (handle->rooms)
91  {
93 
95  }
96 
97  if (handle->contacts)
98  {
100 
102  }
103 
104  GNUNET_free(handle->name);
105 }
struct GNUNET_CONTAINER_MultiHashMap * contacts
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_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)
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.
static int iterate_destroy_contact(void *cls, const struct GNUNET_HashCode *key, void *value)
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
handleHandle
nameNew name

Definition at line 108 of file messenger_api_handle.c.

References GNUNET_free, GNUNET_strdup, and GNUNET_MESSENGER_Handle::name.

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
#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
handleHandle
Returns
Name of the handle or NULL

Definition at line 117 of file messenger_api_handle.c.

References GNUNET_MESSENGER_Handle::name.

Referenced by GNUNET_MESSENGER_get_name(), and GNUNET_MESSENGER_update().

118 {
119  return handle->name;
120 }
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
handleHandle
pubkeyPublic key

Definition at line 123 of file messenger_api_handle.c.

References GNUNET_memcpy, GNUNET_new, and GNUNET_MESSENGER_Handle::pubkey.

Referenced by handle_get_key().

124 {
125  if (!handle->pubkey)
126  handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey);
127 
128  GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey));
129 }
#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
handleHandle
Returns
Public key of the handle

Definition at line 132 of file messenger_api_handle.c.

References GNUNET_IDENTITY_ego_get_anonymous(), GNUNET_IDENTITY_ego_get_public_key(), pubkey, and GNUNET_MESSENGER_Handle::pubkey.

Referenced by GNUNET_MESSENGER_get_key().

133 {
134  if (!handle->pubkey)
135  {
137  static struct GNUNET_IDENTITY_PublicKey pubkey;
138 
140 
141  return &pubkey;
142  }
143 
144  return handle->pubkey;
145 }
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_IDENTITY_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:652
Handle for an ego.
Definition: identity.h:36
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
struct GNUNET_IDENTITY_Ego * GNUNET_IDENTITY_ego_get_anonymous()
Obtain the ego representing 'anonymous' users.
Definition: identity_api.c:156
An identity key as per LSD0001.
struct GNUNET_IDENTITY_PublicKey * pubkey
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_handle_contact_by_pubkey()

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.

If not matching contact is found, NULL gets returned.

Parameters
handleHandle
pubkeyPublic key of EGO
Returns
Contact or NULL

Definition at line 148 of file messenger_api_handle.c.

References GNUNET_MESSENGER_Handle::contacts, create_contact(), destroy_contact(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CRYPTO_hash(), and GNUNET_OK.

Referenced by handle_join_message().

150 {
151  struct GNUNET_HashCode hash;
152 
153  GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &hash);
154 
155  struct GNUNET_MESSENGER_Contact *contact = GNUNET_CONTAINER_multihashmap_get (handle->contacts, &hash);
156 
157  if (contact)
158  return contact;
159 
160  contact = create_contact (pubkey);
161 
162  if (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put (handle->contacts, &hash, contact,
164  return contact;
165 
166  destroy_contact (contact);
167  return NULL;
168 }
struct GNUNET_CONTAINER_MultiHashMap * contacts
void destroy_contact(struct GNUNET_MESSENGER_SrvContact *contact)
Destroys a contact and frees its memory fully.
struct GNUNET_MESSENGER_SrvContact * create_contact(const struct GNUNET_IDENTITY_PublicKey *key)
Creates and allocates a new contact with a given public key from an EGO.
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.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
A 512-bit hashcode.
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap_handle_contact_by_pubkey()

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 entries to access the contact by its updated key.

Parameters
handleHandle
contactContact
pubkeyPublic key of EGO

Definition at line 171 of file messenger_api_handle.c.

References GNUNET_MESSENGER_Handle::contacts, get_contact_id_from_key(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_memcpy, GNUNET_YES, and GNUNET_MESSENGER_Contact::public_key.

Referenced by handle_key_message().

173 {
174  const struct GNUNET_HashCode *hash = get_contact_id_from_key (contact);
175 
176  if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->contacts, hash, contact))
177  {
178  GNUNET_memcpy(&(contact->public_key), pubkey, sizeof(*pubkey));
179 
180  hash = get_contact_id_from_key (contact);
181 
182  GNUNET_CONTAINER_multihashmap_put (handle->contacts, hash, contact,
184  }
185 }
struct GNUNET_CONTAINER_MultiHashMap * contacts
struct GNUNET_IDENTITY_PublicKey public_key
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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.
A 512-bit hashcode.
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.
const struct GNUNET_HashCode * get_contact_id_from_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the resulting hashcode of the public key from a given contact.
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
handleHandle
keyKey of room

Definition at line 188 of file messenger_api_handle.c.

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

189 {
190  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
191 
192  if (room)
193  room->opened = GNUNET_YES;
194 }
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
handleHandle
doorPeer identity
keyKey of room

Definition at line 197 of file messenger_api_handle.c.

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

Referenced by handle_room_entry().

199 {
200  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
201 
202  if (room)
203  add_to_list_tunnels (&(room->entries), door);
204 }
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
handleHandle
keyKey of room

Definition at line 207 of file messenger_api_handle.c.

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

208 {
209  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
210 
211  if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room)))
212  destroy_room (room);
213 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
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: