GNUnet  0.19.5
gnunet_testing_lib.h
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2008, 2009, 2012 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 
44 #ifndef GNUNET_TESTING_LIB_H
45 #define GNUNET_TESTING_LIB_H
46 
47 
48 #include "gnunet_util_lib.h"
50 #include "gnunet_arm_service.h"
51 
52 #ifdef __cplusplus
53 extern "C"
54 {
55 #if 0 /* keep Emacsens' auto-indent happy */
56 }
57 #endif
58 #endif
59 
63 #define GNUNET_TESTING_HOSTKEYFILESIZE sizeof(struct \
64  GNUNET_CRYPTO_EddsaPrivateKey)
65 
70 #define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX"
71 
72 
78 
79 
83 struct GNUNET_TESTING_Peer;
84 
85 
90 {
94  const char *service;
95 
100 
105  unsigned int share;
106 };
107 
108 
129 struct GNUNET_TESTING_System *
130 GNUNET_TESTING_system_create (const char *testdir,
131  const char *trusted_ip,
132  const char *hostname,
133  const struct GNUNET_TESTING_SharedService *
135 
136 
161 struct GNUNET_TESTING_System *
163  const char *trusted_ip,
164  const char *hostname,
165  const struct
168  uint16_t lowport,
169  uint16_t highport);
170 
171 
179 void
181  int remove_paths);
182 
183 
203  uint32_t key_number,
204  struct GNUNET_PeerIdentity *id);
205 
206 
213 uint16_t
215 
216 
224 void
226  uint16_t port);
227 
228 
246 int
249 
250 // FIXME: add dual to 'release' ports again...
251 
252 
266 struct GNUNET_TESTING_Peer *
269  uint32_t key_number,
270  struct GNUNET_PeerIdentity *id,
271  char **emsg);
272 
273 
280 void
282  struct GNUNET_PeerIdentity *id);
283 
284 
292 int
294 
295 
305 int
307 
308 
316 void
318 
319 
327 int
329 
330 
338 int
340 
341 
350 typedef void
351 (*GNUNET_TESTING_PeerStopCallback) (void *cls,
352  struct GNUNET_TESTING_Peer *peer,
353  int success);
354 
355 
367 int
370  void *cb_cls);
371 
372 
382 void
384 
385 
394 typedef void
395 (*GNUNET_TESTING_TestMain) (void *cls,
396  const struct GNUNET_CONFIGURATION_Handle *cfg,
397  struct GNUNET_TESTING_Peer *peer);
398 
399 
416 int
417 GNUNET_TESTING_peer_run (const char *testdir,
418  const char *cfgfilename,
420  void *tm_cls);
421 
422 
444 int
445 GNUNET_TESTING_service_run (const char *testdir,
446  const char *service_name,
447  const char *cfgfilename,
449  void *tm_cls);
450 
451 
452 #if 0 /* keep Emacsens' auto-indent happy */
453 {
454 #endif
455 #ifdef __cplusplus
456 }
457 #endif
458 
459 #endif
460  /* end of group */
462  /* end of group addition */
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
static char * hostname
Our hostname; we give this to all the peers we start.
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:50
API to create, modify and access statistics.
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1485
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services)
Create a system handle.
Definition: testing.c:477
struct GNUNET_TESTING_System * GNUNET_TESTING_system_create_with_portrange(const char *testdir, const char *trusted_ip, const char *hostname, const struct GNUNET_TESTING_SharedService *shared_services, uint16_t lowport, uint16_t highport)
Create a system handle.
Definition: testing.c:392
struct GNUNET_TESTING_Peer * GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint32_t key_number, struct GNUNET_PeerIdentity *id, char **emsg)
Configure a GNUnet peer.
Definition: testing.c:1188
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system, uint32_t key_number, struct GNUNET_PeerIdentity *id)
Testing includes a number of pre-created hostkeys for faster peer startup.
Definition: testing.c:732
int GNUNET_TESTING_peer_run(const char *testdir, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
Start a single peer and run a test using the testing library.
Definition: testing.c:1592
void(* GNUNET_TESTING_TestMain)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)
Signature of the 'main' function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_r...
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:557
int GNUNET_TESTING_service_run(const char *testdir, const char *service_name, const char *cfgfilename, GNUNET_TESTING_TestMain tm, void *tm_cls)
Start a single service (no ARM, except of course if the given service name is 'arm') and run a test u...
Definition: testing.c:1643
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1381
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a port for a peer.
Definition: testing.c:598
void GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system, uint16_t port)
Release reservation of a TCP or UDP port for a peer (used during GNUNET_TESTING_peer_destroy).
Definition: testing.c:694
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1550
int GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer, GNUNET_TESTING_PeerStopCallback cb, void *cb_cls)
Stop a peer asynchronously using ARM API.
Definition: testing.c:1525
int GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system, struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testing.c:1167
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer's main process.
Definition: testing.c:1430
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1566
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1462
void GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer, struct GNUNET_PeerIdentity *id)
Obtain the peer identity from a peer handle.
Definition: testing.c:1359
Private ECC key encoded for transmission.
The identity of the host (wraps the signing key of the peer).
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:195
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:199
uint32_t key_number
The keynumber of this peer's hostkey.
Definition: testing.c:264
void * cb_cls
The closure for the above callback.
Definition: testing.c:239
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:234
Specification of a service that is to be shared among peers.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
unsigned int share
The number of peers which share an instance of the service.
const char * service
The name of the service.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testing.c:122
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:187
char * trusted_ip
The trusted ip.
Definition: testing.c:133
struct SharedService * shared_services
Definition: testing.c:150
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:182
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.