GNUnet  0.11.x
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 
41 #ifndef GNUNET_TESTING_LIB_H
42 #define GNUNET_TESTING_LIB_H
43 
44 #include "gnunet_util_lib.h"
46 #include "gnunet_arm_service.h"
47 
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #if 0 /* keep Emacsens' auto-indent happy */
52 }
53 #endif
54 #endif
55 
59 #define GNUNET_TESTING_HOSTKEYFILESIZE sizeof(struct \
60  GNUNET_CRYPTO_EddsaPrivateKey)
61 
66 #define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX"
67 
68 
74 
75 
79 struct GNUNET_TESTING_Peer;
80 
81 
86 {
90  const char *service;
91 
96 
101  unsigned int share;
102 };
103 
104 
125 struct GNUNET_TESTING_System *
126 GNUNET_TESTING_system_create (const char *testdir,
127  const char *trusted_ip,
128  const char *hostname,
129  const struct GNUNET_TESTING_SharedService *
131 
132 
157 struct GNUNET_TESTING_System *
159  const char *trusted_ip,
160  const char *hostname,
161  const struct
164  uint16_t lowport,
165  uint16_t highport);
166 
167 
175 void
177  int remove_paths);
178 
179 
199  uint32_t key_number,
200  struct GNUNET_PeerIdentity *id);
201 
202 
209 uint16_t
211 
212 
220 void
222  uint16_t port);
223 
224 
242 int
245 
246 // FIXME: add dual to 'release' ports again...
247 
248 
262 struct GNUNET_TESTING_Peer *
265  uint32_t key_number,
266  struct GNUNET_PeerIdentity *id,
267  char **emsg);
268 
269 
276 void
278  struct GNUNET_PeerIdentity *id);
279 
280 
288 int
290 
291 
301 int
303 
304 
312 void
314 
315 
323 int
325 
326 
334 int
336 
337 
346 typedef void
348  struct GNUNET_TESTING_Peer *peer,
349  int success);
350 
351 
363 int
366  void *cb_cls);
367 
368 
378 void
380 
381 
390 typedef void
392  const struct GNUNET_CONFIGURATION_Handle *cfg,
393  struct GNUNET_TESTING_Peer *peer);
394 
395 
412 int
413 GNUNET_TESTING_peer_run (const char *testdir,
414  const char *cfgfilename,
416  void *tm_cls);
417 
418 
440 int
441 GNUNET_TESTING_service_run (const char *testdir,
442  const char *service_name,
443  const char *cfgfilename,
445  void *tm_cls);
446 
447 
461 char *
463 
464 
465 #if 0 /* keep Emacsens' auto-indent happy */
466 {
467 #endif
468 #ifdef __cplusplus
469 }
470 #endif
471 
472 #endif
473  /* end of group */
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:1515
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:158
Specification of a service that is to be shared among peers.
int GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
Start the peer.
Definition: testing.c:1359
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:170
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:1598
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:710
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1464
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:1145
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:1166
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1409
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 &#39;arm&#39;) and run a test u...
Definition: testing.c:1670
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:175
static char * service_name
Option -s: service name (hash to get service descriptor)
Definition: gnunet-vpn.c:51
void * cb_cls
The closure for the above callback.
Definition: testing.c:215
unsigned int share
The number of peers which share an instance of the service.
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:453
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:534
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct SharedService ** shared_services
Definition: testing.c:126
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:97
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1540
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:368
Private ECC key encoded for transmission.
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:1765
The identity of the host (wraps the signing key of the peer).
uint16_t highport
Highest port we are allowed to use.
Definition: testing.c:163
static char * hostname
Our hostname; we give this to all the peers we start.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
configuration data
Definition: configuration.c:85
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration template for the service.
uint16_t GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
Reserve a port for a peer.
Definition: testing.c:576
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:1337
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:240
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:210
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1556
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:672
void(* GNUNET_TESTING_TestMain)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer)
Signature of the &#39;main&#39; function for a (single-peer) testcase that is run using GNUNET_TESTING_peer_r...
int GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
Waits for a peer to terminate.
Definition: testing.c:1441
char * trusted_ip
The trusted ip.
Definition: testing.c:109
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.