diff options
Diffstat (limited to 'src/messenger/test_messenger.c')
-rw-r--r-- | src/messenger/test_messenger.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/src/messenger/test_messenger.c b/src/messenger/test_messenger.c index b42dfe6d9..fb3e3e1bc 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 GNUnet e.V. | 3 | Copyright (C) 2020--2021 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 |
@@ -61,14 +61,13 @@ end (void *cls) | |||
61 | 61 | ||
62 | if (messenger) | 62 | if (messenger) |
63 | { | 63 | { |
64 | GNUNET_MESSENGER_disconnect(messenger); | 64 | GNUNET_MESSENGER_disconnect (messenger); |
65 | messenger = NULL; | 65 | messenger = NULL; |
66 | } | 66 | } |
67 | 67 | ||
68 | status = 0; | 68 | status = 0; |
69 | } | 69 | } |
70 | 70 | ||
71 | |||
72 | static void | 71 | static void |
73 | end_badly (void *cls) | 72 | end_badly (void *cls) |
74 | { | 73 | { |
@@ -83,7 +82,7 @@ end_operation (void *cls) | |||
83 | { | 82 | { |
84 | op_task = NULL; | 83 | op_task = NULL; |
85 | 84 | ||
86 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls? (const char*) cls : "unknown"); | 85 | fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const char*) cls : "unknown"); |
87 | 86 | ||
88 | if (die_task) | 87 | if (die_task) |
89 | GNUNET_SCHEDULER_cancel (die_task); | 88 | GNUNET_SCHEDULER_cancel (die_task); |
@@ -109,30 +108,25 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | |||
109 | op_task = NULL; | 108 | op_task = NULL; |
110 | } | 109 | } |
111 | 110 | ||
112 | const char* name = GNUNET_MESSENGER_get_name(handle); | 111 | const char *name = GNUNET_MESSENGER_get_name (handle); |
113 | 112 | ||
114 | if (0 != strcmp(name, TESTER_NAME)) | 113 | if (0 != strcmp (name, TESTER_NAME)) |
115 | { | 114 | { |
116 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); | 115 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "name"); |
117 | return; | 116 | return; |
118 | } | 117 | } |
119 | 118 | ||
120 | struct GNUNET_IDENTITY_Ego* ego = GNUNET_IDENTITY_ego_get_anonymous(); | 119 | const struct GNUNET_IDENTITY_PublicKey *key = GNUNET_MESSENGER_get_key (handle); |
121 | struct GNUNET_IDENTITY_PublicKey anonymous_key; | ||
122 | |||
123 | GNUNET_IDENTITY_ego_get_public_key(ego, &anonymous_key); | ||
124 | 120 | ||
125 | const struct GNUNET_IDENTITY_PublicKey* key = GNUNET_MESSENGER_get_key(handle); | 121 | if (((!identity_counter) && (key)) || ((identity_counter) && (!key))) |
126 | |||
127 | if (((!identity_counter) && (0 != GNUNET_memcmp(key, (&anonymous_key)))) || | ||
128 | ((identity_counter) && (0 == GNUNET_memcmp(key, (&anonymous_key))))) | ||
129 | { | 122 | { |
130 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); | 123 | op_task = GNUNET_SCHEDULER_add_now (&end_operation, "key"); |
131 | return; | 124 | return; |
132 | } | 125 | } |
133 | 126 | ||
134 | if (identity_counter) { | 127 | if (identity_counter) |
135 | GNUNET_MESSENGER_disconnect(handle); | 128 | { |
129 | GNUNET_MESSENGER_disconnect (handle); | ||
136 | 130 | ||
137 | op_task = NULL; | 131 | op_task = NULL; |
138 | messenger = NULL; | 132 | messenger = NULL; |
@@ -144,7 +138,7 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | |||
144 | return; | 138 | return; |
145 | } | 139 | } |
146 | 140 | ||
147 | GNUNET_MESSENGER_update(messenger); | 141 | GNUNET_MESSENGER_update (messenger); |
148 | identity_counter++; | 142 | identity_counter++; |
149 | } | 143 | } |
150 | 144 | ||
@@ -156,16 +150,14 @@ on_identity (void *cls, struct GNUNET_MESSENGER_Handle *handle) | |||
156 | * @param peer Peer for testing | 150 | * @param peer Peer for testing |
157 | */ | 151 | */ |
158 | static void | 152 | static void |
159 | run (void *cls, | 153 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) |
160 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
161 | struct GNUNET_TESTING_Peer *peer) | ||
162 | { | 154 | { |
163 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); | 155 | die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); |
164 | 156 | ||
165 | identity_counter = 0; | 157 | identity_counter = 0; |
166 | 158 | ||
167 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); | 159 | op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); |
168 | messenger = GNUNET_MESSENGER_connect(cfg, TESTER_NAME, &on_identity, NULL, NULL, NULL); | 160 | messenger = GNUNET_MESSENGER_connect (cfg, TESTER_NAME, &on_identity, NULL, NULL, NULL); |
169 | } | 161 | } |
170 | 162 | ||
171 | /** | 163 | /** |
@@ -176,11 +168,9 @@ run (void *cls, | |||
176 | * @return 0 ok, 1 on error | 168 | * @return 0 ok, 1 on error |
177 | */ | 169 | */ |
178 | int | 170 | int |
179 | main(int argc, char **argv) | 171 | main (int argc, char **argv) |
180 | { | 172 | { |
181 | if (0 != GNUNET_TESTING_peer_run("test-messenger", | 173 | if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) |
182 | "test_messenger_api.conf", | ||
183 | &run, NULL)) | ||
184 | return 1; | 174 | return 1; |
185 | 175 | ||
186 | return status; | 176 | return status; |