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"
32 #include "gnunet_transport_core_service.h"
35 * Timeout for a name resolution
37 #define RESOLUTION_TIMEOUT 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,
336 const struct GNUNET_PeerIdentity *key,
339 struct MonitoredPeer *m = value;
341 GNUNET_assert (GNUNET_OK ==
342 GNUNET_CONTAINER_multipeermap_remove (monitored_peers,
345 GNUNET_free_non_null (m->address);
352 * Task run in monitor mode when the user presses CTRL-C to abort.
353 * Stops monitoring activity.
358 shutdown_task (void *cls)
360 struct GNUNET_TIME_Relative duration;
361 struct ValidationResolutionContext *cur;
362 struct ValidationResolutionContext *next;
363 struct PeerResolutionContext *rc;
365 if (NULL != op_timeout)
367 GNUNET_SCHEDULER_cancel (op_timeout);
372 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
377 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
382 for (cur = next; NULL != cur; cur = next)
386 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
387 GNUNET_CONTAINER_DLL_remove (vc_head,
390 GNUNET_free (cur->transport);
391 GNUNET_HELLO_address_free (cur->addrcp);
394 while (NULL != (rc = rc_head))
396 GNUNET_CONTAINER_DLL_remove (rc_head,
399 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
400 GNUNET_free (rc->transport);
401 GNUNET_free (rc->addrcp);
406 GNUNET_TRANSPORT_core_disconnect (handle);
411 duration = GNUNET_TIME_absolute_get_duration (start_time);
413 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
414 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
416 GNUNET_STRINGS_relative_time_to_string (duration,
419 if (benchmark_receive)
421 duration = GNUNET_TIME_absolute_get_duration (start_time);
423 _("Received %llu bytes/s (%llu bytes in %s)\n"),
424 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
426 GNUNET_STRINGS_relative_time_to_string (duration,
430 if (NULL != monitored_peers)
432 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers,
435 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
436 monitored_peers = NULL;
438 if (NULL != monitored_plugins)
441 GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
442 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
443 monitored_plugins = NULL;
445 if (NULL != blacklist)
447 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
455 * We are done, shut down.
458 operation_timeout (void *cls)
460 struct PeerResolutionContext *cur;
461 struct PeerResolutionContext *next;
464 if ((benchmark_send) || (benchmark_receive))
467 _("Failed to connect to `%s'\n"),
468 GNUNET_i2s_full (&pid));
469 GNUNET_SCHEDULER_shutdown ();
473 if (iterate_connections)
476 while (NULL != (cur = next))
480 _("Failed to resolve address for peer `%s'\n"),
481 GNUNET_i2s (&cur->addrcp->peer));
483 GNUNET_CONTAINER_DLL_remove(rc_head,
486 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
487 GNUNET_free (cur->transport);
488 GNUNET_free (cur->addrcp);
494 _("Failed to list connections, timeout occurred\n"));
495 GNUNET_SCHEDULER_shutdown ();
503 * Function called to notify a client about the socket
504 * begin ready to queue more data. Sends another message.
506 * @param cls closure with the message queue
511 struct GNUNET_MQ_Handle *mq = cls;
512 struct GNUNET_MessageHeader *m;
513 struct GNUNET_MQ_Envelope *env;
515 env = GNUNET_MQ_msg_extra (m,
517 GNUNET_MESSAGE_TYPE_DUMMY);
520 BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
521 traffic_sent += BLOCKSIZE * 1024;
522 GNUNET_MQ_notify_sent (env,
527 _("Transmitting %u bytes\n"),
528 (unsigned int) BLOCKSIZE * 1024);
535 * Function called to notify transport users that another
536 * peer connected to us.
539 * @param peer the peer that connected
540 * @param mq message queue for sending to @a peer
543 notify_connect (void *cls,
544 const struct GNUNET_PeerIdentity *peer,
545 struct GNUNET_MQ_Handle *mq)
547 if (0 != memcmp (&pid,
549 sizeof(struct GNUNET_PeerIdentity)))
552 if (! benchmark_send)
554 if (NULL != op_timeout)
556 GNUNET_SCHEDULER_cancel (op_timeout);
561 _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
564 start_time = GNUNET_TIME_absolute_get ();
571 * Function called to notify transport users that another
572 * peer disconnected from us.
575 * @param peer the peer that disconnected
576 * @param internal_cls what we returned from #notify_connect()
579 notify_disconnect (void *cls,
580 const struct GNUNET_PeerIdentity *peer,
583 if (0 != memcmp (&pid,
585 sizeof(struct GNUNET_PeerIdentity)))
587 if (NULL == internal_cls)
588 return; /* not about target peer */
589 if (! benchmark_send)
590 return; /* not transmitting */
592 _("Disconnected from peer `%s' while benchmarking\n"),
598 * Function called to notify transport users that another
599 * peer connected to us.
602 * @param peer the peer that connected
603 * @param mq for sending messages to @a peer
607 monitor_notify_connect (void *cls,
608 const struct GNUNET_PeerIdentity *peer,
609 struct GNUNET_MQ_Handle *mq)
611 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
612 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
614 monitor_connect_counter++;
616 _("%24s: %-17s %4s (%u connections in total)\n"),
620 monitor_connect_counter);
626 * Function called to notify transport users that another
627 * peer disconnected from us.
630 * @param peer the peer that disconnected
631 * @param internal_cls what we returned from #monitor_notify_connect()
634 monitor_notify_disconnect (void *cls,
635 const struct GNUNET_PeerIdentity *peer,
638 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
639 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
641 GNUNET_assert(monitor_connect_counter > 0);
642 monitor_connect_counter--;
645 _("%24s: %-17s %4s (%u connections in total)\n"),
647 _("Disconnected from"),
649 monitor_connect_counter);
654 * Function called by the transport for each received message.
657 * @param message the message
661 check_dummy (void *cls,
662 const struct GNUNET_MessageHeader *message)
664 return GNUNET_OK; /* all messages are fine */
669 * Function called by the transport for each received message.
672 * @param message the message
675 handle_dummy (void *cls,
676 const struct GNUNET_MessageHeader *message)
678 if (! benchmark_receive)
682 _("Received %u bytes\n"),
683 (unsigned int) ntohs (message->size));
684 if (0 == traffic_received)
685 start_time = GNUNET_TIME_absolute_get ();
686 traffic_received += ntohs (message->size);
691 * Convert address to a printable format.
693 * @param address the address
694 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
695 * to try to use reverse DNS
696 * @param state state the peer is in
697 * @param state_timeout when will the peer's state expire
700 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
702 enum GNUNET_TRANSPORT_PeerState state,
703 struct GNUNET_TIME_Absolute state_timeout);
707 print_info (const struct GNUNET_PeerIdentity *id,
708 const char *transport,
710 enum GNUNET_TRANSPORT_PeerState state,
711 struct GNUNET_TIME_Absolute state_timeout)
714 if ( ((GNUNET_YES == iterate_connections) &&
715 (GNUNET_YES == iterate_all)) ||
716 (GNUNET_YES == monitor_connections))
719 _("Peer `%s': %s %s in state `%s' until %s\n"),
721 (NULL == transport) ? "<none>" : transport,
722 (NULL == transport) ? "<none>" : addr,
723 GNUNET_TRANSPORT_ps2s (state),
724 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
726 else if ( (GNUNET_YES == iterate_connections) &&
727 (GNUNET_TRANSPORT_is_connected(state)) )
729 /* Only connected peers, skip state */
731 _("Peer `%s': %s %s\n"),
740 * Function called with a textual representation of an address. This
741 * function will be called several times with different possible
742 * textual representations, and a last time with @a address being NULL
743 * to signal the end of the iteration. Note that @a address NULL
744 * always is the last call, regardless of the value in @a res.
747 * @param address NULL on end of iteration,
748 * otherwise 0-terminated printable UTF-8 string,
749 * in particular an empty string if @a res is #GNUNET_NO
750 * @param res result of the address to string conversion:
751 * if #GNUNET_OK: conversion successful
752 * if #GNUNET_NO: address was invalid (or not supported)
753 * if #GNUNET_SYSERR: communication error (IPC error)
756 process_peer_string (void *cls,
760 struct PeerResolutionContext *rc = cls;
764 if (GNUNET_SYSERR == res)
767 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
768 GNUNET_i2s (&rc->addrcp->peer),
769 rc->addrcp->transport_name,
770 (unsigned int) rc->addrcp->address_length);
771 print_info (&rc->addrcp->peer,
776 rc->printed = GNUNET_YES;
779 if (GNUNET_OK == res)
781 print_info (&rc->addrcp->peer,
786 rc->printed = GNUNET_YES;
787 return; /* Wait for done call */
789 /* GNUNET_NO == res: ignore, was simply not supported */
792 /* NULL == address, last call, we are done */
795 GNUNET_assert (address_resolutions > 0);
796 address_resolutions--;
797 if (GNUNET_NO == rc->printed)
799 if (numeric == GNUNET_NO)
801 /* Failed to resolve address, try numeric lookup
802 (note: this should not be needed, as transport
803 should fallback to numeric conversion if DNS takes
805 resolve_peer_address (rc->addrcp,
812 print_info (&rc->addrcp->peer,
819 GNUNET_free (rc->transport);
820 GNUNET_free (rc->addrcp);
821 GNUNET_CONTAINER_DLL_remove (rc_head,
825 if ((0 == address_resolutions) && (iterate_connections))
827 if (NULL != op_timeout)
829 GNUNET_SCHEDULER_cancel (op_timeout);
833 GNUNET_SCHEDULER_shutdown ();
839 * Convert address to a printable format and print it
840 * together with the given state data.
842 * @param address the address
843 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
844 * to try to use reverse DNS
845 * @param state state the peer is in
846 * @param state_timeout when will the peer's state expire
849 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
851 enum GNUNET_TRANSPORT_PeerState state,
852 struct GNUNET_TIME_Absolute state_timeout)
854 struct PeerResolutionContext *rc;
856 rc = GNUNET_new (struct PeerResolutionContext);
857 GNUNET_CONTAINER_DLL_insert (rc_head,
860 address_resolutions++;
861 rc->transport = GNUNET_strdup (address->transport_name);
862 rc->addrcp = GNUNET_HELLO_address_copy (address);
863 rc->printed = GNUNET_NO;
865 rc->state_timeout = state_timeout;
866 /* Resolve address to string */
867 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
871 &process_peer_string,
877 * Function called with information about a peers during a one shot iteration
880 * @param peer identity of the peer, NULL for final callback when operation done
881 * @param address binary address used to communicate with this peer,
882 * NULL on disconnect or when done
883 * @param state current state this peer is in
884 * @param state_timeout time out for the current state
887 process_peer_iteration_cb (void *cls,
888 const struct GNUNET_PeerIdentity *peer,
889 const struct GNUNET_HELLO_Address *address,
890 enum GNUNET_TRANSPORT_PeerState state,
891 struct GNUNET_TIME_Absolute state_timeout)
900 if ( (GNUNET_NO == iterate_all) &&
901 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)))
902 return; /* Display only connected peers */
904 if (NULL != op_timeout)
905 GNUNET_SCHEDULER_cancel (op_timeout);
906 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
910 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
911 "Received address for peer `%s': %s\n",
913 address ? address->transport_name : "");
916 resolve_peer_address (address,
930 * Context for address resolution by #plugin_monitoring_cb().
932 struct PluginMonitorAddress
936 * Ongoing resolution request.
938 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
941 * Resolved address as string.
946 * Last event we got and did not yet print because
947 * @e str was NULL (address not yet resolved).
949 struct GNUNET_TRANSPORT_SessionInfo si;
954 * Print information about a plugin monitoring event.
956 * @param addr out internal context
957 * @param info the monitoring information
960 print_plugin_event_info (struct PluginMonitorAddress *addr,
961 const struct GNUNET_TRANSPORT_SessionInfo *info)
967 case GNUNET_TRANSPORT_SS_INIT:
970 case GNUNET_TRANSPORT_SS_HANDSHAKE:
973 case GNUNET_TRANSPORT_SS_UP:
976 case GNUNET_TRANSPORT_SS_UPDATE:
979 case GNUNET_TRANSPORT_SS_DONE:
987 "%s: state %s timeout in %s @ %s%s\n",
988 GNUNET_i2s (&info->address->peer),
990 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (info->session_timeout),
993 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
995 "%s: queue has %3u messages and %6u bytes\n",
996 GNUNET_i2s (&info->address->peer),
997 info->num_msg_pending,
998 info->num_bytes_pending);
999 if (0 != GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
1001 "%s: receiving blocked until %s\n",
1002 GNUNET_i2s (&info->address->peer),
1003 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
1008 * Function called with a textual representation of an address. This
1009 * function will be called several times with different possible
1010 * textual representations, and a last time with @a address being NULL
1011 * to signal the end of the iteration. Note that @a address NULL
1012 * always is the last call, regardless of the value in @a res.
1014 * @param cls closure
1015 * @param address NULL on end of iteration,
1016 * otherwise 0-terminated printable UTF-8 string,
1017 * in particular an empty string if @a res is #GNUNET_NO
1018 * @param res result of the address to string conversion:
1019 * if #GNUNET_OK: conversion successful
1020 * if #GNUNET_NO: address was invalid (or not supported)
1021 * if #GNUNET_SYSERR: communication error (IPC error)
1024 address_cb (void *cls,
1025 const char *address,
1028 struct PluginMonitorAddress *addr = cls;
1030 if (NULL == address)
1035 if (NULL != addr->str)
1037 addr->str = GNUNET_strdup (address);
1038 print_plugin_event_info (addr,
1044 * Function called by the plugin with information about the
1045 * current sessions managed by the plugin (for monitoring).
1047 * @param cls closure (NULL)
1048 * @param session session handle this information is about,
1049 * NULL to indicate that we are "in sync" (initial
1050 * iteration complete)
1051 * @param session_ctx storage location where the application
1052 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
1053 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
1054 * @param info information about the state of the session,
1055 * NULL if @a session is also NULL and we are
1056 * merely signalling that the initial iteration is over;
1057 * NULL with @a session being non-NULL if the monitor
1058 * was being cancelled while sessions were active
1061 plugin_monitoring_cb (void *cls,
1062 struct GNUNET_TRANSPORT_PluginSession *session,
1064 const struct GNUNET_TRANSPORT_SessionInfo *info)
1066 struct PluginMonitorAddress *addr;
1068 if ( (NULL == info) &&
1070 return; /* in sync with transport service */
1071 addr = *session_ctx;
1076 if (NULL != addr->asc)
1078 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1081 GNUNET_free_non_null (addr->str);
1083 *session_ctx = NULL;
1085 return; /* shutdown */
1087 if (0 != memcmp (&info->address->peer,
1089 sizeof (struct GNUNET_PeerIdentity)))
1090 return; /* filtered */
1093 addr = GNUNET_new (struct PluginMonitorAddress);
1094 addr->asc = GNUNET_TRANSPORT_address_to_string (cfg,
1097 GNUNET_TIME_UNIT_FOREVER_REL,
1100 *session_ctx = addr;
1102 if (NULL == addr->str)
1105 print_plugin_event_info (addr,
1107 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1109 if (NULL != addr->asc)
1111 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1114 GNUNET_free_non_null (addr->str);
1116 *session_ctx = NULL;
1122 * Function called with information about a peers
1124 * @param cls closure, NULL
1125 * @param peer identity of the peer, NULL for final callback when operation done
1126 * @param address binary address used to communicate with this peer,
1127 * NULL on disconnect or when done
1128 * @param state current state this peer is in
1129 * @param state_timeout time out for the current state
1132 process_peer_monitoring_cb (void *cls,
1133 const struct GNUNET_PeerIdentity *peer,
1134 const struct GNUNET_HELLO_Address *address,
1135 enum GNUNET_TRANSPORT_PeerState state,
1136 struct GNUNET_TIME_Absolute state_timeout)
1138 struct MonitoredPeer *m;
1144 _("Monitor disconnected from transport service. Reconnecting.\n"));
1148 if (NULL != op_timeout)
1149 GNUNET_SCHEDULER_cancel (op_timeout);
1150 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1154 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers,
1157 m = GNUNET_new (struct MonitoredPeer);
1158 GNUNET_CONTAINER_multipeermap_put (monitored_peers,
1161 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1165 if ( (m->state == state) &&
1166 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1167 (NULL == address) &&
1168 (NULL == m->address) )
1170 return; /* No real change */
1172 if ( (m->state == state) &&
1173 (NULL != address) &&
1174 (NULL != m->address) &&
1175 (0 == GNUNET_HELLO_address_cmp(m->address, address)) )
1176 return; /* No real change */
1179 if (NULL != m->address)
1181 GNUNET_free (m->address);
1184 if (NULL != address)
1185 m->address = GNUNET_HELLO_address_copy (address);
1187 m->state_timeout = state_timeout;
1189 if (NULL != address)
1190 resolve_peer_address (m->address,
1204 * Function called with the transport service checking if we
1205 * want to blacklist a peer. Return #GNUNET_SYSERR for the
1206 * peer that we should disconnect from.
1209 * @param cpid peer to check blacklisting for
1210 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1213 blacklist_cb (void *cls,
1214 const struct GNUNET_PeerIdentity *cpid)
1216 if (0 == memcmp (cpid,
1218 sizeof (struct GNUNET_PeerIdentity)))
1219 return GNUNET_SYSERR;
1225 * Main function that will be run by the scheduler.
1227 * @param cls closure
1228 * @param args remaining command-line arguments
1229 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1230 * @param mycfg configuration
1235 const char *cfgfile,
1236 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1238 static struct GNUNET_PeerIdentity zero_pid;
1242 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1244 counter = benchmark_send + benchmark_receive + iterate_connections
1245 + monitor_connections + monitor_connects + do_disconnect +
1251 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1254 "benchmark receive",
1264 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1267 "benchmark receive",
1275 if (do_disconnect) /* -D: Disconnect from peer */
1277 if (0 == memcmp (&zero_pid,
1282 _("Option `%s' makes no sense without option `%s'.\n"),
1287 blacklist = GNUNET_TRANSPORT_blacklist (cfg,
1290 if (NULL == blacklist)
1294 _("Failed to connect to transport service for disconnection\n"));
1300 _("Blacklisting request in place, stop with CTRL-C\n"));
1302 else if (benchmark_send) /* -s: Benchmark sending */
1304 if (0 == memcmp (&zero_pid,
1309 _("Option `%s' makes no sense without option `%s'.\n"),
1314 handle = GNUNET_TRANSPORT_core_connect (cfg,
1325 _("Failed to connect to transport service\n"));
1329 start_time = GNUNET_TIME_absolute_get ();
1330 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1334 else if (benchmark_receive) /* -b: Benchmark receiving */
1336 struct GNUNET_MQ_MessageHandler handlers[] = {
1337 GNUNET_MQ_hd_var_size (dummy,
1338 GNUNET_MESSAGE_TYPE_DUMMY,
1339 struct GNUNET_MessageHeader,
1341 GNUNET_MQ_handler_end ()
1344 handle = GNUNET_TRANSPORT_core_connect (cfg,
1355 _("Failed to connect to transport service\n"));
1362 _("Starting to receive benchmark data\n"));
1363 start_time = GNUNET_TIME_absolute_get ();
1366 else if (iterate_connections) /* -i: List information about peers once */
1368 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1371 &process_peer_iteration_cb,
1373 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1377 else if (monitor_connections) /* -m: List information about peers continuously */
1379 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10,
1381 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1384 &process_peer_monitoring_cb,
1387 else if (monitor_plugins) /* -P: List information about plugins continuously */
1389 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1390 pm = GNUNET_TRANSPORT_monitor_plugins (cfg,
1391 &plugin_monitoring_cb,
1394 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1396 monitor_connect_counter = 0;
1397 handle = GNUNET_TRANSPORT_core_connect (cfg,
1401 &monitor_notify_connect,
1402 &monitor_notify_disconnect,
1408 _("Failed to connect to transport service\n"));
1420 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1430 struct GNUNET_GETOPT_CommandLineOption options[] = {
1431 GNUNET_GETOPT_option_flag ('a',
1433 gettext_noop ("print information for all peers (instead of only connected peers)"),
1435 GNUNET_GETOPT_option_flag ('b',
1437 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1438 &benchmark_receive),
1439 GNUNET_GETOPT_option_flag ('D',
1441 gettext_noop ("disconnect from a peer"),
1443 GNUNET_GETOPT_option_flag ('i',
1445 gettext_noop ("provide information about all current connections (once)"),
1446 &iterate_connections),
1447 GNUNET_GETOPT_option_flag ('m',
1449 gettext_noop ("provide information about all current connections (continuously)"),
1450 &monitor_connections),
1451 GNUNET_GETOPT_option_flag ('e',
1453 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1455 GNUNET_GETOPT_option_flag ('n',
1457 gettext_noop ("do not resolve hostnames"),
1459 GNUNET_GETOPT_option_base32_auto ('p',
1462 gettext_noop ("peer identity"),
1464 GNUNET_GETOPT_option_flag ('P',
1466 gettext_noop ("monitor plugin sessions"),
1468 GNUNET_GETOPT_option_flag ('s',
1471 ("send data for benchmarking to the other peer (until CTRL-C)"),
1473 GNUNET_GETOPT_option_verbose (&verbosity),
1474 GNUNET_GETOPT_OPTION_END
1477 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1480 res = GNUNET_PROGRAM_run (argc, argv,
1482 gettext_noop ("Direct access to transport service."),
1485 GNUNET_free ((void *) argv);
1486 if (GNUNET_OK == res)
1491 /* end of gnunet-transport.c */