aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/messenger_api_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/messenger_api_handle.c')
-rw-r--r--src/messenger/messenger_api_handle.c79
1 files changed, 61 insertions, 18 deletions
diff --git a/src/messenger/messenger_api_handle.c b/src/messenger/messenger_api_handle.c
index ec8d3dc7a..abede8e21 100644
--- a/src/messenger/messenger_api_handle.c
+++ b/src/messenger/messenger_api_handle.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
@@ -26,12 +26,11 @@
26#include "platform.h" 26#include "platform.h"
27#include "messenger_api_handle.h" 27#include "messenger_api_handle.h"
28 28
29#include "messenger_api_room.h"
29#include "messenger_api_util.h" 30#include "messenger_api_util.h"
30 31
31struct GNUNET_MESSENGER_Handle* 32struct GNUNET_MESSENGER_Handle*
32create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg, 33create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg,
33 GNUNET_MESSENGER_IdentityCallback identity_callback,
34 void *identity_cls,
35 GNUNET_MESSENGER_MessageCallback msg_callback, 34 GNUNET_MESSENGER_MessageCallback msg_callback,
36 void *msg_cls) 35 void *msg_cls)
37{ 36{
@@ -42,13 +41,11 @@ create_handle (const struct GNUNET_CONFIGURATION_Handle *cfg,
42 handle->cfg = cfg; 41 handle->cfg = cfg;
43 handle->mq = NULL; 42 handle->mq = NULL;
44 43
45 handle->identity_callback = identity_callback;
46 handle->identity_cls = identity_cls;
47
48 handle->msg_callback = msg_callback; 44 handle->msg_callback = msg_callback;
49 handle->msg_cls = msg_cls; 45 handle->msg_cls = msg_cls;
50 46
51 handle->name = NULL; 47 handle->name = NULL;
48 handle->key = NULL;
52 handle->pubkey = NULL; 49 handle->pubkey = NULL;
53 50
54 handle->reconnect_time = GNUNET_TIME_relative_get_zero_ (); 51 handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
@@ -87,6 +84,9 @@ destroy_handle (struct GNUNET_MESSENGER_Handle *handle)
87 if (handle->name) 84 if (handle->name)
88 GNUNET_free(handle->name); 85 GNUNET_free(handle->name);
89 86
87 if (handle->key)
88 GNUNET_free(handle->key);
89
90 if (handle->pubkey) 90 if (handle->pubkey)
91 GNUNET_free(handle->pubkey); 91 GNUNET_free(handle->pubkey);
92 92
@@ -106,12 +106,12 @@ void
106set_handle_name (struct GNUNET_MESSENGER_Handle *handle, 106set_handle_name (struct GNUNET_MESSENGER_Handle *handle,
107 const char *name) 107 const char *name)
108{ 108{
109 GNUNET_assert(handle); 109 GNUNET_assert (handle);
110 110
111 if (handle->name) 111 if (handle->name)
112 GNUNET_free(handle->name); 112 GNUNET_free (handle->name);
113 113
114 handle->name = name ? GNUNET_strdup(name) : NULL; 114 handle->name = name ? GNUNET_strdup (name) : NULL;
115} 115}
116 116
117const char* 117const char*
@@ -124,21 +124,49 @@ get_handle_name (const struct GNUNET_MESSENGER_Handle *handle)
124 124
125void 125void
126set_handle_key (struct GNUNET_MESSENGER_Handle *handle, 126set_handle_key (struct GNUNET_MESSENGER_Handle *handle,
127 const struct GNUNET_IDENTITY_PublicKey *pubkey) 127 const struct GNUNET_IDENTITY_PrivateKey *key)
128{ 128{
129 GNUNET_assert(handle); 129 GNUNET_assert (handle);
130
131 if (!key)
132 {
133 if (handle->key)
134 GNUNET_free (handle->key);
135
136 if (handle->pubkey)
137 GNUNET_free (handle->pubkey);
138
139 handle->key = NULL;
140 handle->pubkey = NULL;
141 return;
142 }
143
144 if (!handle->key)
145 handle->key = GNUNET_new (struct GNUNET_IDENTITY_PrivateKey);
130 146
131 if (!handle->pubkey) 147 if (!handle->pubkey)
132 handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey); 148 handle->pubkey = GNUNET_new (struct GNUNET_IDENTITY_PublicKey);
133 149
134 GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey)); 150 GNUNET_memcpy (handle->key, key, sizeof(*key));
151 GNUNET_IDENTITY_key_get_public (key, handle->pubkey);
135} 152}
136 153
137const struct GNUNET_IDENTITY_PublicKey* 154const struct GNUNET_IDENTITY_PrivateKey*
138get_handle_key (const struct GNUNET_MESSENGER_Handle *handle) 155get_handle_key (const struct GNUNET_MESSENGER_Handle *handle)
139{ 156{
140 GNUNET_assert(handle); 157 GNUNET_assert(handle);
141 158
159 if (handle->key)
160 return handle->key;
161
162 return get_anonymous_private_key();
163}
164
165const struct GNUNET_IDENTITY_PublicKey*
166get_handle_pubkey (const struct GNUNET_MESSENGER_Handle *handle)
167{
168 GNUNET_assert(handle);
169
142 if (handle->pubkey) 170 if (handle->pubkey)
143 return handle->pubkey; 171 return handle->pubkey;
144 172
@@ -161,13 +189,19 @@ get_handle_contact (struct GNUNET_MESSENGER_Handle *handle,
161 189
162 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 190 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
163 191
164 if ((!room) || (!(room->contact_id))) 192 if (!room)
193 return NULL;
194
195 const struct GNUNET_ShortHashCode *contact_id = get_room_sender_id (room);
196
197 if (!contact_id)
165 return NULL; 198 return NULL;
166 199
167 struct GNUNET_HashCode context; 200 struct GNUNET_HashCode context;
168 get_context_from_member (key, room->contact_id, &context); 201 get_context_from_member (key, contact_id, &context);
169 202
170 return get_store_contact(get_handle_contact_store(handle), &context, get_handle_key(handle)); 203 return get_store_contact (get_handle_contact_store (handle), &context,
204 get_handle_pubkey (handle));
171} 205}
172 206
173void 207void
@@ -192,7 +226,7 @@ entry_handle_room_at (struct GNUNET_MESSENGER_Handle *handle,
192 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key); 226 struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
193 227
194 if (room) 228 if (room)
195 add_to_list_tunnels (&(room->entries), door); 229 add_to_list_tunnels (&(room->entries), door, NULL);
196} 230}
197 231
198void 232void
@@ -206,3 +240,12 @@ close_handle_room (struct GNUNET_MESSENGER_Handle *handle,
206 if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room))) 240 if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room)))
207 destroy_room (room); 241 destroy_room (room);
208} 242}
243
244struct GNUNET_MESSENGER_Room*
245get_handle_room (struct GNUNET_MESSENGER_Handle *handle,
246 const struct GNUNET_HashCode *key)
247{
248 GNUNET_assert((handle) && (key));
249
250 return GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
251}