diff options
Diffstat (limited to 'src/service/messenger/messenger_api_contact.c')
-rw-r--r-- | src/service/messenger/messenger_api_contact.c | 51 |
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 | ||
29 | struct GNUNET_MESSENGER_Contact* | 29 | struct GNUNET_MESSENGER_Contact* |
30 | create_contact (const struct GNUNET_CRYPTO_PublicKey *key) | 30 | create_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 | |||
44 | void | 48 | void |
45 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | 49 | destroy_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 | |||
55 | const char* | 60 | const char* |
56 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) | 61 | get_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 | |||
63 | void | 69 | void |
64 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, | 70 | set_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 | |||
75 | const struct GNUNET_CRYPTO_PublicKey* | 82 | const struct GNUNET_CRYPTO_PublicKey* |
76 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) | 83 | get_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 | |||
83 | void | 91 | void |
84 | increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | 92 | increase_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 | |||
91 | int | 100 | int |
92 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | 101 | decrease_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 | |||
112 | size_t | ||
113 | get_contact_id (const struct GNUNET_MESSENGER_Contact *contact) | ||
114 | { | ||
115 | GNUNET_assert (contact); | ||
116 | |||
117 | return contact->id; | ||
118 | } | ||
119 | |||
120 | |||
102 | void | 121 | void |
103 | get_context_from_member (const struct GNUNET_HashCode *key, | 122 | get_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); |