GNUnet 0.22.2
testing_messenger_cmd_join_room.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2023 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
26#include "platform.h"
27#include "gnunet_util_lib.h"
32
34{
36 char *room_key;
37
39};
40
41static void
42join_room_run (void *cls,
44{
45 struct GNUNET_MESSENGER_JoinRoomState *jrs = cls;
46 struct GNUNET_HashCode key;
47
48 if (jrs->room_key)
49 GNUNET_CRYPTO_hash (jrs->room_key, strlen (jrs->room_key), &key);
50 else
51 memset (&key, 0, sizeof(key));
52
53 const struct GNUNET_TESTING_Command *service_cmd;
55 jrs->service_label);
56
58 GNUNET_MESSENGER_get_trait_state (service_cmd, &sss);
59
60 unsigned int peer_index;
61 unsigned int stage_index;
63
65 if (rs)
66 goto skip_room_state;
67
70 &key,
71 rs,
73 {
75 "Testing library failed to create a room state with key '%s'\n",
76 jrs->room_key);
78 return;
79 }
80
81skip_room_state:
82 peer_index = sss->peer_index;
83 stage_index = sss->stage_index;
84
85 const unsigned int index = stage_index * sss->topology->peer_amount
86 + peer_index;
87 const struct GNUNET_MESSENGER_TestStage *stage =
88 &(sss->topology->peer_stages[index]);
89
90 unsigned int door_index = stage->door_id;
91
92 if (door_index == 0)
93 door_index = (peer_index + GNUNET_CRYPTO_random_u32 (
95 sss->topology->peer_amount - 1
96 ) + 1) % sss->topology->peer_amount;
97 else
98 door_index = (door_index - 1) % sss->topology->peer_amount;
99
100 struct GNUNET_PeerIdentity *door;
101 door = GNUNET_TESTING_get_peer (door_index, sss->tl_system);
102 if (! door)
103 {
105 "Testing library failed to get peer identity of index '%u'\n",
106 door_index);
108 return;
109 }
110
111 struct GNUNET_MESSENGER_Room *room;
112 switch (stage->join)
113 {
115 room = GNUNET_MESSENGER_open_room (sss->msg, &key);
116
117 if (! room)
118 {
120 "Testing library failed to open room with key '%s'\n",
121 jrs->room_key);
122 GNUNET_free (door);
124 return;
125 }
126
127 break;
129 room = GNUNET_MESSENGER_enter_room (sss->msg, door, &key);
130
131 if (! room)
132 {
134 "Testing library failed to enter room with key '%s'\n",
135 jrs->room_key);
136 GNUNET_free (door);
138 return;
139 }
140
141 break;
142 default:
143 room = NULL;
144 break;
145 }
146
147 jrs->room = room;
148TODO: sss->stage_index++;
149
150 GNUNET_free (door);
151}
152
153
154static void
156{
157 struct GNUNET_MESSENGER_JoinRoomState *jrs = cls;
158
159 GNUNET_free (jrs->room_key);
161 GNUNET_free (jrs);
162}
163
164
167 const char *service_label,
168 const char *room_key)
169{
171
175
176 return GNUNET_TESTING_command_new (jrs,
177 label,
180 NULL);
181}
static struct GNUNET_TESTING_Interpreter * is
struct GNUNET_HashCode key
The key used in the DHT.
char * room_key
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(struct GNUNET_TESTING_Interpreter *is, const char *label)
Lookup command by label.
#define GNUNET_TESTING_command_new(cls, label, run, cleanup, traits)
Create a new command.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
struct GNUNET_PeerIdentity * GNUNET_TESTING_get_peer(unsigned int num, const struct GNUNET_TESTING_System *tl_system)
Retrieve peer identity from the test system with the unique node id.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_open_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Open a room to send and receive messages.
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_enter_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room.
testing lib for messenger service
enum GNUNET_GenericReturnValue GNUNET_MESSENGER_get_trait_state(const struct GNUNET_TESTING_Command *cmd, struct GNUNET_MESSENGER_StartServiceState **ret)
A 512-bit hashcode.
struct GNUNET_MESSENGER_Handle * msg
struct GNUNET_MESSENGER_TestStageTopology * topology
struct GNUNET_CONTAINER_MultiHashMap * rooms
const struct GNUNET_TESTING_System * tl_system
struct GNUNET_MESSENGER_TestStage * peer_stages
enum GNUNET_MESSENGER_TestStageJoin join
The identity of the host (wraps the signing key of the peer).
A command to be run by the interpreter.
struct GNUNET_TESTING_CommandLabel label
Label for the command.
Global state of the interpreter, used by a command to access information about other commands.
struct GNUNET_MESSENGER_RoomState * GNUNET_MESSENGER_create_room_state(struct GNUNET_MESSENGER_TestStageTopology *topology)
@ GNUNET_MESSENGER_STAGE_JOIN_ENTER_ROOM
@ GNUNET_MESSENGER_STAGE_JOIN_OPEN_ROOM
static void join_room_run(void *cls, struct GNUNET_TESTING_Interpreter *is)
static void join_room_cleanup(void *cls)
struct GNUNET_TESTING_Command GNUNET_MESSENGER_cmd_join_room(const char *label, const char *service_label, const char *room_key)