GNUnet  0.17.6
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 #include "gnunet_util_lib.h"
49 #include "gnunet_arm_service.h"
50 
51 #ifdef __cplusplus
52 extern "C"
53 {
54 #if 0 /* keep Emacsens' auto-indent happy */
55 }
56 #endif
57 #endif
58 
62 #define GNUNET_TESTING_HOSTKEYFILESIZE sizeof(struct \
63  GNUNET_CRYPTO_EddsaPrivateKey)
64 
69 #define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX"
70 
71 
77 
78 
82 struct GNUNET_TESTING_Peer;
83 
84 
89 {
93  const char *service;
94 
99 
104  unsigned int share;
105 };
106 
107 
128 struct GNUNET_TESTING_System *
129 GNUNET_TESTING_system_create (const char *testdir,
130  const char *trusted_ip,
131  const char *hostname,
132  const struct GNUNET_TESTING_SharedService *
134 
135 
160 struct GNUNET_TESTING_System *
162  const char *trusted_ip,
163  const char *hostname,
164  const struct
167  uint16_t lowport,
168  uint16_t highport);
169 
170 
178 void
180  int remove_paths);
181 
182 
202  uint32_t key_number,
203  struct GNUNET_PeerIdentity *id);
204 
205 
212 uint16_t
214 
215 
223 void
225  uint16_t port);
226 
227 
245 int
248 
249 // FIXME: add dual to 'release' ports again...
250 
251 
265 struct GNUNET_TESTING_Peer *
268  uint32_t key_number,
269  struct GNUNET_PeerIdentity *id,
270  char **emsg);
271 
272 
279 void
281  struct GNUNET_PeerIdentity *id);
282 
283 
291 int
293 
294 
304 int
306 
307 
315 void
317 
318 
326 int
328 
329 
337 int
339 
340 
349 typedef void
350 (*GNUNET_TESTING_PeerStopCallback) (void *cls,
351  struct GNUNET_TESTING_Peer *peer,
352  int success);
353 
354 
366 int
369  void *cb_cls);
370 
371 
381 void
383 
384 
393 typedef void
394 (*GNUNET_TESTING_TestMain) (void *cls,
395  const struct GNUNET_CONFIGURATION_Handle *cfg,
396  struct GNUNET_TESTING_Peer *peer);
397 
398 
415 int
416 GNUNET_TESTING_peer_run (const char *testdir,
417  const char *cfgfilename,
419  void *tm_cls);
420 
421 
443 int
444 GNUNET_TESTING_service_run (const char *testdir,
445  const char *service_name,
446  const char *cfgfilename,
448  void *tm_cls);
449 
450 
464 char *
466 
467 
468 #if 0 /* keep Emacsens' auto-indent happy */
469 {
470 #endif
471 #ifdef __cplusplus
472 }
473 #endif
474 
475 #endif
476  /* end of group */
478  /* 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:51
API to create, modify and access statistics.
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1467
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:458
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:373
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:1170
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:714
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:1601
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:538
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:1673
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1363
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a port for a peer.
Definition: testing.c:580
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:676
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1543
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:1518
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:1149
char * GNUNET_TESTING_get_testname_from_underscore(const char *argv0)
Sometimes we use the binary name to determine which specific test to run.
Definition: testing.c:1768
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer's main process.
Definition: testing.c:1412
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1559
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1444
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:1341
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:176
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:180
uint32_t key_number
The keynumber of this peer's hostkey.
Definition: testing.c:245
void * cb_cls
The closure for the above callback.
Definition: testing.c:220
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:215
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:103
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:168
char * trusted_ip
The trusted ip.
Definition: testing.c:114
struct SharedService ** shared_services
Definition: testing.c:131
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:163
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.