diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-16 15:09:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-16 15:09:28 +0000 |
commit | 4064deedf4ee722ba8adab7fd3030cea3e20297e (patch) | |
tree | dc4cd66e55a48966b9ff5cab80fb18af10293caf | |
parent | 40d01d900dd900d3cb8f902d6895e43ee74d6bb9 (diff) | |
download | gnunet-4064deedf4ee722ba8adab7fd3030cea3e20297e.tar.gz gnunet-4064deedf4ee722ba8adab7fd3030cea3e20297e.zip |
-towards testing identity service
-rw-r--r-- | src/identity/Makefile.am | 8 | ||||
-rw-r--r-- | src/identity/gnunet-identity.c | 4 | ||||
-rw-r--r-- | src/identity/gnunet-service-identity.c | 5 | ||||
-rw-r--r-- | src/identity/identity.conf.in | 36 | ||||
-rw-r--r-- | src/identity/identity_api.c | 2 | ||||
-rw-r--r-- | src/identity/test_identity.c | 203 | ||||
-rw-r--r-- | src/identity/test_identity.conf | 5 |
7 files changed, 228 insertions, 35 deletions
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am index 1b7767fe1..e68debbc1 100644 --- a/src/identity/Makefile.am +++ b/src/identity/Makefile.am | |||
@@ -56,16 +56,16 @@ gnunet_service_identity_DEPENDENCIES = \ | |||
56 | 56 | ||
57 | if HAVE_TESTING | 57 | if HAVE_TESTING |
58 | check_PROGRAMS = \ | 58 | check_PROGRAMS = \ |
59 | test_identity_api | 59 | test_identity |
60 | endif | 60 | endif |
61 | 61 | ||
62 | if ENABLE_TEST_RUN | 62 | if ENABLE_TEST_RUN |
63 | TESTS = $(check_PROGRAMS) | 63 | TESTS = $(check_PROGRAMS) |
64 | endif | 64 | endif |
65 | 65 | ||
66 | test_identity_api_SOURCES = \ | 66 | test_identity_SOURCES = \ |
67 | test_identity_api.c | 67 | test_identity.c |
68 | test_identity_api_LDADD = \ | 68 | test_identity_LDADD = \ |
69 | $(top_builddir)/src/identity/libgnunetidentity.la \ | 69 | $(top_builddir)/src/identity/libgnunetidentity.la \ |
70 | $(top_builddir)/src/testing/libgnunettesting.la \ | 70 | $(top_builddir)/src/testing/libgnunettesting.la \ |
71 | $(top_builddir)/src/util/libgnunetutil.la | 71 | $(top_builddir)/src/util/libgnunetutil.la |
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 15cb17d1b..c590ab701 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.c | |||
@@ -21,6 +21,10 @@ | |||
21 | * @file identity/gnunet-identity.c | 21 | * @file identity/gnunet-identity.c |
22 | * @brief IDENTITY management command line tool | 22 | * @brief IDENTITY management command line tool |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * | ||
25 | * Todo: | ||
26 | * - add options to get/set default egos | ||
27 | * - print short hashes of egos when printing | ||
24 | */ | 28 | */ |
25 | #include "platform.h" | 29 | #include "platform.h" |
26 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 45c088e44..84da12c2a 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -25,6 +25,11 @@ | |||
25 | * | 25 | * |
26 | * The purpose of this service is to manage private keys that | 26 | * The purpose of this service is to manage private keys that |
27 | * represent the various egos/pseudonyms/identities of a GNUnet user. | 27 | * represent the various egos/pseudonyms/identities of a GNUnet user. |
28 | * | ||
29 | * Todo: | ||
30 | * - testcases | ||
31 | * - auto-initialze default egos; maybe trigger default | ||
32 | * initializations (such as gnunet-gns-import.sh?) | ||
28 | */ | 33 | */ |
29 | #include "platform.h" | 34 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 35 | #include "gnunet_util_lib.h" |
diff --git a/src/identity/identity.conf.in b/src/identity/identity.conf.in index 64e07945e..737614119 100644 --- a/src/identity/identity.conf.in +++ b/src/identity/identity.conf.in | |||
@@ -1,39 +1,15 @@ | |||
1 | [nse] | 1 | [identity] |
2 | AUTOSTART = YES | 2 | AUTOSTART = YES |
3 | @JAVAPORT@PORT = 2097 | 3 | @UNIXONLY@PORT = 2108 |
4 | HOSTNAME = localhost | 4 | HOSTNAME = localhost |
5 | HOME = $SERVICEHOME | 5 | HOME = $SERVICEHOME |
6 | BINARY = gnunet-service-nse | 6 | BINARY = gnunet-service-identity |
7 | ACCEPT_FROM = 127.0.0.1; | 7 | ACCEPT_FROM = 127.0.0.1; |
8 | ACCEPT_FROM6 = ::1; | 8 | ACCEPT_FROM6 = ::1; |
9 | UNIXPATH = /tmp/test-nse-service-nse.unix | 9 | UNIXPATH = /tmp/gnunet-service-identity.unix |
10 | UNIX_MATCH_UID = NO | 10 | UNIX_MATCH_UID = NO |
11 | UNIX_MATCH_GID = YES | 11 | UNIX_MATCH_GID = YES |
12 | PROOFFILE = $SERVICEHOME/.nse-proof | ||
13 | 12 | ||
14 | # The directory where the NSE services logs timestamps everytime | 13 | # Directory where we store information about our egos |
15 | # a size estime flooding message is received | 14 | EGODIR = $SERVICEHOME/egos/ |
16 | # This option is only used for benchmarking, not in production. | ||
17 | HISTOGRAM_DIR = $SERVICEHOME | ||
18 | |||
19 | # How 'slowly' should the proof-of-work be constructed (delay | ||
20 | # between rounds); sane values between 0 and ~1000. | ||
21 | # It should rarely make sense to change this value. | ||
22 | # Only systems with slow CPUs where 5ms is a long time might | ||
23 | # want it to be reduced. | ||
24 | WORKDELAY = 5 ms | ||
25 | |||
26 | # Note: changing any of the values below will make this peer | ||
27 | # completely incompatible with other peers! | ||
28 | |||
29 | # How often do peers exchange network size messages? | ||
30 | # Note that all peers MUST use the same interval. | ||
31 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! | ||
32 | INTERVAL = 1 h | ||
33 | |||
34 | # 2^22 hash operations take about 2-3h on a modern i7 (single-core) | ||
35 | # for SCRYPT; with 2ms/op and 5ms workdelay, we can expect | ||
36 | # the POW calculation to be done by a high-end peer in about 6h | ||
37 | # DO NOT CHANGE THIS VALUE, doing so will break the protocol! | ||
38 | WORKBITS = 22 | ||
39 | 15 | ||
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index 169a7a2ac..4b4c8c3a1 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.c | |||
@@ -862,7 +862,7 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *id, | |||
862 | * @param op operation to cancel | 862 | * @param op operation to cancel |
863 | */ | 863 | */ |
864 | void | 864 | void |
865 | GNUNET_IDENITY_cancel (struct GNUNET_IDENTITY_Operation *op) | 865 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) |
866 | { | 866 | { |
867 | struct GNUNET_IDENTITY_Handle *h = op->h; | 867 | struct GNUNET_IDENTITY_Handle *h = op->h; |
868 | 868 | ||
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c new file mode 100644 index 000000000..3712da3bd --- /dev/null +++ b/src/identity/test_identity.c | |||
@@ -0,0 +1,203 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013 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 identity/test_identity.c | ||
23 | * @brief testcase for identity service | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_common.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_identity_service.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | |||
33 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Return value from 'main'. | ||
38 | */ | ||
39 | static int res; | ||
40 | |||
41 | /** | ||
42 | * Handle to identity service. | ||
43 | */ | ||
44 | static struct GNUNET_IDENTITY_Handle *h; | ||
45 | |||
46 | /** | ||
47 | * Handle to identity operation. | ||
48 | */ | ||
49 | static struct GNUNET_IDENTITY_Operation *op; | ||
50 | |||
51 | /** | ||
52 | * Handle for task for timeout termination. | ||
53 | */ | ||
54 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Clean up all resources used. | ||
59 | */ | ||
60 | static void | ||
61 | cleanup () | ||
62 | { | ||
63 | if (NULL != h) | ||
64 | { | ||
65 | GNUNET_IDENTITY_disconnect (h); | ||
66 | h = NULL; | ||
67 | } | ||
68 | if (NULL != op) | ||
69 | { | ||
70 | GNUNET_IDENTITY_cancel (op); | ||
71 | op = NULL; | ||
72 | } | ||
73 | GNUNET_SCHEDULER_shutdown (); | ||
74 | } | ||
75 | |||
76 | |||
77 | /** | ||
78 | * Termiante the testcase (failure). | ||
79 | * | ||
80 | * @param cls NULL | ||
81 | * @param tc scheduler context | ||
82 | */ | ||
83 | static void | ||
84 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
85 | { | ||
86 | cleanup (); | ||
87 | res = 1; | ||
88 | } | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Termiante the testcase (success). | ||
93 | * | ||
94 | * @param cls NULL | ||
95 | * @param tc scheduler context | ||
96 | */ | ||
97 | static void | ||
98 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
99 | { | ||
100 | cleanup (); | ||
101 | res = 0; | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Finish the testcase (successfully). | ||
107 | */ | ||
108 | static void | ||
109 | end () | ||
110 | { | ||
111 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
112 | { | ||
113 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
114 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
115 | } | ||
116 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Called with events about egos. | ||
122 | * | ||
123 | * @param cls NULL | ||
124 | * @param ego ego handle | ||
125 | * @param ego_ctx context for application to store data for this ego | ||
126 | * (during the lifetime of this process, initially NULL) | ||
127 | * @param identifier identifier assigned by the user for this ego, | ||
128 | * NULL if the user just deleted the ego and it | ||
129 | * must thus no longer be used | ||
130 | */ | ||
131 | static void | ||
132 | notification_cb (void *cls, | ||
133 | struct GNUNET_IDENTITY_Ego *ego, | ||
134 | void **ctx, | ||
135 | const char *identifier) | ||
136 | { | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
141 | * Called with events about created ego. | ||
142 | * | ||
143 | * @param cls NULL | ||
144 | * @param ego ego handle | ||
145 | * @param ego_ctx context for application to store data for this ego | ||
146 | * (during the lifetime of this process, initially NULL) | ||
147 | * @param identifier identifier assigned by the user for this ego, | ||
148 | * NULL if the user just deleted the ego and it | ||
149 | * must thus no longer be used | ||
150 | */ | ||
151 | static void | ||
152 | create_cb (void *cls, | ||
153 | struct GNUNET_IDENTITY_Ego *ego, | ||
154 | void **ctx, | ||
155 | const char *identifier) | ||
156 | { | ||
157 | op = NULL; | ||
158 | end (); /* yepee */ | ||
159 | } | ||
160 | |||
161 | |||
162 | |||
163 | /** | ||
164 | * Main function of the test, run from scheduler. | ||
165 | * | ||
166 | * @param cls NULL | ||
167 | * @param cfg configuration we use (also to connect to identity service) | ||
168 | * @param peer handle to access more of the peer (not used) | ||
169 | */ | ||
170 | static void | ||
171 | run (void *cls, | ||
172 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
173 | struct GNUNET_TESTING_Peer *peer) | ||
174 | { | ||
175 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
176 | &endbadly, NULL); | ||
177 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | ||
178 | op = GNUNET_IDENTITY_create (h, | ||
179 | "test-id", | ||
180 | &create_cb, | ||
181 | NULL); | ||
182 | |||
183 | } | ||
184 | |||
185 | |||
186 | |||
187 | |||
188 | int | ||
189 | main (int argc, char *argv[]) | ||
190 | { | ||
191 | res = 1; | ||
192 | if (0 != | ||
193 | GNUNET_TESTING_service_run ("test-identity", | ||
194 | "identity", | ||
195 | "test_identity.conf", | ||
196 | &run, | ||
197 | NULL)) | ||
198 | return 1; | ||
199 | return res; | ||
200 | } | ||
201 | |||
202 | |||
203 | /* end of test_identity.c */ | ||
diff --git a/src/identity/test_identity.conf b/src/identity/test_identity.conf new file mode 100644 index 000000000..3f57af93e --- /dev/null +++ b/src/identity/test_identity.conf | |||
@@ -0,0 +1,5 @@ | |||
1 | [arm] | ||
2 | PORT = 12000 | ||
3 | DEFAULTSERVICES = identity | ||
4 | UNIXPATH = /tmp/gnunet-p1-service-arm.sock | ||
5 | |||