GNUnet  0.11.x
Functions
gnunet-service-messenger_contact.c File Reference

GNUnet MESSENGER service. More...

#include "gnunet-service-messenger_contact.h"
Include dependency graph for gnunet-service-messenger_contact.c:

Go to the source code of this file.

Functions

struct GNUNET_MESSENGER_SrvContactcreate_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_SrvContact *contact)
 Destroys a contact and frees its memory fully. More...
 
const char * get_contact_name (const struct GNUNET_MESSENGER_SrvContact *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_SrvContact *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_SrvContact *contact)
 Returns the public key of a given contact. More...
 
void increase_contact_rc (struct GNUNET_MESSENGER_SrvContact *contact)
 Increases the reference counter of a given contact which is zero as default. More...
 
int decrease_contact_rc (struct GNUNET_MESSENGER_SrvContact *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...
 
const struct GNUNET_HashCodeget_contact_id_from_key (const struct GNUNET_MESSENGER_SrvContact *contact)
 Returns the resulting hashcode of the public key from a given contact. More...
 

Detailed Description

GNUnet MESSENGER service.

Author
Tobias Frisch

Definition in file gnunet-service-messenger_contact.c.

Function Documentation

◆ create_contact()

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.

Parameters
keyPublic key
Returns
New contact

Definition at line 29 of file gnunet-service-messenger_contact.c.

Referenced by get_handle_contact_by_pubkey(), and get_service_contact_by_pubkey().

30 {
32 
33  contact->name = NULL;
34  contact->rc = 0;
35 
36  GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key));
37 
38  return contact;
39 }
#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.
struct GNUNET_IDENTITY_PublicKey public_key
Here is the caller graph for this function:

◆ destroy_contact()

void destroy_contact ( struct GNUNET_MESSENGER_SrvContact contact)

Destroys a contact and frees its memory fully.

Parameters
contactContact

Definition at line 42 of file gnunet-service-messenger_contact.c.

References GNUNET_free, and GNUNET_MESSENGER_SrvContact::name.

Referenced by get_handle_contact_by_pubkey(), get_service_contact_by_pubkey(), iterate_clear_members(), iterate_destroy_contact(), and iterate_destroy_contacts().

43 {
44  if (contact->name)
45  GNUNET_free(contact->name);
46 
47  GNUNET_free(contact);
48 }
#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_SrvContact contact)

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

Parameters
contactContact
Returns
Name of the contact or NULL

Definition at line 51 of file gnunet-service-messenger_contact.c.

References GNUNET_MESSENGER_SrvContact::name.

Referenced by GNUNET_MESSENGER_contact_get_name().

52 {
53  return contact->name;
54 }
Here is the caller graph for this function:

◆ set_contact_name()

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

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

Parameters
contactContact
nameValid name (may not be NULL!)

Definition at line 57 of file gnunet-service-messenger_contact.c.

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

Referenced by handle_message_name(), and handle_name_message().

58 {
60 
61  if (contact->name)
62  GNUNET_free(contact->name);
63 
64  contact->name = GNUNET_strdup(name);
65 }
#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_SrvContact contact)

Returns the public key of a given contact.

Parameters
contactContact
Returns
Public key of the contact

Definition at line 68 of file gnunet-service-messenger_contact.c.

References GNUNET_MESSENGER_SrvContact::public_key.

Referenced by callback_verify_room_message(), and GNUNET_MESSENGER_contact_get_key().

69 {
70  return &(contact->public_key);
71 }
struct GNUNET_IDENTITY_PublicKey public_key
Here is the caller graph for this function:

◆ increase_contact_rc()

void increase_contact_rc ( struct GNUNET_MESSENGER_SrvContact contact)

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

Parameters
contactContact

Definition at line 74 of file gnunet-service-messenger_contact.c.

References GNUNET_MESSENGER_SrvContact::rc.

Referenced by add_room_contact().

75 {
76  contact->rc++;
77 }
Here is the caller graph for this function:

◆ decrease_contact_rc()

int decrease_contact_rc ( struct GNUNET_MESSENGER_SrvContact 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
contactContact
Returns
GNUNET_YES or GNUNET_NO depending on the reference counter

Definition at line 80 of file gnunet-service-messenger_contact.c.

References GNUNET_NO, GNUNET_YES, and GNUNET_MESSENGER_SrvContact::rc.

Referenced by iterate_clear_members().

81 {
82  if (contact->rc > 0)
83  contact->rc--;
84 
85  return contact->rc ? GNUNET_NO : GNUNET_YES;
86 }
Here is the caller graph for this function:

◆ get_contact_id_from_key()

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.

Parameters
contactContact
Returns
Hash of the contacts public key

Definition at line 89 of file gnunet-service-messenger_contact.c.

References GNUNET_CRYPTO_hash(), id, and GNUNET_MESSENGER_SrvContact::public_key.

Referenced by iterate_clear_members(), swap_handle_contact_by_pubkey(), and swap_service_contact_by_pubkey().

90 {
91  static struct GNUNET_HashCode id;
92 
93  GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id);
94 
95  return &id;
96 }
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
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.
struct GNUNET_IDENTITY_PublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function: