GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
messenger_api_contact.h File Reference
#include "gnunet_util_lib.h"
Include dependency graph for messenger_api_contact.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_Contact
 

Functions

struct GNUNET_MESSENGER_Contactcreate_contact (const struct GNUNET_CRYPTO_PublicKey *key, size_t unique_id)
 Creates and allocates a new contact with a given public key.
 
void destroy_contact (struct GNUNET_MESSENGER_Contact *contact)
 Destroys a contact and frees its memory fully.
 
const char * get_contact_name (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the current name of a given contact or NULL if no valid name was assigned yet.
 
void set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name)
 Changes the current name of a given contact by copying it from the parameter name.
 
const struct GNUNET_CRYPTO_PublicKeyget_contact_key (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the public key of a given contact.
 
void increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
 Increases the reference counter of a given contact which is zero as default.
 
enum GNUNET_GenericReturnValue decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
 Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNET_YES if the counter is equal to zero, otherwise GNUNET_NO.
 
size_t get_contact_id (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the locally unique identifier of a given contact.
 
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.
 

Function Documentation

◆ create_contact()

struct GNUNET_MESSENGER_Contact * create_contact ( const struct GNUNET_CRYPTO_PublicKey key,
size_t  unique_id 
)

Creates and allocates a new contact with a given public key.

Parameters
[in]keyPublic key
[in]unique_idLocally unique identifier
Returns
New contact

Definition at line 29 of file messenger_api_contact.c.

31{
32 struct GNUNET_MESSENGER_Contact *contact;
33
35
36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Create new contact: %lu\n",
37 unique_id);
38
39 contact = GNUNET_new (struct GNUNET_MESSENGER_Contact);
40
41 contact->name = NULL;
42 contact->rc = 0;
43 contact->id = unique_id;
44
45 GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key));
46
47 return contact;
48}
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CRYPTO_PublicKey public_key

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_MESSENGER_Contact::id, key, GNUNET_MESSENGER_Contact::name, GNUNET_MESSENGER_Contact::public_key, and GNUNET_MESSENGER_Contact::rc.

Referenced by get_store_contact().

Here is the caller graph for this function:

◆ destroy_contact()

void destroy_contact ( struct GNUNET_MESSENGER_Contact contact)

Destroys a contact and frees its memory fully.

Parameters
[in,out]contactContact

Definition at line 52 of file messenger_api_contact.c.

53{
54 GNUNET_assert (contact);
55
56 if (contact->name)
57 GNUNET_free (contact->name);
58
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Free contact: %lu\n",
60 contact->id);
61
62 GNUNET_free (contact);
63}
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_MESSENGER_Contact::id, and GNUNET_MESSENGER_Contact::name.

Referenced by get_store_contact(), iterate_destroy_contacts(), and remove_store_contact().

Here is the caller graph for this function:

◆ get_contact_name()

const char * get_contact_name ( const struct GNUNET_MESSENGER_Contact contact)

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

Parameters
[in]contactContact
Returns
Name of the contact or NULL

Definition at line 67 of file messenger_api_contact.c.

68{
69 GNUNET_assert (contact);
70
71 return contact->name;
72}

References GNUNET_assert, and GNUNET_MESSENGER_Contact::name.

Referenced by GNUNET_MESSENGER_contact_get_name().

Here is the caller graph for this function:

◆ set_contact_name()

void set_contact_name ( struct GNUNET_MESSENGER_Contact contact,
const char *  name 
)

Changes the current name of a given contact by copying it from the parameter name.

Parameters
[in,out]contactContact
[in]nameName

Definition at line 76 of file messenger_api_contact.c.

78{
79 GNUNET_assert (contact);
80
81 if (contact->name)
82 GNUNET_free (contact->name);
83
84 contact->name = name ? GNUNET_strdup (name) : NULL;
85}
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, name, and GNUNET_MESSENGER_Contact::name.

Referenced by handle_name_message().

Here is the caller graph for this function:

◆ get_contact_key()

const struct GNUNET_CRYPTO_PublicKey * get_contact_key ( const struct GNUNET_MESSENGER_Contact contact)

Returns the public key of a given contact.

Parameters
[in]contactContact
Returns
Public key of the contact

Definition at line 89 of file messenger_api_contact.c.

90{
91 GNUNET_assert (contact);
92
93 return &(contact->public_key);
94}

References GNUNET_assert, and GNUNET_MESSENGER_Contact::public_key.

Referenced by get_epoch_member_position(), get_store_contact(), GNUNET_MESSENGER_contact_get_key(), GNUNET_MESSENGER_send_message(), handle_id_message(), remove_store_contact(), and update_store_contact().

Here is the caller graph for this function:

◆ increase_contact_rc()

void increase_contact_rc ( struct GNUNET_MESSENGER_Contact contact)

Increases the reference counter of a given contact which is zero as default.

Parameters
[in,out]contactContact

Definition at line 98 of file messenger_api_contact.c.

99{
100 GNUNET_assert (contact);
101
102 contact->rc++;
103}

References GNUNET_assert, and GNUNET_MESSENGER_Contact::rc.

Referenced by create_member_session(), handle_join_message(), reset_member_session(), and switch_member_session().

Here is the caller graph for this function:

◆ decrease_contact_rc()

enum GNUNET_GenericReturnValue decrease_contact_rc ( struct GNUNET_MESSENGER_Contact contact)

Decreases the reference counter if possible (can not underflow!) of a given contact and returns GNUNET_YES if the counter is equal to zero, otherwise GNUNET_NO.

Parameters
[in,out]contactContact
Returns
GNUNET_YES or GNUNET_NO depending on the reference counter

Definition at line 107 of file messenger_api_contact.c.

108{
109 GNUNET_assert (contact);
110
111 if (contact->rc > 0)
112 contact->rc--;
113
114 return contact->rc ? GNUNET_NO : GNUNET_YES;
115}
@ GNUNET_YES
@ GNUNET_NO

References GNUNET_assert, GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_Contact::rc.

Referenced by check_member_session_completion(), destroy_member_session(), and handle_leave_message().

Here is the caller graph for this function:

◆ get_contact_id()

size_t get_contact_id ( const struct GNUNET_MESSENGER_Contact contact)

Returns the locally unique identifier of a given contact.

Parameters
[in]contactcontact Contact
Returns
Locally unique identifier of contact

Definition at line 119 of file messenger_api_contact.c.

120{
121 GNUNET_assert (contact);
122
123 return contact->id;
124}

References GNUNET_assert, and GNUNET_MESSENGER_Contact::id.

Referenced by GNUNET_MESSENGER_contact_get_id().

Here is the caller graph for this function:

◆ get_context_from_member()

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.

Parameters
[in]keyKey of room
[in]idMember id
[out]contextMember context

Definition at line 128 of file messenger_api_contact.c.

131{
132 GNUNET_assert ((key) && (id) && (context));
133
134 GNUNET_CRYPTO_hash (id, sizeof(*id), context);
136}
static pa_context * context
Pulseaudio context.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
void GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b, struct GNUNET_HashCode *result)
compute result = a ^ b

References context, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_xor(), and key.

Referenced by create_member_session(), get_handle_contact(), handle_id_message(), handle_join_message(), handle_key_message(), and switch_member_session().

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