GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-transport.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_service.h"
Include dependency graph for gnunet-transport.c:

Go to the source code of this file.

Data Structures

struct  ValidationResolutionContext
 Context to store name resolutions for validation. More...
 
struct  MonitoredPeer
 Struct to store information about peers in monitor mode. More...
 
struct  PeerResolutionContext
 Context to store name resolutions for validation. More...
 
struct  PluginMonitorAddress
 Context for address resolution by plugin_monitoring_cb(). More...
 

Macros

#define RESOLUTION_TIMEOUT    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 Timeout for a name resolution.
 
#define OP_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
 Timeout for an operation.
 
#define BLOCKSIZE   4
 Benchmarking block size in KB.
 

Functions

static int destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Function called to release data stored in the monitored_peers map.
 
static void shutdown_task (void *cls)
 Task run in monitor mode when the user presses CTRL-C to abort.
 
static void operation_timeout (void *cls)
 We are done, shut down.
 
static void do_send (void *cls)
 Function called to notify a client about the socket begin ready to queue more data.
 
static void * notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Function called to notify transport users that another peer connected to us.
 
static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Function called to notify transport users that another peer disconnected from us.
 
static void * monitor_notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Function called to notify transport users that another peer connected to us.
 
static void monitor_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Function called to notify transport users that another peer disconnected from us.
 
static int check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
 Function called by the transport for each received message.
 
static void handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
 Function called by the transport for each received message.
 
static void resolve_peer_address (const struct GNUNET_HELLO_Address *address, int numeric, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
 Convert address to a printable format.
 
static void print_info (const struct GNUNET_PeerIdentity *id, const char *transport, const char *addr, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
 
static void process_peer_string (void *cls, const char *address, int res)
 Function called with a textual representation of an address.
 
static void process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
 Function called with information about a peers during a one shot iteration.
 
static void print_plugin_event_info (struct PluginMonitorAddress *addr, const struct GNUNET_TRANSPORT_SessionInfo *info)
 Print information about a plugin monitoring event.
 
static void address_cb (void *cls, const char *address, int res)
 Function called with a textual representation of an address.
 
static void plugin_monitoring_cb (void *cls, struct GNUNET_TRANSPORT_PluginSession *session, void **session_ctx, const struct GNUNET_TRANSPORT_SessionInfo *info)
 Function called by the plugin with information about the current sessions managed by the plugin (for monitoring).
 
static void process_peer_monitoring_cb (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
 Function called with information about a peers.
 
static int blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
 Function called with the transport service checking if we want to blacklist a peer.
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *mycfg)
 Main function that will be run by the scheduler.
 
int main (int argc, char *const *argv)
 

Variables

static struct GNUNET_TRANSPORT_CoreHandlehandle
 Handle to transport service.
 
static struct GNUNET_CONFIGURATION_Handlecfg
 Configuration handle.
 
struct GNUNET_TRANSPORT_Blacklist * blacklist
 Blacklisting handle.
 
static int benchmark_send
 Option -s.
 
static int benchmark_receive
 Option -b.
 
static int iterate_connections
 Option -i.
 
static int iterate_all
 Option -a.
 
static int monitor_connects
 Option -c.
 
static int monitor_connections
 Option -m.
 
static int monitor_plugins
 Option -P.
 
static int do_disconnect
 Option -D.
 
static int numeric
 Option -n.
 
static int ret
 Global return value (0 success).
 
static int monitor_connect_counter
 Current number of connections in monitor mode.
 
static unsigned long long traffic_received
 Number of bytes of traffic we received so far.
 
static unsigned long long traffic_sent
 Number of bytes of traffic we sent so far.
 
static struct GNUNET_TIME_Absolute start_time
 Starting time of transmitting/receiving data.
 
static struct GNUNET_CONTAINER_MultiPeerMapmonitored_peers
 Map storing information about monitored peers.
 
static struct GNUNET_CONTAINER_MultiPeerMapmonitored_plugins
 Map storing information about monitored plugins's sessions.
 
static struct GNUNET_TRANSPORT_PeerMonitoringContext * pic
 Handle if we are monitoring peers at the transport level.
 
static struct GNUNET_TRANSPORT_PluginMonitor * pm
 Handle if we are monitoring plugin session activity.
 
static struct GNUNET_PeerIdentity pid
 Identity of the peer we transmit to / connect to.
 
static struct GNUNET_SCHEDULER_Taskop_timeout
 Task for operation timeout.
 
static unsigned int verbosity
 Selected level of verbosity.
 
struct GNUNET_OS_Processresolver
 Resolver process handle.
 
static unsigned int address_resolutions
 Number of address resolutions pending.
 
static struct ValidationResolutionContextvc_head
 DLL: head of validation resolution entries.
 
static struct ValidationResolutionContextvc_tail
 DLL: tail of validation resolution entries.
 
static struct PeerResolutionContextrc_head
 DLL: head of resolution entries.
 
static struct PeerResolutionContextrc_tail
 DLL: head of resolution entries.
 

Macro Definition Documentation

◆ RESOLUTION_TIMEOUT

#define RESOLUTION_TIMEOUT    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)

Timeout for a name resolution.

Definition at line 36 of file gnunet-transport.c.

48{
53
58
62 struct GNUNET_HELLO_Address *addrcp;
63
67 struct GNUNET_TIME_Absolute last_validation;
68
72 struct GNUNET_TIME_Absolute valid_until;
73
77 struct GNUNET_TIME_Absolute next_validation;
78
82 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
83
87 char *transport;
88
92 int printed;
93};
94
98struct MonitoredPeer
99{
103 enum GNUNET_TRANSPORT_PeerState state;
104
109
113 struct GNUNET_HELLO_Address *address;
114};
115
120{
125
130
134 struct GNUNET_HELLO_Address *addrcp;
135
139 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
140
144 enum GNUNET_TRANSPORT_PeerState state;
145
150
154 char *transport;
155
159 int printed;
160};
161
162
166#define BLOCKSIZE 4
167
172
176static struct GNUNET_CONFIGURATION_Handle *cfg;
177
181struct GNUNET_TRANSPORT_Blacklist *blacklist;
182
186static int benchmark_send;
187
191static int benchmark_receive;
192
196static int benchmark_receive;
197
201static int iterate_connections;
202
206static int iterate_all;
207
211static int monitor_connects;
212
216static int monitor_connections;
217
221static int monitor_plugins;
222
226static int do_disconnect;
227
231static int numeric;
232
236static int ret;
237
241static int monitor_connect_counter;
242
246static unsigned long long traffic_received;
247
251static unsigned long long traffic_sent;
252
256static struct GNUNET_TIME_Absolute start_time;
257
262
267
271static struct GNUNET_TRANSPORT_PeerMonitoringContext *pic;
272
276static struct GNUNET_TRANSPORT_PluginMonitor *pm;
277
282static struct GNUNET_PeerIdentity pid;
283
287static struct GNUNET_SCHEDULER_Task *op_timeout;
288
292static unsigned int verbosity;
293
298
302static unsigned int address_resolutions;
303
308
313
317static struct PeerResolutionContext *rc_head;
318
322static struct PeerResolutionContext *rc_tail;
323
324
333static int
334destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
335{
336 struct MonitoredPeer *m = value;
337
339 GNUNET_OK ==
341 GNUNET_free (m->address);
343 return GNUNET_OK;
344}
345
346
353static void
354shutdown_task (void *cls)
355{
357 struct ValidationResolutionContext *cur;
359 struct PeerResolutionContext *rc;
360
361 if (NULL != op_timeout)
362 {
364 op_timeout = NULL;
365 }
366 if (NULL != pic)
367 {
368 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
369 pic = NULL;
370 }
371 if (NULL != pm)
372 {
373 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
374 pm = NULL;
375 }
376
377 next = vc_head;
378 for (cur = next; NULL != cur; cur = next)
379 {
380 next = cur->next;
381
382 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
384 GNUNET_free (cur->transport);
385 GNUNET_HELLO_address_free (cur->addrcp);
386 GNUNET_free (cur);
387 }
388 while (NULL != (rc = rc_head))
389 {
391 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
393 GNUNET_free (rc->addrcp);
394 GNUNET_free (rc);
395 }
396 if (NULL != handle)
397 {
399 handle = NULL;
400 }
401 if (benchmark_send)
402 {
404 fprintf (stdout,
405 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
406 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
409 }
411 {
413 fprintf (stdout,
414 _ ("Received %llu bytes/s (%llu bytes in %s)\n"),
415 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
418 }
419
420 if (NULL != monitored_peers)
421 {
424 monitored_peers = NULL;
425 }
426 if (NULL != monitored_plugins)
427 {
430 monitored_plugins = NULL;
431 }
432 if (NULL != blacklist)
433 {
434 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
435 blacklist = NULL;
436 ret = 0;
437 }
438}
439
440
444static void
445operation_timeout (void *cls)
446{
447 struct PeerResolutionContext *cur;
449
450 op_timeout = NULL;
452 {
453 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
455 ret = 1;
456 return;
457 }
459 {
460 next = rc_head;
461 while (NULL != (cur = next))
462 {
463 next = cur->next;
464 fprintf (stdout,
465 _ ("Failed to resolve address for peer `%s'\n"),
466 GNUNET_i2s (&cur->addrcp->peer));
467
469 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
470 GNUNET_free (cur->transport);
471 GNUNET_free (cur->addrcp);
472 GNUNET_free (cur);
473 }
474 fprintf (stdout,
475 "%s",
476 _ ("Failed to list connections, timeout occurred\n"));
478 ret = 1;
479 return;
480 }
481}
482
483
490static void
491do_send (void *cls)
492{
493 struct GNUNET_MQ_Handle *mq = cls;
494 struct GNUNET_MessageHeader *m;
495 struct GNUNET_MQ_Envelope *env;
496
498 memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
499 traffic_sent += BLOCKSIZE * 1024;
501 if (verbosity > 0)
502 fprintf (stdout,
503 _ ("Transmitting %u bytes\n"),
504 (unsigned int) BLOCKSIZE * 1024);
506}
507
508
517static void *
518notify_connect (void *cls,
519 const struct GNUNET_PeerIdentity *peer,
520 struct GNUNET_MQ_Handle *mq)
521{
522 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
523 return NULL;
524 ret = 0;
525 if (! benchmark_send)
526 return NULL;
527 if (NULL != op_timeout)
528 {
530 op_timeout = NULL;
531 }
532 if (verbosity > 0)
533 fprintf (
534 stdout,
535 _ (
536 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
537 GNUNET_i2s (peer),
538 BLOCKSIZE);
540 do_send (mq);
541 return mq;
542}
543
544
553static void
554notify_disconnect (void *cls,
555 const struct GNUNET_PeerIdentity *peer,
556 void *internal_cls)
557{
558 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
559 return;
560 if (NULL == internal_cls)
561 return; /* not about target peer */
562 if (! benchmark_send)
563 return; /* not transmitting */
564 fprintf (stdout,
565 _ ("Disconnected from peer `%s' while benchmarking\n"),
566 GNUNET_i2s (&pid));
567}
568
569
579static void *
580monitor_notify_connect (void *cls,
581 const struct GNUNET_PeerIdentity *peer,
582 struct GNUNET_MQ_Handle *mq)
583{
585 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
586
588 fprintf (stdout,
589 _ ("%24s: %-17s %4s (%u connections in total)\n"),
590 now_str,
591 _ ("Connected to"),
592 GNUNET_i2s (peer),
594 return NULL;
595}
596
597
606static void
608 const struct GNUNET_PeerIdentity *peer,
609 void *internal_cls)
610{
612 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
613
616
617 fprintf (stdout,
618 _ ("%24s: %-17s %4s (%u connections in total)\n"),
619 now_str,
620 _ ("Disconnected from"),
621 GNUNET_i2s (peer),
623}
624
625
633static int
634check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
635{
636 return GNUNET_OK; /* all messages are fine */
637}
638
639
646static void
647handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
648{
649 if (! benchmark_receive)
650 return;
651 if (verbosity > 0)
652 fprintf (stdout,
653 _ ("Received %u bytes\n"),
654 (unsigned int) ntohs (message->size));
655 if (0 == traffic_received)
657 traffic_received += ntohs (message->size);
658}
659
660
670static void
671resolve_peer_address (const struct GNUNET_HELLO_Address *address,
672 int numeric,
673 enum GNUNET_TRANSPORT_PeerState state,
674 struct GNUNET_TIME_Absolute state_timeout);
675
676
677static void
678print_info (const struct GNUNET_PeerIdentity *id,
679 const char *transport,
680 const char *addr,
681 enum GNUNET_TRANSPORT_PeerState state,
682 struct GNUNET_TIME_Absolute state_timeout)
683{
686 {
687 fprintf (stdout,
688 _ ("Peer `%s': %s %s in state `%s' until %s\n"),
689 GNUNET_i2s (id),
690 (NULL == transport) ? "<none>" : transport,
691 (NULL == transport) ? "<none>" : addr,
692 GNUNET_TRANSPORT_ps2s (state),
694 }
695 else if ((GNUNET_YES == iterate_connections) &&
696 (GNUNET_TRANSPORT_is_connected (state)))
697 {
698 /* Only connected peers, skip state */
699 fprintf (stdout,
700 _ ("Peer `%s': %s %s\n"),
701 GNUNET_i2s (id),
702 transport,
703 addr);
704 }
705}
706
707
724static void
725process_peer_string (void *cls, const char *address, int res)
726{
727 struct PeerResolutionContext *rc = cls;
728
729 if (NULL != address)
730 {
731 if (GNUNET_SYSERR == res)
732 {
733 fprintf (
734 stderr,
735 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
736 GNUNET_i2s (&rc->addrcp->peer),
737 rc->addrcp->transport_name,
738 (unsigned int) rc->addrcp->address_length);
739 print_info (&rc->addrcp->peer,
740 rc->transport,
741 NULL,
742 rc->state,
743 rc->state_timeout);
744 rc->printed = GNUNET_YES;
745 return;
746 }
747 if (GNUNET_OK == res)
748 {
749 print_info (&rc->addrcp->peer,
750 rc->transport,
751 address,
752 rc->state,
753 rc->state_timeout);
754 rc->printed = GNUNET_YES;
755 return; /* Wait for done call */
756 }
757 /* GNUNET_NO == res: ignore, was simply not supported */
758 return;
759 }
760 /* NULL == address, last call, we are done */
761
762 rc->asc = NULL;
765 if (GNUNET_NO == rc->printed)
766 {
767 if (numeric == GNUNET_NO)
768 {
769 /* Failed to resolve address, try numeric lookup
770 (note: this should not be needed, as transport
771 should fallback to numeric conversion if DNS takes
772 too long) */
775 rc->state,
776 rc->state_timeout);
777 }
778 else
779 {
780 print_info (&rc->addrcp->peer,
781 rc->transport,
782 NULL,
783 rc->state,
784 rc->state_timeout);
785 }
786 }
788 GNUNET_free (rc->addrcp);
790 GNUNET_free (rc);
792 {
793 if (NULL != op_timeout)
794 {
796 op_timeout = NULL;
797 }
798 ret = 0;
800 }
801}
802
803
814static void
815resolve_peer_address (const struct GNUNET_HELLO_Address *address,
816 int numeric,
817 enum GNUNET_TRANSPORT_PeerState state,
819{
820 struct PeerResolutionContext *rc;
821
822 rc = GNUNET_new (struct PeerResolutionContext);
825 rc->transport = GNUNET_strdup (address->transport_name);
826 rc->addrcp = GNUNET_HELLO_address_copy (address);
827 rc->printed = GNUNET_NO;
828 rc->state = state;
830 /* Resolve address to string */
831 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
832 address,
833 numeric,
836 rc);
837}
838
839
850static void
852 const struct GNUNET_PeerIdentity *peer,
853 const struct GNUNET_HELLO_Address *address,
854 enum GNUNET_TRANSPORT_PeerState state,
856{
857 if (NULL == peer)
858 {
859 /* done */
860 pic = NULL;
861 return;
862 }
863
864 if ((GNUNET_NO == iterate_all) &&
865 (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state)))
866 return; /* Display only connected peers */
867
868 if (NULL != op_timeout)
870 op_timeout =
872
874 "Received address for peer `%s': %s\n",
875 GNUNET_i2s (peer),
876 address ? address->transport_name : "");
877
878 if (NULL != address)
880 else
881 print_info (peer, NULL, NULL, state, state_timeout);
882}
883
884
889{
893 struct GNUNET_TRANSPORT_AddressToStringContext *asc;
894
898 char *str;
899
904 struct GNUNET_TRANSPORT_SessionInfo si;
905};
906
907
914static void
916 const struct GNUNET_TRANSPORT_SessionInfo *info)
917{
918 const char *state;
919
920 switch (info->state)
921 {
922 case GNUNET_TRANSPORT_SS_INIT:
923 state = "INIT";
924 break;
925
926 case GNUNET_TRANSPORT_SS_HANDSHAKE:
927 state = "HANDSHAKE";
928 break;
929
930 case GNUNET_TRANSPORT_SS_UP:
931 state = "UP";
932 break;
933
934 case GNUNET_TRANSPORT_SS_UPDATE:
935 state = "UPDATE";
936 break;
937
938 case GNUNET_TRANSPORT_SS_DONE:
939 state = "DONE";
940 break;
941
942 default:
943 state = "UNKNOWN";
944 break;
945 }
946 fprintf (stdout,
947 "%s: state %s timeout in %s @ %s%s\n",
948 GNUNET_i2s (&info->address->peer),
949 state,
951 GNUNET_TIME_absolute_get_remaining (info->session_timeout),
952 GNUNET_YES),
953 addr->str,
954 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
955 fprintf (stdout,
956 "%s: queue has %3u messages and %6u bytes\n",
957 GNUNET_i2s (&info->address->peer),
958 info->num_msg_pending,
959 info->num_bytes_pending);
960 if (0 !=
962 fprintf (stdout,
963 "%s: receiving blocked until %s\n",
964 GNUNET_i2s (&info->address->peer),
966}
967
968
985static void
986address_cb (void *cls, const char *address, int res)
987{
988 struct PluginMonitorAddress *addr = cls;
989
990 if (NULL == address)
991 {
992 addr->asc = NULL;
993 return;
994 }
995 if (NULL != addr->str)
996 return;
997 addr->str = GNUNET_strdup (address);
998 print_plugin_event_info (addr, &addr->si);
999}
1000
1001
1019static void
1020plugin_monitoring_cb (void *cls,
1021 struct GNUNET_TRANSPORT_PluginSession *session,
1022 void **session_ctx,
1023 const struct GNUNET_TRANSPORT_SessionInfo *info)
1024{
1025 struct PluginMonitorAddress *addr;
1026
1027 if ((NULL == info) && (NULL == session))
1028 return; /* in sync with transport service */
1029 addr = *session_ctx;
1030 if (NULL == info)
1031 {
1032 if (NULL != addr)
1033 {
1034 if (NULL != addr->asc)
1035 {
1036 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1037 addr->asc = NULL;
1038 }
1039 GNUNET_free (addr->str);
1040 GNUNET_free (addr);
1041 *session_ctx = NULL;
1042 }
1043 return; /* shutdown */
1044 }
1045 if (0 !=
1046 memcmp (&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity)))
1047 return; /* filtered */
1048 if (NULL == addr)
1049 {
1050 addr = GNUNET_new (struct PluginMonitorAddress);
1051 addr->asc =
1052 GNUNET_TRANSPORT_address_to_string (cfg,
1053 info->address,
1054 numeric,
1056 &address_cb,
1057 addr);
1058 *session_ctx = addr;
1059 }
1060 if (NULL == addr->str)
1061 addr->si = *info;
1062 else
1064 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1065 {
1066 if (NULL != addr->asc)
1067 {
1068 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1069 addr->asc = NULL;
1070 }
1071 GNUNET_free (addr->str);
1072 GNUNET_free (addr);
1073 *session_ctx = NULL;
1074 }
1075}
1076
1077
1088static void
1090 const struct GNUNET_PeerIdentity *peer,
1091 const struct GNUNET_HELLO_Address *address,
1092 enum GNUNET_TRANSPORT_PeerState state,
1093 struct GNUNET_TIME_Absolute state_timeout)
1094{
1095 struct MonitoredPeer *m;
1096
1097 if (NULL == peer)
1098 {
1099 fprintf (stdout,
1100 "%s",
1101 _ (
1102 "Monitor disconnected from transport service. Reconnecting.\n"));
1103 return;
1104 }
1105
1106 if (NULL != op_timeout)
1108 op_timeout =
1110
1111 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1112 {
1113 m = GNUNET_new (struct MonitoredPeer);
1116 peer,
1117 m,
1119 }
1120 else
1121 {
1122 if ((m->state == state) &&
1123 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1124 (NULL == address) && (NULL == m->address))
1125 {
1126 return; /* No real change */
1127 }
1128 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1129 (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1130 return; /* No real change */
1131 }
1132
1133 if (NULL != m->address)
1134 {
1135 GNUNET_free (m->address);
1136 m->address = NULL;
1137 }
1138 if (NULL != address)
1139 m->address = GNUNET_HELLO_address_copy (address);
1140 m->state = state;
1141 m->state_timeout = state_timeout;
1142
1143 if (NULL != address)
1144 resolve_peer_address (m->address, numeric, m->state, m->state_timeout);
1145 else
1146 print_info (peer, NULL, NULL, m->state, m->state_timeout);
1147}
1148
1149
1159static int
1160blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
1161{
1162 if (0 == memcmp (cpid, &pid, sizeof(struct GNUNET_PeerIdentity)))
1163 return GNUNET_SYSERR;
1164 return GNUNET_OK;
1165}
1166
1167
1176static void
1177run (void *cls,
1178 char *const *args,
1179 const char *cfgfile,
1180 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1181{
1182 static struct GNUNET_PeerIdentity zero_pid;
1183 int counter = 0;
1184
1185 ret = 1;
1186
1187 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1188
1192
1193 if (1 < counter)
1194 {
1195 fprintf (
1196 stderr,
1197 _ (
1198 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1199 "disconnect",
1200 "benchmark send",
1201 "benchmark receive",
1202 "information",
1203 "monitor",
1204 "events",
1205 "plugins");
1206 return;
1207 }
1208 if (0 == counter)
1209 {
1210 fprintf (
1211 stderr,
1212 _ (
1213 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1214 "disconnect",
1215 "benchmark send",
1216 "benchmark receive",
1217 "information",
1218 "monitor",
1219 "events",
1220 "plugins");
1221 return;
1222 }
1223
1224 if (do_disconnect) /* -D: Disconnect from peer */
1225 {
1226 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1227 {
1228 fprintf (stderr,
1229 _ ("Option `%s' makes no sense without option `%s'.\n"),
1230 "-D",
1231 "-p");
1232 ret = 1;
1233 return;
1234 }
1235 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1236 if (NULL == blacklist)
1237 {
1238 fprintf (stderr,
1239 "%s",
1240 _ (
1241 "Failed to connect to transport service for disconnection\n"));
1242 ret = 1;
1243 return;
1244 }
1245 fprintf (stdout,
1246 "%s",
1247 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1248 }
1249 else if (benchmark_send) /* -s: Benchmark sending */
1250 {
1251 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1252 {
1253 fprintf (stderr,
1254 _ ("Option `%s' makes no sense without option `%s'.\n"),
1255 "-s",
1256 "-p");
1257 ret = 1;
1258 return;
1259 }
1261 NULL,
1262 NULL,
1263 NULL,
1266 NULL);
1267 if (NULL == handle)
1268 {
1269 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1270 ret = 1;
1271 return;
1272 }
1274 op_timeout =
1276 }
1277 else if (benchmark_receive) /* -b: Benchmark receiving */
1278 {
1282 struct GNUNET_MessageHeader,
1283 NULL),
1285
1287 NULL,
1288 handlers,
1289 NULL,
1290 NULL,
1291 NULL,
1292 NULL);
1293 if (NULL == handle)
1294 {
1295 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1296 ret = 1;
1297 return;
1298 }
1299 if (verbosity > 0)
1300 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1302 }
1303 else if (iterate_connections) /* -i: List information about peers once */
1304 {
1305 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1306 &pid,
1307 GNUNET_YES,
1309 (void *) cfg);
1310 op_timeout =
1312 }
1313 else if (monitor_connections) /* -m: List information about peers continuously
1314 */
1315 {
1317 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1318 &pid,
1319 GNUNET_NO,
1321 NULL);
1322 }
1323 else if (monitor_plugins) /* -P: List information about plugins continuously
1324 */
1325 {
1327 pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL);
1328 }
1329 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1330 {
1333 NULL,
1334 NULL,
1335 NULL,
1338 NULL);
1339 if (NULL == handle)
1340 {
1341 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1342 ret = 1;
1343 return;
1344 }
1345 ret = 0;
1346 }
1347 else
1348 {
1349 GNUNET_break (0);
1350 return;
1351 }
1352
1354}
1355
1356
1357int
1358main (int argc, char *const *argv)
1359{
1360 int res;
1363 'a',
1364 "all",
1365 gettext_noop (
1366 "print information for all peers (instead of only connected peers)"),
1367 &iterate_all),
1369 'b',
1370 "benchmark",
1371 gettext_noop (
1372 "measure how fast we are receiving data from all peers (until CTRL-C)"),
1375 "disconnect",
1376 gettext_noop ("disconnect from a peer"),
1377 &do_disconnect),
1379 'i',
1380 "information",
1381 gettext_noop (
1382 "provide information about all current connections (once)"),
1385 'm',
1386 "monitor",
1387 gettext_noop (
1388 "provide information about all current connections (continuously)"),
1391 'e',
1392 "events",
1393 gettext_noop (
1394 "provide information about all connects and disconnect events (continuously)"),
1397 "numeric",
1398 gettext_noop ("do not resolve hostnames"),
1399 &numeric),
1401 "peer",
1402 "PEER",
1403 gettext_noop ("peer identity"),
1404 &pid),
1406 "plugins",
1407 gettext_noop ("monitor plugin sessions"),
1410 's',
1411 "send",
1412 gettext_noop (
1413 "send data for benchmarking to the other peer (until CTRL-C)"),
1417
1418 res =
1419 GNUNET_PROGRAM_run (argc,
1420 argv,
1421 "gnunet-transport",
1422 gettext_noop ("Direct access to transport service."),
1423 options,
1424 &run,
1425 NULL);
1426 if (GNUNET_OK == res)
1427 return ret;
1428 return 1;
1429}
1430
1431
1432/* end of gnunet-transport.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
static char * address
GNS address for this phone.
struct GNUNET_HashCode key
The key used in the DHT.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
struct GNUNET_SCHEDULER_Task * shutdown_task
static int state
The current state of the parser.
static char * res
Currently read line or NULL on EOF.
static char * value
Value of the record to add/remove.
#define info
struct GNUNET_TRANSPORT_ApplicationHandle * transport
Handle to Transport service.
static void print_info(const struct GNUNET_PeerIdentity *id, const char *transport, const char *addr, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
static int benchmark_send
Option -s.
static int monitor_connections
Option -m.
static struct PeerResolutionContext * rc_tail
DLL: head of resolution entries.
static void process_peer_monitoring_cb(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
Function called with information about a peers.
static unsigned int verbosity
Selected level of verbosity.
struct GNUNET_TRANSPORT_Blacklist * blacklist
Blacklisting handle.
#define OP_TIMEOUT
Timeout for an operation.
static unsigned int address_resolutions
Number of address resolutions pending.
static void process_peer_string(void *cls, const char *address, int res)
Function called with a textual representation of an address.
static unsigned long long traffic_sent
Number of bytes of traffic we sent so far.
static int monitor_plugins
Option -P.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static void address_cb(void *cls, const char *address, int res)
Function called with a textual representation of an address.
static int numeric
Option -n.
static struct ValidationResolutionContext * vc_tail
DLL: tail of validation resolution entries.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *mycfg)
Main function that will be run by the scheduler.
static int monitor_connect_counter
Current number of connections in monitor mode.
static struct GNUNET_TIME_Absolute start_time
Starting time of transmitting/receiving data.
static struct GNUNET_TRANSPORT_CoreHandle * handle
Handle to transport service.
static void do_send(void *cls)
Function called to notify a client about the socket begin ready to queue more data.
static void * monitor_notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
static int ret
Global return value (0 success).
static struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
static void * notify_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
static void plugin_monitoring_cb(void *cls, struct GNUNET_TRANSPORT_PluginSession *session, void **session_ctx, const struct GNUNET_TRANSPORT_SessionInfo *info)
Function called by the plugin with information about the current sessions managed by the plugin (for ...
static struct GNUNET_CONTAINER_MultiPeerMap * monitored_plugins
Map storing information about monitored plugins's sessions.
static struct GNUNET_TRANSPORT_PeerMonitoringContext * pic
Handle if we are monitoring peers at the transport level.
static int monitor_connects
Option -c.
static int iterate_all
Option -a.
static struct PeerResolutionContext * rc_head
DLL: head of resolution entries.
static void print_plugin_event_info(struct PluginMonitorAddress *addr, const struct GNUNET_TRANSPORT_SessionInfo *info)
Print information about a plugin monitoring event.
static void handle_dummy(void *cls, const struct GNUNET_MessageHeader *message)
Function called by the transport for each received message.
struct GNUNET_OS_Process * resolver
Resolver process handle.
static void operation_timeout(void *cls)
We are done, shut down.
static int do_disconnect
Option -D.
static void process_peer_iteration_cb(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
Function called with information about a peers during a one shot iteration.
static void notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Function called to notify transport users that another peer disconnected from us.
static struct ValidationResolutionContext * vc_head
DLL: head of validation resolution entries.
static int check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
Function called by the transport for each received message.
static int blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid)
Function called with the transport service checking if we want to blacklist a peer.
static struct GNUNET_CONTAINER_MultiPeerMap * monitored_peers
Map storing information about monitored peers.
static int benchmark_receive
Option -b.
static int iterate_connections
Option -i.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
static struct GNUNET_SCHEDULER_Task * op_timeout
Task for operation timeout.
static unsigned long long traffic_received
Number of bytes of traffic we received so far.
static int destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function called to release data stored in the monitored_peers map.
static void monitor_notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Function called to notify transport users that another peer disconnected from us.
#define RESOLUTION_TIMEOUT
Timeout for a name resolution.
static void resolve_peer_address(const struct GNUNET_HELLO_Address *address, int numeric, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
Convert address to a printable format.
#define BLOCKSIZE
Benchmarking block size in KB.
static struct GNUNET_TIME_Relative duration
Option '-d': duration of the mapping.
Definition gnunet-vpn.c:90
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_GETOPT_option_base32_auto(shortName, name, argumentHelp, description, val)
Allow user to specify a binary value using Crockford Base32 encoding where the size of the binary val...
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
#define GNUNET_log(kind,...)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition mq.c:655
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
#define GNUNET_MESSAGE_TYPE_DUMMY
Dummy messages for testing / benchmarking.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1277
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition time.c:438
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition strings.c:599
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:660
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Internal representation of the hash map.
Definition of a command line option.
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
Header for all communications.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:136
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Handle for the transport service (includes all of the state for the transport service).
Struct to store information about peers in monitor mode.
enum GNUNET_TRANSPORT_PeerState state
State of the peer.
struct GNUNET_TIME_Absolute state_timeout
Timeout.
struct GNUNET_HELLO_Address * address
The address to convert.
Context to store name resolutions for validation.
struct PeerResolutionContext * next
Next in DLL.
int printed
was the entry printed
struct GNUNET_HELLO_Address * addrcp
address to resolve
struct PeerResolutionContext * prev
Prev in DLL.
struct GNUNET_TIME_Absolute state_timeout
state timeout
enum GNUNET_TRANSPORT_PeerState state
peer state
struct GNUNET_TRANSPORT_AddressToStringContext * asc
transport conversiion context
char * transport
transport plugin
Context for address resolution by plugin_monitoring_cb().
char * str
Resolved address as string.
struct GNUNET_TRANSPORT_AddressToStringContext * asc
Ongoing resolution request.
struct GNUNET_TRANSPORT_SessionInfo si
Last event we got and did not yet print because str was NULL (address not yet resolved).
Context to store name resolutions for validation.
struct GNUNET_TRANSPORT_AddressToStringContext * asc
Transport conversion handle.
struct ValidationResolutionContext * next
Next in DLL.
struct ValidationResolutionContext * prev
Previous in DLL.
struct GNUNET_HELLO_Address * addrcp
Address to resolve.

◆ OP_TIMEOUT

Timeout for an operation.

Definition at line 42 of file gnunet-transport.c.

◆ BLOCKSIZE

#define BLOCKSIZE   4

Benchmarking block size in KB.

Definition at line 167 of file gnunet-transport.c.

Function Documentation

◆ destroy_it()

static int destroy_it ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Function called to release data stored in the monitored_peers map.

Parameters
clsunused
keythe peer identity
valuea struct MonitoredPeer to release
Returns
GNUNET_OK (continue to iterate)

Definition at line 335 of file gnunet-transport.c.

336{
337 struct MonitoredPeer *m = value;
338
340 GNUNET_OK ==
342 GNUNET_free (m->address);
344 return GNUNET_OK;
345}

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_OK, key, m, monitored_peers, and value.

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run in monitor mode when the user presses CTRL-C to abort.

Stops monitoring activity.

Parameters
clsNULL

Definition at line 355 of file gnunet-transport.c.

356{
358 struct ValidationResolutionContext *cur;
360 struct PeerResolutionContext *rc;
361
362 if (NULL != op_timeout)
363 {
365 op_timeout = NULL;
366 }
367 if (NULL != pic)
368 {
369 GNUNET_TRANSPORT_monitor_peers_cancel (pic);
370 pic = NULL;
371 }
372 if (NULL != pm)
373 {
374 GNUNET_TRANSPORT_monitor_plugins_cancel (pm);
375 pm = NULL;
376 }
377
378 next = vc_head;
379 for (cur = next; NULL != cur; cur = next)
380 {
381 next = cur->next;
382
383 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
385 GNUNET_free (cur->transport);
386 GNUNET_HELLO_address_free (cur->addrcp);
387 GNUNET_free (cur);
388 }
389 while (NULL != (rc = rc_head))
390 {
392 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc);
394 GNUNET_free (rc->addrcp);
395 GNUNET_free (rc);
396 }
397 if (NULL != handle)
398 {
400 handle = NULL;
401 }
402 if (benchmark_send)
403 {
405 fprintf (stdout,
406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
410 }
412 {
414 fprintf (stdout,
415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"),
416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
419 }
420
421 if (NULL != monitored_peers)
422 {
425 monitored_peers = NULL;
426 }
427 if (NULL != monitored_plugins)
428 {
431 monitored_plugins = NULL;
432 }
433 if (NULL != blacklist)
434 {
435 GNUNET_TRANSPORT_blacklist_cancel (blacklist);
436 blacklist = NULL;
437 ret = 0;
438 }
439}

References _, ValidationResolutionContext::addrcp, PeerResolutionContext::addrcp, ValidationResolutionContext::asc, PeerResolutionContext::asc, benchmark_receive, benchmark_send, blacklist, destroy_it(), duration, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TRANSPORT_core_disconnect(), GNUNET_YES, handle, monitored_peers, monitored_plugins, ValidationResolutionContext::next, PeerResolutionContext::next, op_timeout, pic, pm, rc_head, rc_tail, GNUNET_TIME_Relative::rel_value_us, ret, start_time, traffic_received, traffic_sent, ValidationResolutionContext::transport, PeerResolutionContext::transport, vc_head, and vc_tail.

Here is the call graph for this function:

◆ operation_timeout()

static void operation_timeout ( void *  cls)
static

We are done, shut down.

Definition at line 446 of file gnunet-transport.c.

447{
448 struct PeerResolutionContext *cur;
450
451 op_timeout = NULL;
453 {
454 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid));
456 ret = 1;
457 return;
458 }
460 {
461 next = rc_head;
462 while (NULL != (cur = next))
463 {
464 next = cur->next;
465 fprintf (stdout,
466 _ ("Failed to resolve address for peer `%s'\n"),
467 GNUNET_i2s (&cur->addrcp->peer));
468
470 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc);
471 GNUNET_free (cur->transport);
472 GNUNET_free (cur->addrcp);
473 GNUNET_free (cur);
474 }
475 fprintf (stdout,
476 "%s",
477 _ ("Failed to list connections, timeout occurred\n"));
479 ret = 1;
480 return;
481 }
482}

References _, PeerResolutionContext::addrcp, PeerResolutionContext::asc, benchmark_receive, benchmark_send, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_i2s(), GNUNET_i2s_full(), GNUNET_SCHEDULER_shutdown(), iterate_connections, PeerResolutionContext::next, op_timeout, pid, rc_head, rc_tail, ret, and PeerResolutionContext::transport.

Referenced by process_peer_iteration_cb(), process_peer_monitoring_cb(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_send()

static void do_send ( void *  cls)
static

Function called to notify a client about the socket begin ready to queue more data.

Sends another message.

Parameters
clsclosure with the message queue

Definition at line 492 of file gnunet-transport.c.

493{
494 struct GNUNET_MQ_Handle *mq = cls;
495 struct GNUNET_MessageHeader *m;
496 struct GNUNET_MQ_Envelope *env;
497
499 memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
500 traffic_sent += BLOCKSIZE * 1024;
502 if (verbosity > 0)
503 fprintf (stdout,
504 _ ("Transmitting %u bytes\n"),
505 (unsigned int) BLOCKSIZE * 1024);
507}

References _, BLOCKSIZE, do_send(), env, GNUNET_MESSAGE_TYPE_DUMMY, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), m, mq, traffic_sent, and verbosity.

Referenced by do_send(), and notify_connect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_connect()

static void * notify_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Function called to notify transport users that another peer connected to us.

Parameters
clsclosure
peerthe peer that connected
mqmessage queue for sending to peer

Definition at line 519 of file gnunet-transport.c.

522{
523 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
524 return NULL;
525 ret = 0;
526 if (! benchmark_send)
527 return NULL;
528 if (NULL != op_timeout)
529 {
531 op_timeout = NULL;
532 }
533 if (verbosity > 0)
534 fprintf (
535 stdout,
536 _ (
537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
538 GNUNET_i2s (peer),
539 BLOCKSIZE);
541 do_send (mq);
542 return mq;
543}

References _, benchmark_send, BLOCKSIZE, do_send(), GNUNET_i2s(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get(), mq, op_timeout, pid, ret, start_time, and verbosity.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_disconnect()

static void notify_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Function called to notify transport users that another peer disconnected from us.

Parameters
clsclosure
peerthe peer that disconnected
internal_clswhat we returned from notify_connect()

Definition at line 555 of file gnunet-transport.c.

558{
559 if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
560 return;
561 if (NULL == internal_cls)
562 return; /* not about target peer */
563 if (! benchmark_send)
564 return; /* not transmitting */
565 fprintf (stdout,
566 _ ("Disconnected from peer `%s' while benchmarking\n"),
567 GNUNET_i2s (&pid));
568}

References _, benchmark_send, GNUNET_i2s(), and pid.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ monitor_notify_connect()

static void * monitor_notify_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Function called to notify transport users that another peer connected to us.

Parameters
clsclosure
peerthe peer that connected
mqfor sending messages to peer
Returns
NULL

Definition at line 581 of file gnunet-transport.c.

584{
586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
587
589 fprintf (stdout,
590 _ ("%24s: %-17s %4s (%u connections in total)\n"),
591 now_str,
592 _ ("Connected to"),
593 GNUNET_i2s (peer),
595 return NULL;
596}

References _, GNUNET_i2s(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_get(), and monitor_connect_counter.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ monitor_notify_disconnect()

static void monitor_notify_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Function called to notify transport users that another peer disconnected from us.

Parameters
clsclosure
peerthe peer that disconnected
internal_clswhat we returned from monitor_notify_connect()

Definition at line 608 of file gnunet-transport.c.

611{
613 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now);
614
617
618 fprintf (stdout,
619 _ ("%24s: %-17s %4s (%u connections in total)\n"),
620 now_str,
621 _ ("Disconnected from"),
622 GNUNET_i2s (peer),
624}

References _, GNUNET_assert, GNUNET_i2s(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_get(), and monitor_connect_counter.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_dummy()

static int check_dummy ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Function called by the transport for each received message.

Parameters
clsclosure
messagethe message
Returns
GNUNET_OK

Definition at line 635 of file gnunet-transport.c.

636{
637 return GNUNET_OK; /* all messages are fine */
638}

References GNUNET_OK.

◆ handle_dummy()

static void handle_dummy ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Function called by the transport for each received message.

Parameters
clsclosure
messagethe message

Definition at line 648 of file gnunet-transport.c.

649{
650 if (! benchmark_receive)
651 return;
652 if (verbosity > 0)
653 fprintf (stdout,
654 _ ("Received %u bytes\n"),
655 (unsigned int) ntohs (message->size));
656 if (0 == traffic_received)
658 traffic_received += ntohs (message->size);
659}

References _, benchmark_receive, GNUNET_TIME_absolute_get(), GNUNET_MessageHeader::size, start_time, traffic_received, and verbosity.

Here is the call graph for this function:

◆ resolve_peer_address()

static void resolve_peer_address ( const struct GNUNET_HELLO_Address *  address,
int  numeric,
enum GNUNET_TRANSPORT_PeerState  state,
struct GNUNET_TIME_Absolute  state_timeout 
)
static

Convert address to a printable format.

Convert address to a printable format and print it together with the given state data.

Parameters
addressthe address
numericGNUNET_YES to convert to numeric format, GNUNET_NO to try to use reverse DNS
statestate the peer is in
state_timeoutwhen will the peer's state expire

Definition at line 816 of file gnunet-transport.c.

820{
821 struct PeerResolutionContext *rc;
822
823 rc = GNUNET_new (struct PeerResolutionContext);
826 rc->transport = GNUNET_strdup (address->transport_name);
827 rc->addrcp = GNUNET_HELLO_address_copy (address);
828 rc->printed = GNUNET_NO;
829 rc->state = state;
831 /* Resolve address to string */
832 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg,
833 address,
834 numeric,
837 rc);
838}

References PeerResolutionContext::addrcp, address, address_resolutions, PeerResolutionContext::asc, cfg, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_NO, GNUNET_strdup, numeric, PeerResolutionContext::printed, process_peer_string(), rc_head, rc_tail, RESOLUTION_TIMEOUT, state, PeerResolutionContext::state, PeerResolutionContext::state_timeout, and PeerResolutionContext::transport.

Referenced by process_peer_iteration_cb(), process_peer_monitoring_cb(), and process_peer_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_info()

static void print_info ( const struct GNUNET_PeerIdentity id,
const char *  transport,
const char *  addr,
enum GNUNET_TRANSPORT_PeerState  state,
struct GNUNET_TIME_Absolute  state_timeout 
)
static

Definition at line 679 of file gnunet-transport.c.

684{
687 {
688 fprintf (stdout,
689 _ ("Peer `%s': %s %s in state `%s' until %s\n"),
690 GNUNET_i2s (id),
691 (NULL == transport) ? "<none>" : transport,
692 (NULL == transport) ? "<none>" : addr,
693 GNUNET_TRANSPORT_ps2s (state),
695 }
696 else if ((GNUNET_YES == iterate_connections) &&
697 (GNUNET_TRANSPORT_is_connected (state)))
698 {
699 /* Only connected peers, skip state */
700 fprintf (stdout,
701 _ ("Peer `%s': %s %s\n"),
702 GNUNET_i2s (id),
703 transport,
704 addr);
705 }
706}

References _, GNUNET_i2s(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_YES, iterate_all, iterate_connections, monitor_connections, state, and transport.

Referenced by process_peer_iteration_cb(), process_peer_monitoring_cb(), and process_peer_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_peer_string()

static void process_peer_string ( void *  cls,
const char *  address,
int  res 
)
static

Function called with a textual representation of an address.

This function will be called several times with different possible textual representations, and a last time with address being NULL to signal the end of the iteration. Note that address NULL always is the last call, regardless of the value in res.

Parameters
clsclosure
addressNULL on end of iteration, otherwise 0-terminated printable UTF-8 string, in particular an empty string if res is GNUNET_NO
resresult of the address to string conversion: if GNUNET_OK: conversion successful if GNUNET_NO: address was invalid (or not supported) if GNUNET_SYSERR: communication error (IPC error)

Definition at line 726 of file gnunet-transport.c.

727{
728 struct PeerResolutionContext *rc = cls;
729
730 if (NULL != address)
731 {
732 if (GNUNET_SYSERR == res)
733 {
734 fprintf (
735 stderr,
736 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
737 GNUNET_i2s (&rc->addrcp->peer),
738 rc->addrcp->transport_name,
739 (unsigned int) rc->addrcp->address_length);
740 print_info (&rc->addrcp->peer,
741 rc->transport,
742 NULL,
743 rc->state,
744 rc->state_timeout);
745 rc->printed = GNUNET_YES;
746 return;
747 }
748 if (GNUNET_OK == res)
749 {
750 print_info (&rc->addrcp->peer,
751 rc->transport,
752 address,
753 rc->state,
754 rc->state_timeout);
755 rc->printed = GNUNET_YES;
756 return; /* Wait for done call */
757 }
758 /* GNUNET_NO == res: ignore, was simply not supported */
759 return;
760 }
761 /* NULL == address, last call, we are done */
762
763 rc->asc = NULL;
766 if (GNUNET_NO == rc->printed)
767 {
768 if (numeric == GNUNET_NO)
769 {
770 /* Failed to resolve address, try numeric lookup
771 (note: this should not be needed, as transport
772 should fallback to numeric conversion if DNS takes
773 too long) */
776 rc->state,
777 rc->state_timeout);
778 }
779 else
780 {
781 print_info (&rc->addrcp->peer,
782 rc->transport,
783 NULL,
784 rc->state,
785 rc->state_timeout);
786 }
787 }
789 GNUNET_free (rc->addrcp);
791 GNUNET_free (rc);
793 {
794 if (NULL != op_timeout)
795 {
797 op_timeout = NULL;
798 }
799 ret = 0;
801 }
802}

References PeerResolutionContext::addrcp, address, address_resolutions, PeerResolutionContext::asc, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_YES, iterate_connections, numeric, op_timeout, print_info(), PeerResolutionContext::printed, rc_head, rc_tail, res, resolve_peer_address(), ret, PeerResolutionContext::state, PeerResolutionContext::state_timeout, and PeerResolutionContext::transport.

Referenced by resolve_peer_address().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_peer_iteration_cb()

static void process_peer_iteration_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Address *  address,
enum GNUNET_TRANSPORT_PeerState  state,
struct GNUNET_TIME_Absolute  state_timeout 
)
static

Function called with information about a peers during a one shot iteration.

Parameters
clsclosure
peeridentity of the peer, NULL for final callback when operation done
addressbinary address used to communicate with this peer, NULL on disconnect or when done
statecurrent state this peer is in
state_timeouttime out for the current state

Definition at line 852 of file gnunet-transport.c.

857{
858 if (NULL == peer)
859 {
860 /* done */
861 pic = NULL;
862 return;
863 }
864
865 if ((GNUNET_NO == iterate_all) &&
866 (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state)))
867 return; /* Display only connected peers */
868
869 if (NULL != op_timeout)
871 op_timeout =
873
875 "Received address for peer `%s': %s\n",
876 GNUNET_i2s (peer),
877 address ? address->transport_name : "");
878
879 if (NULL != address)
880 resolve_peer_address (address, numeric, state, state_timeout);
881 else
882 print_info (peer, NULL, NULL, state, state_timeout);
883}

