diff options
Diffstat (limited to 'src/messenger/test_messenger.c')
-rw-r--r-- | src/messenger/test_messenger.c | 187 |
1 files changed, 0 insertions, 187 deletions
diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c deleted file mode 100644 index b42dfe6d9..000000000 --- a/src/messenger/test_messenger.c +++ /dev/null | |||
@@ -1,187 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | /** | ||
21 | * @file messenger/test_messenger.c | ||
22 | * @author Tobias Frisch | ||
23 | * @brief Test for the messenger service using cadet API. | ||
24 | */ | ||
25 | #include <stdio.h> | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | #include "gnunet_messenger_service.h" | ||
30 | |||
31 | /** | ||
32 | * How long until we really give up on a particular testcase portion? | ||
33 | */ | ||
34 | #define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ | ||
35 | 60) | ||
36 | |||
37 | /** | ||
38 | * How long until we give up on any particular operation (and retry)? | ||
39 | */ | ||
40 | #define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
41 | |||
42 | #define TESTER_NAME "tester" | ||
43 | |||
44 | static int status = 1; | ||
45 | |||
46 | static struct GNUNET_SCHEDULER_Task *die_task = NULL; | ||
47 | static struct GNUNET_SCHEDULER_Task *op_task = NULL; | ||
48 | |||
49 | struct GNUNET_MESSENGER_Handle *messenger = NULL; | ||
50 | |||
51 | static void | ||
52 | end (void *cls) | ||
53 | { | ||
54 | die_task = NULL; | ||
55 | |||
56 | if (op_task) | ||
57 | { | ||
58 | GNUNET_SCHEDULER_cancel (op_task); | ||
59 | op_task = NULL; | ||
60 | } | ||
61 | |||
62 | if (messenger) | ||
63 | { | ||
64 | GNUNET_MESSENGER_disconnect(messenger); | ||
65 | messenger = NULL; | ||
66 | } | ||
67 | |||
68 | status = 0; | ||
69 | } | ||
70 | |||
71 | |||
72 | static void | ||
73 | end_badly (void *cls) | ||
74 | { | ||
75 | fprintf (stderr, "Testcase failed (timeout).\n"); | ||
76 | |||
77 | end (NULL); | ||
78 | status = 1; | ||
79 | } | ||
80 | |||
81 | static void | ||
82 | end_operation (void *cls) | ||
83 | { | ||
84 | op_task = NULL; | ||
85 | |||
86 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls? (const char*) cls : "unknown"); | ||
87 | |||
88 | if (die_task) | ||
89 | GNUNET_SCHEDULER_cancel (die_task); | ||
90 | |||
91 | end (NULL); | ||
92 | status = 1; | ||
93 | } | ||
94 | |||
95 | static int identity_counter = 0; | ||
96 | |||
97 | /** | ||
98 | * Function called when an identity is retrieved. | ||
99 | * | ||
100 | * @param cls Closure | ||
101 | * @param handle Handle of messenger service | ||
102 | */ | ||
103 | static void | ||
104 | on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | ||
105 | { | ||
106 | if (op_task) | ||
107 | { | ||
108 | GNUNET_SCHEDULER_cancel (op_task); | ||
109 | op_task = NULL; | ||
110 | } | ||
111 | |||
112 | const char* name = GNUNET_MESSENGER_get_name(handle); | ||
113 | |||
114 | if (0 != strcmp(name, TESTER_NAME)) | ||
115 | { | ||
116 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous(); | ||
121 | struct GNUNET_IDENTITY_PublicKey anonymous_key; | ||
122 | |||
123 | GNUNET_IDENTITY_ego_get_public_key(ego, &anonymous_key); | ||
124 | |||
125 | const struct GNUNET_IDENTITY_PublicKey* key = GNUNET_MESSENGER_get_key(handle); | ||
126 | |||
127 | if (((!identity_counter) && (0 != GNUNET_memcmp(key, (&anonymous_key)))) || | ||
128 | ((identity_counter) && (0 == GNUNET_memcmp(key, (&anonymous_key))))) | ||
129 | { | ||
130 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); | ||
131 | return; | ||
132 | } | ||
133 | |||
134 | if (identity_counter) { | ||
135 | GNUNET_MESSENGER_disconnect(handle); | ||
136 | |||
137 | op_task = NULL; | ||
138 | messenger = NULL; | ||
139 | |||
140 | if (die_task) | ||
141 | GNUNET_SCHEDULER_cancel (die_task); | ||
142 | |||
143 | die_task = GNUNET_SCHEDULER_add_now (&end, NULL); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | GNUNET_MESSENGER_update(messenger); | ||
148 | identity_counter++; | ||
149 | } | ||
150 | |||
151 | /** | ||
152 | * Main function for testcase. | ||
153 | * | ||
154 | * @param cls Closure | ||
155 | * @param cfg Configuration | ||
156 | * @param peer Peer for testing | ||
157 | */ | ||
158 | static void | ||
159 | run (void *cls, | ||
160 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
161 | struct GNUNET_TESTING_Peer *peer) | ||
162 | { | ||
163 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); | ||
164 | |||
165 | identity_counter = 0; | ||
166 | |||
167 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | ||
168 | messenger = GNUNET_MESSENGER_connect(cfg, TESTER_NAME, &on_identity, NULL, NULL, NULL); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * The main function. | ||
173 | * | ||
174 | * @param argc number of arguments from the command line | ||
175 | * @param argv command line arguments | ||
176 | * @return 0 ok, 1 on error | ||
177 | */ | ||
178 | int | ||
179 | main(int argc, char **argv) | ||
180 | { | ||
181 | if (0 != GNUNET_TESTING_peer_run("test-messenger", | ||
182 | "test_messenger_api.conf", | ||
183 | &run, NULL)) | ||
184 | return 1; | ||
185 | |||
186 | return status; | ||
187 | } | ||