GNUnet 0.21.2
testing_api_cmd_get_topo.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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"
29
33#define LOG(kind, ...) GNUNET_log_from (kind, "udp-backchannel",__VA_ARGS__)
34
36{
40 const char *label;
41
46
51 const char *topology_string;
52
58
62 const char *file_name;
63};
64
69static void
70cleanup (void *cls)
71{
72 struct TopologyState *ts = cls;
73
74 if (NULL != ts->topology)
75 {
77 ts->topology = NULL;
78 }
80 GNUNET_free (ts);
81}
82
83
88traits (void *cls,
89 const void **ret,
90 const char *trait,
91 unsigned int index)
92{
93 struct TopologyState *ts = cls;
94 struct GNUNET_TESTING_Trait traits[] = {
95 GNUNET_TESTING_make_trait_topology (ts->topology),
96 GNUNET_TESTING_make_trait_topology_string (ts->topology_string),
98 };
99
101 ret,
102 trait,
103 index);
104}
105
106
107static char *
108get_topo_string_from_file (const char *topology_data_file)
109{
110 uint64_t fs;
111 char *data;
112
113 if (GNUNET_YES !=
114 GNUNET_DISK_file_test (topology_data_file))
115 {
117 "Topology file %s not found\n",
118 topology_data_file);
119 return NULL;
120 }
121 if (GNUNET_OK !=
122 GNUNET_DISK_file_size (topology_data_file,
123 &fs,
125 GNUNET_YES))
126 {
128 "Could not determine size of topology file %s\n",
129 topology_data_file);
130 return NULL;
131 }
133 GNUNET_assert (NULL != data);
134 if (fs !=
135 GNUNET_DISK_fn_read (topology_data_file,
136 data,
137 fs))
138 {
140 "Topology file %s cannot be read\n",
141 topology_data_file);
143 return NULL;
144 }
145 return data;
146}
147
148
155static void
156run (void *cls,
158{
159 struct TopologyState *ts = cls;
160
161 if (NULL == ts->topology_string)
162 {
165 if (NULL == ts->topology_alloc)
168 }
169 ts->topology
171 if (NULL == ts->topology)
173}
174
175
178 const char *label,
179 const char *file_name)
180{
181 struct TopologyState *ts;
182
183 ts = GNUNET_new (struct TopologyState);
184 ts->label = label;
185 ts->file_name = file_name;
187 ts,
188 label,
189 &run,
190 &cleanup,
191 traits,
192 NULL);
193}
194
195
198 const char *label,
199 const char *topology_string)
200{
201 struct TopologyState *ts;
202
204 ts = GNUNET_new (struct TopologyState);
205 ts->label = label;
208 ts,
209 label,
210 &run,
211 &cleanup,
212 traits,
213 NULL);
214}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_TESTING_Interpreter * is
static char * file_name
Dump file name.
static char * data
The data to insert into the dht.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:37
struct GNUNET_TESTING_Command GNUNET_TESTING_command_new_ac(void *cls, const char *label, GNUNET_TESTING_CommandRunRoutine run, GNUNET_TESTING_CommandCleanupRoutine cleanup, GNUNET_TESTING_CommandGetTraits traits, struct GNUNET_TESTING_AsyncContext *ac)
Create a new command that may be asynchronous.
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
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.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:221
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:664
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_malloc_large(size)
Wrapper around malloc.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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.
Toplogy of our netjail setup.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
const char * file_name
A string with the name of the topology file.
struct GNUNET_TESTING_NetjailTopology * topology
The topology we parsed.
char * topology_alloc
Same as topology_string, but set if we need to release the memory.
const char * topology_string
A string with the name of the topology file, if read_file is true, otherwise a string containing the ...
const char * label
The label of the command.
static void run(void *cls, struct GNUNET_TESTING_Interpreter *is)
The run method starts the script which setup the network namespaces.
static void cleanup(void *cls)
The cleanup function of this cmd frees resources the cmd allocated.
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.
static char * get_topo_string_from_file(const char *topology_data_file)
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_file(const char *label, const char *file_name)
#define LOG(kind,...)
Generic logging shortcut.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_string(const char *label, const char *topology_string)
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_string_(const char *input)
Parse the topology data.