diff options
Diffstat (limited to 'src/transport/test_communicator_unix.c')
-rw-r--r-- | src/transport/test_communicator_unix.c | 228 |
1 files changed, 119 insertions, 109 deletions
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c index 77bd4bb38..d1ab99910 100644 --- a/src/transport/test_communicator_unix.c +++ b/src/transport/test_communicator_unix.c | |||
@@ -33,55 +33,61 @@ | |||
33 | #include <inttypes.h> | 33 | #include <inttypes.h> |
34 | 34 | ||
35 | 35 | ||
36 | #define LOG(kind, ...) GNUNET_log_from(kind, "test_transport_communicator_unix", __VA_ARGS__) | 36 | #define LOG(kind, ...) GNUNET_log_from (kind, \ |
37 | "test_transport_communicator_unix", \ | ||
38 | __VA_ARGS__) | ||
37 | 39 | ||
38 | #define NUM_PEERS 2 | 40 | #define NUM_PEERS 2 |
39 | 41 | ||
40 | static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; | 42 | static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; |
41 | 43 | ||
42 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; | 44 | static struct |
45 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; | ||
43 | 46 | ||
44 | //static char *addresses[NUM_PEERS]; | 47 | // static char *addresses[NUM_PEERS]; |
45 | 48 | ||
46 | 49 | ||
47 | #define PAYLOAD_SIZE 256 | 50 | #define PAYLOAD_SIZE 256 |
48 | 51 | ||
49 | //static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD"; | 52 | // static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD"; |
50 | //static char payload[] = "TEST PAYLOAD"; | 53 | // static char payload[] = "TEST PAYLOAD"; |
51 | static uint32_t payload = 42; | 54 | static uint32_t payload = 42; |
52 | 55 | ||
53 | 56 | ||
54 | static void | 57 | static void |
55 | communicator_available_cb(void *cls, | 58 | communicator_available_cb (void *cls, |
56 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 59 | struct |
57 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | 60 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
58 | char *address_prefix) | 61 | *tc_h, |
62 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | ||
63 | char *address_prefix) | ||
59 | { | 64 | { |
60 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 65 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
61 | "Communicator available. (cc: %u, prefix: %s)\n", | 66 | "Communicator available. (cc: %u, prefix: %s)\n", |
62 | cc, | 67 | cc, |
63 | address_prefix); | 68 | address_prefix); |
64 | } | 69 | } |
65 | 70 | ||
66 | 71 | ||
67 | static void | 72 | static void |
68 | add_address_cb(void *cls, | 73 | add_address_cb (void *cls, |
69 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 74 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * |
70 | const char *address, | 75 | tc_h, |
71 | struct GNUNET_TIME_Relative expiration, | 76 | const char *address, |
72 | uint32_t aid, | 77 | struct GNUNET_TIME_Relative expiration, |
73 | enum GNUNET_NetworkType nt) | 78 | uint32_t aid, |
79 | enum GNUNET_NetworkType nt) | ||
74 | { | 80 | { |
75 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 81 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
76 | "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", | 82 | "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", |
77 | address, | 83 | address, |
78 | expiration.rel_value_us, | 84 | expiration.rel_value_us, |
79 | aid, | 85 | aid, |
80 | nt); | 86 | nt); |
81 | //addresses[1] = GNUNET_strdup (address); | 87 | // addresses[1] = GNUNET_strdup (address); |
82 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(tc_hs[0], | 88 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0], |
83 | &peer_id[1], | 89 | &peer_id[1], |
84 | address); | 90 | address); |
85 | } | 91 | } |
86 | 92 | ||
87 | 93 | ||
@@ -97,16 +103,18 @@ add_address_cb(void *cls, | |||
97 | * #GNUNET_NO if queue will not be established (bogous address) | 103 | * #GNUNET_NO if queue will not be established (bogous address) |
98 | */ | 104 | */ |
99 | static void | 105 | static void |
100 | queue_create_reply_cb(void *cls, | 106 | queue_create_reply_cb (void *cls, |
101 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 107 | struct |
102 | int will_try) | 108 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * |
109 | tc_h, | ||
110 | int will_try) | ||
103 | { | 111 | { |
104 | if (GNUNET_YES == will_try) | 112 | if (GNUNET_YES == will_try) |
105 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 113 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
106 | "Queue will be established!\n"); | 114 | "Queue will be established!\n"); |
107 | else | 115 | else |
108 | LOG(GNUNET_ERROR_TYPE_WARNING, | 116 | LOG (GNUNET_ERROR_TYPE_WARNING, |
109 | "Queue won't be established (bougus address?)!\n"); | 117 | "Queue won't be established (bougus address?)!\n"); |
110 | } | 118 | } |
111 | 119 | ||
112 | 120 | ||
@@ -122,15 +130,16 @@ queue_create_reply_cb(void *cls, | |||
122 | * @param tc_queue Handle to newly opened queue | 130 | * @param tc_queue Handle to newly opened queue |
123 | */ | 131 | */ |
124 | static void | 132 | static void |
125 | add_queue_cb(void *cls, | 133 | add_queue_cb (void *cls, |
126 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 134 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, |
127 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue) | 135 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * |
136 | tc_queue) | ||
128 | { | 137 | { |
129 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 138 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
130 | "Got Queue!\n"); | 139 | "Got Queue!\n"); |
131 | GNUNET_TRANSPORT_TESTING_transport_communicator_send(tc_queue, | 140 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue, |
132 | &payload, | 141 | &payload, |
133 | sizeof(payload)); | 142 | sizeof(payload)); |
134 | } | 143 | } |
135 | 144 | ||
136 | 145 | ||
@@ -144,9 +153,10 @@ add_queue_cb(void *cls, | |||
144 | * @param msg Received message | 153 | * @param msg Received message |
145 | */ | 154 | */ |
146 | void | 155 | void |
147 | incoming_message_cb(void *cls, | 156 | incoming_message_cb (void *cls, |
148 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | 157 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle |
149 | const struct GNUNET_MessageHeader *msg) | 158 | *tc_h, |
159 | const struct GNUNET_MessageHeader *msg) | ||
150 | { | 160 | { |
151 | } | 161 | } |
152 | 162 | ||
@@ -157,11 +167,11 @@ incoming_message_cb(void *cls, | |||
157 | * @param cls Closure - Handle to configuration | 167 | * @param cls Closure - Handle to configuration |
158 | */ | 168 | */ |
159 | static void | 169 | static void |
160 | run(void *cls) | 170 | run (void *cls) |
161 | { | 171 | { |
162 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 172 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
163 | 173 | ||
164 | tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( | 174 | tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( |
165 | "transport", | 175 | "transport", |
166 | "gnunet-communicator-unix", | 176 | "gnunet-communicator-unix", |
167 | "test_communicator_1.conf", | 177 | "test_communicator_1.conf", |
@@ -171,7 +181,7 @@ run(void *cls) | |||
171 | &add_queue_cb, | 181 | &add_queue_cb, |
172 | NULL, | 182 | NULL, |
173 | NULL); /* cls */ | 183 | NULL); /* cls */ |
174 | tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start( | 184 | tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( |
175 | "transport", | 185 | "transport", |
176 | "gnunet-communicator-unix", | 186 | "gnunet-communicator-unix", |
177 | "test_communicator_2.conf", | 187 | "test_communicator_2.conf", |
@@ -184,8 +194,8 @@ run(void *cls) | |||
184 | } | 194 | } |
185 | 195 | ||
186 | int | 196 | int |
187 | main(int argc, | 197 | main (int argc, |
188 | char *const *argv) | 198 | char *const *argv) |
189 | { | 199 | { |
190 | char *cfg_filename; | 200 | char *cfg_filename; |
191 | char *opt_cfg_filename; | 201 | char *opt_cfg_filename; |
@@ -195,73 +205,73 @@ main(int argc, | |||
195 | struct GNUNET_CONFIGURATION_Handle *cfg; | 205 | struct GNUNET_CONFIGURATION_Handle *cfg; |
196 | 206 | ||
197 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 207 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { |
198 | GNUNET_GETOPT_option_cfgfile(&opt_cfg_filename), | 208 | GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), |
199 | GNUNET_GETOPT_option_help(NULL), | 209 | GNUNET_GETOPT_option_help (NULL), |
200 | GNUNET_GETOPT_option_loglevel(&loglev), | 210 | GNUNET_GETOPT_option_loglevel (&loglev), |
201 | GNUNET_GETOPT_option_logfile(&logfile), | 211 | GNUNET_GETOPT_option_logfile (&logfile), |
202 | GNUNET_GETOPT_OPTION_END | 212 | GNUNET_GETOPT_OPTION_END |
203 | }; | 213 | }; |
204 | 214 | ||
205 | if (GNUNET_OK != GNUNET_log_setup("test_communicator_unix", | 215 | if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix", |
206 | loglev, | 216 | loglev, |
207 | logfile)) | 217 | logfile)) |
208 | { | 218 | { |
209 | GNUNET_break(0); | 219 | GNUNET_break (0); |
210 | return GNUNET_SYSERR; | 220 | return GNUNET_SYSERR; |
211 | } | 221 | } |
212 | 222 | ||
213 | xdg = getenv("XDG_CONFIG_HOME"); | 223 | xdg = getenv ("XDG_CONFIG_HOME"); |
214 | if (NULL != xdg) | 224 | if (NULL != xdg) |
215 | GNUNET_asprintf(&cfg_filename, | 225 | GNUNET_asprintf (&cfg_filename, |
216 | "%s%s%s", | 226 | "%s%s%s", |
217 | xdg, | 227 | xdg, |
218 | DIR_SEPARATOR_STR, | 228 | DIR_SEPARATOR_STR, |
219 | GNUNET_OS_project_data_get()->config_file); | 229 | GNUNET_OS_project_data_get ()->config_file); |
220 | else | 230 | else |
221 | cfg_filename = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file); | 231 | cfg_filename = GNUNET_strdup ( |
222 | cfg = GNUNET_CONFIGURATION_create(); | 232 | GNUNET_OS_project_data_get ()->user_config_file); |
233 | cfg = GNUNET_CONFIGURATION_create (); | ||
223 | if (NULL != opt_cfg_filename) | 234 | if (NULL != opt_cfg_filename) |
235 | { | ||
236 | if ((GNUNET_YES != | ||
237 | GNUNET_DISK_file_test (opt_cfg_filename)) || | ||
238 | (GNUNET_SYSERR == | ||
239 | GNUNET_CONFIGURATION_load (cfg, | ||
240 | opt_cfg_filename))) | ||
224 | { | 241 | { |
225 | if ((GNUNET_YES != | 242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
226 | GNUNET_DISK_file_test(opt_cfg_filename)) || | 243 | _ ("Malformed configuration file `%s', exit ...\n"), |
227 | (GNUNET_SYSERR == | 244 | opt_cfg_filename); |
228 | GNUNET_CONFIGURATION_load(cfg, | 245 | return GNUNET_SYSERR; |
229 | opt_cfg_filename))) | ||
230 | { | ||
231 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
232 | _("Malformed configuration file `%s', exit ...\n"), | ||
233 | opt_cfg_filename); | ||
234 | return GNUNET_SYSERR; | ||
235 | } | ||
236 | } | 246 | } |
247 | } | ||
237 | else | 248 | else |
249 | { | ||
250 | if (GNUNET_YES == | ||
251 | GNUNET_DISK_file_test (cfg_filename)) | ||
238 | { | 252 | { |
239 | if (GNUNET_YES == | 253 | if (GNUNET_SYSERR == |
240 | GNUNET_DISK_file_test(cfg_filename)) | 254 | GNUNET_CONFIGURATION_load (cfg, |
241 | { | 255 | cfg_filename)) |
242 | if (GNUNET_SYSERR == | 256 | { |
243 | GNUNET_CONFIGURATION_load(cfg, | 257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
244 | cfg_filename)) | 258 | _ ("Malformed configuration file `%s', exit ...\n"), |
245 | { | 259 | cfg_filename); |
246 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 260 | return GNUNET_SYSERR; |
247 | _("Malformed configuration file `%s', exit ...\n"), | 261 | } |
248 | cfg_filename); | ||
249 | return GNUNET_SYSERR; | ||
250 | } | ||
251 | } | ||
252 | else | ||
253 | { | ||
254 | if (GNUNET_SYSERR == | ||
255 | GNUNET_CONFIGURATION_load(cfg, | ||
256 | NULL)) | ||
257 | { | ||
258 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
259 | _("Malformed configuration, exit ...\n")); | ||
260 | return GNUNET_SYSERR; | ||
261 | } | ||
262 | } | ||
263 | } | 262 | } |
264 | GNUNET_SCHEDULER_run(&run, | 263 | else |
265 | cfg); | 264 | { |
265 | if (GNUNET_SYSERR == | ||
266 | GNUNET_CONFIGURATION_load (cfg, | ||
267 | NULL)) | ||
268 | { | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
270 | _ ("Malformed configuration, exit ...\n")); | ||
271 | return GNUNET_SYSERR; | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | GNUNET_SCHEDULER_run (&run, | ||
276 | cfg); | ||
266 | } | 277 | } |
267 | |||