2 This file is part of GNUnet.
3 Copyright (C) 2011-2014, 2016, 2017 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file src/transport/gnunet-transport.c
23 * @brief Tool to help configure, measure and control the transport subsystem.
24 * @author Christian Grothoff
25 * @author Nathan Evans
28 #include "gnunet_util_lib.h"
29 #include "gnunet_resolver_service.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_transport_service.h"
34 * Timeout for a name resolution
36 #define RESOLUTION_TIMEOUT \
37 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
40 * Timeout for an operation
42 #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
46 * Context to store name resolutions for valiation
48 struct ValidationResolutionContext
53 struct ValidationResolutionContext *next;
58 struct ValidationResolutionContext *prev;
63 struct GNUNET_HELLO_Address *addrcp;
66 * Time of last validation
68 struct GNUNET_TIME_Absolute last_validation;
71 * Address is valid until
73 struct GNUNET_TIME_Absolute valid_until;
76 * Time of next validation
78 struct GNUNET_TIME_Absolute next_validation;
81 * Tranport conversion handle
83 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
91 * was the entry printed
97 * Struct to store information about peers in monitor mode
104 enum GNUNET_TRANSPORT_PeerState state;
109 struct GNUNET_TIME_Absolute state_timeout;
112 * The address to convert
114 struct GNUNET_HELLO_Address *address;
118 * Context to store name resolutions for valiation
120 struct PeerResolutionContext
125 struct PeerResolutionContext *next;
130 struct PeerResolutionContext *prev;
135 struct GNUNET_HELLO_Address *addrcp;
138 * transport conversiion context
140 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
145 enum GNUNET_TRANSPORT_PeerState state;
150 struct GNUNET_TIME_Absolute state_timeout;
158 * was the entry printed
165 * Benchmarking block size in KB
170 * Handle to transport service.
172 static struct GNUNET_TRANSPORT_CoreHandle *handle;
175 * Configuration handle
177 static struct GNUNET_CONFIGURATION_Handle *cfg;
180 * Blacklisting handle
182 struct GNUNET_TRANSPORT_Blacklist *blacklist;
187 static int benchmark_send;
192 static int benchmark_receive;
197 static int benchmark_receive;
202 static int iterate_connections;
207 static int iterate_all;
212 static int monitor_connects;
217 static int monitor_connections;
222 static int monitor_plugins;
227 static int do_disconnect;
235 * Global return value (0 success).
240 * Current number of connections in monitor mode
242 static int monitor_connect_counter;
245 * Number of bytes of traffic we received so far.
247 static unsigned long long traffic_received;
250 * Number of bytes of traffic we sent so far.
252 static unsigned long long traffic_sent;
255 * Starting time of transmitting/receiving data.
257 static struct GNUNET_TIME_Absolute start_time;
260 * Map storing information about monitored peers
262 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_peers;
265 * Map storing information about monitored plugins's sessions.
267 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins;
270 * Handle if we are monitoring peers at the transport level.
272 static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
275 * Handle if we are monitoring plugin session activity.
277 static struct GNUNET_TRANSPORT_PluginMonitor *pm;
280 * Identity of the peer we transmit to / connect to.
281 * ('-p' command-line option).
283 static struct GNUNET_PeerIdentity pid;
286 * Task for operation timeout
288 static struct GNUNET_SCHEDULER_Task *op_timeout;
291 * Selected level of verbosity.
293 static unsigned int verbosity;
296 * Resolver process handle.
298 struct GNUNET_OS_Process *resolver;
301 * Number of address resolutions pending
303 static unsigned int address_resolutions;
306 * DLL: head of validation resolution entries
308 static struct ValidationResolutionContext *vc_head;
311 * DLL: tail of validation resolution entries
313 static struct ValidationResolutionContext *vc_tail;
316 * DLL: head of resolution entries
318 static struct PeerResolutionContext *rc_head;
321 * DLL: head of resolution entries
323 static struct PeerResolutionContext *rc_tail;
327 * Function called to release data stored in the #monitored_peers map.
330 * @param key the peer identity
331 * @param value a `struct MonitoredPeer` to release
332 * @return #GNUNET_OK (continue to iterate)
335 destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
337 struct MonitoredPeer *m = value;
341 GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value));
342 GNUNET_free_non_null (m->address);
349 * Task run in monitor mode when the user presses CTRL-C to abort.
350 * Stops monitoring activity.
355 shutdown_task (void *cls)
357 struct GNUNET_TIME_Relative duration;
358 struct ValidationResolutionContext *cur;
359 struct ValidationResolutionContext *next;
360 struct PeerResolutionContext *rc;
362 if (NULL != op_timeout)
364 GNUNET_SCHEDULER_cancel (op_timeout);
369 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
374 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
379 for (cur = next; NULL != cur; cur = next)
383 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
384 GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur);
385 GNUNET_free (cur->transport);
386 GNUNET_HELLO_address_free (cur->addrcp);
389 while (NULL != (rc = rc_head))
391 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
392 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
393 GNUNET_free (rc->transport);
394 GNUNET_free (rc->addrcp);
399 GNUNET_TRANSPORT_core_disconnect (handle);
404 duration = GNUNET_TIME_absolute_get_duration (start_time);
406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
409 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
411 if (benchmark_receive)
413 duration = GNUNET_TIME_absolute_get_duration (start_time);
415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"),
416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
418 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
421 if (NULL != monitored_peers)
423 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL);
424 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
425 monitored_peers = NULL;
427 if (NULL != monitored_plugins)
429 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
430 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
431 monitored_plugins = NULL;
433 if (NULL != blacklist)
435 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
443 * We are done, shut down.
446 operation_timeout (void *cls)
448 struct PeerResolutionContext *cur;
449 struct PeerResolutionContext *next;
452 if ((benchmark_send) || (benchmark_receive))
454 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
455 GNUNET_SCHEDULER_shutdown ();
459 if (iterate_connections)
462 while (NULL != (cur = next))
466 _ ("Failed to resolve address for peer `%s'\n"),
467 GNUNET_i2s (&cur->addrcp->peer));
469 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur);
470 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
471 GNUNET_free (cur->transport);
472 GNUNET_free (cur->addrcp);
477 _ ("Failed to list connections, timeout occurred\n"));
478 GNUNET_SCHEDULER_shutdown ();
486 * Function called to notify a client about the socket
487 * begin ready to queue more data. Sends another message.
489 * @param cls closure with the message queue
494 struct GNUNET_MQ_Handle *mq = cls;
495 struct GNUNET_MessageHeader *m;
496 struct GNUNET_MQ_Envelope *env;
498 env = GNUNET_MQ_msg_extra (m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY);
499 memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
500 traffic_sent += BLOCKSIZE * 1024;
501 GNUNET_MQ_notify_sent (env, &do_send, mq);
504 _ ("Transmitting %u bytes\n"),
505 (unsigned int) BLOCKSIZE * 1024);
506 GNUNET_MQ_send (mq, env);
511 * Function called to notify transport users that another
512 * peer connected to us.
515 * @param peer the peer that connected
516 * @param mq message queue for sending to @a peer
519 notify_connect (void *cls,
520 const struct GNUNET_PeerIdentity *peer,
521 struct GNUNET_MQ_Handle *mq)
523 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
526 if (! benchmark_send)
528 if (NULL != op_timeout)
530 GNUNET_SCHEDULER_cancel (op_timeout);
537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
540 start_time = GNUNET_TIME_absolute_get ();
547 * Function called to notify transport users that another
548 * peer disconnected from us.
551 * @param peer the peer that disconnected
552 * @param internal_cls what we returned from #notify_connect()
555 notify_disconnect (void *cls,
556 const struct GNUNET_PeerIdentity *peer,
559 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
561 if (NULL == internal_cls)
562 return; /* not about target peer */
563 if (! benchmark_send)
564 return; /* not transmitting */
566 _ ("Disconnected from peer `%s' while benchmarking\n"),
572 * Function called to notify transport users that another
573 * peer connected to us.
576 * @param peer the peer that connected
577 * @param mq for sending messages to @a peer
581 monitor_notify_connect (void *cls,
582 const struct GNUNET_PeerIdentity *peer,
583 struct GNUNET_MQ_Handle *mq)
585 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
588 monitor_connect_counter++;
590 _ ("%24s: %-17s %4s (%u connections in total)\n"),
594 monitor_connect_counter);
600 * Function called to notify transport users that another
601 * peer disconnected from us.
604 * @param peer the peer that disconnected
605 * @param internal_cls what we returned from #monitor_notify_connect()
608 monitor_notify_disconnect (void *cls,
609 const struct GNUNET_PeerIdentity *peer,
612 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
613 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
615 GNUNET_assert (monitor_connect_counter > 0);
616 monitor_connect_counter--;
619 _ ("%24s: %-17s %4s (%u connections in total)\n"),
621 _ ("Disconnected from"),
623 monitor_connect_counter);
628 * Function called by the transport for each received message.
631 * @param message the message
635 check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
637 return GNUNET_OK; /* all messages are fine */
642 * Function called by the transport for each received message.
645 * @param message the message
648 handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
650 if (! benchmark_receive)
654 _ ("Received %u bytes\n"),
655 (unsigned int) ntohs (message->size));
656 if (0 == traffic_received)
657 start_time = GNUNET_TIME_absolute_get ();
658 traffic_received += ntohs (message->size);
663 * Convert address to a printable format.
665 * @param address the address
666 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
667 * to try to use reverse DNS
668 * @param state state the peer is in
669 * @param state_timeout when will the peer's state expire
672 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
674 enum GNUNET_TRANSPORT_PeerState state,
675 struct GNUNET_TIME_Absolute state_timeout);
679 print_info (const struct GNUNET_PeerIdentity *id,
680 const char *transport,
682 enum GNUNET_TRANSPORT_PeerState state,
683 struct GNUNET_TIME_Absolute state_timeout)
685 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
686 (GNUNET_YES == monitor_connections))
689 _ ("Peer `%s': %s %s in state `%s' until %s\n"),
691 (NULL == transport) ? "<none>" : transport,
692 (NULL == transport) ? "<none>" : addr,
693 GNUNET_TRANSPORT_ps2s (state),
694 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
696 else if ((GNUNET_YES == iterate_connections) &&
697 (GNUNET_TRANSPORT_is_connected (state)))
699 /* Only connected peers, skip state */
701 _ ("Peer `%s': %s %s\n"),
710 * Function called with a textual representation of an address. This
711 * function will be called several times with different possible
712 * textual representations, and a last time with @a address being NULL
713 * to signal the end of the iteration. Note that @a address NULL
714 * always is the last call, regardless of the value in @a res.
717 * @param address NULL on end of iteration,
718 * otherwise 0-terminated printable UTF-8 string,
719 * in particular an empty string if @a res is #GNUNET_NO
720 * @param res result of the address to string conversion:
721 * if #GNUNET_OK: conversion successful
722 * if #GNUNET_NO: address was invalid (or not supported)
723 * if #GNUNET_SYSERR: communication error (IPC error)
726 process_peer_string (void *cls, const char *address, int res)
728 struct PeerResolutionContext *rc = cls;
732 if (GNUNET_SYSERR == res)
736 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
737 GNUNET_i2s (&rc->addrcp->peer),
738 rc->addrcp->transport_name,
739 (unsigned int) rc->addrcp->address_length);
740 print_info (&rc->addrcp->peer,
745 rc->printed = GNUNET_YES;
748 if (GNUNET_OK == res)
750 print_info (&rc->addrcp->peer,
755 rc->printed = GNUNET_YES;
756 return; /* Wait for done call */
758 /* GNUNET_NO == res: ignore, was simply not supported */
761 /* NULL == address, last call, we are done */
764 GNUNET_assert (address_resolutions > 0);
765 address_resolutions--;
766 if (GNUNET_NO == rc->printed)
768 if (numeric == GNUNET_NO)
770 /* Failed to resolve address, try numeric lookup
771 (note: this should not be needed, as transport
772 should fallback to numeric conversion if DNS takes
774 resolve_peer_address (rc->addrcp,
781 print_info (&rc->addrcp->peer,
788 GNUNET_free (rc->transport);
789 GNUNET_free (rc->addrcp);
790 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
792 if ((0 == address_resolutions) && (iterate_connections))
794 if (NULL != op_timeout)
796 GNUNET_SCHEDULER_cancel (op_timeout);
800 GNUNET_SCHEDULER_shutdown ();
806 * Convert address to a printable format and print it
807 * together with the given state data.
809 * @param address the address
810 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
811 * to try to use reverse DNS
812 * @param state state the peer is in
813 * @param state_timeout when will the peer's state expire
816 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
818 enum GNUNET_TRANSPORT_PeerState state,
819 struct GNUNET_TIME_Absolute state_timeout)
821 struct PeerResolutionContext *rc;
823 rc = GNUNET_new (struct PeerResolutionContext);
824 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc);
825 address_resolutions++;
826 rc->transport = GNUNET_strdup (address->transport_name);
827 rc->addrcp = GNUNET_HELLO_address_copy (address);
828 rc->printed = GNUNET_NO;
830 rc->state_timeout = state_timeout;
831 /* Resolve address to string */
832 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
836 &process_peer_string,
842 * Function called with information about a peers during a one shot iteration
845 * @param peer identity of the peer, NULL for final callback when operation done
846 * @param address binary address used to communicate with this peer,
847 * NULL on disconnect or when done
848 * @param state current state this peer is in
849 * @param state_timeout time out for the current state
852 process_peer_iteration_cb (void *cls,
853 const struct GNUNET_PeerIdentity *peer,
854 const struct GNUNET_HELLO_Address *address,
855 enum GNUNET_TRANSPORT_PeerState state,
856 struct GNUNET_TIME_Absolute state_timeout)
865 if ((GNUNET_NO == iterate_all) &&
866 (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state)))
867 return; /* Display only connected peers */
869 if (NULL != op_timeout)
870 GNUNET_SCHEDULER_cancel (op_timeout);
872 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
874 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
875 "Received address for peer `%s': %s\n",
877 address ? address->transport_name : "");
880 resolve_peer_address (address, numeric, state, state_timeout);
882 print_info (peer, NULL, NULL, state, state_timeout);
887 * Context for address resolution by #plugin_monitoring_cb().
889 struct PluginMonitorAddress
892 * Ongoing resolution request.
894 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
897 * Resolved address as string.
902 * Last event we got and did not yet print because
903 * @e str was NULL (address not yet resolved).
905 struct GNUNET_TRANSPORT_SessionInfo si;
910 * Print information about a plugin monitoring event.
912 * @param addr out internal context
913 * @param info the monitoring information
916 print_plugin_event_info (struct PluginMonitorAddress *addr,
917 const struct GNUNET_TRANSPORT_SessionInfo *info)
923 case GNUNET_TRANSPORT_SS_INIT:
927 case GNUNET_TRANSPORT_SS_HANDSHAKE:
931 case GNUNET_TRANSPORT_SS_UP:
935 case GNUNET_TRANSPORT_SS_UPDATE:
939 case GNUNET_TRANSPORT_SS_DONE:
948 "%s: state %s timeout in %s @ %s%s\n",
949 GNUNET_i2s (&info->address->peer),
951 GNUNET_STRINGS_relative_time_to_string (
952 GNUNET_TIME_absolute_get_remaining (info->session_timeout),
955 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
957 "%s: queue has %3u messages and %6u bytes\n",
958 GNUNET_i2s (&info->address->peer),
959 info->num_msg_pending,
960 info->num_bytes_pending);
962 GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
964 "%s: receiving blocked until %s\n",
965 GNUNET_i2s (&info->address->peer),
966 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
971 * Function called with a textual representation of an address. This
972 * function will be called several times with different possible
973 * textual representations, and a last time with @a address being NULL
974 * to signal the end of the iteration. Note that @a address NULL
975 * always is the last call, regardless of the value in @a res.
978 * @param address NULL on end of iteration,
979 * otherwise 0-terminated printable UTF-8 string,
980 * in particular an empty string if @a res is #GNUNET_NO
981 * @param res result of the address to string conversion:
982 * if #GNUNET_OK: conversion successful
983 * if #GNUNET_NO: address was invalid (or not supported)
984 * if #GNUNET_SYSERR: communication error (IPC error)
987 address_cb (void *cls, const char *address, int res)
989 struct PluginMonitorAddress *addr = cls;
996 if (NULL != addr->str)
998 addr->str = GNUNET_strdup (address);
999 print_plugin_event_info (addr, &addr->si);
1004 * Function called by the plugin with information about the
1005 * current sessions managed by the plugin (for monitoring).
1007 * @param cls closure (NULL)
1008 * @param session session handle this information is about,
1009 * NULL to indicate that we are "in sync" (initial
1010 * iteration complete)
1011 * @param session_ctx storage location where the application
1012 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
1013 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
1014 * @param info information about the state of the session,
1015 * NULL if @a session is also NULL and we are
1016 * merely signalling that the initial iteration is over;
1017 * NULL with @a session being non-NULL if the monitor
1018 * was being cancelled while sessions were active
1021 plugin_monitoring_cb (void *cls,
1022 struct GNUNET_TRANSPORT_PluginSession *session,
1024 const struct GNUNET_TRANSPORT_SessionInfo *info)
1026 struct PluginMonitorAddress *addr;
1028 if ((NULL == info) && (NULL == session))
1029 return; /* in sync with transport service */
1030 addr = *session_ctx;
1035 if (NULL != addr->asc)
1037 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1040 GNUNET_free_non_null (addr->str);
1042 *session_ctx = NULL;
1044 return; /* shutdown */
1047 memcmp (&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity)))
1048 return; /* filtered */
1051 addr = GNUNET_new (struct PluginMonitorAddress);
1053 GNUNET_TRANSPORT_address_to_string (cfg,
1056 GNUNET_TIME_UNIT_FOREVER_REL,
1059 *session_ctx = addr;
1061 if (NULL == addr->str)
1064 print_plugin_event_info (addr, info);
1065 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1067 if (NULL != addr->asc)
1069 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1072 GNUNET_free_non_null (addr->str);
1074 *session_ctx = NULL;
1080 * Function called with information about a peers
1082 * @param cls closure, NULL
1083 * @param peer identity of the peer, NULL for final callback when operation done
1084 * @param address binary address used to communicate with this peer,
1085 * NULL on disconnect or when done
1086 * @param state current state this peer is in
1087 * @param state_timeout time out for the current state
1090 process_peer_monitoring_cb (void *cls,
1091 const struct GNUNET_PeerIdentity *peer,
1092 const struct GNUNET_HELLO_Address *address,
1093 enum GNUNET_TRANSPORT_PeerState state,
1094 struct GNUNET_TIME_Absolute state_timeout)
1096 struct MonitoredPeer *m;
1103 "Monitor disconnected from transport service. Reconnecting.\n"));
1107 if (NULL != op_timeout)
1108 GNUNET_SCHEDULER_cancel (op_timeout);
1110 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1112 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1114 m = GNUNET_new (struct MonitoredPeer);
1115 GNUNET_CONTAINER_multipeermap_put (
1119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1123 if ((m->state == state) &&
1124 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1125 (NULL == address) && (NULL == m->address))
1127 return; /* No real change */
1129 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1130 (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1131 return; /* No real change */
1134 if (NULL != m->address)
1136 GNUNET_free (m->address);
1139 if (NULL != address)
1140 m->address = GNUNET_HELLO_address_copy (address);
1142 m->state_timeout = state_timeout;
1144 if (NULL != address)
1145 resolve_peer_address (m->address, numeric, m->state, m->state_timeout);
1147 print_info (peer, NULL, NULL, m->state, m->state_timeout);
1152 * Function called with the transport service checking if we
1153 * want to blacklist a peer. Return #GNUNET_SYSERR for the
1154 * peer that we should disconnect from.
1157 * @param cpid peer to check blacklisting for
1158 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1161 blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
1163 if (0 == memcmp (cpid, &pid, sizeof(struct GNUNET_PeerIdentity)))
1164 return GNUNET_SYSERR;
1170 * Main function that will be run by the scheduler.
1172 * @param cls closure
1173 * @param args remaining command-line arguments
1174 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1175 * @param mycfg configuration
1180 const char *cfgfile,
1181 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1183 static struct GNUNET_PeerIdentity zero_pid;
1188 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1190 counter = benchmark_send + benchmark_receive + iterate_connections
1191 + monitor_connections + monitor_connects + do_disconnect
1199 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1202 "benchmark receive",
1214 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1217 "benchmark receive",
1225 if (do_disconnect) /* -D: Disconnect from peer */
1227 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1230 _ ("Option `%s' makes no sense without option `%s'.\n"),
1236 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1237 if (NULL == blacklist)
1242 "Failed to connect to transport service for disconnection\n"));
1248 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1250 else if (benchmark_send) /* -s: Benchmark sending */
1252 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1255 _ ("Option `%s' makes no sense without option `%s'.\n"),
1261 handle = GNUNET_TRANSPORT_core_connect (cfg,
1270 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1274 start_time = GNUNET_TIME_absolute_get ();
1276 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1278 else if (benchmark_receive) /* -b: Benchmark receiving */
1280 struct GNUNET_MQ_MessageHandler handlers[] =
1281 { GNUNET_MQ_hd_var_size (dummy,
1282 GNUNET_MESSAGE_TYPE_DUMMY,
1283 struct GNUNET_MessageHeader,
1285 GNUNET_MQ_handler_end () };
1287 handle = GNUNET_TRANSPORT_core_connect (cfg,
1296 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1301 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1302 start_time = GNUNET_TIME_absolute_get ();
1304 else if (iterate_connections) /* -i: List information about peers once */
1306 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1309 &process_peer_iteration_cb,
1312 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1314 else if (monitor_connections) /* -m: List information about peers continuously
1317 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1318 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1321 &process_peer_monitoring_cb,
1324 else if (monitor_plugins) /* -P: List information about plugins continuously
1327 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1328 pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL);
1330 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1332 monitor_connect_counter = 0;
1333 handle = GNUNET_TRANSPORT_core_connect (cfg,
1337 &monitor_notify_connect,
1338 &monitor_notify_disconnect,
1342 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1354 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1359 main (int argc, char *const *argv)
1362 struct GNUNET_GETOPT_CommandLineOption options[] =
1363 { GNUNET_GETOPT_option_flag (
1367 "print information for all peers (instead of only connected peers)"),
1369 GNUNET_GETOPT_option_flag (
1373 "measure how fast we are receiving data from all peers (until CTRL-C)"),
1374 &benchmark_receive),
1375 GNUNET_GETOPT_option_flag ('D',
1377 gettext_noop ("disconnect from a peer"),
1379 GNUNET_GETOPT_option_flag (
1383 "provide information about all current connections (once)"),
1384 &iterate_connections),
1385 GNUNET_GETOPT_option_flag (
1389 "provide information about all current connections (continuously)"),
1390 &monitor_connections),
1391 GNUNET_GETOPT_option_flag (
1395 "provide information about all connects and disconnect events (continuously)"),
1397 GNUNET_GETOPT_option_flag ('n',
1399 gettext_noop ("do not resolve hostnames"),
1401 GNUNET_GETOPT_option_base32_auto ('p',
1404 gettext_noop ("peer identity"),
1406 GNUNET_GETOPT_option_flag ('P',
1408 gettext_noop ("monitor plugin sessions"),
1410 GNUNET_GETOPT_option_flag (
1414 "send data for benchmarking to the other peer (until CTRL-C)"),
1416 GNUNET_GETOPT_option_verbose (&verbosity),
1417 GNUNET_GETOPT_OPTION_END };
1419 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1423 GNUNET_PROGRAM_run (argc,
1426 gettext_noop ("Direct access to transport service."),
1430 GNUNET_free ((void *) argv);
1431 if (GNUNET_OK == res)
1437 /* end of gnunet-transport.c */