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/>.
20 * @file src/transport/gnunet-transport.c
21 * @brief Tool to help configure, measure and control the transport subsystem.
22 * @author Christian Grothoff
23 * @author Nathan Evans
26 #include "gnunet_util_lib.h"
27 #include "gnunet_resolver_service.h"
28 #include "gnunet_protocols.h"
29 #include "gnunet_transport_service.h"
30 #include "gnunet_transport_core_service.h"
33 * Timeout for a name resolution
35 #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 * Timeout for an operation
40 #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
44 * Context to store name resolutions for valiation
46 struct ValidationResolutionContext
51 struct ValidationResolutionContext *next;
56 struct ValidationResolutionContext *prev;
61 struct GNUNET_HELLO_Address *addrcp;
64 * Time of last validation
66 struct GNUNET_TIME_Absolute last_validation;
69 * Address is valid until
71 struct GNUNET_TIME_Absolute valid_until;
74 * Time of next validation
76 struct GNUNET_TIME_Absolute next_validation;
79 * Tranport conversion handle
81 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
89 * was the entry printed
95 * Struct to store information about peers in monitor mode
102 enum GNUNET_TRANSPORT_PeerState state;
107 struct GNUNET_TIME_Absolute state_timeout;
110 * The address to convert
112 struct GNUNET_HELLO_Address *address;
116 * Context to store name resolutions for valiation
118 struct PeerResolutionContext
123 struct PeerResolutionContext *next;
128 struct PeerResolutionContext *prev;
133 struct GNUNET_HELLO_Address *addrcp;
136 * transport conversiion context
138 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
143 enum GNUNET_TRANSPORT_PeerState state;
148 struct GNUNET_TIME_Absolute state_timeout;
156 * was the entry printed
163 * Benchmarking block size in KB
168 * Handle to transport service.
170 static struct GNUNET_TRANSPORT_CoreHandle *handle;
173 * Configuration handle
175 static struct GNUNET_CONFIGURATION_Handle *cfg;
178 * Blacklisting handle
180 struct GNUNET_TRANSPORT_Blacklist *blacklist;
185 static int benchmark_send;
190 static int benchmark_receive;
195 static int benchmark_receive;
200 static int iterate_connections;
205 static int iterate_all;
210 static int monitor_connects;
215 static int monitor_connections;
220 static int monitor_plugins;
225 static int do_disconnect;
233 * Global return value (0 success).
238 * Current number of connections in monitor mode
240 static int monitor_connect_counter;
243 * Number of bytes of traffic we received so far.
245 static unsigned long long traffic_received;
248 * Number of bytes of traffic we sent so far.
250 static unsigned long long traffic_sent;
253 * Starting time of transmitting/receiving data.
255 static struct GNUNET_TIME_Absolute start_time;
258 * Map storing information about monitored peers
260 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_peers;
263 * Map storing information about monitored plugins's sessions.
265 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins;
268 * Handle if we are monitoring peers at the transport level.
270 static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
273 * Handle if we are monitoring plugin session activity.
275 static struct GNUNET_TRANSPORT_PluginMonitor *pm;
278 * Identity of the peer we transmit to / connect to.
279 * ('-p' command-line option).
281 static struct GNUNET_PeerIdentity pid;
284 * Task for operation timeout
286 static struct GNUNET_SCHEDULER_Task *op_timeout;
289 * Selected level of verbosity.
291 static unsigned int verbosity;
294 * Resolver process handle.
296 struct GNUNET_OS_Process *resolver;
299 * Number of address resolutions pending
301 static unsigned int address_resolutions;
304 * DLL: head of validation resolution entries
306 static struct ValidationResolutionContext *vc_head;
309 * DLL: tail of validation resolution entries
311 static struct ValidationResolutionContext *vc_tail;
314 * DLL: head of resolution entries
316 static struct PeerResolutionContext *rc_head;
319 * DLL: head of resolution entries
321 static struct PeerResolutionContext *rc_tail;
325 * Function called to release data stored in the #monitored_peers map.
328 * @param key the peer identity
329 * @param value a `struct MonitoredPeer` to release
330 * @return #GNUNET_OK (continue to iterate)
333 destroy_it (void *cls,
334 const struct GNUNET_PeerIdentity *key,
337 struct MonitoredPeer *m = value;
339 GNUNET_assert (GNUNET_OK ==
340 GNUNET_CONTAINER_multipeermap_remove (monitored_peers,
343 GNUNET_free_non_null (m->address);
350 * Task run in monitor mode when the user presses CTRL-C to abort.
351 * Stops monitoring activity.
356 shutdown_task (void *cls)
358 struct GNUNET_TIME_Relative duration;
359 struct ValidationResolutionContext *cur;
360 struct ValidationResolutionContext *next;
361 struct PeerResolutionContext *rc;
363 if (NULL != op_timeout)
365 GNUNET_SCHEDULER_cancel (op_timeout);
370 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
375 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
380 for (cur = next; NULL != cur; cur = next)
384 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
385 GNUNET_CONTAINER_DLL_remove (vc_head,
388 GNUNET_free (cur->transport);
389 GNUNET_HELLO_address_free (cur->addrcp);
392 while (NULL != (rc = rc_head))
394 GNUNET_CONTAINER_DLL_remove (rc_head,
397 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
398 GNUNET_free (rc->transport);
399 GNUNET_free (rc->addrcp);
404 GNUNET_TRANSPORT_core_disconnect (handle);
409 duration = GNUNET_TIME_absolute_get_duration (start_time);
411 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
412 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
414 GNUNET_STRINGS_relative_time_to_string (duration,
417 if (benchmark_receive)
419 duration = GNUNET_TIME_absolute_get_duration (start_time);
421 _("Received %llu bytes/s (%llu bytes in %s)\n"),
422 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
424 GNUNET_STRINGS_relative_time_to_string (duration,
428 if (NULL != monitored_peers)
430 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers,
433 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
434 monitored_peers = NULL;
436 if (NULL != monitored_plugins)
439 GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
440 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
441 monitored_plugins = NULL;
443 if (NULL != blacklist)
445 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
453 * We are done, shut down.
456 operation_timeout (void *cls)
458 struct PeerResolutionContext *cur;
459 struct PeerResolutionContext *next;
462 if ((benchmark_send) || (benchmark_receive))
465 _("Failed to connect to `%s'\n"),
466 GNUNET_i2s_full (&pid));
467 GNUNET_SCHEDULER_shutdown ();
471 if (iterate_connections)
474 while (NULL != (cur = next))
478 _("Failed to resolve address for peer `%s'\n"),
479 GNUNET_i2s (&cur->addrcp->peer));
481 GNUNET_CONTAINER_DLL_remove(rc_head,
484 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
485 GNUNET_free (cur->transport);
486 GNUNET_free (cur->addrcp);
492 _("Failed to list connections, timeout occurred\n"));
493 GNUNET_SCHEDULER_shutdown ();
501 * Function called to notify a client about the socket
502 * begin ready to queue more data. Sends another message.
504 * @param cls closure with the message queue
509 struct GNUNET_MQ_Handle *mq = cls;
510 struct GNUNET_MessageHeader *m;
511 struct GNUNET_MQ_Envelope *env;
513 env = GNUNET_MQ_msg_extra (m,
515 GNUNET_MESSAGE_TYPE_DUMMY);
518 BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
519 traffic_sent += BLOCKSIZE * 1024;
520 GNUNET_MQ_notify_sent (env,
525 _("Transmitting %u bytes\n"),
526 (unsigned int) BLOCKSIZE * 1024);
533 * Function called to notify transport users that another
534 * peer connected to us.
537 * @param peer the peer that connected
538 * @param mq message queue for sending to @a peer
541 notify_connect (void *cls,
542 const struct GNUNET_PeerIdentity *peer,
543 struct GNUNET_MQ_Handle *mq)
545 if (0 != memcmp (&pid,
547 sizeof(struct GNUNET_PeerIdentity)))
550 if (! benchmark_send)
552 if (NULL != op_timeout)
554 GNUNET_SCHEDULER_cancel (op_timeout);
559 _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
562 start_time = GNUNET_TIME_absolute_get ();
569 * Function called to notify transport users that another
570 * peer disconnected from us.
573 * @param peer the peer that disconnected
574 * @param internal_cls what we returned from #notify_connect()
577 notify_disconnect (void *cls,
578 const struct GNUNET_PeerIdentity *peer,
581 if (0 != memcmp (&pid,
583 sizeof(struct GNUNET_PeerIdentity)))
585 if (NULL == internal_cls)
586 return; /* not about target peer */
587 if (! benchmark_send)
588 return; /* not transmitting */
590 _("Disconnected from peer `%s' while benchmarking\n"),
596 * Function called to notify transport users that another
597 * peer connected to us.
600 * @param peer the peer that connected
601 * @param mq for sending messages to @a peer
605 monitor_notify_connect (void *cls,
606 const struct GNUNET_PeerIdentity *peer,
607 struct GNUNET_MQ_Handle *mq)
609 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
610 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
612 monitor_connect_counter++;
614 _("%24s: %-17s %4s (%u connections in total)\n"),
618 monitor_connect_counter);
624 * Function called to notify transport users that another
625 * peer disconnected from us.
628 * @param peer the peer that disconnected
629 * @param internal_cls what we returned from #monitor_notify_connect()
632 monitor_notify_disconnect (void *cls,
633 const struct GNUNET_PeerIdentity *peer,
636 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
637 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
639 GNUNET_assert(monitor_connect_counter > 0);
640 monitor_connect_counter--;
643 _("%24s: %-17s %4s (%u connections in total)\n"),
645 _("Disconnected from"),
647 monitor_connect_counter);
652 * Function called by the transport for each received message.
655 * @param message the message
659 check_dummy (void *cls,
660 const struct GNUNET_MessageHeader *message)
662 return GNUNET_OK; /* all messages are fine */
667 * Function called by the transport for each received message.
670 * @param message the message
673 handle_dummy (void *cls,
674 const struct GNUNET_MessageHeader *message)
676 if (! benchmark_receive)
680 _("Received %u bytes\n"),
681 (unsigned int) ntohs (message->size));
682 if (0 == traffic_received)
683 start_time = GNUNET_TIME_absolute_get ();
684 traffic_received += ntohs (message->size);
689 * Convert address to a printable format.
691 * @param address the address
692 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
693 * to try to use reverse DNS
694 * @param state state the peer is in
695 * @param state_timeout when will the peer's state expire
698 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
700 enum GNUNET_TRANSPORT_PeerState state,
701 struct GNUNET_TIME_Absolute state_timeout);
705 print_info (const struct GNUNET_PeerIdentity *id,
706 const char *transport,
708 enum GNUNET_TRANSPORT_PeerState state,
709 struct GNUNET_TIME_Absolute state_timeout)
712 if ( ((GNUNET_YES == iterate_connections) &&
713 (GNUNET_YES == iterate_all)) ||
714 (GNUNET_YES == monitor_connections))
717 _("Peer `%s': %s %s in state `%s' until %s\n"),
719 (NULL == transport) ? "<none>" : transport,
720 (NULL == transport) ? "<none>" : addr,
721 GNUNET_TRANSPORT_ps2s (state),
722 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
724 else if ( (GNUNET_YES == iterate_connections) &&
725 (GNUNET_TRANSPORT_is_connected(state)) )
727 /* Only connected peers, skip state */
729 _("Peer `%s': %s %s\n"),
738 * Function called with a textual representation of an address. This
739 * function will be called several times with different possible
740 * textual representations, and a last time with @a address being NULL
741 * to signal the end of the iteration. Note that @a address NULL
742 * always is the last call, regardless of the value in @a res.
745 * @param address NULL on end of iteration,
746 * otherwise 0-terminated printable UTF-8 string,
747 * in particular an empty string if @a res is #GNUNET_NO
748 * @param res result of the address to string conversion:
749 * if #GNUNET_OK: conversion successful
750 * if #GNUNET_NO: address was invalid (or not supported)
751 * if #GNUNET_SYSERR: communication error (IPC error)
754 process_peer_string (void *cls,
758 struct PeerResolutionContext *rc = cls;
762 if (GNUNET_SYSERR == res)
765 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
766 GNUNET_i2s (&rc->addrcp->peer),
767 rc->addrcp->transport_name,
768 (unsigned int) rc->addrcp->address_length);
769 print_info (&rc->addrcp->peer,
774 rc->printed = GNUNET_YES;
777 if (GNUNET_OK == res)
779 print_info (&rc->addrcp->peer,
784 rc->printed = GNUNET_YES;
785 return; /* Wait for done call */
787 /* GNUNET_NO == res: ignore, was simply not supported */
790 /* NULL == address, last call, we are done */
793 GNUNET_assert (address_resolutions > 0);
794 address_resolutions--;
795 if (GNUNET_NO == rc->printed)
797 if (numeric == GNUNET_NO)
799 /* Failed to resolve address, try numeric lookup
800 (note: this should not be needed, as transport
801 should fallback to numeric conversion if DNS takes
803 resolve_peer_address (rc->addrcp,
810 print_info (&rc->addrcp->peer,
817 GNUNET_free (rc->transport);
818 GNUNET_free (rc->addrcp);
819 GNUNET_CONTAINER_DLL_remove (rc_head,
823 if ((0 == address_resolutions) && (iterate_connections))
825 if (NULL != op_timeout)
827 GNUNET_SCHEDULER_cancel (op_timeout);
831 GNUNET_SCHEDULER_shutdown ();
837 * Convert address to a printable format and print it
838 * together with the given state data.
840 * @param address the address
841 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
842 * to try to use reverse DNS
843 * @param state state the peer is in
844 * @param state_timeout when will the peer's state expire
847 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
849 enum GNUNET_TRANSPORT_PeerState state,
850 struct GNUNET_TIME_Absolute state_timeout)
852 struct PeerResolutionContext *rc;
854 rc = GNUNET_new (struct PeerResolutionContext);
855 GNUNET_CONTAINER_DLL_insert (rc_head,
858 address_resolutions++;
859 rc->transport = GNUNET_strdup (address->transport_name);
860 rc->addrcp = GNUNET_HELLO_address_copy (address);
861 rc->printed = GNUNET_NO;
863 rc->state_timeout = state_timeout;
864 /* Resolve address to string */
865 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
869 &process_peer_string,
875 * Function called with information about a peers during a one shot iteration
878 * @param peer identity of the peer, NULL for final callback when operation done
879 * @param address binary address used to communicate with this peer,
880 * NULL on disconnect or when done
881 * @param state current state this peer is in
882 * @param state_timeout time out for the current state
885 process_peer_iteration_cb (void *cls,
886 const struct GNUNET_PeerIdentity *peer,
887 const struct GNUNET_HELLO_Address *address,
888 enum GNUNET_TRANSPORT_PeerState state,
889 struct GNUNET_TIME_Absolute state_timeout)
898 if ( (GNUNET_NO == iterate_all) &&
899 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)))
900 return; /* Display only connected peers */
902 if (NULL != op_timeout)
903 GNUNET_SCHEDULER_cancel (op_timeout);
904 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Received address for peer `%s': %s\n",
911 address ? address->transport_name : "");
914 resolve_peer_address (address,
928 * Context for address resolution by #plugin_monitoring_cb().
930 struct PluginMonitorAddress
934 * Ongoing resolution request.
936 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
939 * Resolved address as string.
944 * Last event we got and did not yet print because
945 * @e str was NULL (address not yet resolved).
947 struct GNUNET_TRANSPORT_SessionInfo si;
952 * Print information about a plugin monitoring event.
954 * @param addr out internal context
955 * @param info the monitoring information
958 print_plugin_event_info (struct PluginMonitorAddress *addr,
959 const struct GNUNET_TRANSPORT_SessionInfo *info)
965 case GNUNET_TRANSPORT_SS_INIT:
968 case GNUNET_TRANSPORT_SS_HANDSHAKE:
971 case GNUNET_TRANSPORT_SS_UP:
974 case GNUNET_TRANSPORT_SS_UPDATE:
977 case GNUNET_TRANSPORT_SS_DONE:
985 "%s: state %s timeout in %s @ %s%s\n",
986 GNUNET_i2s (&info->address->peer),
988 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (info->session_timeout),
991 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
993 "%s: queue has %3u messages and %6u bytes\n",
994 GNUNET_i2s (&info->address->peer),
995 info->num_msg_pending,
996 info->num_bytes_pending);
997 if (0 != GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
999 "%s: receiving blocked until %s\n",
1000 GNUNET_i2s (&info->address->peer),
1001 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
1006 * Function called with a textual representation of an address. This
1007 * function will be called several times with different possible
1008 * textual representations, and a last time with @a address being NULL
1009 * to signal the end of the iteration. Note that @a address NULL
1010 * always is the last call, regardless of the value in @a res.
1012 * @param cls closure
1013 * @param address NULL on end of iteration,
1014 * otherwise 0-terminated printable UTF-8 string,
1015 * in particular an empty string if @a res is #GNUNET_NO
1016 * @param res result of the address to string conversion:
1017 * if #GNUNET_OK: conversion successful
1018 * if #GNUNET_NO: address was invalid (or not supported)
1019 * if #GNUNET_SYSERR: communication error (IPC error)
1022 address_cb (void *cls,
1023 const char *address,
1026 struct PluginMonitorAddress *addr = cls;
1028 if (NULL == address)
1033 if (NULL != addr->str)
1035 addr->str = GNUNET_strdup (address);
1036 print_plugin_event_info (addr,
1042 * Function called by the plugin with information about the
1043 * current sessions managed by the plugin (for monitoring).
1045 * @param cls closure (NULL)
1046 * @param session session handle this information is about,
1047 * NULL to indicate that we are "in sync" (initial
1048 * iteration complete)
1049 * @param session_ctx storage location where the application
1050 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
1051 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
1052 * @param info information about the state of the session,
1053 * NULL if @a session is also NULL and we are
1054 * merely signalling that the initial iteration is over;
1055 * NULL with @a session being non-NULL if the monitor
1056 * was being cancelled while sessions were active
1059 plugin_monitoring_cb (void *cls,
1060 struct GNUNET_TRANSPORT_PluginSession *session,
1062 const struct GNUNET_TRANSPORT_SessionInfo *info)
1064 struct PluginMonitorAddress *addr;
1066 if ( (NULL == info) &&
1068 return; /* in sync with transport service */
1069 addr = *session_ctx;
1074 if (NULL != addr->asc)
1076 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1079 GNUNET_free_non_null (addr->str);
1081 *session_ctx = NULL;
1083 return; /* shutdown */
1085 if (0 != memcmp (&info->address->peer,
1087 sizeof (struct GNUNET_PeerIdentity)))
1088 return; /* filtered */
1091 addr = GNUNET_new (struct PluginMonitorAddress);
1092 addr->asc = GNUNET_TRANSPORT_address_to_string (cfg,
1095 GNUNET_TIME_UNIT_FOREVER_REL,
1098 *session_ctx = addr;
1100 if (NULL == addr->str)
1103 print_plugin_event_info (addr,
1105 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1107 if (NULL != addr->asc)
1109 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1112 GNUNET_free_non_null (addr->str);
1114 *session_ctx = NULL;
1120 * Function called with information about a peers
1122 * @param cls closure, NULL
1123 * @param peer identity of the peer, NULL for final callback when operation done
1124 * @param address binary address used to communicate with this peer,
1125 * NULL on disconnect or when done
1126 * @param state current state this peer is in
1127 * @param state_timeout time out for the current state
1130 process_peer_monitoring_cb (void *cls,
1131 const struct GNUNET_PeerIdentity *peer,
1132 const struct GNUNET_HELLO_Address *address,
1133 enum GNUNET_TRANSPORT_PeerState state,
1134 struct GNUNET_TIME_Absolute state_timeout)
1136 struct MonitoredPeer *m;
1142 _("Monitor disconnected from transport service. Reconnecting.\n"));
1146 if (NULL != op_timeout)
1147 GNUNET_SCHEDULER_cancel (op_timeout);
1148 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1152 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers,
1155 m = GNUNET_new (struct MonitoredPeer);
1156 GNUNET_CONTAINER_multipeermap_put (monitored_peers,
1159 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1163 if ( (m->state == state) &&
1164 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1165 (NULL == address) &&
1166 (NULL == m->address) )
1168 return; /* No real change */
1170 if ( (m->state == state) &&
1171 (NULL != address) &&
1172 (NULL != m->address) &&
1173 (0 == GNUNET_HELLO_address_cmp(m->address, address)) )
1174 return; /* No real change */
1177 if (NULL != m->address)
1179 GNUNET_free (m->address);
1182 if (NULL != address)
1183 m->address = GNUNET_HELLO_address_copy (address);
1185 m->state_timeout = state_timeout;
1187 if (NULL != address)
1188 resolve_peer_address (m->address,
1202 * Function called with the transport service checking if we
1203 * want to blacklist a peer. Return #GNUNET_SYSERR for the
1204 * peer that we should disconnect from.
1207 * @param cpid peer to check blacklisting for
1208 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1211 blacklist_cb (void *cls,
1212 const struct GNUNET_PeerIdentity *cpid)
1214 if (0 == memcmp (cpid,
1216 sizeof (struct GNUNET_PeerIdentity)))
1217 return GNUNET_SYSERR;
1223 * Main function that will be run by the scheduler.
1225 * @param cls closure
1226 * @param args remaining command-line arguments
1227 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1228 * @param mycfg configuration
1233 const char *cfgfile,
1234 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1236 static struct GNUNET_PeerIdentity zero_pid;
1240 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1242 counter = benchmark_send + benchmark_receive + iterate_connections
1243 + monitor_connections + monitor_connects + do_disconnect +
1249 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1252 "benchmark receive",
1262 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1265 "benchmark receive",
1273 if (do_disconnect) /* -D: Disconnect from peer */
1275 if (0 == memcmp (&zero_pid,
1280 _("Option `%s' makes no sense without option `%s'.\n"),
1285 blacklist = GNUNET_TRANSPORT_blacklist (cfg,
1288 if (NULL == blacklist)
1292 _("Failed to connect to transport service for disconnection\n"));
1298 _("Blacklisting request in place, stop with CTRL-C\n"));
1300 else if (benchmark_send) /* -s: Benchmark sending */
1302 if (0 == memcmp (&zero_pid,
1307 _("Option `%s' makes no sense without option `%s'.\n"),
1312 handle = GNUNET_TRANSPORT_core_connect (cfg,
1323 _("Failed to connect to transport service\n"));
1327 start_time = GNUNET_TIME_absolute_get ();
1328 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1332 else if (benchmark_receive) /* -b: Benchmark receiving */
1334 struct GNUNET_MQ_MessageHandler handlers[] = {
1335 GNUNET_MQ_hd_var_size (dummy,
1336 GNUNET_MESSAGE_TYPE_DUMMY,
1337 struct GNUNET_MessageHeader,
1339 GNUNET_MQ_handler_end ()
1342 handle = GNUNET_TRANSPORT_core_connect (cfg,
1353 _("Failed to connect to transport service\n"));
1360 _("Starting to receive benchmark data\n"));
1361 start_time = GNUNET_TIME_absolute_get ();
1364 else if (iterate_connections) /* -i: List information about peers once */
1366 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1369 &process_peer_iteration_cb,
1371 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1375 else if (monitor_connections) /* -m: List information about peers continuously */
1377 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10,
1379 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1382 &process_peer_monitoring_cb,
1385 else if (monitor_plugins) /* -P: List information about plugins continuously */
1387 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1388 pm = GNUNET_TRANSPORT_monitor_plugins (cfg,
1389 &plugin_monitoring_cb,
1392 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1394 monitor_connect_counter = 0;
1395 handle = GNUNET_TRANSPORT_core_connect (cfg,
1399 &monitor_notify_connect,
1400 &monitor_notify_disconnect,
1406 _("Failed to connect to transport service\n"));
1418 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1428 struct GNUNET_GETOPT_CommandLineOption options[] = {
1429 GNUNET_GETOPT_option_flag ('a',
1431 gettext_noop ("print information for all peers (instead of only connected peers)"),
1433 GNUNET_GETOPT_option_flag ('b',
1435 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1436 &benchmark_receive),
1437 GNUNET_GETOPT_option_flag ('D',
1439 gettext_noop ("disconnect from a peer"),
1441 GNUNET_GETOPT_option_flag ('i',
1443 gettext_noop ("provide information about all current connections (once)"),
1444 &iterate_connections),
1445 GNUNET_GETOPT_option_flag ('m',
1447 gettext_noop ("provide information about all current connections (continuously)"),
1448 &monitor_connections),
1449 GNUNET_GETOPT_option_flag ('e',
1451 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1453 GNUNET_GETOPT_option_flag ('n',
1455 gettext_noop ("do not resolve hostnames"),
1457 GNUNET_GETOPT_option_base32_auto ('p',
1460 gettext_noop ("peer identity"),
1462 GNUNET_GETOPT_option_flag ('P',
1464 gettext_noop ("monitor plugin sessions"),
1466 GNUNET_GETOPT_option_flag ('s',
1469 ("send data for benchmarking to the other peer (until CTRL-C)"),
1471 GNUNET_GETOPT_option_verbose (&verbosity),
1472 GNUNET_GETOPT_OPTION_END
1475 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1478 res = GNUNET_PROGRAM_run (argc, argv,
1480 gettext_noop ("Direct access to transport service."),
1483 GNUNET_free ((void *) argv);
1484 if (GNUNET_OK == res)
1489 /* end of gnunet-transport.c */