References address, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), iterate_all, numeric, OP_TIMEOUT, op_timeout, operation_timeout(), pic, print_info(), resolve_peer_address(), state, and PeerResolutionContext::state_timeout.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_plugin_event_info()

static void print_plugin_event_info ( struct PluginMonitorAddress addr,
const struct GNUNET_TRANSPORT_SessionInfo *  info 
)
static

Print information about a plugin monitoring event.

Parameters
addrout internal context
infothe monitoring information

Definition at line 916 of file gnunet-transport.c.

918{
919 const char *state;
920
921 switch (info->state)
922 {
923 case GNUNET_TRANSPORT_SS_INIT:
924 state = "INIT";
925 break;
926
927 case GNUNET_TRANSPORT_SS_HANDSHAKE:
928 state = "HANDSHAKE";
929 break;
930
931 case GNUNET_TRANSPORT_SS_UP:
932 state = "UP";
933 break;
934
935 case GNUNET_TRANSPORT_SS_UPDATE:
936 state = "UPDATE";
937 break;
938
939 case GNUNET_TRANSPORT_SS_DONE:
940 state = "DONE";
941 break;
942
943 default:
944 state = "UNKNOWN";
945 break;
946 }
947 fprintf (stdout,
948 "%s: state %s timeout in %s @ %s%s\n",
949 GNUNET_i2s (&info->address->peer),
950 state,
952 GNUNET_TIME_absolute_get_remaining (info->session_timeout),
953 GNUNET_YES),
954 addr->str,
955 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
956 fprintf (stdout,
957 "%s: queue has %3u messages and %6u bytes\n",
958 GNUNET_i2s (&info->address->peer),
959 info->num_msg_pending,
960 info->num_bytes_pending);
961 if (0 !=
963 fprintf (stdout,
964 "%s: receiving blocked until %s\n",
965 GNUNET_i2s (&info->address->peer),
967}

References GNUNET_i2s(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, info, GNUNET_TIME_Relative::rel_value_us, state, and PluginMonitorAddress::str.

Referenced by address_cb(), and plugin_monitoring_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ address_cb()

static void address_cb ( void *  cls,
const char *  address,
int  res 
)
static

Function called with a textual representation of an address.

This function will be called several times with different possible textual representations, and a last time with address being NULL to signal the end of the iteration. Note that address NULL always is the last call, regardless of the value in res.

Parameters
clsclosure
addressNULL on end of iteration, otherwise 0-terminated printable UTF-8 string, in particular an empty string if res is GNUNET_NO
resresult of the address to string conversion: if GNUNET_OK: conversion successful if GNUNET_NO: address was invalid (or not supported) if GNUNET_SYSERR: communication error (IPC error)

Definition at line 987 of file gnunet-transport.c.

988{
989 struct PluginMonitorAddress *addr = cls;
990
991 if (NULL == address)
992 {
993 addr->asc = NULL;
994 return;
995 }
996 if (NULL != addr->str)
997 return;
998 addr->str = GNUNET_strdup (address);
999 print_plugin_event_info (addr, &addr->si);
1000}

References address, PluginMonitorAddress::asc, GNUNET_strdup, print_plugin_event_info(), PluginMonitorAddress::si, and PluginMonitorAddress::str.

Referenced by plugin_monitoring_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ plugin_monitoring_cb()

static void plugin_monitoring_cb ( void *  cls,
struct GNUNET_TRANSPORT_PluginSession *  session,
void **  session_ctx,
const struct GNUNET_TRANSPORT_SessionInfo *  info 
)
static

Function called by the plugin with information about the current sessions managed by the plugin (for monitoring).

Parameters
clsclosure (NULL)
sessionsession handle this information is about, NULL to indicate that we are "in sync" (initial iteration complete)
session_ctxstorage location where the application can store data; will point to NULL on #GNUNET_TRANSPORT_SS_INIT, and must be reset to NULL on #GNUNET_TRANSPORT_SS_DONE
infoinformation about the state of the session, NULL if session is also NULL and we are merely signalling that the initial iteration is over; NULL with session being non-NULL if the monitor was being cancelled while sessions were active

Definition at line 1021 of file gnunet-transport.c.

1025{
1026 struct PluginMonitorAddress *addr;
1027
1028 if ((NULL == info) && (NULL == session))
1029 return; /* in sync with transport service */
1030 addr = *session_ctx;
1031 if (NULL == info)
1032 {
1033 if (NULL != addr)
1034 {
1035 if (NULL != addr->asc)
1036 {
1037 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1038 addr->asc = NULL;
1039 }
1040 GNUNET_free (addr->str);
1041 GNUNET_free (addr);
1042 *session_ctx = NULL;
1043 }
1044 return; /* shutdown */
1045 }
1046 if (0 !=
1047 memcmp (&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity)))
1048 return; /* filtered */
1049 if (NULL == addr)
1050 {
1051 addr = GNUNET_new (struct PluginMonitorAddress);
1052 addr->asc =
1053 GNUNET_TRANSPORT_address_to_string (cfg,
1054 info->address,
1055 numeric,
1057 &address_cb,
1058 addr);
1059 *session_ctx = addr;
1060 }
1061 if (NULL == addr->str)
1062 addr->si = *info;
1063 else
1065 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1066 {
1067 if (NULL != addr->asc)
1068 {
1069 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc);
1070 addr->asc = NULL;
1071 }
1072 GNUNET_free (addr->str);
1073 GNUNET_free (addr);
1074 *session_ctx = NULL;
1075 }
1076}

References address_cb(), PluginMonitorAddress::asc, cfg, GNUNET_free, GNUNET_new, GNUNET_TIME_UNIT_FOREVER_REL, info, numeric, pid, print_plugin_event_info(), PluginMonitorAddress::si, and PluginMonitorAddress::str.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_peer_monitoring_cb()

static void process_peer_monitoring_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Address *  address,
enum GNUNET_TRANSPORT_PeerState  state,
struct GNUNET_TIME_Absolute  state_timeout 
)
static

Function called with information about a peers.

Parameters
clsclosure, NULL
peeridentity of the peer, NULL for final callback when operation done
addressbinary address used to communicate with this peer, NULL on disconnect or when done
statecurrent state this peer is in
state_timeouttime out for the current state

Definition at line 1090 of file gnunet-transport.c.

1095{
1096 struct MonitoredPeer *m;
1097
1098 if (NULL == peer)
1099 {
1100 fprintf (stdout,
1101 "%s",
1102 _ (
1103 "Monitor disconnected from transport service. Reconnecting.\n"));
1104 return;
1105 }
1106
1107 if (NULL != op_timeout)
1109 op_timeout =
1111
1112 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1113 {
1114 m = GNUNET_new (struct MonitoredPeer);
1117 peer,
1118 m,
1120 }
1121 else
1122 {
1123 if ((m->state == state) &&
1124 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1125 (NULL == address) && (NULL == m->address))
1126 {
1127 return; /* No real change */
1128 }
1129 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1130 (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1131 return; /* No real change */
1132 }
1133
1134 if (NULL != m->address)
1135 {
1136 GNUNET_free (m->address);
1137 m->address = NULL;
1138 }
1139 if (NULL != address)
1140 m->address = GNUNET_HELLO_address_copy (address);
1141 m->state = state;
1142 m->state_timeout = state_timeout;
1143
1144 if (NULL != address)
1145 resolve_peer_address (m->address, numeric, m->state, m->state_timeout);
1146 else
1147 print_info (peer, NULL, NULL, m->state, m->state_timeout);
1148}

References _, GNUNET_TIME_Absolute::abs_value_us, address, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_free, GNUNET_new, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), m, monitored_peers, numeric, OP_TIMEOUT, op_timeout, operation_timeout(), print_info(), resolve_peer_address(), state, and MonitoredPeer::state_timeout.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ blacklist_cb()

static int blacklist_cb ( void *  cls,
const struct GNUNET_PeerIdentity cpid 
)
static

Function called with the transport service checking if we want to blacklist a peer.

Return GNUNET_SYSERR for the peer that we should disconnect from.

Parameters
clsNULL
cpidpeer to check blacklisting for
Returns
GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not

Definition at line 1161 of file gnunet-transport.c.

1162{
1163 if (0 == memcmp (cpid, &pid, sizeof(struct GNUNET_PeerIdentity)))
1164 return GNUNET_SYSERR;
1165 return GNUNET_OK;
1166}

References GNUNET_OK, GNUNET_SYSERR, and pid.

Referenced by run().

Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle mycfg 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
mycfgconfiguration

Definition at line 1178 of file gnunet-transport.c.

1182{
1183 static struct GNUNET_PeerIdentity zero_pid;
1184 int counter = 0;
1185
1186 ret = 1;
1187
1188 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1189
1193
1194 if (1 < counter)
1195 {
1196 fprintf (
1197 stderr,
1198 _ (
1199 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1200 "disconnect",
1201 "benchmark send",
1202 "benchmark receive",
1203 "information",
1204 "monitor",
1205 "events",
1206 "plugins");
1207 return;
1208 }
1209 if (0 == counter)
1210 {
1211 fprintf (
1212 stderr,
1213 _ (
1214 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1215 "disconnect",
1216 "benchmark send",
1217 "benchmark receive",
1218 "information",
1219 "monitor",
1220 "events",
1221 "plugins");
1222 return;
1223 }
1224
1225 if (do_disconnect) /* -D: Disconnect from peer */
1226 {
1227 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1228 {
1229 fprintf (stderr,
1230 _ ("Option `%s' makes no sense without option `%s'.\n"),
1231 "-D",
1232 "-p");
1233 ret = 1;
1234 return;
1235 }
1236 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1237 if (NULL == blacklist)
1238 {
1239 fprintf (stderr,
1240 "%s",
1241 _ (
1242 "Failed to connect to transport service for disconnection\n"));
1243 ret = 1;
1244 return;
1245 }
1246 fprintf (stdout,
1247 "%s",
1248 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1249 }
1250 else if (benchmark_send) /* -s: Benchmark sending */
1251 {
1252 if (0 == memcmp (&zero_pid, &pid, sizeof(pid)))
1253 {
1254 fprintf (stderr,
1255 _ ("Option `%s' makes no sense without option `%s'.\n"),
1256 "-s",
1257 "-p");
1258 ret = 1;
1259 return;
1260 }
1262 NULL,
1263 NULL,
1264 NULL,
1267 NULL);
1268 if (NULL == handle)
1269 {
1270 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1271 ret = 1;
1272 return;
1273 }
1275 op_timeout =
1277 }
1278 else if (benchmark_receive) /* -b: Benchmark receiving */
1279 {
1283 struct GNUNET_MessageHeader,
1284 NULL),
1286
1288 NULL,
1289 handlers,
1290 NULL,
1291 NULL,
1292 NULL,
1293 NULL);
1294 if (NULL == handle)
1295 {
1296 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1297 ret = 1;
1298 return;
1299 }
1300 if (verbosity > 0)
1301 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1303 }
1304 else if (iterate_connections) /* -i: List information about peers once */
1305 {
1306 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1307 &pid,
1308 GNUNET_YES,
1310 (void *) cfg);
1311 op_timeout =
1313 }
1314 else if (monitor_connections) /* -m: List information about peers continuously
1315 */
1316 {
1318 pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1319 &pid,
1320 GNUNET_NO,
1322 NULL);
1323 }
1324 else if (monitor_plugins) /* -P: List information about plugins continuously
1325 */
1326 {
1328 pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL);
1329 }
1330 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1331 {
1334 NULL,
1335 NULL,
1336 NULL,
1339 NULL);
1340 if (NULL == handle)
1341 {
1342 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n"));
1343 ret = 1;
1344 return;
1345 }
1346 ret = 0;
1347 }
1348 else
1349 {
1350 GNUNET_break (0);
1351 return;
1352 }
1353
1355}

References _, benchmark_receive, benchmark_send, blacklist, blacklist_cb(), cfg, do_disconnect, dummy, GNUNET_break, GNUNET_CONTAINER_multipeermap_create(), GNUNET_MESSAGE_TYPE_DUMMY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_TIME_absolute_get(), GNUNET_TRANSPORT_core_connect(), GNUNET_YES, handle, handlers, iterate_connections, monitor_connect_counter, monitor_connections, monitor_connects, monitor_notify_connect(), monitor_notify_disconnect(), monitor_plugins, monitored_peers, monitored_plugins, notify_connect(), notify_disconnect(), OP_TIMEOUT, op_timeout, operation_timeout(), pic, pid, plugin_monitoring_cb(), pm, process_peer_iteration_cb(), process_peer_monitoring_cb(), ret, shutdown_task, start_time, and verbosity.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

Definition at line 1359 of file gnunet-transport.c.

1360{
1361 int res;
1364 'a',
1365 "all",
1366 gettext_noop (
1367 "print information for all peers (instead of only connected peers)"),
1368 &iterate_all),
1370 'b',
1371 "benchmark",
1372 gettext_noop (
1373 "measure how fast we are receiving data from all peers (until CTRL-C)"),
1376 "disconnect",
1377 gettext_noop ("disconnect from a peer"),
1378 &do_disconnect),
1380 'i',
1381 "information",
1382 gettext_noop (
1383 "provide information about all current connections (once)"),
1386 'm',
1387 "monitor",
1388 gettext_noop (
1389 "provide information about all current connections (continuously)"),
1392 'e',
1393 "events",
1394 gettext_noop (
1395 "provide information about all connects and disconnect events (continuously)"),
1398 "numeric",
1399 gettext_noop ("do not resolve hostnames"),
1400 &numeric),
1402 "peer",
1403 "PEER",
1404 gettext_noop ("peer identity"),
1405 &pid),
1407 "plugins",
1408 gettext_noop ("monitor plugin sessions"),
1411 's',
1412 "send",
1413 gettext_noop (
1414 "send data for benchmarking to the other peer (until CTRL-C)"),
1418
1419 res =
1420 GNUNET_PROGRAM_run (argc,
1421 argv,
1422 "gnunet-transport",
1423 gettext_noop ("Direct access to transport service."),
1424 options,
1425 &run,
1426 NULL);
1427 if (GNUNET_OK == res)
1428 return ret;
1429 return 1;
1430}

