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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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 * Which peer should we connect to?
175 * Handle to transport service.
177 static struct GNUNET_TRANSPORT_CoreHandle *handle;
180 * Configuration handle
182 static struct GNUNET_CONFIGURATION_Handle *cfg;
185 * Blacklisting handle
187 struct GNUNET_TRANSPORT_Blacklist *blacklist;
192 static int benchmark_send;
197 static int benchmark_receive;
202 static int benchmark_receive;
207 static int iterate_connections;
212 static int iterate_all;
217 static int monitor_connects;
222 static int monitor_connections;
227 static int monitor_plugins;
232 static int do_disconnect;
240 * Global return value (0 success).
245 * Current number of connections in monitor mode
247 static int monitor_connect_counter;
250 * Number of bytes of traffic we received so far.
252 static unsigned long long traffic_received;
255 * Number of bytes of traffic we sent so far.
257 static unsigned long long traffic_sent;
260 * Starting time of transmitting/receiving data.
262 static struct GNUNET_TIME_Absolute start_time;
265 * Map storing information about monitored peers
267 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_peers;
270 * Map storing information about monitored plugins's sessions.
272 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins;
275 * Handle if we are monitoring peers at the transport level.
277 static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
280 * Handle if we are monitoring plugin session activity.
282 static struct GNUNET_TRANSPORT_PluginMonitor *pm;
285 * Identity of the peer we transmit to / connect to.
286 * (equivalent to 'cpid' string).
288 static struct GNUNET_PeerIdentity pid;
291 * Task for operation timeout
293 static struct GNUNET_SCHEDULER_Task *op_timeout;
296 * Selected level of verbosity.
298 static int verbosity;
301 * Resolver process handle.
303 struct GNUNET_OS_Process *resolver;
306 * Number of address resolutions pending
308 static unsigned int address_resolutions;
311 * DLL: head of validation resolution entries
313 static struct ValidationResolutionContext *vc_head;
316 * DLL: tail of validation resolution entries
318 static struct ValidationResolutionContext *vc_tail;
321 * DLL: head of resolution entries
323 static struct PeerResolutionContext *rc_head;
326 * DLL: head of resolution entries
328 static struct PeerResolutionContext *rc_tail;
332 * Function called to release data stored in the #monitored_peers map.
335 * @param key the peer identity
336 * @param value a `struct MonitoredPeer` to release
337 * @return #GNUNET_OK (continue to iterate)
340 destroy_it (void *cls,
341 const struct GNUNET_PeerIdentity *key,
344 struct MonitoredPeer *m = value;
346 GNUNET_assert (GNUNET_OK ==
347 GNUNET_CONTAINER_multipeermap_remove (monitored_peers,
350 GNUNET_free_non_null (m->address);
357 * Task run in monitor mode when the user presses CTRL-C to abort.
358 * Stops monitoring activity.
363 shutdown_task (void *cls)
365 struct GNUNET_TIME_Relative duration;
366 struct ValidationResolutionContext *cur;
367 struct ValidationResolutionContext *next;
368 struct PeerResolutionContext *rc;
370 if (NULL != op_timeout)
372 GNUNET_SCHEDULER_cancel (op_timeout);
377 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
382 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
387 for (cur = next; NULL != cur; cur = next)
391 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
392 GNUNET_CONTAINER_DLL_remove (vc_head,
395 GNUNET_free (cur->transport);
396 GNUNET_HELLO_address_free (cur->addrcp);
399 while (NULL != (rc = rc_head))
401 GNUNET_CONTAINER_DLL_remove (rc_head,
404 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
405 GNUNET_free (rc->transport);
406 GNUNET_free (rc->addrcp);
411 GNUNET_TRANSPORT_core_disconnect (handle);
416 duration = GNUNET_TIME_absolute_get_duration (start_time);
418 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
419 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
421 GNUNET_STRINGS_relative_time_to_string (duration,
424 if (benchmark_receive)
426 duration = GNUNET_TIME_absolute_get_duration (start_time);
428 _("Received %llu bytes/s (%llu bytes in %s)\n"),
429 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
431 GNUNET_STRINGS_relative_time_to_string (duration,
435 if (NULL != monitored_peers)
437 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers,
440 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
441 monitored_peers = NULL;
443 if (NULL != monitored_plugins)
446 GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
447 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
448 monitored_plugins = NULL;
450 if (NULL != blacklist)
452 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
460 * We are done, shut down.
463 operation_timeout (void *cls)
465 struct PeerResolutionContext *cur;
466 struct PeerResolutionContext *next;
469 if ((benchmark_send) || (benchmark_receive))
472 _("Failed to connect to `%s'\n"),
473 GNUNET_i2s_full (&pid));
474 GNUNET_SCHEDULER_shutdown ();
478 if (iterate_connections)
481 while (NULL != (cur = next))
485 _("Failed to resolve address for peer `%s'\n"),
486 GNUNET_i2s (&cur->addrcp->peer));
488 GNUNET_CONTAINER_DLL_remove(rc_head,
491 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
492 GNUNET_free (cur->transport);
493 GNUNET_free (cur->addrcp);
499 _("Failed to list connections, timeout occured\n"));
500 GNUNET_SCHEDULER_shutdown ();
508 * Function called to notify a client about the socket
509 * begin ready to queue more data. Sends another message.
511 * @param cls closure with the message queue
516 struct GNUNET_MQ_Handle *mq = cls;
517 struct GNUNET_MessageHeader *m;
518 struct GNUNET_MQ_Envelope *env;
520 env = GNUNET_MQ_msg_extra (m,
522 GNUNET_MESSAGE_TYPE_DUMMY);
525 BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
526 traffic_sent += BLOCKSIZE * 1024;
527 GNUNET_MQ_notify_sent (env,
532 _("Transmitting %u bytes\n"),
533 (unsigned int) BLOCKSIZE * 1024);
540 * Function called to notify transport users that another
541 * peer connected to us.
544 * @param peer the peer that connected
545 * @param mq message queue for sending to @a peer
548 notify_connect (void *cls,
549 const struct GNUNET_PeerIdentity *peer,
550 struct GNUNET_MQ_Handle *mq)
552 if (0 != memcmp (&pid,
554 sizeof(struct GNUNET_PeerIdentity)))
557 if (! benchmark_send)
559 if (NULL != op_timeout)
561 GNUNET_SCHEDULER_cancel (op_timeout);
566 _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
569 start_time = GNUNET_TIME_absolute_get ();
576 * Function called to notify transport users that another
577 * peer disconnected from us.
580 * @param peer the peer that disconnected
581 * @param internal_cls what we returned from #notify_connect()
584 notify_disconnect (void *cls,
585 const struct GNUNET_PeerIdentity *peer,
588 if (0 != memcmp (&pid,
590 sizeof(struct GNUNET_PeerIdentity)))
592 if (NULL == internal_cls)
593 return; /* not about target peer */
594 if (! benchmark_send)
595 return; /* not transmitting */
597 _("Disconnected from peer `%s' while benchmarking\n"),
603 * Function called to notify transport users that another
604 * peer connected to us.
607 * @param peer the peer that connected
608 * @param mq for sending messages to @a peer
612 monitor_notify_connect (void *cls,
613 const struct GNUNET_PeerIdentity *peer,
614 struct GNUNET_MQ_Handle *mq)
616 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
617 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
619 monitor_connect_counter++;
621 _("%24s: %-17s %4s (%u connections in total)\n"),
625 monitor_connect_counter);
631 * Function called to notify transport users that another
632 * peer disconnected from us.
635 * @param peer the peer that disconnected
636 * @param internal_cls what we returned from #monitor_notify_connect()
639 monitor_notify_disconnect (void *cls,
640 const struct GNUNET_PeerIdentity *peer,
643 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
644 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
646 GNUNET_assert(monitor_connect_counter > 0);
647 monitor_connect_counter--;
650 _("%24s: %-17s %4s (%u connections in total)\n"),
652 _("Disconnected from"),
654 monitor_connect_counter);
659 * Function called by the transport for each received message.
662 * @param message the message
666 check_dummy (void *cls,
667 const struct GNUNET_MessageHeader *message)
669 return GNUNET_OK; /* all messages are fine */
674 * Function called by the transport for each received message.
677 * @param message the message
680 handle_dummy (void *cls,
681 const struct GNUNET_MessageHeader *message)
683 if (! benchmark_receive)
687 _("Received %u bytes\n"),
688 (unsigned int) ntohs (message->size));
689 if (0 == traffic_received)
690 start_time = GNUNET_TIME_absolute_get ();
691 traffic_received += ntohs (message->size);
696 * Convert address to a printable format.
698 * @param address the address
699 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
700 * to try to use reverse DNS
701 * @param state state the peer is in
702 * @param state_timeout when will the peer's state expire
705 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
707 enum GNUNET_TRANSPORT_PeerState state,
708 struct GNUNET_TIME_Absolute state_timeout);
712 print_info (const struct GNUNET_PeerIdentity *id,
713 const char *transport,
715 enum GNUNET_TRANSPORT_PeerState state,
716 struct GNUNET_TIME_Absolute state_timeout)
719 if ( ((GNUNET_YES == iterate_connections) &&
720 (GNUNET_YES == iterate_all)) ||
721 (GNUNET_YES == monitor_connections))
724 _("Peer `%s': %s %s in state `%s' until %s\n"),
726 (NULL == transport) ? "<none>" : transport,
727 (NULL == transport) ? "<none>" : addr,
728 GNUNET_TRANSPORT_ps2s (state),
729 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
731 else if ( (GNUNET_YES == iterate_connections) &&
732 (GNUNET_TRANSPORT_is_connected(state)) )
734 /* Only connected peers, skip state */
736 _("Peer `%s': %s %s\n"),
745 * Function called with a textual representation of an address. This
746 * function will be called several times with different possible
747 * textual representations, and a last time with @a address being NULL
748 * to signal the end of the iteration. Note that @a address NULL
749 * always is the last call, regardless of the value in @a res.
752 * @param address NULL on end of iteration,
753 * otherwise 0-terminated printable UTF-8 string,
754 * in particular an empty string if @a res is #GNUNET_NO
755 * @param res result of the address to string conversion:
756 * if #GNUNET_OK: conversion successful
757 * if #GNUNET_NO: address was invalid (or not supported)
758 * if #GNUNET_SYSERR: communication error (IPC error)
761 process_peer_string (void *cls,
765 struct PeerResolutionContext *rc = cls;
769 if (GNUNET_SYSERR == res)
772 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
773 GNUNET_i2s (&rc->addrcp->peer),
774 rc->addrcp->transport_name,
775 (unsigned int) rc->addrcp->address_length);
776 print_info (&rc->addrcp->peer,
781 rc->printed = GNUNET_YES;
784 if (GNUNET_OK == res)
786 print_info (&rc->addrcp->peer,
791 rc->printed = GNUNET_YES;
792 return; /* Wait for done call */
794 /* GNUNET_NO == res: ignore, was simply not supported */
797 /* NULL == address, last call, we are done */
800 GNUNET_assert (address_resolutions > 0);
801 address_resolutions--;
802 if (GNUNET_NO == rc->printed)
804 if (numeric == GNUNET_NO)
806 /* Failed to resolve address, try numeric lookup
807 (note: this should not be needed, as transport
808 should fallback to numeric conversion if DNS takes
810 resolve_peer_address (rc->addrcp,
817 print_info (&rc->addrcp->peer,
824 GNUNET_free (rc->transport);
825 GNUNET_free (rc->addrcp);
826 GNUNET_CONTAINER_DLL_remove (rc_head,
830 if ((0 == address_resolutions) && (iterate_connections))
832 if (NULL != op_timeout)
834 GNUNET_SCHEDULER_cancel (op_timeout);
838 GNUNET_SCHEDULER_shutdown ();
844 * Convert address to a printable format and print it
845 * together with the given state data.
847 * @param address the address
848 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
849 * to try to use reverse DNS
850 * @param state state the peer is in
851 * @param state_timeout when will the peer's state expire
854 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
856 enum GNUNET_TRANSPORT_PeerState state,
857 struct GNUNET_TIME_Absolute state_timeout)
859 struct PeerResolutionContext *rc;
861 rc = GNUNET_new (struct PeerResolutionContext);
862 GNUNET_CONTAINER_DLL_insert (rc_head,
865 address_resolutions++;
866 rc->transport = GNUNET_strdup (address->transport_name);
867 rc->addrcp = GNUNET_HELLO_address_copy (address);
868 rc->printed = GNUNET_NO;
870 rc->state_timeout = state_timeout;
871 /* Resolve address to string */
872 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
876 &process_peer_string,
882 * Function called with information about a peers during a one shot iteration
885 * @param peer identity of the peer, NULL for final callback when operation done
886 * @param address binary address used to communicate with this peer,
887 * NULL on disconnect or when done
888 * @param state current state this peer is in
889 * @param state_timeout time out for the current state
892 process_peer_iteration_cb (void *cls,
893 const struct GNUNET_PeerIdentity *peer,
894 const struct GNUNET_HELLO_Address *address,
895 enum GNUNET_TRANSPORT_PeerState state,
896 struct GNUNET_TIME_Absolute state_timeout)
905 if ( (GNUNET_NO == iterate_all) &&
906 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)))
907 return; /* Display only connected peers */
909 if (NULL != op_timeout)
910 GNUNET_SCHEDULER_cancel (op_timeout);
911 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
916 "Received address for peer `%s': %s\n",
918 address ? address->transport_name : "");
921 resolve_peer_address (address,
935 * Context for address resolution by #plugin_monitoring_cb().
937 struct PluginMonitorAddress
941 * Ongoing resolution request.
943 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
946 * Resolved address as string.
951 * Last event we got and did not yet print because
952 * @e str was NULL (address not yet resolved).
954 struct GNUNET_TRANSPORT_SessionInfo si;
959 * Print information about a plugin monitoring event.
961 * @param addr out internal context
962 * @param info the monitoring information
965 print_plugin_event_info (struct PluginMonitorAddress *addr,
966 const struct GNUNET_TRANSPORT_SessionInfo *info)
972 case GNUNET_TRANSPORT_SS_INIT:
975 case GNUNET_TRANSPORT_SS_HANDSHAKE:
978 case GNUNET_TRANSPORT_SS_UP:
981 case GNUNET_TRANSPORT_SS_UPDATE:
984 case GNUNET_TRANSPORT_SS_DONE:
992 "%s: state %s timeout in %s @ %s%s\n",
993 GNUNET_i2s (&info->address->peer),
995 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (info->session_timeout),
998 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
1000 "%s: queue has %3u messages and %6u bytes\n",
1001 GNUNET_i2s (&info->address->peer),
1002 info->num_msg_pending,
1003 info->num_bytes_pending);
1004 if (0 != GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
1006 "%s: receiving blocked until %s\n",
1007 GNUNET_i2s (&info->address->peer),
1008 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
1013 * Function called with a textual representation of an address. This
1014 * function will be called several times with different possible
1015 * textual representations, and a last time with @a address being NULL
1016 * to signal the end of the iteration. Note that @a address NULL
1017 * always is the last call, regardless of the value in @a res.
1019 * @param cls closure
1020 * @param address NULL on end of iteration,
1021 * otherwise 0-terminated printable UTF-8 string,
1022 * in particular an empty string if @a res is #GNUNET_NO
1023 * @param res result of the address to string conversion:
1024 * if #GNUNET_OK: conversion successful
1025 * if #GNUNET_NO: address was invalid (or not supported)
1026 * if #GNUNET_SYSERR: communication error (IPC error)
1029 address_cb (void *cls,
1030 const char *address,
1033 struct PluginMonitorAddress *addr = cls;
1035 if (NULL == address)
1040 if (NULL != addr->str)
1042 addr->str = GNUNET_strdup (address);
1043 print_plugin_event_info (addr,
1049 * Function called by the plugin with information about the
1050 * current sessions managed by the plugin (for monitoring).
1052 * @param cls closure (NULL)
1053 * @param session session handle this information is about,
1054 * NULL to indicate that we are "in sync" (initial
1055 * iteration complete)
1056 * @param session_ctx storage location where the application
1057 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
1058 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
1059 * @param info information about the state of the session,
1060 * NULL if @a session is also NULL and we are
1061 * merely signalling that the initial iteration is over;
1062 * NULL with @a session being non-NULL if the monitor
1063 * was being cancelled while sessions were active
1066 plugin_monitoring_cb (void *cls,
1067 struct GNUNET_TRANSPORT_PluginSession *session,
1069 const struct GNUNET_TRANSPORT_SessionInfo *info)
1071 struct PluginMonitorAddress *addr;
1073 if ( (NULL == info) &&
1075 return; /* in sync with transport service */
1076 addr = *session_ctx;
1081 if (NULL != addr->asc)
1083 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1086 GNUNET_free_non_null (addr->str);
1088 *session_ctx = NULL;
1090 return; /* shutdown */
1092 if ( (NULL != cpid) &&
1093 (0 != memcmp (&info->address->peer,
1095 sizeof (struct GNUNET_PeerIdentity))) )
1096 return; /* filtered */
1099 addr = GNUNET_new (struct PluginMonitorAddress);
1100 addr->asc = GNUNET_TRANSPORT_address_to_string (cfg,
1103 GNUNET_TIME_UNIT_FOREVER_REL,
1106 *session_ctx = addr;
1108 if (NULL == addr->str)
1111 print_plugin_event_info (addr,
1113 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1115 if (NULL != addr->asc)
1117 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1120 GNUNET_free_non_null (addr->str);
1122 *session_ctx = NULL;
1128 * Function called with information about a peers
1130 * @param cls closure, NULL
1131 * @param peer identity of the peer, NULL for final callback when operation done
1132 * @param address binary address used to communicate with this peer,
1133 * NULL on disconnect or when done
1134 * @param state current state this peer is in
1135 * @param state_timeout time out for the current state
1138 process_peer_monitoring_cb (void *cls,
1139 const struct GNUNET_PeerIdentity *peer,
1140 const struct GNUNET_HELLO_Address *address,
1141 enum GNUNET_TRANSPORT_PeerState state,
1142 struct GNUNET_TIME_Absolute state_timeout)
1144 struct MonitoredPeer *m;
1150 _("Monitor disconnected from transport service. Reconnecting.\n"));
1154 if (NULL != op_timeout)
1155 GNUNET_SCHEDULER_cancel (op_timeout);
1156 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1160 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers,
1163 m = GNUNET_new (struct MonitoredPeer);
1164 GNUNET_CONTAINER_multipeermap_put (monitored_peers,
1167 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1171 if ( (m->state == state) &&
1172 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1173 (NULL == address) &&
1174 (NULL == m->address) )
1176 return; /* No real change */
1178 if ( (m->state == state) &&
1179 (NULL != address) &&
1180 (NULL != m->address) &&
1181 (0 == GNUNET_HELLO_address_cmp(m->address, address)) )
1182 return; /* No real change */
1185 if (NULL != m->address)
1187 GNUNET_free (m->address);
1190 if (NULL != address)
1191 m->address = GNUNET_HELLO_address_copy (address);
1193 m->state_timeout = state_timeout;
1195 if (NULL != address)
1196 resolve_peer_address (m->address,
1210 * Function called with the transport service checking if we
1211 * want to blacklist a peer. Return #GNUNET_SYSERR for the
1212 * peer that we should disconnect from.
1215 * @param cpid peer to check blacklisting for
1216 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1219 blacklist_cb (void *cls,
1220 const struct GNUNET_PeerIdentity *cpid)
1222 if (0 == memcmp (cpid,
1224 sizeof (struct GNUNET_PeerIdentity)))
1225 return GNUNET_SYSERR;
1231 * Main function that will be run by the scheduler.
1233 * @param cls closure
1234 * @param args remaining command-line arguments
1235 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1236 * @param mycfg configuration
1241 const char *cfgfile,
1242 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1247 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1248 if ( (NULL != cpid) &&
1250 GNUNET_CRYPTO_eddsa_public_key_from_string (cpid,
1255 _("Failed to parse peer identity `%s'\n"),
1260 counter = benchmark_send + benchmark_receive + iterate_connections
1261 + monitor_connections + monitor_connects + do_disconnect +
1267 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1270 "benchmark receive",
1280 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1283 "benchmark receive",
1291 if (do_disconnect) /* -D: Disconnect from peer */
1296 _("Option `%s' makes no sense without option `%s'.\n"),
1301 blacklist = GNUNET_TRANSPORT_blacklist (cfg,
1304 if (NULL == blacklist)
1308 _("Failed to connect to transport service for disconnection\n"));
1314 _("Blacklisting request in place, stop with CTRL-C\n"));
1316 else if (benchmark_send) /* -s: Benchmark sending */
1321 _("Option `%s' makes no sense without option `%s'.\n"),
1326 handle = GNUNET_TRANSPORT_core_connect (cfg,
1337 _("Failed to connect to transport service\n"));
1341 start_time = GNUNET_TIME_absolute_get ();
1342 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1346 else if (benchmark_receive) /* -b: Benchmark receiving */
1348 struct GNUNET_MQ_MessageHandler handlers[] = {
1349 GNUNET_MQ_hd_var_size (dummy,
1350 GNUNET_MESSAGE_TYPE_DUMMY,
1351 struct GNUNET_MessageHeader,
1353 GNUNET_MQ_handler_end ()
1356 handle = GNUNET_TRANSPORT_core_connect (cfg,
1367 _("Failed to connect to transport service\n"));
1374 _("Starting to receive benchmark data\n"));
1375 start_time = GNUNET_TIME_absolute_get ();
1378 else if (iterate_connections) /* -i: List information about peers once */
1380 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1381 (NULL == cpid) ? NULL : &pid,
1383 &process_peer_iteration_cb,
1385 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1389 else if (monitor_connections) /* -m: List information about peers continuously */
1391 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10,
1393 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1394 (NULL == cpid) ? NULL : &pid,
1396 &process_peer_monitoring_cb,
1399 else if (monitor_plugins) /* -P: List information about plugins continuously */
1401 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1402 pm = GNUNET_TRANSPORT_monitor_plugins (cfg,
1403 &plugin_monitoring_cb,
1406 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1408 monitor_connect_counter = 0;
1409 handle = GNUNET_TRANSPORT_core_connect (cfg,
1413 &monitor_notify_connect,
1414 &monitor_notify_disconnect,
1420 _("Failed to connect to transport service\n"));
1432 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1442 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1444 gettext_noop ("print information for all peers (instead of only connected peers)"),
1445 0, &GNUNET_GETOPT_set_one, &iterate_all },
1446 { 'b', "benchmark", NULL,
1447 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1448 0, &GNUNET_GETOPT_set_one, &benchmark_receive },
1449 { 'D', "disconnect",
1450 NULL, gettext_noop ("disconnect from a peer"), 0,
1451 &GNUNET_GETOPT_set_one, &do_disconnect },
1452 { 'i', "information", NULL,
1453 gettext_noop ("provide information about all current connections (once)"),
1454 0, &GNUNET_GETOPT_set_one, &iterate_connections },
1455 { 'm', "monitor", NULL,
1456 gettext_noop ("provide information about all current connections (continuously)"),
1457 0, &GNUNET_GETOPT_set_one, &monitor_connections },
1458 { 'e', "events", NULL,
1459 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1460 0, &GNUNET_GETOPT_set_one, &monitor_connects },
1462 NULL, gettext_noop ("do not resolve hostnames"), 0,
1463 &GNUNET_GETOPT_set_one, &numeric },
1464 { 'p', "peer", "PEER",
1465 gettext_noop ("peer identity"), 1, &GNUNET_GETOPT_set_string,
1467 { 'P', "plugins", NULL,
1468 gettext_noop ("monitor plugin sessions"), 0, &GNUNET_GETOPT_set_one,
1470 { 's', "send", NULL, gettext_noop
1471 ("send data for benchmarking to the other peer (until CTRL-C)"), 0,
1472 &GNUNET_GETOPT_set_one, &benchmark_send },
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 */