GNUnet 0.22.2
testing_api_cmd_get_topo.c File Reference

Command to start the netjail script. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "testing_api_topology.h"
Include dependency graph for testing_api_cmd_get_topo.c:

Go to the source code of this file.

Data Structures

struct  TopologyState
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "udp-backchannel",__VA_ARGS__)
 Generic logging shortcut. More...
 

Functions

static void cleanup (void *cls)
 The cleanup function of this cmd frees resources the cmd allocated. More...
 
static enum GNUNET_GenericReturnValue traits (void *cls, const void **ret, const char *trait, unsigned int index)
 This function prepares an array with traits. More...
 
static char * get_topo_string_from_file (const char *topology_data_file)
 
static void run (void *cls, struct GNUNET_TESTING_Interpreter *is)
 The run method starts the script which setup the network namespaces. More...
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_file (const char *label, const char *file_name)
 
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_string (const char *label, const char *topology_string)
 

Detailed Description

Command to start the netjail script.

Author
t3sserakt

Definition in file testing_api_cmd_get_topo.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "udp-backchannel",__VA_ARGS__)

Generic logging shortcut.

Definition at line 33 of file testing_api_cmd_get_topo.c.

Function Documentation

◆ cleanup()

static void cleanup ( void *  cls)
static

The cleanup function of this cmd frees resources the cmd allocated.

Definition at line 70 of file testing_api_cmd_get_topo.c.

71{
72 struct TopologyState *ts = cls;
73
74 if (NULL != ts->topology)
75 {
77 ts->topology = NULL;
78 }
80 GNUNET_free (ts);
81}
#define GNUNET_free(ptr)
Wrapper around free.
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.
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.

References GNUNET_free, GNUNET_TESTING_free_topology(), TopologyState::topology, and TopologyState::topology_alloc.

Referenced by GNUNET_TESTING_cmd_load_topology_from_file(), and GNUNET_TESTING_cmd_load_topology_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ traits()

static enum GNUNET_GenericReturnValue traits ( void *  cls,
const void **  ret,
const char *  trait,
unsigned int  index 
)
static

This function prepares an array with traits.

Definition at line 88 of file testing_api_cmd_get_topo.c.

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}
static int ret
Final status code.
Definition: gnunet-arm.c:93
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.
A struct GNUNET_TESTING_Trait can be used to exchange data between cmds.
unsigned int index
Index number associated with the trait.
const char * topology_string
A string with the name of the topology file, if read_file is true, otherwise a string containing the ...
static enum GNUNET_GenericReturnValue traits(void *cls, const void **ret, const char *trait, unsigned int index)
This function prepares an array with traits.

References GNUNET_TESTING_get_trait(), GNUNET_TESTING_trait_end(), GNUNET_TESTING_Trait::index, ret, TopologyState::topology, TopologyState::topology_string, and traits().

Referenced by GNUNET_TESTING_cmd_load_topology_from_file(), GNUNET_TESTING_cmd_load_topology_from_string(), and traits().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_topo_string_from_file()

static char * get_topo_string_from_file ( const char *  topology_data_file)
static

Definition at line 108 of file testing_api_cmd_get_topo.c.

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}
static char * data
The data to insert into the dht.
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:35
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:506
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:222
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:660
@ 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 LOG(kind,...)
Generic logging shortcut.

References data, fs, GNUNET_assert, GNUNET_DISK_file_size(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_malloc_large, GNUNET_OK, GNUNET_YES, and LOG.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
struct GNUNET_TESTING_Interpreter is 
)
static

The run method starts the script which setup the network namespaces.

Parameters
clsclosure.
isinterpreter state.

Definition at line 156 of file testing_api_cmd_get_topo.c.

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}
static struct GNUNET_TESTING_Interpreter * is
#define GNUNET_TESTING_FAIL(is)
Print failing line number and trigger shutdown.
const char * file_name
A string with the name of the topology file.
static char * get_topo_string_from_file(const char *topology_data_file)
struct GNUNET_TESTING_NetjailTopology * GNUNET_TESTING_get_topo_from_string_(const char *input)
Parse the topology data.

References TopologyState::file_name, get_topo_string_from_file(), GNUNET_TESTING_FAIL, GNUNET_TESTING_get_topo_from_string_(), is, TopologyState::topology, TopologyState::topology_alloc, and TopologyState::topology_string.

Referenced by GNUNET_TESTING_cmd_load_topology_from_file(), and GNUNET_TESTING_cmd_load_topology_from_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_load_topology_from_file()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_file ( const char *  label,
const char *  file_name 
)

Definition at line 177 of file testing_api_cmd_get_topo.c.

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}
static char * file_name
Dump file name.
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_new(type)
Allocate a struct or union of the given type.
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.

References cleanup(), file_name, TopologyState::file_name, GNUNET_new, GNUNET_TESTING_command_new_ac(), TopologyState::label, run(), and traits().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_TESTING_cmd_load_topology_from_string()

struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_load_topology_from_string ( const char *  label,
const char *  topology_string 
)

Definition at line 197 of file testing_api_cmd_get_topo.c.

200{
201 struct TopologyState *ts;
202
204 ts = GNUNET_new (struct TopologyState);
205 ts->label = label;
206 if (NULL != topology_string)
207 {
210 }
212 ts,
213 label,
214 &run,
215 &cleanup,
216 traits,
217 NULL);
218}
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.

References cleanup(), GNUNET_assert, GNUNET_new, GNUNET_strdup, GNUNET_TESTING_command_new_ac(), TopologyState::label, run(), TopologyState::topology_alloc, TopologyState::topology_string, topology_string, and traits().

Referenced by main(), and start_testcase().

Here is the call graph for this function:
Here is the caller graph for this function: