aboutsummaryrefslogtreecommitdiff
path: root/src/messenger/test_messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/messenger/test_messenger.c')
-rw-r--r--src/messenger/test_messenger.c217
1 files changed, 0 insertions, 217 deletions
diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c
deleted file mode 100644
index 716105380..000000000
--- a/src/messenger/test_messenger.c
+++ /dev/null
@@ -1,217 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2023 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 "platform.h"
26#include <stdio.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
44static int status = 1;
45
46static struct GNUNET_SCHEDULER_Task *die_task = NULL;
47static struct GNUNET_SCHEDULER_Task *op_task = NULL;
48static struct GNUNET_SCHEDULER_Task *it_task = NULL;
49
50struct GNUNET_MESSENGER_Handle *messenger = NULL;
51
52static struct GNUNET_IDENTITY_PrivateKey identity;
53
54static void
55end (void *cls)
56{
57 die_task = NULL;
58
59 if (it_task)
60 {
61 GNUNET_SCHEDULER_cancel (it_task);
62 it_task = NULL;
63 }
64
65 if (op_task)
66 {
67 GNUNET_SCHEDULER_cancel (op_task);
68 op_task = NULL;
69 }
70
71 if (messenger)
72 {
73 GNUNET_MESSENGER_disconnect (messenger);
74 messenger = NULL;
75 }
76
77 status = 0;
78}
79
80
81static void
82end_badly (void *cls)
83{
84 fprintf (stderr, "Testcase failed (timeout).\n");
85
86 end (NULL);
87 status = 1;
88}
89
90
91static void
92end_operation (void *cls)
93{
94 op_task = NULL;
95
96 fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const
97 char*) cls :
98 "unknown");
99
100 if (die_task)
101 GNUNET_SCHEDULER_cancel (die_task);
102
103 end (NULL);
104 status = 1;
105}
106
107
108static int identity_counter = 0;
109
110/**
111 * Function called when an identity is retrieved.
112 *
113 * @param cls Closure
114 * @param handle Handle of messenger service
115 */
116static void
117on_iteration (void *cls)
118{
119 struct GNUNET_MESSENGER_Handle *handle = cls;
120 it_task = NULL;
121
122 if (op_task)
123 {
124 GNUNET_SCHEDULER_cancel (op_task);
125 op_task = NULL;
126 }
127
128 const char *name = GNUNET_MESSENGER_get_name (handle);
129
130 if ((! name) || (0 != strcmp (name, TESTER_NAME)))
131 {
132 op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name");
133 return;
134 }
135
136 const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key (
137 handle);
138
139 struct GNUNET_IDENTITY_PublicKey pubkey;
140 GNUNET_IDENTITY_key_get_public (&identity, &pubkey);
141
142 if (((! identity_counter) && (key)) || ((identity_counter) && ((! key) ||
143 (0 !=
144 GNUNET_memcmp (
145 key,
146 &pubkey)))))
147 {
148 op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key");
149 return;
150 }
151
152 if (identity_counter)
153 {
154 GNUNET_MESSENGER_disconnect (handle);
155
156 op_task = NULL;
157 messenger = NULL;
158
159 if (die_task)
160 GNUNET_SCHEDULER_cancel (die_task);
161
162 die_task = GNUNET_SCHEDULER_add_now (&end, NULL);
163 return;
164 }
165
166 GNUNET_MESSENGER_set_key (handle, &identity);
167 identity_counter++;
168
169 it_task = GNUNET_SCHEDULER_add_now (&on_iteration, handle);
170}
171
172
173/**
174 * Main function for testcase.
175 *
176 * @param cls Closure
177 * @param cfg Configuration
178 * @param peer Peer for testing
179 */
180static void
181run (void *cls,
182 const struct GNUNET_CONFIGURATION_Handle *cfg,
183 struct GNUNET_TESTING_Peer *peer)
184{
185 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL);
186
187 identity_counter = 0;
188
189 op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation,
190 "connect");
191 messenger = GNUNET_MESSENGER_connect (cfg, TESTER_NAME, NULL, NULL, NULL);
192
193 identity.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA);
194 GNUNET_CRYPTO_ecdsa_key_create (&(identity.ecdsa_key));
195
196 if (messenger)
197 it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger);
198}
199
200
201/**
202 * The main function.
203 *
204 * @param argc number of arguments from the command line
205 * @param argv command line arguments
206 * @return 0 ok, 1 on error
207 */
208int
209main (int argc,
210 char **argv)
211{
212 if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf",
213 &run, NULL))
214 return 1;
215
216 return status;
217}