aboutsummaryrefslogtreecommitdiff
path: root/src/service/messenger/test_messenger_anonymous.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/messenger/test_messenger_anonymous.c')
-rw-r--r--src/service/messenger/test_messenger_anonymous.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/service/messenger/test_messenger_anonymous.c b/src/service/messenger/test_messenger_anonymous.c
index 367d1c3b7..d3dadf2c5 100644
--- a/src/service/messenger/test_messenger_anonymous.c
+++ b/src/service/messenger/test_messenger_anonymous.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
@@ -43,6 +43,7 @@ static int status = 1;
43 43
44static struct GNUNET_SCHEDULER_Task *die_task = NULL; 44static struct GNUNET_SCHEDULER_Task *die_task = NULL;
45static struct GNUNET_SCHEDULER_Task *op_task = NULL; 45static struct GNUNET_SCHEDULER_Task *op_task = NULL;
46static struct GNUNET_SCHEDULER_Task *it_task = NULL;
46 47
47struct GNUNET_MESSENGER_Handle *messenger = NULL; 48struct GNUNET_MESSENGER_Handle *messenger = NULL;
48 49
@@ -51,6 +52,12 @@ end (void *cls)
51{ 52{
52 die_task = NULL; 53 die_task = NULL;
53 54
55 if (it_task)
56 {
57 GNUNET_SCHEDULER_cancel (it_task);
58 it_task = NULL;
59 }
60
54 if (op_task) 61 if (op_task)
55 { 62 {
56 GNUNET_SCHEDULER_cancel (op_task); 63 GNUNET_SCHEDULER_cancel (op_task);
@@ -66,6 +73,7 @@ end (void *cls)
66 status = 0; 73 status = 0;
67} 74}
68 75
76
69static void 77static void
70end_badly (void *cls) 78end_badly (void *cls)
71{ 79{
@@ -75,12 +83,15 @@ end_badly (void *cls)
75 status = 1; 83 status = 1;
76} 84}
77 85
86
78static void 87static void
79end_operation (void *cls) 88end_operation (void *cls)
80{ 89{
81 op_task = NULL; 90 op_task = NULL;
82 91
83 fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const char*) cls : "unknown"); 92 fprintf (stderr, "Testcase failed (operation: '%s').\n", cls ? (const
93 char*) cls :
94 "unknown");
84 95
85 if (die_task) 96 if (die_task)
86 GNUNET_SCHEDULER_cancel (die_task); 97 GNUNET_SCHEDULER_cancel (die_task);
@@ -89,6 +100,7 @@ end_operation (void *cls)
89 status = 1; 100 status = 1;
90} 101}
91 102
103
92/** 104/**
93 * Function called when an identity is retrieved. 105 * Function called when an identity is retrieved.
94 * 106 *
@@ -96,9 +108,12 @@ end_operation (void *cls)
96 * @param handle Handle of messenger service 108 * @param handle Handle of messenger service
97 */ 109 */
98static void 110static void
99on_identity (void *cls, 111on_iteration (void *cls)
100 struct GNUNET_MESSENGER_Handle *handle)
101{ 112{
113 struct GNUNET_MESSENGER_Handle *handle = cls;
114
115 it_task = NULL;
116
102 if (op_task) 117 if (op_task)
103 { 118 {
104 GNUNET_SCHEDULER_cancel (op_task); 119 GNUNET_SCHEDULER_cancel (op_task);
@@ -113,13 +128,8 @@ on_identity (void *cls,
113 return; 128 return;
114 } 129 }
115 130
116 if (GNUNET_SYSERR != GNUNET_MESSENGER_update (handle)) 131 const struct GNUNET_CRYPTO_PublicKey *key = GNUNET_MESSENGER_get_key (
117 { 132 handle);
118 op_task = GNUNET_SCHEDULER_add_now (&end_operation, "update-fail");
119 return;
120 }
121
122 const struct GNUNET_CRYPTO_PublicKey *key = GNUNET_MESSENGER_get_key (handle);
123 133
124 if (key) 134 if (key)
125 { 135 {
@@ -137,6 +147,7 @@ on_identity (void *cls,
137 die_task = GNUNET_SCHEDULER_add_now (&end, NULL); 147 die_task = GNUNET_SCHEDULER_add_now (&end, NULL);
138} 148}
139 149
150
140/** 151/**
141 * Main function for testcase. 152 * Main function for testcase.
142 * 153 *
@@ -151,10 +162,15 @@ run (void *cls,
151{ 162{
152 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL); 163 die_task = GNUNET_SCHEDULER_add_delayed (TOTAL_TIMEOUT, &end_badly, NULL);
153 164
154 op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation, "connect"); 165 op_task = GNUNET_SCHEDULER_add_delayed (BASE_TIMEOUT, &end_operation,
155 messenger = GNUNET_MESSENGER_connect (cfg, NULL, &on_identity, NULL, NULL, NULL); 166 "connect");
167 messenger = GNUNET_MESSENGER_connect (cfg, NULL, NULL, NULL, NULL);
168
169 if (messenger)
170 it_task = GNUNET_SCHEDULER_add_now (&on_iteration, messenger);
156} 171}
157 172
173
158/** 174/**
159 * The main function. 175 * The main function.
160 * 176 *
@@ -166,7 +182,8 @@ int
166main (int argc, 182main (int argc,
167 char **argv) 183 char **argv)
168{ 184{
169 if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf", &run, NULL)) 185 if (0 != GNUNET_TESTING_peer_run ("test-messenger", "test_messenger_api.conf",
186 &run, NULL))
170 return 1; 187 return 1;
171 188
172 return status; 189 return status;