diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-18 19:28:14 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-18 19:28:14 +0000 |
commit | 6b2fb63de633b086a91e7733ca0dd5591198c20c (patch) | |
tree | a6e69cfd3ebeb58f37a7c40e584fa3fd4a3c2eaf | |
parent | 7393b25a78f3afb70bed4eb39c0e2db1a7010e4f (diff) | |
download | gnunet-6b2fb63de633b086a91e7733ca0dd5591198c20c.tar.gz gnunet-6b2fb63de633b086a91e7733ca0dd5591198c20c.zip |
implementing GNUNET_TESTING_get_peer_identity (addressing #2083)
-rw-r--r-- | src/include/gnunet_testing_lib.h | 14 | ||||
-rw-r--r-- | src/testing/Makefile.am | 1 | ||||
-rw-r--r-- | src/testing/helper.c | 75 |
3 files changed, 90 insertions, 0 deletions
diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index 711d676a2..03b837668 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h | |||
@@ -506,6 +506,20 @@ GNUNET_TESTING_test_daemon_running (struct GNUNET_TESTING_Daemon *daemon); | |||
506 | 506 | ||
507 | 507 | ||
508 | /** | 508 | /** |
509 | * Obtain the peer identity of the peer with the given configuration | ||
510 | * handle. This function reads the private key of the peer, obtains | ||
511 | * the public key and hashes it. | ||
512 | * | ||
513 | * @param cfg configuration of the peer | ||
514 | * @param pid where to store the peer identity | ||
515 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
516 | */ | ||
517 | int | ||
518 | GNUNET_TESTING_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
519 | struct GNUNET_PeerIdentity *pid); | ||
520 | |||
521 | |||
522 | /** | ||
509 | * Restart (stop and start) a GNUnet daemon. | 523 | * Restart (stop and start) a GNUnet daemon. |
510 | * | 524 | * |
511 | * @param d the daemon that should be restarted | 525 | * @param d the daemon that should be restarted |
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am index 5432fb0d1..050691d13 100644 --- a/src/testing/Makefile.am +++ b/src/testing/Makefile.am | |||
@@ -36,6 +36,7 @@ endif | |||
36 | lib_LTLIBRARIES = libgnunettesting.la | 36 | lib_LTLIBRARIES = libgnunettesting.la |
37 | 37 | ||
38 | libgnunettesting_la_SOURCES = \ | 38 | libgnunettesting_la_SOURCES = \ |
39 | helper.c \ | ||
39 | testing.c \ | 40 | testing.c \ |
40 | testing_group.c \ | 41 | testing_group.c \ |
41 | testing_peergroup.c | 42 | testing_peergroup.c |
diff --git a/src/testing/helper.c b/src/testing/helper.c new file mode 100644 index 000000000..ebb37ebe5 --- /dev/null +++ b/src/testing/helper.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testing/helper.c | ||
23 | * @brief helper functions for testing | ||
24 | * @author Christian Grothoff | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | |||
30 | |||
31 | |||
32 | |||
33 | /** | ||
34 | * Obtain the peer identity of the peer with the given configuration | ||
35 | * handle. This function reads the private key of the peer, obtains | ||
36 | * the public key and hashes it. | ||
37 | * | ||
38 | * @param cfg configuration of the peer | ||
39 | * @param pid where to store the peer identity | ||
40 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
41 | */ | ||
42 | int | ||
43 | GNUNET_TESTING_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
44 | struct GNUNET_PeerIdentity *pid) | ||
45 | { | ||
46 | char *keyfile; | ||
47 | struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | ||
48 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; | ||
49 | |||
50 | if (GNUNET_OK != | ||
51 | GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", | ||
52 | &keyfile)) | ||
53 | { | ||
54 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
55 | _ | ||
56 | ("Peer is lacking HOSTKEY configuration setting.\n")); | ||
57 | return GNUNET_SYSERR; | ||
58 | } | ||
59 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | ||
60 | GNUNET_free (keyfile); | ||
61 | if (my_private_key == NULL) | ||
62 | { | ||
63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
64 | _("Could not access hostkey.\n")); | ||
65 | return GNUNET_SYSERR; | ||
66 | } | ||
67 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | ||
68 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | ||
69 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
70 | &pid->hashPubKey); | ||
71 | return GNUNET_OK; | ||
72 | } | ||
73 | |||
74 | |||
75 | /* end of helper.c */ | ||