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

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

#include "platform.h"
#include "gnunet_crypto_lib.h"
#include "gnunet_identity_service.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_IDENTITY_PublicKey *key)
 Creates and allocates a new contact with a given public key from an EGO. More...
 
void destroy_contact (struct GNUNET_MESSENGER_Contact *contact)
 Destroys a contact and frees its memory fully. More...
 
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. More...
 
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. More...
 
const struct GNUNET_IDENTITY_PublicKeyget_contact_key (const struct GNUNET_MESSENGER_Contact *contact)
 Returns the public key of a given contact. More...
 
void increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
 Increases the reference counter of a given contact which is zero as default. More...
 
int 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. More...
 
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. More...
 

Detailed Description

messenger api: client implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api_contact.h.

Function Documentation

◆ create_contact()

struct GNUNET_MESSENGER_Contact* create_contact ( const struct GNUNET_IDENTITY_PublicKey key)

Creates and allocates a new contact with a given public key from an EGO.

Parameters
[in]keyPublic key
Returns
New contact

Definition at line 29 of file messenger_api_contact.c.

References GNUNET_assert, GNUNET_memcpy, GNUNET_new, GNUNET_MESSENGER_Contact::name, GNUNET_MESSENGER_Contact::public_key, and GNUNET_MESSENGER_Contact::rc.

Referenced by get_store_contact().

30 {
31  GNUNET_assert(key);
32 
34 
35  contact->name = NULL;
36  contact->rc = 0;
37 
38  GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key));
39 
40  return contact;
41 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_IDENTITY_PublicKey public_key
#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.
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

Definition at line 44 of file messenger_api_contact.c.

References GNUNET_assert, GNUNET_free, and GNUNET_MESSENGER_Contact::name.

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

45 {
46  GNUNET_assert(contact);
47 
48  if (contact->name)
49  GNUNET_free(contact->name);
50 
51  GNUNET_free(contact);
52 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free(ptr)
Wrapper around free.
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 55 of file messenger_api_contact.c.

References GNUNET_assert, and GNUNET_MESSENGER_Contact::name.

Referenced by GNUNET_MESSENGER_contact_get_name().

56 {
57  GNUNET_assert(contact);
58 
59  return contact->name;
60 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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

Definition at line 63 of file messenger_api_contact.c.

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

Referenced by handle_message_name(), and handle_name_message().

64 {
65  GNUNET_assert(contact);
66 
67  if (contact->name)
68  GNUNET_free(contact->name);
69 
70  contact->name = name ? GNUNET_strdup(name) : NULL;
71 }
#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.
Here is the caller graph for this function:

◆ get_contact_key()

const struct GNUNET_IDENTITY_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 74 of file messenger_api_contact.c.

References GNUNET_assert, and GNUNET_MESSENGER_Contact::public_key.

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

75 {
76  GNUNET_assert(contact);
77 
78  return &(contact->public_key);
79 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_IDENTITY_PublicKey public_key
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

Definition at line 82 of file messenger_api_contact.c.

References GNUNET_assert, and GNUNET_MESSENGER_Contact::rc.

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

83 {
84  GNUNET_assert(contact);
85 
86  contact->rc++;
87 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ decrease_contact_rc()

int 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

Definition at line 90 of file messenger_api_contact.c.

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().

91 {
92  GNUNET_assert(contact);
93 
94  if (contact->rc > 0)
95  contact->rc--;
96 
97  return contact->rc ? GNUNET_NO : GNUNET_YES;
98 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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]hashMember context

Definition at line 101 of file messenger_api_contact.c.

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

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

103 {
104  GNUNET_assert((key) && (id) && (context));
105 
106  GNUNET_CRYPTO_hash (id, sizeof(*id), context);
107  GNUNET_CRYPTO_hash_xor (key, context, context);
108 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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
Definition: crypto_hash.c:134
Here is the call graph for this function:
Here is the caller graph for this function: