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 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.
17 * @file src/transport/gnunet-transport.c
18 * @brief Tool to help configure, measure and control the transport subsystem.
19 * @author Christian Grothoff
20 * @author Nathan Evans
23 #include "gnunet_util_lib.h"
24 #include "gnunet_resolver_service.h"
25 #include "gnunet_protocols.h"
26 #include "gnunet_transport_service.h"
27 #include "gnunet_transport_core_service.h"
30 * Timeout for a name resolution
32 #define RESOLUTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
35 * Timeout for an operation
37 #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
41 * Context to store name resolutions for valiation
43 struct ValidationResolutionContext
48 struct ValidationResolutionContext *next;
53 struct ValidationResolutionContext *prev;
58 struct GNUNET_HELLO_Address *addrcp;
61 * Time of last validation
63 struct GNUNET_TIME_Absolute last_validation;
66 * Address is valid until
68 struct GNUNET_TIME_Absolute valid_until;
71 * Time of next validation
73 struct GNUNET_TIME_Absolute next_validation;
76 * Tranport conversion handle
78 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
86 * was the entry printed
92 * Struct to store information about peers in monitor mode
99 enum GNUNET_TRANSPORT_PeerState state;
104 struct GNUNET_TIME_Absolute state_timeout;
107 * The address to convert
109 struct GNUNET_HELLO_Address *address;
113 * Context to store name resolutions for valiation
115 struct PeerResolutionContext
120 struct PeerResolutionContext *next;
125 struct PeerResolutionContext *prev;
130 struct GNUNET_HELLO_Address *addrcp;
133 * transport conversiion context
135 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
140 enum GNUNET_TRANSPORT_PeerState state;
145 struct GNUNET_TIME_Absolute state_timeout;
153 * was the entry printed
160 * Benchmarking block size in KB
165 * Handle to transport service.
167 static struct GNUNET_TRANSPORT_CoreHandle *handle;
170 * Configuration handle
172 static struct GNUNET_CONFIGURATION_Handle *cfg;
175 * Blacklisting handle
177 struct GNUNET_TRANSPORT_Blacklist *blacklist;
182 static int benchmark_send;
187 static int benchmark_receive;
192 static int benchmark_receive;
197 static int iterate_connections;
202 static int iterate_all;
207 static int monitor_connects;
212 static int monitor_connections;
217 static int monitor_plugins;
222 static int do_disconnect;
230 * Global return value (0 success).
235 * Current number of connections in monitor mode
237 static int monitor_connect_counter;
240 * Number of bytes of traffic we received so far.
242 static unsigned long long traffic_received;
245 * Number of bytes of traffic we sent so far.
247 static unsigned long long traffic_sent;
250 * Starting time of transmitting/receiving data.
252 static struct GNUNET_TIME_Absolute start_time;
255 * Map storing information about monitored peers
257 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_peers;
260 * Map storing information about monitored plugins's sessions.
262 static struct GNUNET_CONTAINER_MultiPeerMap *monitored_plugins;
265 * Handle if we are monitoring peers at the transport level.
267 static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
270 * Handle if we are monitoring plugin session activity.
272 static struct GNUNET_TRANSPORT_PluginMonitor *pm;
275 * Identity of the peer we transmit to / connect to.
276 * ('-p' command-line option).
278 static struct GNUNET_PeerIdentity pid;
281 * Task for operation timeout
283 static struct GNUNET_SCHEDULER_Task *op_timeout;
286 * Selected level of verbosity.
288 static unsigned int verbosity;
291 * Resolver process handle.
293 struct GNUNET_OS_Process *resolver;
296 * Number of address resolutions pending
298 static unsigned int address_resolutions;
301 * DLL: head of validation resolution entries
303 static struct ValidationResolutionContext *vc_head;
306 * DLL: tail of validation resolution entries
308 static struct ValidationResolutionContext *vc_tail;
311 * DLL: head of resolution entries
313 static struct PeerResolutionContext *rc_head;
316 * DLL: head of resolution entries
318 static struct PeerResolutionContext *rc_tail;
322 * Function called to release data stored in the #monitored_peers map.
325 * @param key the peer identity
326 * @param value a `struct MonitoredPeer` to release
327 * @return #GNUNET_OK (continue to iterate)
330 destroy_it (void *cls,
331 const struct GNUNET_PeerIdentity *key,
334 struct MonitoredPeer *m = value;
336 GNUNET_assert (GNUNET_OK ==
337 GNUNET_CONTAINER_multipeermap_remove (monitored_peers,
340 GNUNET_free_non_null (m->address);
347 * Task run in monitor mode when the user presses CTRL-C to abort.
348 * Stops monitoring activity.
353 shutdown_task (void *cls)
355 struct GNUNET_TIME_Relative duration;
356 struct ValidationResolutionContext *cur;
357 struct ValidationResolutionContext *next;
358 struct PeerResolutionContext *rc;
360 if (NULL != op_timeout)
362 GNUNET_SCHEDULER_cancel (op_timeout);
367 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
372 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
377 for (cur = next; NULL != cur; cur = next)
381 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
382 GNUNET_CONTAINER_DLL_remove (vc_head,
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,
394 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
395 GNUNET_free (rc->transport);
396 GNUNET_free (rc->addrcp);
401 GNUNET_TRANSPORT_core_disconnect (handle);
406 duration = GNUNET_TIME_absolute_get_duration (start_time);
408 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
409 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
411 GNUNET_STRINGS_relative_time_to_string (duration,
414 if (benchmark_receive)
416 duration = GNUNET_TIME_absolute_get_duration (start_time);
418 _("Received %llu bytes/s (%llu bytes in %s)\n"),
419 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
421 GNUNET_STRINGS_relative_time_to_string (duration,
425 if (NULL != monitored_peers)
427 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers,
430 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
431 monitored_peers = NULL;
433 if (NULL != monitored_plugins)
436 GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
437 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
438 monitored_plugins = NULL;
440 if (NULL != blacklist)
442 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
450 * We are done, shut down.
453 operation_timeout (void *cls)
455 struct PeerResolutionContext *cur;
456 struct PeerResolutionContext *next;
459 if ((benchmark_send) || (benchmark_receive))
462 _("Failed to connect to `%s'\n"),
463 GNUNET_i2s_full (&pid));
464 GNUNET_SCHEDULER_shutdown ();
468 if (iterate_connections)
471 while (NULL != (cur = next))
475 _("Failed to resolve address for peer `%s'\n"),
476 GNUNET_i2s (&cur->addrcp->peer));
478 GNUNET_CONTAINER_DLL_remove(rc_head,
481 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
482 GNUNET_free (cur->transport);
483 GNUNET_free (cur->addrcp);
489 _("Failed to list connections, timeout occured\n"));
490 GNUNET_SCHEDULER_shutdown ();
498 * Function called to notify a client about the socket
499 * begin ready to queue more data. Sends another message.
501 * @param cls closure with the message queue
506 struct GNUNET_MQ_Handle *mq = cls;
507 struct GNUNET_MessageHeader *m;
508 struct GNUNET_MQ_Envelope *env;
510 env = GNUNET_MQ_msg_extra (m,
512 GNUNET_MESSAGE_TYPE_DUMMY);
515 BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
516 traffic_sent += BLOCKSIZE * 1024;
517 GNUNET_MQ_notify_sent (env,
522 _("Transmitting %u bytes\n"),
523 (unsigned int) BLOCKSIZE * 1024);
530 * Function called to notify transport users that another
531 * peer connected to us.
534 * @param peer the peer that connected
535 * @param mq message queue for sending to @a peer
538 notify_connect (void *cls,
539 const struct GNUNET_PeerIdentity *peer,
540 struct GNUNET_MQ_Handle *mq)
542 if (0 != memcmp (&pid,
544 sizeof(struct GNUNET_PeerIdentity)))
547 if (! benchmark_send)
549 if (NULL != op_timeout)
551 GNUNET_SCHEDULER_cancel (op_timeout);
556 _("Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
559 start_time = GNUNET_TIME_absolute_get ();
566 * Function called to notify transport users that another
567 * peer disconnected from us.
570 * @param peer the peer that disconnected
571 * @param internal_cls what we returned from #notify_connect()
574 notify_disconnect (void *cls,
575 const struct GNUNET_PeerIdentity *peer,
578 if (0 != memcmp (&pid,
580 sizeof(struct GNUNET_PeerIdentity)))
582 if (NULL == internal_cls)
583 return; /* not about target peer */
584 if (! benchmark_send)
585 return; /* not transmitting */
587 _("Disconnected from peer `%s' while benchmarking\n"),
593 * Function called to notify transport users that another
594 * peer connected to us.
597 * @param peer the peer that connected
598 * @param mq for sending messages to @a peer
602 monitor_notify_connect (void *cls,
603 const struct GNUNET_PeerIdentity *peer,
604 struct GNUNET_MQ_Handle *mq)
606 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
607 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
609 monitor_connect_counter++;
611 _("%24s: %-17s %4s (%u connections in total)\n"),
615 monitor_connect_counter);
621 * Function called to notify transport users that another
622 * peer disconnected from us.
625 * @param peer the peer that disconnected
626 * @param internal_cls what we returned from #monitor_notify_connect()
629 monitor_notify_disconnect (void *cls,
630 const struct GNUNET_PeerIdentity *peer,
633 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
634 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
636 GNUNET_assert(monitor_connect_counter > 0);
637 monitor_connect_counter--;
640 _("%24s: %-17s %4s (%u connections in total)\n"),
642 _("Disconnected from"),
644 monitor_connect_counter);
649 * Function called by the transport for each received message.
652 * @param message the message
656 check_dummy (void *cls,
657 const struct GNUNET_MessageHeader *message)
659 return GNUNET_OK; /* all messages are fine */
664 * Function called by the transport for each received message.
667 * @param message the message
670 handle_dummy (void *cls,
671 const struct GNUNET_MessageHeader *message)
673 if (! benchmark_receive)
677 _("Received %u bytes\n"),
678 (unsigned int) ntohs (message->size));
679 if (0 == traffic_received)
680 start_time = GNUNET_TIME_absolute_get ();
681 traffic_received += ntohs (message->size);
686 * Convert address to a printable format.
688 * @param address the address
689 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
690 * to try to use reverse DNS
691 * @param state state the peer is in
692 * @param state_timeout when will the peer's state expire
695 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
697 enum GNUNET_TRANSPORT_PeerState state,
698 struct GNUNET_TIME_Absolute state_timeout);
702 print_info (const struct GNUNET_PeerIdentity *id,
703 const char *transport,
705 enum GNUNET_TRANSPORT_PeerState state,
706 struct GNUNET_TIME_Absolute state_timeout)
709 if ( ((GNUNET_YES == iterate_connections) &&
710 (GNUNET_YES == iterate_all)) ||
711 (GNUNET_YES == monitor_connections))
714 _("Peer `%s': %s %s in state `%s' until %s\n"),
716 (NULL == transport) ? "<none>" : transport,
717 (NULL == transport) ? "<none>" : addr,
718 GNUNET_TRANSPORT_ps2s (state),
719 GNUNET_STRINGS_absolute_time_to_string (state_timeout));
721 else if ( (GNUNET_YES == iterate_connections) &&
722 (GNUNET_TRANSPORT_is_connected(state)) )
724 /* Only connected peers, skip state */
726 _("Peer `%s': %s %s\n"),
735 * Function called with a textual representation of an address. This
736 * function will be called several times with different possible
737 * textual representations, and a last time with @a address being NULL
738 * to signal the end of the iteration. Note that @a address NULL
739 * always is the last call, regardless of the value in @a res.
742 * @param address NULL on end of iteration,
743 * otherwise 0-terminated printable UTF-8 string,
744 * in particular an empty string if @a res is #GNUNET_NO
745 * @param res result of the address to string conversion:
746 * if #GNUNET_OK: conversion successful
747 * if #GNUNET_NO: address was invalid (or not supported)
748 * if #GNUNET_SYSERR: communication error (IPC error)
751 process_peer_string (void *cls,
755 struct PeerResolutionContext *rc = cls;
759 if (GNUNET_SYSERR == res)
762 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
763 GNUNET_i2s (&rc->addrcp->peer),
764 rc->addrcp->transport_name,
765 (unsigned int) rc->addrcp->address_length);
766 print_info (&rc->addrcp->peer,
771 rc->printed = GNUNET_YES;
774 if (GNUNET_OK == res)
776 print_info (&rc->addrcp->peer,
781 rc->printed = GNUNET_YES;
782 return; /* Wait for done call */
784 /* GNUNET_NO == res: ignore, was simply not supported */
787 /* NULL == address, last call, we are done */
790 GNUNET_assert (address_resolutions > 0);
791 address_resolutions--;
792 if (GNUNET_NO == rc->printed)
794 if (numeric == GNUNET_NO)
796 /* Failed to resolve address, try numeric lookup
797 (note: this should not be needed, as transport
798 should fallback to numeric conversion if DNS takes
800 resolve_peer_address (rc->addrcp,
807 print_info (&rc->addrcp->peer,
814 GNUNET_free (rc->transport);
815 GNUNET_free (rc->addrcp);
816 GNUNET_CONTAINER_DLL_remove (rc_head,
820 if ((0 == address_resolutions) && (iterate_connections))
822 if (NULL != op_timeout)
824 GNUNET_SCHEDULER_cancel (op_timeout);
828 GNUNET_SCHEDULER_shutdown ();
834 * Convert address to a printable format and print it
835 * together with the given state data.
837 * @param address the address
838 * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO
839 * to try to use reverse DNS
840 * @param state state the peer is in
841 * @param state_timeout when will the peer's state expire
844 resolve_peer_address (const struct GNUNET_HELLO_Address *address,
846 enum GNUNET_TRANSPORT_PeerState state,
847 struct GNUNET_TIME_Absolute state_timeout)
849 struct PeerResolutionContext *rc;
851 rc = GNUNET_new (struct PeerResolutionContext);
852 GNUNET_CONTAINER_DLL_insert (rc_head,
855 address_resolutions++;
856 rc->transport = GNUNET_strdup (address->transport_name);
857 rc->addrcp = GNUNET_HELLO_address_copy (address);
858 rc->printed = GNUNET_NO;
860 rc->state_timeout = state_timeout;
861 /* Resolve address to string */
862 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
866 &process_peer_string,
872 * Function called with information about a peers during a one shot iteration
875 * @param peer identity of the peer, NULL for final callback when operation done
876 * @param address binary address used to communicate with this peer,
877 * NULL on disconnect or when done
878 * @param state current state this peer is in
879 * @param state_timeout time out for the current state
882 process_peer_iteration_cb (void *cls,
883 const struct GNUNET_PeerIdentity *peer,
884 const struct GNUNET_HELLO_Address *address,
885 enum GNUNET_TRANSPORT_PeerState state,
886 struct GNUNET_TIME_Absolute state_timeout)
895 if ( (GNUNET_NO == iterate_all) &&
896 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)))
897 return; /* Display only connected peers */
899 if (NULL != op_timeout)
900 GNUNET_SCHEDULER_cancel (op_timeout);
901 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
906 "Received address for peer `%s': %s\n",
908 address ? address->transport_name : "");
911 resolve_peer_address (address,
925 * Context for address resolution by #plugin_monitoring_cb().
927 struct PluginMonitorAddress
931 * Ongoing resolution request.
933 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
936 * Resolved address as string.
941 * Last event we got and did not yet print because
942 * @e str was NULL (address not yet resolved).
944 struct GNUNET_TRANSPORT_SessionInfo si;
949 * Print information about a plugin monitoring event.
951 * @param addr out internal context
952 * @param info the monitoring information
955 print_plugin_event_info (struct PluginMonitorAddress *addr,
956 const struct GNUNET_TRANSPORT_SessionInfo *info)
962 case GNUNET_TRANSPORT_SS_INIT:
965 case GNUNET_TRANSPORT_SS_HANDSHAKE:
968 case GNUNET_TRANSPORT_SS_UP:
971 case GNUNET_TRANSPORT_SS_UPDATE:
974 case GNUNET_TRANSPORT_SS_DONE:
982 "%s: state %s timeout in %s @ %s%s\n",
983 GNUNET_i2s (&info->address->peer),
985 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (info->session_timeout),
988 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
990 "%s: queue has %3u messages and %6u bytes\n",
991 GNUNET_i2s (&info->address->peer),
992 info->num_msg_pending,
993 info->num_bytes_pending);
994 if (0 != GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us)
996 "%s: receiving blocked until %s\n",
997 GNUNET_i2s (&info->address->peer),
998 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay));
1003 * Function called with a textual representation of an address. This
1004 * function will be called several times with different possible
1005 * textual representations, and a last time with @a address being NULL
1006 * to signal the end of the iteration. Note that @a address NULL
1007 * always is the last call, regardless of the value in @a res.
1009 * @param cls closure
1010 * @param address NULL on end of iteration,
1011 * otherwise 0-terminated printable UTF-8 string,
1012 * in particular an empty string if @a res is #GNUNET_NO
1013 * @param res result of the address to string conversion:
1014 * if #GNUNET_OK: conversion successful
1015 * if #GNUNET_NO: address was invalid (or not supported)
1016 * if #GNUNET_SYSERR: communication error (IPC error)
1019 address_cb (void *cls,
1020 const char *address,
1023 struct PluginMonitorAddress *addr = cls;
1025 if (NULL == address)
1030 if (NULL != addr->str)
1032 addr->str = GNUNET_strdup (address);
1033 print_plugin_event_info (addr,
1039 * Function called by the plugin with information about the
1040 * current sessions managed by the plugin (for monitoring).
1042 * @param cls closure (NULL)
1043 * @param session session handle this information is about,
1044 * NULL to indicate that we are "in sync" (initial
1045 * iteration complete)
1046 * @param session_ctx storage location where the application
1047 * can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT,
1048 * and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
1049 * @param info information about the state of the session,
1050 * NULL if @a session is also NULL and we are
1051 * merely signalling that the initial iteration is over;
1052 * NULL with @a session being non-NULL if the monitor
1053 * was being cancelled while sessions were active
1056 plugin_monitoring_cb (void *cls,
1057 struct GNUNET_TRANSPORT_PluginSession *session,
1059 const struct GNUNET_TRANSPORT_SessionInfo *info)
1061 struct PluginMonitorAddress *addr;
1063 if ( (NULL == info) &&
1065 return; /* in sync with transport service */
1066 addr = *session_ctx;
1071 if (NULL != addr->asc)
1073 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1076 GNUNET_free_non_null (addr->str);
1078 *session_ctx = NULL;
1080 return; /* shutdown */
1082 if (0 != memcmp (&info->address->peer,
1084 sizeof (struct GNUNET_PeerIdentity)))
1085 return; /* filtered */
1088 addr = GNUNET_new (struct PluginMonitorAddress);
1089 addr->asc = GNUNET_TRANSPORT_address_to_string (cfg,
1092 GNUNET_TIME_UNIT_FOREVER_REL,
1095 *session_ctx = addr;
1097 if (NULL == addr->str)
1100 print_plugin_event_info (addr,
1102 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1104 if (NULL != addr->asc)
1106 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1109 GNUNET_free_non_null (addr->str);
1111 *session_ctx = NULL;
1117 * Function called with information about a peers
1119 * @param cls closure, NULL
1120 * @param peer identity of the peer, NULL for final callback when operation done
1121 * @param address binary address used to communicate with this peer,
1122 * NULL on disconnect or when done
1123 * @param state current state this peer is in
1124 * @param state_timeout time out for the current state
1127 process_peer_monitoring_cb (void *cls,
1128 const struct GNUNET_PeerIdentity *peer,
1129 const struct GNUNET_HELLO_Address *address,
1130 enum GNUNET_TRANSPORT_PeerState state,
1131 struct GNUNET_TIME_Absolute state_timeout)
1133 struct MonitoredPeer *m;
1139 _("Monitor disconnected from transport service. Reconnecting.\n"));
1143 if (NULL != op_timeout)
1144 GNUNET_SCHEDULER_cancel (op_timeout);
1145 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1149 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers,
1152 m = GNUNET_new (struct MonitoredPeer);
1153 GNUNET_CONTAINER_multipeermap_put (monitored_peers,
1156 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1160 if ( (m->state == state) &&
1161 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1162 (NULL == address) &&
1163 (NULL == m->address) )
1165 return; /* No real change */
1167 if ( (m->state == state) &&
1168 (NULL != address) &&
1169 (NULL != m->address) &&
1170 (0 == GNUNET_HELLO_address_cmp(m->address, address)) )
1171 return; /* No real change */
1174 if (NULL != m->address)
1176 GNUNET_free (m->address);
1179 if (NULL != address)
1180 m->address = GNUNET_HELLO_address_copy (address);
1182 m->state_timeout = state_timeout;
1184 if (NULL != address)
1185 resolve_peer_address (m->address,
1199 * Function called with the transport service checking if we
1200 * want to blacklist a peer. Return #GNUNET_SYSERR for the
1201 * peer that we should disconnect from.
1204 * @param cpid peer to check blacklisting for
1205 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1208 blacklist_cb (void *cls,
1209 const struct GNUNET_PeerIdentity *cpid)
1211 if (0 == memcmp (cpid,
1213 sizeof (struct GNUNET_PeerIdentity)))
1214 return GNUNET_SYSERR;
1220 * Main function that will be run by the scheduler.
1222 * @param cls closure
1223 * @param args remaining command-line arguments
1224 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1225 * @param mycfg configuration
1230 const char *cfgfile,
1231 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1233 static struct GNUNET_PeerIdentity zero_pid;
1237 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1239 counter = benchmark_send + benchmark_receive + iterate_connections
1240 + monitor_connections + monitor_connects + do_disconnect +
1246 _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1249 "benchmark receive",
1259 _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1262 "benchmark receive",
1270 if (do_disconnect) /* -D: Disconnect from peer */
1272 if (0 == memcmp (&zero_pid,
1277 _("Option `%s' makes no sense without option `%s'.\n"),
1282 blacklist = GNUNET_TRANSPORT_blacklist (cfg,
1285 if (NULL == blacklist)
1289 _("Failed to connect to transport service for disconnection\n"));
1295 _("Blacklisting request in place, stop with CTRL-C\n"));
1297 else if (benchmark_send) /* -s: Benchmark sending */
1299 if (0 == memcmp (&zero_pid,
1304 _("Option `%s' makes no sense without option `%s'.\n"),
1309 handle = GNUNET_TRANSPORT_core_connect (cfg,
1320 _("Failed to connect to transport service\n"));
1324 start_time = GNUNET_TIME_absolute_get ();
1325 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1329 else if (benchmark_receive) /* -b: Benchmark receiving */
1331 struct GNUNET_MQ_MessageHandler handlers[] = {
1332 GNUNET_MQ_hd_var_size (dummy,
1333 GNUNET_MESSAGE_TYPE_DUMMY,
1334 struct GNUNET_MessageHeader,
1336 GNUNET_MQ_handler_end ()
1339 handle = GNUNET_TRANSPORT_core_connect (cfg,
1350 _("Failed to connect to transport service\n"));
1357 _("Starting to receive benchmark data\n"));
1358 start_time = GNUNET_TIME_absolute_get ();
1361 else if (iterate_connections) /* -i: List information about peers once */
1363 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1366 &process_peer_iteration_cb,
1368 op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
1372 else if (monitor_connections) /* -m: List information about peers continuously */
1374 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10,
1376 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1379 &process_peer_monitoring_cb,
1382 else if (monitor_plugins) /* -P: List information about plugins continuously */
1384 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1385 pm = GNUNET_TRANSPORT_monitor_plugins (cfg,
1386 &plugin_monitoring_cb,
1389 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1391 monitor_connect_counter = 0;
1392 handle = GNUNET_TRANSPORT_core_connect (cfg,
1396 &monitor_notify_connect,
1397 &monitor_notify_disconnect,
1403 _("Failed to connect to transport service\n"));
1415 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
1425 struct GNUNET_GETOPT_CommandLineOption options[] = {
1426 GNUNET_GETOPT_option_flag ('a',
1428 gettext_noop ("print information for all peers (instead of only connected peers)"),
1430 GNUNET_GETOPT_option_flag ('b',
1432 gettext_noop ("measure how fast we are receiving data from all peers (until CTRL-C)"),
1433 &benchmark_receive),
1434 GNUNET_GETOPT_option_flag ('D',
1436 gettext_noop ("disconnect from a peer"),
1438 GNUNET_GETOPT_option_flag ('i',
1440 gettext_noop ("provide information about all current connections (once)"),
1441 &iterate_connections),
1442 GNUNET_GETOPT_option_flag ('m',
1444 gettext_noop ("provide information about all current connections (continuously)"),
1445 &monitor_connections),
1446 GNUNET_GETOPT_option_flag ('e',
1448 gettext_noop ("provide information about all connects and disconnect events (continuously)"),
1450 GNUNET_GETOPT_option_flag ('n',
1452 gettext_noop ("do not resolve hostnames"),
1454 GNUNET_GETOPT_option_base32_auto ('p',
1457 gettext_noop ("peer identity"),
1459 GNUNET_GETOPT_option_flag ('P',
1461 gettext_noop ("monitor plugin sessions"),
1463 GNUNET_GETOPT_option_flag ('s',
1466 ("send data for benchmarking to the other peer (until CTRL-C)"),
1468 GNUNET_GETOPT_option_verbose (&verbosity),
1469 GNUNET_GETOPT_OPTION_END
1472 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1475 res = GNUNET_PROGRAM_run (argc, argv,
1477 gettext_noop ("Direct access to transport service."),
1480 GNUNET_free ((void *) argv);
1481 if (GNUNET_OK == res)
1486 /* end of gnunet-transport.c */