gnunet_chat_lobby_intern.c (3221B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2022--2026 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_intern.c 23 */ 24 25 #include "gnunet_chat_context.h" 26 #include "gnunet_chat_handle.h" 27 28 void 29 cont_lobby_write_records (void *cls, 30 enum GNUNET_ErrorCode ec) 31 { 32 struct GNUNET_CHAT_Lobby *lobby = cls; 33 34 GNUNET_assert(lobby); 35 36 lobby->query = NULL; 37 38 handle_delete_lobby(lobby->handle, lobby); 39 40 if (GNUNET_EC_NONE == ec) 41 { 42 context_write_records(lobby->context); 43 goto call_cb; 44 } 45 46 handle_send_internal_message( 47 lobby->handle, 48 NULL, 49 lobby->context, 50 GNUNET_CHAT_FLAG_WARNING, 51 GNUNET_ErrorCode_get_hint(ec), 52 GNUNET_YES 53 ); 54 55 if (lobby->uri) 56 uri_destroy(lobby->uri); 57 58 lobby->uri = NULL; 59 60 call_cb: 61 if (lobby->callback) 62 lobby->callback(lobby->cls, lobby->uri); 63 } 64 65 void 66 cont_lobby_identity_create (void *cls, 67 const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, 68 enum GNUNET_ErrorCode ec) 69 { 70 struct GNUNET_CHAT_Lobby *lobby = cls; 71 72 GNUNET_assert(lobby); 73 74 lobby->op = NULL; 75 76 if (GNUNET_EC_NONE != ec) 77 { 78 handle_send_internal_message( 79 lobby->handle, 80 NULL, 81 lobby->context, 82 GNUNET_CHAT_FLAG_WARNING, 83 GNUNET_ErrorCode_get_hint(ec), 84 GNUNET_YES 85 ); 86 87 return; 88 } 89 90 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( 91 lobby->context->room 92 ); 93 94 const struct GNUNET_PeerIdentity *pid = lobby->handle->pid; 95 96 struct GNUNET_MESSENGER_RoomEntryRecord room; 97 GNUNET_memcpy(&(room.key), key, sizeof(room.key)); 98 99 if (pid) 100 GNUNET_memcpy(&(room.door), pid, sizeof(room.door)); 101 else 102 memset(&(room.door), 0, sizeof(room.door)); 103 104 struct GNUNET_GNSRECORD_Data data [1]; 105 data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY; 106 data[0].data = &room; 107 data[0].data_size = sizeof(room); 108 data[0].expiration_time = lobby->expiration.abs_value_us; 109 data[0].flags = GNUNET_GNSRECORD_RF_NONE; 110 111 if (lobby->uri) 112 uri_destroy(lobby->uri); 113 114 struct GNUNET_CRYPTO_BlindablePublicKey public_zone; 115 GNUNET_CRYPTO_blindable_key_get_public(zone, &public_zone); 116 117 char *label; 118 util_get_context_label(lobby->context->type, key, &label); 119 120 lobby->uri = uri_create_chat(&public_zone, label); 121 GNUNET_free(label); 122 123 lobby->query = GNUNET_NAMESTORE_record_set_store( 124 lobby->handle->namestore, 125 zone, 126 lobby->uri->chat.label, 127 1, 128 data, 129 cont_lobby_write_records, 130 lobby 131 ); 132 }