diff options
Diffstat (limited to 'src/messenger/messenger_api_contact.c')
-rw-r--r-- | src/messenger/messenger_api_contact.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/messenger/messenger_api_contact.c b/src/messenger/messenger_api_contact.c index 9a242aa00..04e1f60c1 100644 --- a/src/messenger/messenger_api_contact.c +++ b/src/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 GNUnet e.V. | 3 | Copyright (C) 2020--2021 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 |
@@ -28,9 +28,12 @@ | |||
28 | struct GNUNET_MESSENGER_Contact* | 28 | struct GNUNET_MESSENGER_Contact* |
29 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | 29 | create_contact (const struct GNUNET_IDENTITY_PublicKey *key) |
30 | { | 30 | { |
31 | GNUNET_assert(key); | ||
32 | |||
31 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); | 33 | struct GNUNET_MESSENGER_Contact *contact = GNUNET_new(struct GNUNET_MESSENGER_Contact); |
32 | 34 | ||
33 | contact->name = NULL; | 35 | contact->name = NULL; |
36 | contact->rc = 0; | ||
34 | 37 | ||
35 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); | 38 | GNUNET_memcpy(&(contact->public_key), key, sizeof(contact->public_key)); |
36 | 39 | ||
@@ -40,6 +43,8 @@ create_contact (const struct GNUNET_IDENTITY_PublicKey *key) | |||
40 | void | 43 | void |
41 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | 44 | destroy_contact (struct GNUNET_MESSENGER_Contact *contact) |
42 | { | 45 | { |
46 | GNUNET_assert(contact); | ||
47 | |||
43 | if (contact->name) | 48 | if (contact->name) |
44 | GNUNET_free(contact->name); | 49 | GNUNET_free(contact->name); |
45 | 50 | ||
@@ -49,30 +54,55 @@ destroy_contact (struct GNUNET_MESSENGER_Contact *contact) | |||
49 | const char* | 54 | const char* |
50 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) | 55 | get_contact_name (const struct GNUNET_MESSENGER_Contact *contact) |
51 | { | 56 | { |
57 | GNUNET_assert(contact); | ||
58 | |||
52 | return contact->name; | 59 | return contact->name; |
53 | } | 60 | } |
54 | 61 | ||
55 | void | 62 | void |
56 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name) | 63 | set_contact_name (struct GNUNET_MESSENGER_Contact *contact, const char *name) |
57 | { | 64 | { |
65 | GNUNET_assert(contact); | ||
66 | |||
58 | if (contact->name) | 67 | if (contact->name) |
59 | GNUNET_free(contact->name); | 68 | GNUNET_free(contact->name); |
60 | 69 | ||
61 | contact->name = name? GNUNET_strdup(name) : NULL; | 70 | contact->name = name ? GNUNET_strdup(name) : NULL; |
62 | } | 71 | } |
63 | 72 | ||
64 | const struct GNUNET_IDENTITY_PublicKey* | 73 | const struct GNUNET_IDENTITY_PublicKey* |
65 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) | 74 | get_contact_key (const struct GNUNET_MESSENGER_Contact *contact) |
66 | { | 75 | { |
76 | GNUNET_assert(contact); | ||
77 | |||
67 | return &(contact->public_key); | 78 | return &(contact->public_key); |
68 | } | 79 | } |
69 | 80 | ||
70 | const struct GNUNET_HashCode* | 81 | void |
71 | get_contact_id_from_key (const struct GNUNET_MESSENGER_Contact *contact) | 82 | increase_contact_rc (struct GNUNET_MESSENGER_Contact *contact) |
72 | { | 83 | { |
73 | static struct GNUNET_HashCode id; | 84 | GNUNET_assert(contact); |
85 | |||
86 | contact->rc++; | ||
87 | } | ||
74 | 88 | ||
75 | GNUNET_CRYPTO_hash (&(contact->public_key), sizeof(contact->public_key), &id); | 89 | int |
90 | decrease_contact_rc (struct GNUNET_MESSENGER_Contact *contact) | ||
91 | { | ||
92 | GNUNET_assert(contact); | ||
93 | |||
94 | if (contact->rc > 0) | ||
95 | contact->rc--; | ||
96 | |||
97 | return contact->rc ? GNUNET_NO : GNUNET_YES; | ||
98 | } | ||
99 | |||
100 | void | ||
101 | get_context_from_member (const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, | ||
102 | struct GNUNET_HashCode *context) | ||
103 | { | ||
104 | GNUNET_assert((key) && (id) && (context)); | ||
76 | 105 | ||
77 | return &id; | 106 | GNUNET_CRYPTO_hash (id, sizeof(*id), context); |
107 | GNUNET_CRYPTO_hash_xor (key, context, context); | ||
78 | } | 108 | } |