References benchmark_receive, benchmark_send, do_disconnect, gettext_noop, GNUNET_GETOPT_option_base32_auto, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_verbose(), GNUNET_OK, GNUNET_PROGRAM_run(), iterate_all, iterate_connections, monitor_connections, monitor_connects, monitor_plugins, numeric, options, pid, res, ret, run(), and verbosity.

Here is the call graph for this function:

Variable Documentation

◆ handle

struct GNUNET_TRANSPORT_CoreHandle* handle
static

Handle to transport service.

Definition at line 172 of file gnunet-transport.c.

Referenced by run(), and shutdown_task().

◆ cfg

struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration handle.

Definition at line 177 of file gnunet-transport.c.

Referenced by plugin_monitoring_cb(), resolve_peer_address(), and run().

◆ blacklist

struct GNUNET_TRANSPORT_Blacklist* blacklist

Blacklisting handle.

Definition at line 182 of file gnunet-transport.c.

Referenced by run(), and shutdown_task().

◆ benchmark_send

int benchmark_send
static

Option -s.

Definition at line 187 of file gnunet-transport.c.

Referenced by main(), notify_connect(), notify_disconnect(), operation_timeout(), run(), and shutdown_task().

◆ benchmark_receive

static int benchmark_receive
static

Option -b.

Option -l.

Definition at line 192 of file gnunet-transport.c.

Referenced by handle_dummy(), main(), operation_timeout(), run(), and shutdown_task().

◆ iterate_connections

int iterate_connections
static

Option -i.

Definition at line 202 of file gnunet-transport.c.

Referenced by main(), operation_timeout(), print_info(), process_peer_string(), and run().

◆ iterate_all

int iterate_all
static

Option -a.

Definition at line 207 of file gnunet-transport.c.

Referenced by main(), print_info(), and process_peer_iteration_cb().

◆ monitor_connects

int monitor_connects
static

Option -c.

Definition at line 212 of file gnunet-transport.c.

Referenced by main(), and run().

◆ monitor_connections

int monitor_connections
static

Option -m.

Definition at line 217 of file gnunet-transport.c.

Referenced by main(), print_info(), and run().

◆ monitor_plugins

int monitor_plugins
static

Option -P.

Definition at line 222 of file gnunet-transport.c.

Referenced by main(), and run().

◆ do_disconnect

◆ numeric

◆ ret

int ret
static

Global return value (0 success).

Definition at line 237 of file gnunet-transport.c.

Referenced by main(), notify_connect(), operation_timeout(), process_peer_string(), run(), and shutdown_task().

◆ monitor_connect_counter

int monitor_connect_counter
static

Current number of connections in monitor mode.

Definition at line 242 of file gnunet-transport.c.

Referenced by monitor_notify_connect(), monitor_notify_disconnect(), and run().

◆ traffic_received

unsigned long long traffic_received
static

Number of bytes of traffic we received so far.

Definition at line 247 of file gnunet-transport.c.

Referenced by handle_dummy(), and shutdown_task().

◆ traffic_sent

unsigned long long traffic_sent
static

Number of bytes of traffic we sent so far.

Definition at line 252 of file gnunet-transport.c.

Referenced by do_send(), and shutdown_task().

◆ start_time

struct GNUNET_TIME_Absolute start_time
static

Starting time of transmitting/receiving data.

Definition at line 257 of file gnunet-transport.c.

Referenced by handle_dummy(), notify_connect(), run(), and shutdown_task().

◆ monitored_peers

struct GNUNET_CONTAINER_MultiPeerMap* monitored_peers
static

Map storing information about monitored peers.

Definition at line 262 of file gnunet-transport.c.

Referenced by destroy_it(), process_peer_monitoring_cb(), run(), and shutdown_task().

◆ monitored_plugins

struct GNUNET_CONTAINER_MultiPeerMap* monitored_plugins
static

Map storing information about monitored plugins's sessions.

Definition at line 267 of file gnunet-transport.c.

Referenced by run(), and shutdown_task().

◆ pic

struct GNUNET_TRANSPORT_PeerMonitoringContext* pic
static

Handle if we are monitoring peers at the transport level.

Definition at line 272 of file gnunet-transport.c.

Referenced by process_peer_iteration_cb(), run(), and shutdown_task().

◆ pm

◆ pid

struct GNUNET_PeerIdentity pid
static

Identity of the peer we transmit to / connect to.

('-p' command-line option).

Definition at line 283 of file gnunet-transport.c.

Referenced by address_iterator(), blacklist_cb(), block_plugin_dht_check_block(), block_plugin_dht_check_reply(), block_plugin_dht_get_key(), check_connection_quality(), check_hello(), check_known_address(), check_known_challenge(), check_validation_request_pending(), consider_for_advertising(), consider_peer_for_forwarding(), core_send_connect_info(), cores_send_connect_info(), cores_send_disconnect_info(), create_target(), cummulative_ack(), detach_terminal(), dv_neighbour_selection(), dv_neighbour_transmission(), env_resign_cb(), find_list_tunnels(), find_list_tunnels_alternate(), find_queue(), find_target(), flush_respect(), fork_and_exec(), fork_and_exec(), free_ack_cummulator_cb(), free_backtalker_cb(), free_dv_routes_cb(), free_neighbour_cb(), free_peer(), free_validation_state_cb(), GCPP_try_path_from_dht(), GDS_try_connect(), GDS_u_connect(), GDS_u_try_connect(), gns_resolve_name(), GNUNET_CORE_get_mq(), GNUNET_HELLO_build_url(), GNUNET_HELLO_builder_from_parser(), GNUNET_HELLO_builder_to_block(), GNUNET_HELLO_builder_to_dht_hello_msg(), GNUNET_HELLO_builder_to_env(), GNUNET_HELLO_builder_to_url(), GNUNET_HELLO_builder_to_url2(), GNUNET_HELLO_dht_msg_to_block(), GNUNET_HELLO_parser_from_url(), GNUNET_i2s(), GNUNET_i2s2(), GNUNET_i2s_full(), GNUNET_OS_process_wait(), GNUNET_PEER_intern(), GNUNET_PEER_resolve(), GNUNET_PEER_search(), GNUNET_PEERSTORE_hello_add(), GNUNET_TRANSPORT_communicator_notify(), gnunet_try_connect(), GSC_SESSIONS_end(), GSC_SESSIONS_solicit(), handle_p2p_put(), handle_search_response(), handshake_ack_monotime_cb(), handshake_ack_monotime_cb(), handshake_monotime_cb(), handshake_monotime_cb(), hello_for_client_cb(), hello_for_incoming_cb(), hello_iter(), hosts_directory_scan_callback(), http_recv_data_cb(), ip_try_connect(), lookup_neighbour(), lookup_virtual_link(), main(), maint_child_death(), netjail_start_run(), notify_client_connect_info(), notify_client_queues(), notify_connect(), notify_disconnect(), operation_timeout(), parser_new(), pils_sign_hello_cb(), plugin_monitoring_cb(), read_cb(), recv_from_streams(), rekey_monotime_cb(), rekey_monotime_cb(), run(), run(), save_list_tunnels(), show_peer(), start_address_validation(), start_burst(), stop_peer_request(), suggest_to_connect(), update_ax_by_kx(), url_resign_cb(), verify_list_tunnels_flag_token(), and write_benchmark_data().

◆ op_timeout

struct GNUNET_SCHEDULER_Task* op_timeout
static

◆ verbosity

unsigned int verbosity
static

Selected level of verbosity.

Definition at line 293 of file gnunet-transport.c.

Referenced by do_send(), handle_dummy(), main(), notify_connect(), and run().

◆ resolver

struct GNUNET_OS_Process* resolver

Resolver process handle.

Definition at line 298 of file gnunet-transport.c.

◆ address_resolutions

unsigned int address_resolutions
static

Number of address resolutions pending.

Definition at line 303 of file gnunet-transport.c.

Referenced by process_peer_string(), and resolve_peer_address().

◆ vc_head

struct ValidationResolutionContext* vc_head
static

DLL: head of validation resolution entries.

Definition at line 308 of file gnunet-transport.c.

Referenced by shutdown_task().

◆ vc_tail

struct ValidationResolutionContext* vc_tail
static

DLL: tail of validation resolution entries.

Definition at line 313 of file gnunet-transport.c.

Referenced by shutdown_task().

◆ rc_head

struct PeerResolutionContext* rc_head
static

DLL: head of resolution entries.

Definition at line 318 of file gnunet-transport.c.

Referenced by operation_timeout(), process_peer_string(), resolve_peer_address(), and shutdown_task().

◆ rc_tail

struct PeerResolutionContext* rc_tail
static

DLL: head of resolution entries.

Definition at line 323 of file gnunet-transport.c.

Referenced by operation_timeout(), process_peer_string(), resolve_peer_address(), and shutdown_task().