GNUnet 0.22.2
testing_messenger_cmd_start_service.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2023--2024 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"
28#include "gnunet_testing_lib.h"
32
33static void
34on_message_cb (void *cls,
35 struct GNUNET_MESSENGER_Room *room,
36 const struct GNUNET_MESSENGER_Contact *sender,
37 const struct GNUNET_MESSENGER_Contact *recipient,
38 const struct GNUNET_MESSENGER_Message *message,
39 const struct GNUNET_HashCode *hash,
41{
42 struct GNUNET_MESSENGER_StartServiceState *sss = cls;
43
46
48 if (! rs)
49 {
51 "Testing library failed to find room state\n");
53 return;
54 }
55
57 return;
58
60 &(message->body.peer.peer)
61 ,
62 NULL,
64 {
66 "Testing library failed to register peer identity as found door\n");
68 return;
69 }
70}
71
72
73static void
76{
77 struct GNUNET_MESSENGER_StartServiceState *sss = cls;
78
79 sss->is = is;
80
81 const struct GNUNET_TESTING_Command *peer_cmd;
83 sss->peer_label);
84
85 const struct GNUNET_TESTING_StartPeerState *sps;
87
88 const struct GNUNET_TESTING_Command *system_cmd;
90 sss->system_label);
91
92 const struct GNUNET_TESTING_System *tl_system;
93 GNUNET_TESTING_get_trait_test_system (system_cmd,
94 &tl_system);
95
96 sss->tl_system = tl_system;
97
98 sss->msg = GNUNET_MESSENGER_connect (sps->cfg, NULL, NULL, on_message_cb,
99 sss);
100 if (! sss->msg)
101 {
103 "Testing library failed to connect to messenger service\n");
105 return;
106 }
107
110}
111
112
113static void
115{
116 struct GNUNET_MESSENGER_StartServiceState *sss = cls;
117
119 GNUNET_free (sss->peer_label);
120 GNUNET_free (sss);
121}
122
123
126 const void **ret,
127 const char *trait,
128 unsigned int index)
129{
130 struct GNUNET_MESSENGER_StartServiceState *sss = cls;
131
132 struct GNUNET_TESTING_Trait traits[] = {
135 };
136
138 ret,
139 trait,
140 index);
141}
142
143
146 const char *peer_label,
147 const char *system_label,
149 topology,
150 unsigned int peer_index)
151{
153
157 sss->topology = topology;
158
159 sss->is = NULL;
160 sss->tl_system = NULL;
161 sss->msg = NULL;
162 sss->rooms = NULL;
163 sss->peer_index = peer_index;
164 sss->stage_index = 0;
165
166 return GNUNET_TESTING_command_new (sss,
167 label,
171}
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_TESTING_Interpreter * is
struct GNUNET_HashCode key
The key used in the DHT.
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.
struct GNUNET_TESTING_Trait GNUNET_TESTING_trait_end(void)
"end" of traits array.
enum GNUNET_GenericReturnValue GNUNET_TESTING_get_trait(const struct GNUNET_TESTING_Trait *traits, const void **ret, const char *trait, unsigned int index)
Obtain value of a trait from a command.
void GNUNET_TESTING_interpreter_fail(struct GNUNET_TESTING_Interpreter *is)
Current command failed, clean up and fail the test case.
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_TESTING_get_trait_state(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_StartPeerState **ret)
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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
@ 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.
const struct GNUNET_HashCode * GNUNET_MESSENGER_room_get_key(const struct GNUNET_MESSENGER_Room *room)
Get the key of a given room.
GNUNET_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling.
struct GNUNET_MESSENGER_Handle * GNUNET_MESSENGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, const struct GNUNET_CRYPTO_PrivateKey *key, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Set up a handle for the messenger related functions and connects to all necessary services.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
testing lib for messenger service
struct GNUNET_TESTING_Trait GNUNET_MESSENGER_make_trait_state(struct GNUNET_MESSENGER_StartServiceState *value)
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessagePeer peer
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_CONTAINER_MultiPeerMap * doors
struct GNUNET_MESSENGER_Handle * msg
struct GNUNET_MESSENGER_TestStageTopology * topology
struct GNUNET_TESTING_Interpreter * is
struct GNUNET_CONTAINER_MultiHashMap * rooms
const struct GNUNET_TESTING_System * tl_system
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.
Handle for a peer controlled via ARM.
struct GNUNET_CONFIGURATION_Handle * cfg
Peer's configuration.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
static void on_message_cb(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Contact *recipient, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
static enum GNUNET_GenericReturnValue start_service_traits(void *cls, const void **ret, const char *trait, unsigned int index)
static void start_service_cleanup(void *cls)
struct GNUNET_TESTING_Command GNUNET_MESSENGER_cmd_start_service(const char *label, const char *peer_label, const char *system_label, struct GNUNET_MESSENGER_TestStageTopology *topology, unsigned int peer_index)
static void start_service_run(void *cls, struct GNUNET_TESTING_Interpreter *is)