aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/messenger_api_contact.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/messenger_api_contact.c')
-rw-r--r--src/service/messenger/messenger_api_contact.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/service/messenger/messenger_api_contact.c b/src/service/messenger/messenger_api_contact.c
index a11190c2c..47733fe07 100644
--- a/src/service/messenger/messenger_api_contact.c
+++ b/src/service/messenger/messenger_api_contact.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2020--2021 GNUnet e.V. 3 Copyright (C) 2020--2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -27,71 +27,80 @@
27#include "messenger_api_contact.h" 27#include "messenger_api_contact.h"
28 28
29struct GNUNET_MESSENGER_Contact* 29struct GNUNET_MESSENGER_Contact*
30create_contact (const struct GNUNET_CRYPTO_PublicKey *key) 30create_contact (const struct GNUNET_CRYPTO_PublicKey *key,
31 size_t unique_id)
31{ 32{
32 GNUNET_assert(key); 33 GNUNET_assert (key);
33 34
34 struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); 35 struct GNUNET_MESSENGER_Contact *contact = GNUNET_new (struct
36 GNUNET_MESSENGER_Contact);
35 37
36 contact->name = NULL; 38 contact->name = NULL;
37 contact->rc = 0; 39 contact->rc = 0;
40 contact->id = unique_id;
38 41
39 GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); 42 GNUNET_memcpy (&(contact->public_key), key, sizeof(contact->public_key));
40 43
41 return contact; 44 return contact;
42} 45}
43 46
47
44void 48void
45destroy_contact (struct GNUNET_MESSENGER_Contact *contact) 49destroy_contact (struct GNUNET_MESSENGER_Contact *contact)
46{ 50{
47 GNUNET_assert(contact); 51 GNUNET_assert (contact);
48 52
49 if (contact->name) 53 if (contact->name)
50 GNUNET_free(contact->name); 54 GNUNET_free (contact->name);
51 55
52 GNUNET_free(contact); 56 GNUNET_free (contact);
53} 57}
54 58
59
55const char* 60const char*
56get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) 61get_contact_name (const struct GNUNET_MESSENGER_Contact *contact)
57{ 62{
58 GNUNET_assert(contact); 63 GNUNET_assert (contact);
59 64
60 return contact->name; 65 return contact->name;
61} 66}
62 67
68
63void 69void
64set_contact_name (struct GNUNET_MESSENGER_Contact *contact, 70set_contact_name (struct GNUNET_MESSENGER_Contact *contact,
65 const char *name) 71 const char *name)
66{ 72{
67 GNUNET_assert(contact); 73 GNUNET_assert (contact);
68 74
69 if (contact->name) 75 if (contact->name)
70 GNUNET_free(contact->name); 76 GNUNET_free (contact->name);
71 77
72 contact->name = name ? GNUNET_strdup(name) : NULL; 78 contact->name = name ? GNUNET_strdup (name) : NULL;
73} 79}
74 80
81
75const struct GNUNET_CRYPTO_PublicKey* 82const struct GNUNET_CRYPTO_PublicKey*
76get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) 83get_contact_key (const struct GNUNET_MESSENGER_Contact *contact)
77{ 84{
78 GNUNET_assert(contact); 85 GNUNET_assert (contact);
79 86
80 return &(contact->public_key); 87 return &(contact->public_key);
81} 88}
82 89
90
83void 91void
84increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) 92increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
85{ 93{
86 GNUNET_assert(contact); 94 GNUNET_assert (contact);
87 95
88 contact->rc++; 96 contact->rc++;
89} 97}
90 98
99
91int 100int
92decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) 101decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
93{ 102{
94 GNUNET_assert(contact); 103 GNUNET_assert (contact);
95 104
96 if (contact->rc > 0) 105 if (contact->rc > 0)
97 contact->rc--; 106 contact->rc--;
@@ -99,12 +108,22 @@ decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact)
99 return contact->rc ? GNUNET_NO : GNUNET_YES; 108 return contact->rc ? GNUNET_NO : GNUNET_YES;
100} 109}
101 110
111
112size_t
113get_contact_id (const struct GNUNET_MESSENGER_Contact *contact)
114{
115 GNUNET_assert (contact);
116
117 return contact->id;
118}
119
120
102void 121void
103get_context_from_member (const struct GNUNET_HashCode *key, 122get_context_from_member (const struct GNUNET_HashCode *key,
104 const struct GNUNET_ShortHashCode *id, 123 const struct GNUNET_ShortHashCode *id,
105 struct GNUNET_HashCode *context) 124 struct GNUNET_HashCode *context)
106{ 125{
107 GNUNET_assert((key) && (id) && (context)); 126 GNUNET_assert ((key) && (id) && (context));
108 127
109 GNUNET_CRYPTO_hash (id, sizeof(*id), context); 128 GNUNET_CRYPTO_hash (id, sizeof(*id), context);
110 GNUNET_CRYPTO_hash_xor (key, context, context); 129 GNUNET_CRYPTO_hash_xor (key, context, context);