GNUnet  0.10.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 GNUNET_CRYPTO_EddsaPrivateKey)
60 
65 #define GNUNET_TESTING_PREFIX "GNUNET_TESTING_PREFIX"
66 
67 
73 
74 
78 struct GNUNET_TESTING_Peer;
79 
80 
88  const char *service;
89 
94 
99  unsigned int share;
100 };
101 
102 
123 struct GNUNET_TESTING_System *
124 GNUNET_TESTING_system_create(const char *testdir,
125  const char *trusted_ip,
126  const char *hostname,
127  const struct GNUNET_TESTING_SharedService *
129 
130 
155 struct GNUNET_TESTING_System *
157  const char *trusted_ip,
158  const char *hostname,
160  uint16_t lowport,
161  uint16_t highport);
162 
163 
171 void
173  int remove_paths);
174 
175 
195  uint32_t key_number,
196  struct GNUNET_PeerIdentity *id);
197 
198 
205 uint16_t
207 
208 
216 void
218  uint16_t port);
219 
220 
238 int
241 // FIXME: add dual to 'release' ports again...
242 
243 
257 struct GNUNET_TESTING_Peer *
260  uint32_t key_number,
261  struct GNUNET_PeerIdentity *id,
262  char **emsg);
263 
264 
271 void
273  struct GNUNET_PeerIdentity *id);
274 
275 
283 int
285 
286 
296 int
298 
299 
307 void
309 
310 
318 int
320 
321 
329 int
331 
332 
341 typedef void
343  struct GNUNET_TESTING_Peer *peer,
344  int success);
345 
346 
358 int
361  void *cb_cls);
362 
363 
373 void
375 
376 
385 typedef void
387  const struct GNUNET_CONFIGURATION_Handle *cfg,
388  struct GNUNET_TESTING_Peer *peer);
389 
390 
407 int
408 GNUNET_TESTING_peer_run(const char *testdir,
409  const char *cfgfilename,
411  void *tm_cls);
412 
413 
435 int
436 GNUNET_TESTING_service_run(const char *testdir,
437  const char *service_name,
438  const char *cfgfilename,
440  void *tm_cls);
441 
442 
456 char *
458 
459 
460 #if 0 /* keep Emacsens' auto-indent happy */
461 {
462 #endif
463 #ifdef __cplusplus
464 }
465 #endif
466 
467 #endif
468  /* 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:1511
uint16_t lowport
Lowest port we are allowed to use.
Definition: testing.c:155
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:1355
Handle for a GNUnet peer controlled by testing.
Definition: testing.c:167
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:1594
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:707
int GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
Stop the peer.
Definition: testing.c:1460
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:1141
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:1162
int GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
Sends SIGTERM to the peer&#39;s main process.
Definition: testing.c:1405
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:1665
struct GNUNET_TESTING_System * system
The TESTING system associated with this peer.
Definition: testing.c:171
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:211
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:449
void GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system, int remove_paths)
Free system resources.
Definition: testing.c:530
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct SharedService ** shared_services
Definition: testing.c:123
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:95
void GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
Cancel a previous asynchronous peer stop request.
Definition: testing.c:1536
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:364
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:1760
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:160
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:83
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:572
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:1333
uint32_t key_number
The keynumber of this peer&#39;s hostkey.
Definition: testing.c:236
GNUNET_TESTING_PeerStopCallback cb
The callback to call asynchronously when a peer is stopped.
Definition: testing.c:206
void GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
Destroy the peer.
Definition: testing.c:1552
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:669
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:1437
char * trusted_ip
The trusted ip.
Definition: testing.c:106
void(* GNUNET_TESTING_PeerStopCallback)(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
Callback to inform whether the peer is running or stopped.