diff options
Diffstat (limited to 'src/transport/test_communicator_unix.c')
-rw-r--r-- | src/transport/test_communicator_unix.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c new file mode 100644 index 000000000..f94587a12 --- /dev/null +++ b/src/transport/test_communicator_unix.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2019 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file transport/test_communicator_unix.c | ||
23 | * @brief test the unix communicator | ||
24 | * @author Julius Bünger | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "transport-testing2.h" | ||
29 | #include "gnunet_ats_transport_service.h" | ||
30 | #include "gnunet_signatures.h" | ||
31 | #include "transport.h" | ||
32 | |||
33 | /** | ||
34 | * TODO | ||
35 | * - start two communicators | ||
36 | * - act like transport services | ||
37 | * - get_server_addresses (service.c) | ||
38 | * - open_listen_socket (service.c) | ||
39 | * - GNUNET_MQ_queue_for_callbacks (service.c) | ||
40 | * - let them communicate | ||
41 | * | ||
42 | */ | ||
43 | |||
44 | |||
45 | |||
46 | #define LOG(kind,...) GNUNET_log_from (kind, "test_transport_communicator_unix", __VA_ARGS__) | ||
47 | |||
48 | static void | ||
49 | communicator_available (void *cls, | ||
50 | const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) | ||
51 | { | ||
52 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
53 | "communicator_available()\n"); | ||
54 | } | ||
55 | |||
56 | static void | ||
57 | run (void *cls) | ||
58 | { | ||
59 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
60 | |||
61 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | ||
62 | "transport", | ||
63 | cfg, | ||
64 | &communicator_available, | ||
65 | NULL); /* cls */ | ||
66 | } | ||
67 | |||
68 | int | ||
69 | main (int argc, | ||
70 | char *const *argv) | ||
71 | { | ||
72 | char *cfg_filename; | ||
73 | char *opt_cfg_filename; | ||
74 | const char *xdg; | ||
75 | char *loglev; | ||
76 | char *logfile; | ||
77 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
78 | |||
79 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | ||
80 | GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), | ||
81 | GNUNET_GETOPT_option_help (NULL), | ||
82 | GNUNET_GETOPT_option_loglevel (&loglev), | ||
83 | GNUNET_GETOPT_option_logfile (&logfile), | ||
84 | GNUNET_GETOPT_OPTION_END | ||
85 | }; | ||
86 | |||
87 | if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix", | ||
88 | loglev, | ||
89 | logfile)) | ||
90 | { | ||
91 | GNUNET_break (0); | ||
92 | return GNUNET_SYSERR; | ||
93 | } | ||
94 | |||
95 | xdg = getenv ("XDG_CONFIG_HOME"); | ||
96 | if (NULL != xdg) | ||
97 | GNUNET_asprintf (&cfg_filename, | ||
98 | "%s%s%s", | ||
99 | xdg, | ||
100 | DIR_SEPARATOR_STR, | ||
101 | GNUNET_OS_project_data_get ()->config_file); | ||
102 | else | ||
103 | cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); | ||
104 | cfg = GNUNET_CONFIGURATION_create (); | ||
105 | if (NULL != opt_cfg_filename) | ||
106 | { | ||
107 | if ( (GNUNET_YES != | ||
108 | GNUNET_DISK_file_test (opt_cfg_filename)) || | ||
109 | (GNUNET_SYSERR == | ||
110 | GNUNET_CONFIGURATION_load (cfg, | ||
111 | opt_cfg_filename)) ) | ||
112 | { | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
114 | _("Malformed configuration file `%s', exit ...\n"), | ||
115 | opt_cfg_filename); | ||
116 | return GNUNET_SYSERR; | ||
117 | } | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | if (GNUNET_YES == | ||
122 | GNUNET_DISK_file_test (cfg_filename)) | ||
123 | { | ||
124 | if (GNUNET_SYSERR == | ||
125 | GNUNET_CONFIGURATION_load (cfg, | ||
126 | cfg_filename)) | ||
127 | { | ||
128 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
129 | _("Malformed configuration file `%s', exit ...\n"), | ||
130 | cfg_filename); | ||
131 | return GNUNET_SYSERR; | ||
132 | } | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | if (GNUNET_SYSERR == | ||
137 | GNUNET_CONFIGURATION_load (cfg, | ||
138 | NULL)) | ||
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
141 | _("Malformed configuration, exit ...\n")); | ||
142 | return GNUNET_SYSERR; | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | GNUNET_SCHEDULER_run (&run, | ||
147 | cfg); | ||
148 | } | ||
149 | |||