GNUnet 0.28.1-dev.4-47-g3e168ca2d
 
Loading...
Searching...
No Matches
gnunet-transport.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2026 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
27#include "platform.h"
28#include "gnunet_util_lib.h"
30
34static int ret;
35
40
44static int verbose;
45
49static char *peer_id;
50
55
59static unsigned int num_links;
60
61
67static void
68shutdown_task (void *cls)
69{
70 (void) cls;
71 if (NULL != llc)
72 {
74 llc = NULL;
75 }
76}
77
78
87static const char *
89 char *buf,
90 size_t buf_size)
91{
93 {
94 GNUNET_snprintf (buf, buf_size, "%s", _ ("direct"));
95 return buf;
96 }
97 /* `distance' counts neither the next hop nor the target, so the number
98 of hops a user would count is two more. */
99 GNUNET_snprintf (buf, buf_size, _ ("dv (%u hops)"), li->distance + 2);
100 return buf;
101}
102
103
110static void
112 const struct GNUNET_TRANSPORT_LinkInformation *li)
113{
114 char route[64];
115 char *s1;
116 char *s2;
117
118 fprintf (stdout, "%s\n", GNUNET_i2s_full (peer));
119 fprintf (stdout,
120 _ (" routed: %s over %s (%u queue(s))\n"),
121 route_to_string (li, route, sizeof (route)),
122 ('\0' == li->communicators[0]) ? "-" : li->communicators,
123 li->num_queues);
124 fprintf (stdout,
125 _ (" established: %s\n"),
126 (GNUNET_YES == li->confirmed) ? _ ("yes") : _ ("no"));
127 fprintf (stdout,
128 _ (" CORE receive window: %d\n"),
129 li->core_recv_window);
130 fprintf (stdout,
131 _ (" stalled for CORE: %u message(s)\n"),
132 li->stalled);
133 fprintf (stdout,
134 _ (" pending transmission: %u message(s)\n"),
135 li->pending);
138 fprintf (stdout, _ (" inbound window used: %s of %s\n"), s1, s2);
139 GNUNET_free (s1);
140 GNUNET_free (s2);
143 fprintf (stdout, _ (" outbound window used: %s of %s\n"), s1, s2);
144 GNUNET_free (s1);
145 GNUNET_free (s2);
148 fprintf (stdout, _ (" buffer used: %s of %s\n"), s1, s2);
149 GNUNET_free (s1);
150 GNUNET_free (s2);
151 fprintf (stdout,
152 _ (" estimated loss: %lld byte(s)\n"),
153 (long long) li->incoming_fc_window_size_loss);
154 fprintf (stdout,
155 _ (" flow control RTT: %s (peer reports %s)\n"),
157 GNUNET_YES),
159 GNUNET_YES));
160 fprintf (stdout,
161 _ (" last flow control: %s ago (%u retransmission(s))\n"),
164 GNUNET_YES),
166 fprintf (stdout, "\n");
167}
168
169
178static void
179link_cb (void *cls,
180 const struct GNUNET_PeerIdentity *peer,
181 const struct GNUNET_TRANSPORT_LinkInformation *li)
182{
183 char route[64];
184
185 (void) cls;
186 if (NULL == peer)
187 {
188 /* The listing completed; the handle released itself. */
189 llc = NULL;
190 if (0 == num_links)
191 fprintf (stdout, "%s\n", _ ("No virtual links."));
193 return;
194 }
195 if (verbose)
196 {
197 print_link_verbose (peer, li);
198 num_links++;
199 return;
200 }
201 if (0 == num_links)
202 fprintf (stdout,
203 "%-10s %-14s %-12s %9s %8s %8s %10s\n",
204 _ ("PEER"),
205 _ ("ROUTE"),
206 _ ("VIA"),
207 _ ("CORE-WIN"),
208 _ ("STALLED"),
209 _ ("PENDING"),
210 _ ("RTT"));
211 num_links++;
212 fprintf (stdout,
213 "%-10s %-14s %-12s %9d %8u %8u %10s\n",
214 GNUNET_i2s (peer),
215 route_to_string (li, route, sizeof (route)),
216 ('\0' == li->communicators[0]) ? "-" : li->communicators,
218 li->stalled,
219 li->pending,
221 GNUNET_YES));
222}
223
224
233static void
234run (void *cls,
235 char *const *args,
236 const char *cfgfile,
237 const struct GNUNET_CONFIGURATION_Handle *cfg)
238{
239 struct GNUNET_PeerIdentity pid;
240 const struct GNUNET_PeerIdentity *pidp = NULL;
241
242 (void) cls;
243 (void) cfgfile;
244 if (NULL != args[0])
245 {
246 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
247 ret = 1;
248 return;
249 }
250 if (NULL != peer_id)
251 {
252 if (GNUNET_OK !=
254 strlen (peer_id),
255 &pid.public_key))
256 {
257 fprintf (stderr, _ ("Invalid peer ID `%s'\n"), peer_id);
258 ret = 1;
259 return;
260 }
261 pidp = &pid;
262 }
265 pidp,
267 : GNUNET_NO,
268 &link_cb,
269 NULL);
270 if (NULL == llc)
271 {
272 fprintf (stderr, "%s", _ ("Failed to connect to transport service!\n"));
273 ret = 1;
275 }
276}
277
278
286int
287main (int argc, char *const *argv)
288{
289 int res;
292 'a',
293 "all",
294 gettext_noop ("also show links that are not established yet"),
297 'p',
298 "peer",
299 "PEERID",
300 gettext_noop ("only show the link to this peer"),
301 &peer_id),
303 'V',
304 "verbose",
305 gettext_noop ("show the full flow control state of every link"),
306 &verbose),
308 };
309
311 argc,
312 argv,
313 "gnunet-transport",
315 "Print information about the virtual links of "
316 "the transport service."),
317 options,
318 &run,
319 NULL);
320 if (GNUNET_OK == res)
321 return ret;
322 return 1;
323}
324
325
326/* end of gnunet-transport.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
struct GNUNET_SCHEDULER_Task * shutdown_task
static char * res
Currently read line or NULL on EOF.
static unsigned int num_links
Number of links reported so far.
static int verbose
Option -V: show the full flow control state of every link.
static void link_cb(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_LinkInformation *li)
Function called once per virtual link, and a final time with both arguments NULL.
static char * peer_id
Option -p: restrict the listing to this peer.
static void print_link_verbose(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_LinkInformation *li)
Print everything we know about li, one field per line.
static int ret
Return code.
static struct GNUNET_TRANSPORT_LinkListContext * llc
Handle to the running listing, NULL once it completed.
static int include_unconfirmed
Option -a: also show links that are not established yet.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
static const char * route_to_string(const struct GNUNET_TRANSPORT_LinkInformation *li, char *buf, size_t buf_size)
Render how a link is routed into buf.
Monitoring / diagnostics API for the transport service.
void GNUNET_TRANSPORT_links_list_cancel(struct GNUNET_TRANSPORT_LinkListContext *llc)
Cancel a request to list virtual links.
struct GNUNET_TRANSPORT_LinkListContext * GNUNET_TRANSPORT_links_list(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, int include_unconfirmed, GNUNET_TRANSPORT_LinkCallback cb, void *cb_cls)
Ask the transport service for the virtual links it currently has.
@ GNUNET_TRANSPORT_LINK_ROUTE_DIRECT
Over one or more queues to a directly connected neighbour.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition crypto_ecc.c:362
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:406
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:572
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1345
char * GNUNET_STRINGS_byte_size_fancy(unsigned long long size)
Convert a given filesize into a fancy human-readable format.
Definition strings.c:105
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition time.c:438
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition strings.c:610
#define _(String)
GNU gettext support macro.
Definition platform.h:179
Definition of a command line option.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
State of one virtual link, the abstraction CORE sits on top of.
unsigned int pending
Number of messages queued for transmission to the target.
int64_t incoming_fc_window_size_loss
Current estimate of the message loss rate for the sender.
uint64_t outbound_fc_window_size
Window the other peer granted us.
uint64_t incoming_fc_window_size_used
How much of incoming_fc_window_size the other peer used.
uint64_t incoming_fc_window_size_ram
RAM currently held for this link.
uint64_t outbound_fc_window_size_used
How much of outbound_fc_window_size we used.
unsigned int distance
Hops of the shortest DV path, excluding the next hop and the target itself; so 0 already means two ho...
unsigned int num_queues
Number of queues to the neighbour carrying the link.
int core_recv_window
How many more messages we may hand to CORE before it must acknowledge them.
enum GNUNET_TRANSPORT_LinkRoute route
How the link is routed.
struct GNUNET_TIME_Relative other_rtt
RTT over all DV paths, as calculated by the target.
int confirmed
GNUNET_YES if the link is confirmed, i.e.
unsigned int fc_retransmit_count
Number of flow control retransmissions of the running task.
const char * communicators
Comma-separated address prefixes of the communicators currently carrying the link ("tcp",...
uint64_t available_fc_window_size
RAM transport is willing to spend on this link.
unsigned int stalled
Number of messages whose flow control ACK transport is withholding because core_recv_window is exhaus...
struct GNUNET_TIME_Absolute last_fc_transmission
When did we last send a flow control message?
uint64_t incoming_fc_window_size
Window we last granted the other peer.
struct GNUNET_TIME_Relative last_fc_rtt
RTT of the last flow control exchange.
Opaque handle for a GNUNET_TRANSPORT_links_list() operation.