diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-12 14:38:12 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-12 14:38:12 +0100 |
commit | ba528dd455716f73fbfb3191401b8978e9900453 (patch) | |
tree | 4c8521087eab07be002f2706e565d438f3cca5f0 /src/gnunet_chat_lobby.c | |
parent | afd5d7cb5fdb8d2cf20f50d3942f553be78ca0ca (diff) | |
download | libgnunetchat-ba528dd455716f73fbfb3191401b8978e9900453.tar.gz libgnunetchat-ba528dd455716f73fbfb3191401b8978e9900453.zip |
Implemented lobby functionality and uri solving to add contacts
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/gnunet_chat_lobby.c')
-rw-r--r-- | src/gnunet_chat_lobby.c | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c new file mode 100644 index 0000000..e656ebb --- /dev/null +++ b/src/gnunet_chat_lobby.c | |||
@@ -0,0 +1,130 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /* | ||
21 | * @author Tobias Frisch | ||
22 | * @file gnunet_chat_lobby.c | ||
23 | */ | ||
24 | |||
25 | #include "gnunet_chat_lobby.h" | ||
26 | |||
27 | #include "gnunet_chat_handle.h" | ||
28 | #include "gnunet_chat_lobby_intern.c" | ||
29 | |||
30 | struct GNUNET_CHAT_Lobby* | ||
31 | lobby_create (struct GNUNET_CHAT_Handle *handle) | ||
32 | { | ||
33 | GNUNET_assert(handle); | ||
34 | |||
35 | struct GNUNET_CHAT_Lobby *lobby = GNUNET_new(struct GNUNET_CHAT_Lobby); | ||
36 | |||
37 | lobby->handle = handle; | ||
38 | lobby->context = NULL; | ||
39 | lobby->uri = NULL; | ||
40 | |||
41 | lobby->op_create = NULL; | ||
42 | lobby->op_delete = NULL; | ||
43 | |||
44 | lobby->expiration = GNUNET_TIME_absolute_get_forever_(); | ||
45 | lobby->callback = NULL; | ||
46 | lobby->cls = NULL; | ||
47 | |||
48 | return lobby; | ||
49 | } | ||
50 | |||
51 | void | ||
52 | lobby_destroy (struct GNUNET_CHAT_Lobby *lobby) | ||
53 | { | ||
54 | GNUNET_assert(lobby); | ||
55 | |||
56 | if (lobby->op_create) | ||
57 | GNUNET_IDENTITY_cancel(lobby->op_create); | ||
58 | |||
59 | if (lobby->op_delete) | ||
60 | GNUNET_IDENTITY_cancel(lobby->op_delete); | ||
61 | |||
62 | if (lobby->uri) | ||
63 | uri_destroy(lobby->uri); | ||
64 | |||
65 | if (lobby->context) | ||
66 | context_destroy(lobby->context); | ||
67 | |||
68 | GNUNET_free(lobby); | ||
69 | } | ||
70 | |||
71 | void | ||
72 | lobby_open (struct GNUNET_CHAT_Lobby *lobby, | ||
73 | struct GNUNET_TIME_Relative delay, | ||
74 | GNUNET_CHAT_LobbyCallback callback, | ||
75 | void *cls) | ||
76 | { | ||
77 | GNUNET_assert(lobby); | ||
78 | |||
79 | char *name; | ||
80 | |||
81 | lobby->expiration = GNUNET_TIME_relative_to_absolute(delay); | ||
82 | lobby->callback = callback; | ||
83 | lobby->cls = cls; | ||
84 | |||
85 | if (lobby->op_create) | ||
86 | { | ||
87 | GNUNET_IDENTITY_cancel(lobby->op_create); | ||
88 | goto open_zone; | ||
89 | } | ||
90 | |||
91 | struct GNUNET_HashCode key; | ||
92 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); | ||
93 | |||
94 | struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( | ||
95 | lobby->handle->messenger, | ||
96 | &key | ||
97 | ); | ||
98 | |||
99 | if (!room) | ||
100 | return; | ||
101 | |||
102 | lobby->context = context_create_from_room(lobby->handle, room); | ||
103 | |||
104 | handle_send_room_name(lobby->handle, room); | ||
105 | |||
106 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
107 | lobby->handle->contexts, &key, lobby->context, | ||
108 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
109 | { | ||
110 | context_destroy(lobby->context); | ||
111 | lobby->context = NULL; | ||
112 | |||
113 | GNUNET_MESSENGER_close_room(room); | ||
114 | return; | ||
115 | } | ||
116 | |||
117 | open_zone: | ||
118 | util_lobby_name(&key, &name); | ||
119 | |||
120 | lobby->op_create = GNUNET_IDENTITY_create( | ||
121 | lobby->handle->identity, | ||
122 | name, | ||
123 | NULL, | ||
124 | GNUNET_IDENTITY_TYPE_EDDSA, | ||
125 | cont_lobby_identity_create, | ||
126 | lobby | ||
127 | ); | ||
128 | |||
129 | GNUNET_free(name); | ||
130 | } | ||