aboutsummaryrefslogtreecommitdiff
path: root/src/core/test_core_api_start_only.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/core/test_core_api_start_only.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/core/test_core_api_start_only.c')
-rw-r--r--src/core/test_core_api_start_only.c223
1 files changed, 112 insertions, 111 deletions
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index c8a848359..f2eda4e7a 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -32,7 +32,8 @@
32 32
33#define MTYPE 12345 33#define MTYPE 12345
34 34
35struct PeerContext { 35struct PeerContext
36{
36 struct GNUNET_CONFIGURATION_Handle *cfg; 37 struct GNUNET_CONFIGURATION_Handle *cfg;
37 struct GNUNET_CORE_Handle *ch; 38 struct GNUNET_CORE_Handle *ch;
38 struct GNUNET_PeerIdentity id; 39 struct GNUNET_PeerIdentity id;
@@ -49,157 +50,157 @@ static int ok;
49 50
50 51
51static void * 52static void *
52connect_notify(void *cls, 53connect_notify (void *cls,
53 const struct GNUNET_PeerIdentity *peer, 54 const struct GNUNET_PeerIdentity *peer,
54 struct GNUNET_MQ_Handle *mq) 55 struct GNUNET_MQ_Handle *mq)
55{ 56{
56 return NULL; 57 return NULL;
57} 58}
58 59
59 60
60static void 61static void
61disconnect_notify(void *cls, 62disconnect_notify (void *cls,
62 const struct GNUNET_PeerIdentity *peer, 63 const struct GNUNET_PeerIdentity *peer,
63 void *internal_cls) 64 void *internal_cls)
64{ 65{
65} 66}
66 67
67 68
68static struct GNUNET_MQ_MessageHandler handlers[] = { 69static struct GNUNET_MQ_MessageHandler handlers[] = {
69 GNUNET_MQ_handler_end() 70 GNUNET_MQ_handler_end ()
70}; 71};
71 72
72 73
73static void 74static void
74shutdown_task(void *cls) 75shutdown_task (void *cls)
75{ 76{
76 GNUNET_CORE_disconnect(p1.ch); 77 GNUNET_CORE_disconnect (p1.ch);
77 p1.ch = NULL; 78 p1.ch = NULL;
78 GNUNET_CORE_disconnect(p2.ch); 79 GNUNET_CORE_disconnect (p2.ch);
79 p2.ch = NULL; 80 p2.ch = NULL;
80 ok = 0; 81 ok = 0;
81} 82}
82 83
83 84
84static void 85static void
85init_notify(void *cls, 86init_notify (void *cls,
86 const struct GNUNET_PeerIdentity *my_identity) 87 const struct GNUNET_PeerIdentity *my_identity)
87{ 88{
88 struct PeerContext *p = cls; 89 struct PeerContext *p = cls;
89 90
90 if (p == &p1) 91 if (p == &p1)
91 { 92 {
92 /* connect p2 */ 93 /* connect p2 */
93 p2.ch = GNUNET_CORE_connect(p2.cfg, 94 p2.ch = GNUNET_CORE_connect (p2.cfg,
94 &p2, 95 &p2,
95 &init_notify, 96 &init_notify,
96 &connect_notify, 97 &connect_notify,
97 &disconnect_notify, 98 &disconnect_notify,
98 handlers); 99 handlers);
99 } 100 }
100 else 101 else
101 { 102 {
102 GNUNET_assert(p == &p2); 103 GNUNET_assert (p == &p2);
103 GNUNET_SCHEDULER_cancel(timeout_task_id); 104 GNUNET_SCHEDULER_cancel (timeout_task_id);
104 timeout_task_id = NULL; 105 timeout_task_id = NULL;
105 GNUNET_SCHEDULER_add_now(&shutdown_task, 106 GNUNET_SCHEDULER_add_now (&shutdown_task,
106 NULL); 107 NULL);
107 } 108 }
108} 109}
109 110
110 111
111static void 112static void
112setup_peer(struct PeerContext *p, 113setup_peer (struct PeerContext *p,
113 const char *cfgname) 114 const char *cfgname)
114{ 115{
115 char *binary; 116 char *binary;
116 117
117 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm"); 118 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm");
118 p->cfg = GNUNET_CONFIGURATION_create(); 119 p->cfg = GNUNET_CONFIGURATION_create ();
119 p->arm_proc = 120 p->arm_proc =
120 GNUNET_OS_start_process(GNUNET_YES, 121 GNUNET_OS_start_process (GNUNET_YES,
121 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 122 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
122 NULL, NULL, NULL, 123 NULL, NULL, NULL,
123 binary, 124 binary,
124 "gnunet-service-arm", 125 "gnunet-service-arm",
125 "-c", cfgname, 126 "-c", cfgname,
126 NULL); 127 NULL);
127 GNUNET_assert(GNUNET_OK == 128 GNUNET_assert (GNUNET_OK ==
128 GNUNET_CONFIGURATION_load(p->cfg, 129 GNUNET_CONFIGURATION_load (p->cfg,
129 cfgname)); 130 cfgname));
130 GNUNET_free(binary); 131 GNUNET_free (binary);
131} 132}
132 133
133 134
134static void 135static void
135timeout_task(void *cls) 136timeout_task (void *cls)
136{ 137{
137 fprintf(stderr, 138 fprintf (stderr,
138 "%s", 139 "%s",
139 "Timeout.\n"); 140 "Timeout.\n");
140 if (NULL != p1.ch) 141 if (NULL != p1.ch)
141 { 142 {
142 GNUNET_CORE_disconnect(p1.ch); 143 GNUNET_CORE_disconnect (p1.ch);
143 p1.ch = NULL; 144 p1.ch = NULL;
144 } 145 }
145 if (NULL != p2.ch) 146 if (NULL != p2.ch)
146 { 147 {
147 GNUNET_CORE_disconnect(p2.ch); 148 GNUNET_CORE_disconnect (p2.ch);
148 p2.ch = NULL; 149 p2.ch = NULL;
149 } 150 }
150 ok = 42; 151 ok = 42;
151} 152}
152 153
153 154
154static void 155static void
155run(void *cls, 156run (void *cls,
156 char *const *args, 157 char *const *args,
157 const char *cfgfile, 158 const char *cfgfile,
158 const struct GNUNET_CONFIGURATION_Handle *cfg) 159 const struct GNUNET_CONFIGURATION_Handle *cfg)
159{ 160{
160 GNUNET_assert(ok == 1); 161 GNUNET_assert (ok == 1);
161 ok++; 162 ok++;
162 setup_peer(&p1, "test_core_api_peer1.conf"); 163 setup_peer (&p1, "test_core_api_peer1.conf");
163 setup_peer(&p2, "test_core_api_peer2.conf"); 164 setup_peer (&p2, "test_core_api_peer2.conf");
164 timeout_task_id = 165 timeout_task_id =
165 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply 166 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
166 (GNUNET_TIME_UNIT_MINUTES, 167 (GNUNET_TIME_UNIT_MINUTES,
167 TIMEOUT), 168 TIMEOUT),
168 &timeout_task, 169 &timeout_task,
169 NULL); 170 NULL);
170 p1.ch = GNUNET_CORE_connect(p1.cfg, 171 p1.ch = GNUNET_CORE_connect (p1.cfg,
171 &p1, 172 &p1,
172 &init_notify, 173 &init_notify,
173 &connect_notify, 174 &connect_notify,
174 &disconnect_notify, 175 &disconnect_notify,
175 handlers); 176 handlers);
176} 177}
177 178
178 179
179static void 180static void
180stop_arm(struct PeerContext *p) 181stop_arm (struct PeerContext *p)
181{ 182{
182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
183 "Stopping peer\n"); 184 "Stopping peer\n");
184 if (0 != GNUNET_OS_process_kill(p->arm_proc, 185 if (0 != GNUNET_OS_process_kill (p->arm_proc,
185 GNUNET_TERM_SIG)) 186 GNUNET_TERM_SIG))
186 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, 187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
187 "kill"); 188 "kill");
188 if (GNUNET_OK != 189 if (GNUNET_OK !=
189 GNUNET_OS_process_wait(p->arm_proc)) 190 GNUNET_OS_process_wait (p->arm_proc))
190 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, 191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
191 "waitpid"); 192 "waitpid");
192 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
193 "ARM process %u stopped\n", 194 "ARM process %u stopped\n",
194 (unsigned int)GNUNET_OS_process_get_pid(p->arm_proc)); 195 (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc));
195 GNUNET_OS_process_destroy(p->arm_proc); 196 GNUNET_OS_process_destroy (p->arm_proc);
196 p->arm_proc = NULL; 197 p->arm_proc = NULL;
197 GNUNET_CONFIGURATION_destroy(p->cfg); 198 GNUNET_CONFIGURATION_destroy (p->cfg);
198} 199}
199 200
200 201
201static int 202static int
202check() 203check ()
203{ 204{
204 char *const argv[] = { 205 char *const argv[] = {
205 "test-core-api-start-only", 206 "test-core-api-start-only",
@@ -211,37 +212,37 @@ check()
211 GNUNET_GETOPT_OPTION_END 212 GNUNET_GETOPT_OPTION_END
212 }; 213 };
213 214
214 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1"); 215 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
215 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2"); 216 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
216 217
217 ok = 1; 218 ok = 1;
218 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, 219 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1,
219 argv, 220 argv,
220 "test-core-api-start-only", 221 "test-core-api-start-only",
221 "nohelp", 222 "nohelp",
222 options, 223 options,
223 &run, 224 &run,
224 &ok); 225 &ok);
225 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Test finished\n"); 227 "Test finished\n");
227 stop_arm(&p1); 228 stop_arm (&p1);
228 stop_arm(&p2); 229 stop_arm (&p2);
229 return ok; 230 return ok;
230} 231}
231 232
232 233
233int 234int
234main(int argc, 235main (int argc,
235 char *argv[]) 236 char *argv[])
236{ 237{
237 int ret; 238 int ret;
238 239
239 GNUNET_log_setup("test-core-api-start-only", 240 GNUNET_log_setup ("test-core-api-start-only",
240 "WARNING", 241 "WARNING",
241 NULL); 242 NULL);
242 ret = check(); 243 ret = check ();
243 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1"); 244 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
244 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2"); 245 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
245 return ret; 246 return ret;
246} 247}
247 248