libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

gnunet_chat_lobby_intern.c (3071B)


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