diff options
Diffstat (limited to 'src/messenger/test_messenger.c')
-rw-r--r-- | src/messenger/test_messenger.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c index 9958ce19e..716105380 100644 --- a/src/messenger/test_messenger.c +++ b/src/messenger/test_messenger.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -77,6 +77,7 @@ end (void *cls) | |||
77 | status = 0; | 77 | status = 0; |
78 | } | 78 | } |
79 | 79 | ||
80 | |||
80 | static void | 81 | static void |
81 | end_badly (void *cls) | 82 | end_badly (void *cls) |
82 | { | 83 | { |
@@ -86,12 +87,15 @@ end_badly (void *cls) | |||
86 | status = 1; | 87 | status = 1; |
87 | } | 88 | } |
88 | 89 | ||
90 | |||
89 | static void | 91 | static void |
90 | end_operation (void *cls) | 92 | end_operation (void *cls) |
91 | { | 93 | { |
92 | op_task = NULL; | 94 | op_task = NULL; |
93 | 95 | ||
94 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const char*) cls : "unknown"); | 96 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const |
97 | char*) cls : | ||
98 | "unknown"); | ||
95 | 99 | ||
96 | if (die_task) | 100 | if (die_task) |
97 | GNUNET_SCHEDULER_cancel (die_task); | 101 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -100,6 +104,7 @@ end_operation (void *cls) | |||
100 | status = 1; | 104 | status = 1; |
101 | } | 105 | } |
102 | 106 | ||
107 | |||
103 | static int identity_counter = 0; | 108 | static int identity_counter = 0; |
104 | 109 | ||
105 | /** | 110 | /** |
@@ -122,18 +127,23 @@ on_iteration (void *cls) | |||
122 | 127 | ||
123 | const char *name = GNUNET_MESSENGER_get_name (handle); | 128 | const char *name = GNUNET_MESSENGER_get_name (handle); |
124 | 129 | ||
125 | if ((!name) || (0 != strcmp (name, TESTER_NAME))) | 130 | if ((! name) || (0 != strcmp (name, TESTER_NAME))) |
126 | { | 131 | { |
127 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); | 132 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); |
128 | return; | 133 | return; |
129 | } | 134 | } |
130 | 135 | ||
131 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key (handle); | 136 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key ( |
137 | handle); | ||
132 | 138 | ||
133 | struct GNUNET_IDENTITY_PublicKey pubkey; | 139 | struct GNUNET_IDENTITY_PublicKey pubkey; |
134 | GNUNET_IDENTITY_key_get_public(&identity, &pubkey); | 140 | GNUNET_IDENTITY_key_get_public (&identity, &pubkey); |
135 | 141 | ||
136 | if (((!identity_counter) && (key)) || ((identity_counter) && ((!key) || (0 != GNUNET_memcmp (key, &pubkey))))) | 142 | if (((! identity_counter) && (key)) || ((identity_counter) && ((! key) || |
143 | (0 != | ||
144 | GNUNET_memcmp ( | ||
145 | key, | ||
146 | &pubkey))))) | ||
137 | { | 147 | { |
138 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); | 148 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); |
139 | return; | 149 | return; |
@@ -159,6 +169,7 @@ on_iteration (void *cls) | |||
159 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, handle); | 169 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, handle); |
160 | } | 170 | } |
161 | 171 | ||
172 | |||
162 | /** | 173 | /** |
163 | * Main function for testcase. | 174 | * Main function for testcase. |
164 | * | 175 | * |
@@ -175,7 +186,8 @@ run (void *cls, | |||
175 | 186 | ||
176 | identity_counter = 0; | 187 | identity_counter = 0; |
177 | 188 | ||
178 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | 189 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, |
190 | "connect"); | ||
179 | messenger = GNUNET_MESSENGER_connect (cfg, TESTER_NAME, NULL, NULL, NULL); | 191 | messenger = GNUNET_MESSENGER_connect (cfg, TESTER_NAME, NULL, NULL, NULL); |
180 | 192 | ||
181 | identity.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); | 193 | identity.type = htonl (GNUNET_IDENTITY_TYPE_ECDSA); |
@@ -185,6 +197,7 @@ run (void *cls, | |||
185 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger); | 197 | it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger); |
186 | } | 198 | } |
187 | 199 | ||
200 | |||
188 | /** | 201 | /** |
189 | * The main function. | 202 | * The main function. |
190 | * | 203 | * |
@@ -196,7 +209,8 @@ int | |||
196 | main (int argc, | 209 | main (int argc, |
197 | char **argv) | 210 | char **argv) |
198 | { | 211 | { |
199 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) | 212 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", |
213 | &run, NULL)) | ||
200 | return 1; | 214 | return 1; |
201 | 215 | ||
202 | return status; | 216 | return status; |