aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gnunet-core.c')
-rw-r--r--src/core/gnunet-core.c196
1 files changed, 102 insertions, 94 deletions
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index aeb3ba61f..2ffafc075 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file core/gnunet-core.c 22 * @file core/gnunet-core.c
@@ -46,14 +46,14 @@ static struct GNUNET_CORE_MonitorHandle *mh;
46 * @param cls NULL 46 * @param cls NULL
47 */ 47 */
48static void 48static void
49shutdown_task (void *cls) 49shutdown_task(void *cls)
50{ 50{
51 (void) cls; 51 (void)cls;
52 if (NULL != mh) 52 if (NULL != mh)
53 { 53 {
54 GNUNET_CORE_monitor_stop (mh); 54 GNUNET_CORE_monitor_stop(mh);
55 mh = NULL; 55 mh = NULL;
56 } 56 }
57} 57}
58 58
59 59
@@ -67,64 +67,72 @@ shutdown_task (void *cls)
67 * @param timeout timeout for the new state 67 * @param timeout timeout for the new state
68 */ 68 */
69static void 69static void
70monitor_cb (void *cls, 70monitor_cb(void *cls,
71 const struct GNUNET_PeerIdentity *peer, 71 const struct GNUNET_PeerIdentity *peer,
72 enum GNUNET_CORE_KxState state, 72 enum GNUNET_CORE_KxState state,
73 struct GNUNET_TIME_Absolute timeout) 73 struct GNUNET_TIME_Absolute timeout)
74{ 74{
75 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 75 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
76 const char *now_str; 76 const char *now_str;
77 const char *state_str; 77 const char *state_str;
78 78
79 (void) cls; 79 (void)cls;
80 if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) && 80 if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) &&
81 (GNUNET_NO == monitor_connections)) 81 (GNUNET_NO == monitor_connections))
82 { 82 {
83 GNUNET_SCHEDULER_shutdown (); 83 GNUNET_SCHEDULER_shutdown();
84 return; 84 return;
85 } 85 }
86 86
87 switch (state) 87 switch (state)
88 { 88 {
89 case GNUNET_CORE_KX_STATE_DOWN: 89 case GNUNET_CORE_KX_STATE_DOWN:
90 /* should never happen, as we immediately send the key */ 90 /* should never happen, as we immediately send the key */
91 state_str = _ ("fresh connection"); 91 state_str = _("fresh connection");
92 break; 92 break;
93 case GNUNET_CORE_KX_STATE_KEY_SENT: 93
94 state_str = _ ("key sent"); 94 case GNUNET_CORE_KX_STATE_KEY_SENT:
95 break; 95 state_str = _("key sent");
96 case GNUNET_CORE_KX_STATE_KEY_RECEIVED: 96 break;
97 state_str = _ ("key received"); 97
98 break; 98 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
99 case GNUNET_CORE_KX_STATE_UP: 99 state_str = _("key received");
100 state_str = _ ("connection established"); 100 break;
101 break; 101
102 case GNUNET_CORE_KX_STATE_REKEY_SENT: 102 case GNUNET_CORE_KX_STATE_UP:
103 state_str = _ ("rekeying"); 103 state_str = _("connection established");
104 break; 104 break;
105 case GNUNET_CORE_KX_PEER_DISCONNECT: 105
106 state_str = _ ("disconnected"); 106 case GNUNET_CORE_KX_STATE_REKEY_SENT:
107 break; 107 state_str = _("rekeying");
108 case GNUNET_CORE_KX_ITERATION_FINISHED: 108 break;
109 return; 109
110 case GNUNET_CORE_KX_CORE_DISCONNECT: 110 case GNUNET_CORE_KX_PEER_DISCONNECT:
111 fprintf (stderr, 111 state_str = _("disconnected");
112 "%s\n", 112 break;
113 _ ("Connection to CORE service lost (reconnecting)")); 113
114 return; 114 case GNUNET_CORE_KX_ITERATION_FINISHED:
115 default: 115 return;
116 state_str = _ ("unknown state"); 116
117 break; 117 case GNUNET_CORE_KX_CORE_DISCONNECT:
118 } 118 fprintf(stderr,
119 now_str = GNUNET_STRINGS_absolute_time_to_string (now); 119 "%s\n",
120 fprintf (stdout, 120 _("Connection to CORE service lost (reconnecting)"));
121 _ ("%24s: %-30s %4s (timeout in %6s)\n"), 121 return;
122 now_str, 122
123 state_str, 123 default:
124 GNUNET_i2s (peer), 124 state_str = _("unknown state");
125 GNUNET_STRINGS_relative_time_to_string ( 125 break;
126 GNUNET_TIME_absolute_get_remaining (timeout), 126 }
127 GNUNET_YES)); 127 now_str = GNUNET_STRINGS_absolute_time_to_string(now);
128 fprintf(stdout,
129 _("%24s: %-30s %4s (timeout in %6s)\n"),
130 now_str,
131 state_str,
132 GNUNET_i2s(peer),
133 GNUNET_STRINGS_relative_time_to_string(
134 GNUNET_TIME_absolute_get_remaining(timeout),
135 GNUNET_YES));
128} 136}
129 137
130 138
@@ -137,25 +145,25 @@ monitor_cb (void *cls,
137 * @param cfg configuration 145 * @param cfg configuration
138 */ 146 */
139static void 147static void
140run (void *cls, 148run(void *cls,
141 char *const *args, 149 char *const *args,
142 const char *cfgfile, 150 const char *cfgfile,
143 const struct GNUNET_CONFIGURATION_Handle *cfg) 151 const struct GNUNET_CONFIGURATION_Handle *cfg)
144{ 152{
145 (void) cls; 153 (void)cls;
146 (void) cfgfile; 154 (void)cfgfile;
147 if (NULL != args[0]) 155 if (NULL != args[0])
148 { 156 {
149 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]); 157 fprintf(stderr, _("Invalid command line argument `%s'\n"), args[0]);
150 return; 158 return;
151 } 159 }
152 mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL); 160 mh = GNUNET_CORE_monitor_start(cfg, &monitor_cb, NULL);
153 if (NULL == mh) 161 if (NULL == mh)
154 { 162 {
155 fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n")); 163 fprintf(stderr, "%s", _("Failed to connect to CORE service!\n"));
156 return; 164 return;
157 } 165 }
158 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 166 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
159} 167}
160 168
161 169
@@ -167,30 +175,30 @@ run (void *cls,
167 * @return 0 ok, 1 on error 175 * @return 0 ok, 1 on error
168 */ 176 */
169int 177int
170main (int argc, char *const *argv) 178main(int argc, char *const *argv)
171{ 179{
172 int res; 180 int res;
173 struct GNUNET_GETOPT_CommandLineOption options[] = 181 struct GNUNET_GETOPT_CommandLineOption options[] =
174 {GNUNET_GETOPT_option_flag ( 182 { GNUNET_GETOPT_option_flag(
175 'm', 183 'm',
176 "monitor", 184 "monitor",
177 gettext_noop ( 185 gettext_noop(
178 "provide information about all current connections (continuously)"), 186 "provide information about all current connections (continuously)"),
179 &monitor_connections), 187 &monitor_connections),
180 GNUNET_GETOPT_OPTION_END}; 188 GNUNET_GETOPT_OPTION_END };
181 189
182 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 190 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
183 return 2; 191 return 2;
184 res = GNUNET_PROGRAM_run (argc, 192 res = GNUNET_PROGRAM_run(argc,
185 argv, 193 argv,
186 "gnunet-core", 194 "gnunet-core",
187 gettext_noop ( 195 gettext_noop(
188 "Print information about connected peers."), 196 "Print information about connected peers."),
189 options, 197 options,
190 &run, 198 &run,
191 NULL); 199 NULL);
192 200
193 GNUNET_free ((void *) argv); 201 GNUNET_free((void *)argv);
194 if (GNUNET_OK == res) 202 if (GNUNET_OK == res)
195 return 0; 203 return 0;
196 return 1; 204 return 1;