GNUnet  0.10.x
gnunet-transport.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2014, 2016, 2017 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
30 #include "gnunet_protocols.h"
32 
36 #define RESOLUTION_TIMEOUT \
37  GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
38 
42 #define OP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
43 
44 
49 {
54 
59 
64 
69 
74 
79 
84 
88  char *transport;
89 
93  int printed;
94 };
95 
100 {
105 
109  struct GNUNET_TIME_Absolute state_timeout;
110 
115 };
116 
121 {
126 
131 
136 
141 
146 
150  struct GNUNET_TIME_Absolute state_timeout;
151 
155  char *transport;
156 
160  int printed;
161 };
162 
163 
167 #define BLOCKSIZE 4
168 
173 
178 
183 
187 static int benchmark_send;
188 
192 static int benchmark_receive;
193 
197 static int benchmark_receive;
198 
203 
207 static int iterate_all;
208 
212 static int monitor_connects;
213 
218 
222 static int monitor_plugins;
223 
227 static int do_disconnect;
228 
232 static int numeric;
233 
237 static int ret;
238 
243 
247 static unsigned long long traffic_received;
248 
252 static unsigned long long traffic_sent;
253 
258 
263 
268 
273 
278 
283 static struct GNUNET_PeerIdentity pid;
284 
289 
293 static unsigned int verbosity;
294 
299 
303 static unsigned int address_resolutions;
304 
309 
314 
319 
324 
325 
334 static int
335 destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
336 {
337  struct MonitoredPeer *m = value;
338 
339  GNUNET_assert (
340  GNUNET_OK ==
341  GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value));
343  GNUNET_free (value);
344  return GNUNET_OK;
345 }
346 
347 
354 static void
355 shutdown_task (void *cls)
356 {
357  struct GNUNET_TIME_Relative duration;
358  struct ValidationResolutionContext *cur;
360  struct PeerResolutionContext *rc;
361 
362  if (NULL != op_timeout)
363  {
364  GNUNET_SCHEDULER_cancel (op_timeout);
365  op_timeout = NULL;
366  }
367  if (NULL != pic)
368  {
370  pic = NULL;
371  }
372  if (NULL != pm)
373  {
375  pm = NULL;
376  }
377 
378  next = vc_head;
379  for (cur = next; NULL != cur; cur = next)
380  {
381  next = cur->next;
382 
384  GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur);
385  GNUNET_free (cur->transport);
387  GNUNET_free (cur);
388  }
389  while (NULL != (rc = rc_head))
390  {
391  GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
393  GNUNET_free (rc->transport);
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),
408  traffic_sent,
410  }
411  if (benchmark_receive)
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  {
423  GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL);
424  GNUNET_CONTAINER_multipeermap_destroy (monitored_peers);
425  monitored_peers = NULL;
426  }
427  if (NULL != monitored_plugins)
428  {
429  GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins));
430  GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins);
431  monitored_plugins = NULL;
432  }
433  if (NULL != blacklist)
434  {
436  blacklist = NULL;
437  ret = 0;
438  }
439 }
440 
441 
445 static void
446 operation_timeout (void *cls)
447 {
448  struct PeerResolutionContext *cur;
449  struct PeerResolutionContext *next;
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 
469  GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur);
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 }
483 
484 
491 static void
492 do_send (void *cls)
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;
501  GNUNET_MQ_notify_sent (env, &do_send, mq);
502  if (verbosity > 0)
503  FPRINTF (stdout,
504  _ ("Transmitting %u bytes\n"),
505  (unsigned int) BLOCKSIZE * 1024);
506  GNUNET_MQ_send (mq, env);
507 }
508 
509 
518 static void *
519 notify_connect (void *cls,
520  const struct GNUNET_PeerIdentity *peer,
521  struct GNUNET_MQ_Handle *mq)
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  {
530  GNUNET_SCHEDULER_cancel (op_timeout);
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 }
544 
545 
554 static void
555 notify_disconnect (void *cls,
556  const struct GNUNET_PeerIdentity *peer,
557  void *internal_cls)
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 }
569 
570 
580 static void *
582  const struct GNUNET_PeerIdentity *peer,
583  struct GNUNET_MQ_Handle *mq)
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 }
597 
598 
607 static void
609  const struct GNUNET_PeerIdentity *peer,
610  void *internal_cls)
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 }
625 
626 
634 static int
635 check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
636 {
637  return GNUNET_OK; /* all messages are fine */
638 }
639 
640 
647 static void
648 handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
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 }
660 
661 
671 static void
673  int numeric,
675  struct GNUNET_TIME_Absolute state_timeout);
676 
677 
678 static void
679 print_info (const struct GNUNET_PeerIdentity *id,
680  const char *transport,
681  const char *addr,
683  struct GNUNET_TIME_Absolute state_timeout)
684 {
685 
688  {
689  FPRINTF (stdout,
690  _ ("Peer `%s': %s %s in state `%s' until %s\n"),
691  GNUNET_i2s (id),
692  (NULL == transport) ? "<none>" : transport,
693  (NULL == transport) ? "<none>" : addr,
694  GNUNET_TRANSPORT_ps2s (state),
696  }
697  else if ((GNUNET_YES == iterate_connections) &&
699  {
700  /* Only connected peers, skip state */
701  FPRINTF (stdout,
702  _ ("Peer `%s': %s %s\n"),
703  GNUNET_i2s (id),
704  transport,
705  addr);
706  }
707 }
708 
709 
726 static void
727 process_peer_string (void *cls, const char *address, int res)
728 {
729  struct PeerResolutionContext *rc = cls;
730 
731  if (NULL != address)
732  {
733  if (GNUNET_SYSERR == res)
734  {
735  FPRINTF (
736  stderr,
737  "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
738  GNUNET_i2s (&rc->addrcp->peer),
739  rc->addrcp->transport_name,
740  (unsigned int) rc->addrcp->address_length);
741  print_info (&rc->addrcp->peer,
742  rc->transport,
743  NULL,
744  rc->state,
745  rc->state_timeout);
746  rc->printed = GNUNET_YES;
747  return;
748  }
749  if (GNUNET_OK == res)
750  {
751  print_info (&rc->addrcp->peer,
752  rc->transport,
753  address,
754  rc->state,
755  rc->state_timeout);
756  rc->printed = GNUNET_YES;
757  return; /* Wait for done call */
758  }
759  /* GNUNET_NO == res: ignore, was simply not supported */
760  return;
761  }
762  /* NULL == address, last call, we are done */
763 
764  rc->asc = NULL;
767  if (GNUNET_NO == rc->printed)
768  {
769  if (numeric == GNUNET_NO)
770  {
771  /* Failed to resolve address, try numeric lookup
772  (note: this should not be needed, as transport
773  should fallback to numeric conversion if DNS takes
774  too long) */
776  GNUNET_YES,
777  rc->state,
778  rc->state_timeout);
779  }
780  else
781  {
782  print_info (&rc->addrcp->peer,
783  rc->transport,
784  NULL,
785  rc->state,
786  rc->state_timeout);
787  }
788  }
789  GNUNET_free (rc->transport);
790  GNUNET_free (rc->addrcp);
791  GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc);
792  GNUNET_free (rc);
794  {
795  if (NULL != op_timeout)
796  {
797  GNUNET_SCHEDULER_cancel (op_timeout);
798  op_timeout = NULL;
799  }
800  ret = 0;
802  }
803 }
804 
805 
816 static void
818  int numeric,
820  struct GNUNET_TIME_Absolute state_timeout)
821 {
822  struct PeerResolutionContext *rc;
823 
824  rc = GNUNET_new (struct PeerResolutionContext);
825  GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc);
827  rc->transport = GNUNET_strdup (address->transport_name);
828  rc->addrcp = GNUNET_HELLO_address_copy (address);
829  rc->printed = GNUNET_NO;
830  rc->state = state;
832  /* Resolve address to string */
834  address,
835  numeric,
838  rc);
839 }
840 
841 
852 static void
854  const struct GNUNET_PeerIdentity *peer,
855  const struct GNUNET_HELLO_Address *address,
857  struct GNUNET_TIME_Absolute state_timeout)
858 {
859  if (NULL == peer)
860  {
861  /* done */
862  pic = NULL;
863  return;
864  }
865 
866  if ((GNUNET_NO == iterate_all) &&
868  return; /* Display only connected peers */
869 
870  if (NULL != op_timeout)
871  GNUNET_SCHEDULER_cancel (op_timeout);
872  op_timeout =
874 
876  "Received address for peer `%s': %s\n",
877  GNUNET_i2s (peer),
878  address ? address->transport_name : "");
879 
880  if (NULL != address)
881  resolve_peer_address (address, numeric, state, state_timeout);
882  else
883  print_info (peer, NULL, NULL, state, state_timeout);
884 }
885 
886 
891 {
892 
897 
901  char *str;
902 
908 };
909 
910 
917 static void
919  const struct GNUNET_TRANSPORT_SessionInfo *info)
920 {
921  const char *state;
922 
923  switch (info->state)
924  {
926  state = "INIT";
927  break;
929  state = "HANDSHAKE";
930  break;
932  state = "UP";
933  break;
935  state = "UPDATE";
936  break;
938  state = "DONE";
939  break;
940  default:
941  state = "UNKNOWN";
942  break;
943  }
944  fprintf (stdout,
945  "%s: state %s timeout in %s @ %s%s\n",
946  GNUNET_i2s (&info->address->peer),
947  state,
950  GNUNET_YES),
951  addr->str,
952  (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
953  fprintf (stdout,
954  "%s: queue has %3u messages and %6u bytes\n",
955  GNUNET_i2s (&info->address->peer),
956  info->num_msg_pending,
957  info->num_bytes_pending);
958  if (0 !=
960  fprintf (stdout,
961  "%s: receiving blocked until %s\n",
962  GNUNET_i2s (&info->address->peer),
964 }
965 
966 
983 static void
984 address_cb (void *cls, const char *address, int res)
985 {
986  struct PluginMonitorAddress *addr = cls;
987 
988  if (NULL == address)
989  {
990  addr->asc = NULL;
991  return;
992  }
993  if (NULL != addr->str)
994  return;
995  addr->str = GNUNET_strdup (address);
996  print_plugin_event_info (addr, &addr->si);
997 }
998 
999 
1017 static void
1019  struct GNUNET_TRANSPORT_PluginSession *session,
1020  void **session_ctx,
1021  const struct GNUNET_TRANSPORT_SessionInfo *info)
1022 {
1023  struct PluginMonitorAddress *addr;
1024 
1025  if ((NULL == info) && (NULL == session))
1026  return; /* in sync with transport service */
1027  addr = *session_ctx;
1028  if (NULL == info)
1029  {
1030  if (NULL != addr)
1031  {
1032  if (NULL != addr->asc)
1033  {
1035  addr->asc = NULL;
1036  }
1037  GNUNET_free_non_null (addr->str);
1038  GNUNET_free (addr);
1039  *session_ctx = NULL;
1040  }
1041  return; /* shutdown */
1042  }
1043  if (0 !=
1044  memcmp (&info->address->peer, &pid, sizeof (struct GNUNET_PeerIdentity)))
1045  return; /* filtered */
1046  if (NULL == addr)
1047  {
1048  addr = GNUNET_new (struct PluginMonitorAddress);
1049  addr->asc =
1051  info->address,
1052  numeric,
1054  &address_cb,
1055  addr);
1056  *session_ctx = addr;
1057  }
1058  if (NULL == addr->str)
1059  addr->si = *info;
1060  else
1061  print_plugin_event_info (addr, info);
1062  if (GNUNET_TRANSPORT_SS_DONE == info->state)
1063  {
1064  if (NULL != addr->asc)
1065  {
1067  addr->asc = NULL;
1068  }
1069  GNUNET_free_non_null (addr->str);
1070  GNUNET_free (addr);
1071  *session_ctx = NULL;
1072  }
1073 }
1074 
1075 
1086 static void
1088  const struct GNUNET_PeerIdentity *peer,
1089  const struct GNUNET_HELLO_Address *address,
1091  struct GNUNET_TIME_Absolute state_timeout)
1092 {
1093  struct MonitoredPeer *m;
1094 
1095  if (NULL == peer)
1096  {
1097  FPRINTF (stdout,
1098  "%s",
1099  _ (
1100  "Monitor disconnected from transport service. Reconnecting.\n"));
1101  return;
1102  }
1103 
1104  if (NULL != op_timeout)
1105  GNUNET_SCHEDULER_cancel (op_timeout);
1106  op_timeout =
1108 
1109  if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer)))
1110  {
1111  m = GNUNET_new (struct MonitoredPeer);
1113  monitored_peers,
1114  peer,
1115  m,
1117  }
1118  else
1119  {
1120  if ((m->state == state) &&
1121  (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1122  (NULL == address) && (NULL == m->address))
1123  {
1124  return; /* No real change */
1125  }
1126  if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1127  (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1128  return; /* No real change */
1129  }
1130 
1131  if (NULL != m->address)
1132  {
1133  GNUNET_free (m->address);
1134  m->address = NULL;
1135  }
1136  if (NULL != address)
1137  m->address = GNUNET_HELLO_address_copy (address);
1138  m->state = state;
1140 
1141  if (NULL != address)
1143  else
1144  print_info (peer, NULL, NULL, m->state, m->state_timeout);
1145 }
1146 
1147 
1157 static int
1158 blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
1159 {
1160  if (0 == memcmp (cpid, &pid, sizeof (struct GNUNET_PeerIdentity)))
1161  return GNUNET_SYSERR;
1162  return GNUNET_OK;
1163 }
1164 
1165 
1174 static void
1175 run (void *cls,
1176  char *const *args,
1177  const char *cfgfile,
1178  const struct GNUNET_CONFIGURATION_Handle *mycfg)
1179 {
1180  static struct GNUNET_PeerIdentity zero_pid;
1181  int counter = 0;
1182  ret = 1;
1183 
1184  cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
1185 
1189 
1190  if (1 < counter)
1191  {
1192  FPRINTF (
1193  stderr,
1194  _ (
1195  "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1196  "disconnect",
1197  "benchmark send",
1198  "benchmark receive",
1199  "information",
1200  "monitor",
1201  "events",
1202  "plugins");
1203  return;
1204  }
1205  if (0 == counter)
1206  {
1207  FPRINTF (
1208  stderr,
1209  _ (
1210  "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1211  "disconnect",
1212  "benchmark send",
1213  "benchmark receive",
1214  "information",
1215  "monitor",
1216  "events",
1217  "plugins");
1218  return;
1219  }
1220 
1221  if (do_disconnect) /* -D: Disconnect from peer */
1222  {
1223  if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
1224  {
1225  FPRINTF (stderr,
1226  _ ("Option `%s' makes no sense without option `%s'.\n"),
1227  "-D",
1228  "-p");
1229  ret = 1;
1230  return;
1231  }
1232  blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL);
1233  if (NULL == blacklist)
1234  {
1235  FPRINTF (stderr,
1236  "%s",
1237  _ (
1238  "Failed to connect to transport service for disconnection\n"));
1239  ret = 1;
1240  return;
1241  }
1242  FPRINTF (stdout,
1243  "%s",
1244  _ ("Blacklisting request in place, stop with CTRL-C\n"));
1245  }
1246  else if (benchmark_send) /* -s: Benchmark sending */
1247  {
1248  if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
1249  {
1250  FPRINTF (stderr,
1251  _ ("Option `%s' makes no sense without option `%s'.\n"),
1252  "-s",
1253  "-p");
1254  ret = 1;
1255  return;
1256  }
1257  handle = GNUNET_TRANSPORT_core_connect (cfg,
1258  NULL,
1259  NULL,
1260  NULL,
1261  &notify_connect,
1263  NULL);
1264  if (NULL == handle)
1265  {
1266  FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n"));
1267  ret = 1;
1268  return;
1269  }
1271  op_timeout =
1273  }
1274  else if (benchmark_receive) /* -b: Benchmark receiving */
1275  {
1276  struct GNUNET_MQ_MessageHandler handlers[] =
1279  struct GNUNET_MessageHeader,
1280  NULL),
1282 
1283  handle = GNUNET_TRANSPORT_core_connect (cfg,
1284  NULL,
1285  handlers,
1286  NULL,
1287  NULL,
1288  NULL,
1289  NULL);
1290  if (NULL == handle)
1291  {
1292  FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n"));
1293  ret = 1;
1294  return;
1295  }
1296  if (verbosity > 0)
1297  FPRINTF (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1299  }
1300  else if (iterate_connections) /* -i: List information about peers once */
1301  {
1302  pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1303  &pid,
1304  GNUNET_YES,
1306  (void *) cfg);
1307  op_timeout =
1309  }
1310  else if (monitor_connections) /* -m: List information about peers continuously
1311  */
1312  {
1313  monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1314  pic = GNUNET_TRANSPORT_monitor_peers (cfg,
1315  &pid,
1316  GNUNET_NO,
1318  NULL);
1319  }
1320  else if (monitor_plugins) /* -P: List information about plugins continuously
1321  */
1322  {
1323  monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1325  }
1326  else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1327  {
1329  handle = GNUNET_TRANSPORT_core_connect (cfg,
1330  NULL,
1331  NULL,
1332  NULL,
1335  NULL);
1336  if (NULL == handle)
1337  {
1338  FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n"));
1339  ret = 1;
1340  return;
1341  }
1342  ret = 0;
1343  }
1344  else
1345  {
1346  GNUNET_break (0);
1347  return;
1348  }
1349 
1351 }
1352 
1353 
1354 int
1355 main (int argc, char *const *argv)
1356 {
1357  int res;
1358  struct GNUNET_GETOPT_CommandLineOption options[] =
1360  'a',
1361  "all",
1362  gettext_noop (
1363  "print information for all peers (instead of only connected peers)"),
1364  &iterate_all),
1366  'b',
1367  "benchmark",
1368  gettext_noop (
1369  "measure how fast we are receiving data from all peers (until CTRL-C)"),
1372  "disconnect",
1373  gettext_noop ("disconnect from a peer"),
1374  &do_disconnect),
1376  'i',
1377  "information",
1378  gettext_noop (
1379  "provide information about all current connections (once)"),
1382  'm',
1383  "monitor",
1384  gettext_noop (
1385  "provide information about all current connections (continuously)"),
1388  'e',
1389  "events",
1390  gettext_noop (
1391  "provide information about all connects and disconnect events (continuously)"),
1392  &monitor_connects),
1394  "numeric",
1395  gettext_noop ("do not resolve hostnames"),
1396  &numeric),
1398  "peer",
1399  "PEER",
1400  gettext_noop ("peer identity"),
1401  &pid),
1403  "plugins",
1404  gettext_noop ("monitor plugin sessions"),
1405  &monitor_plugins),
1407  's',
1408  "send",
1409  gettext_noop (
1410  "send data for benchmarking to the other peer (until CTRL-C)"),
1411  &benchmark_send),
1414 
1415  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1416  return 2;
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  GNUNET_free ((void *) argv);
1427  if (GNUNET_OK == res)
1428  return ret;
1429  return 1;
1430 }
1431 
1432 /* end of gnunet-transport.c */
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
Session is being torn down and about to disappear.
static unsigned int address_resolutions
Number of address resolutions pending.
static char * cpid
Which peer should we connect to?
static void print_plugin_event_info(struct PluginMonitorAddress *addr, const struct GNUNET_TRANSPORT_SessionInfo *info)
Print information about a plugin monitoring event.
uint32_t num_bytes_pending
Number of bytes pending transmission for this session.
int printed
was the entry printed
static int iterate_all
Option -a.
struct ValidationResolutionContext * prev
Previous in DLL.
static int benchmark_send
Option -s.
struct GNUNET_TIME_Absolute state_timeout
state timeout
enum GNUNET_TRANSPORT_PeerState state
peer state
GNUNET_TRANSPORT_PeerState
Possible state of a neighbour.
uint64_t rel_value_us
The actual value.
static struct in_addr dummy
Target "dummy" address.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct PeerResolutionContext * prev
Prev in DLL.
static void address_cb(void *cls, const char *address, int res)
Function called with a textual representation of an address.
static struct GNUNET_SCHEDULER_Task * op_timeout
Task for operation timeout.
static struct GNUNET_TRANSPORT_PeerMonitoringContext * pic
Handle if we are monitoring peers at the transport level.
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.
#define FPRINTF
Definition: plibc.h:683
static struct GNUNET_CONTAINER_MultiPeerMap * monitored_plugins
Map storing information about monitored plugins&#39;s sessions.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the &#39;-V&#39; verbosity option.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
int is_inbound
GNUNET_YES if this is an inbound connection, GNUNET_NO if this is an outbound connection, GNUNET_SYSERR if connections of this plugin are so fundamentally bidirectional that they have no &#39;initiator&#39;
char * transport
plugin name
enum GNUNET_TRANSPORT_SessionState state
New state of the session.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
struct GNUNET_TRANSPORT_AddressToStringContext * asc
Ongoing resolution request.
Context for iterating validation entries.
Context to store name resolutions for valiation.
static int monitor_connect_counter
Current number of connections in monitor mode.
Abstract representation of a plugin&#39;s session.
static int ret
Global return value (0 success).
Initial session handshake is in progress.
#define GNUNET_MESSAGE_TYPE_DUMMY
Dummy messages for testing / benchmarking.
Struct to store information about peers in monitor mode.
static struct GNUNET_CONTAINER_MultiPeerMap * monitored_peers
Map storing information about monitored peers.
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.
enum GNUNET_TRANSPORT_PeerState state
State of the peer.
Handle for a plugin session state monitor.
static int benchmark_receive
Option -b.
int 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.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int numeric
Option -n.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
void GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br)
Abort the blacklist.
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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
const struct GNUNET_HELLO_Address * address
Address used by the session.
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 int monitor_connections
Option -m.
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).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_TRANSPORT_PeerMonitoringContext * GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *peer, int one_shot, GNUNET_TRANSPORT_PeerIterateCallback peer_callback, void *peer_callback_cls)
Return information about a specific peer or all peers currently known to transport service once or in...
uint64_t abs_value_us
The actual value.
uint32_t num_msg_pending
Number of messages pending transmission for this session.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static void shutdown_task(void *cls)
Task run in monitor mode when the user presses CTRL-C to abort.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static struct ValidationResolutionContext * vc_tail
DLL: tail of validation resolution entries.
struct GNUNET_TIME_Absolute receive_delay
Until when does this plugin refuse to receive to manage staying within the inbound quota...
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. ...
void GNUNET_TRANSPORT_monitor_peers_cancel(struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
Cancel request to monitor peers.
int GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state)
Check if a state is defined as connected.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct ValidationResolutionContext * next
Next in DLL.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_TRANSPORT_AddressToStringContext * asc
Tranport conversion handle.
static int iterate_connections
Option -i.
#define BLOCKSIZE
Benchmarking block size in KB.
Information about a plugin&#39;s session.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
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:1246
static struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
char * str
Resolved address as string.
enum State state
current state of profiling
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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:774
static char * value
Value of the record to add/remove.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
Cancel request for address conversion.
struct GNUNET_TRANSPORT_Blacklist * GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
Install a blacklist callback.
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)
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:727
int printed
was the entry printed
static int monitor_plugins
Option -P.
static int check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
Function called by the transport for each received message.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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 ...
#define RESOLUTION_TIMEOUT
Timeout for a name resolution.
struct GNUNET_TIME_Absolute session_timeout
At what time will this session timeout (unless activity happens)?
Internal representation of the hash map.
struct GNUNET_TRANSPORT_PluginMonitor * GNUNET_TRANSPORT_monitor_plugins(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_SessionMonitorCallback cb, void *cb_cls)
Install a plugin session state monitor callback.
struct GNUNET_TIME_Absolute state_timeout
Timeout.
struct GNUNET_TIME_Absolute next_validation
Time of next validation.
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.
Message handler for a specific message type.
static int res
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static unsigned long long traffic_received
Number of bytes of traffic we received so far.
Handle for blacklisting requests.
static struct GNUNET_TIME_Absolute start_time
Starting time of transmitting/receiving data.
const char * GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
Convert a transport state to a human readable string.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_TRANSPORT_AddressToStringContext * GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls)
Convert a binary address into a human readable address.
static void operation_timeout(void *cls)
We are done, shut down.
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.
#define OP_TIMEOUT
Timeout for an operation.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_PeerIdentity peer
For which peer is this an address?
char * transport
transport plugin
struct GNUNET_HELLO_Address * addrcp
Address to resolve.
static void process_peer_string(void *cls, const char *address, int res)
Function called with a textual representation of an address.
static int do_disconnect
Option -D.
struct GNUNET_TIME_Absolute valid_until
Address is valid until.
struct GNUNET_TRANSPORT_SessionInfo si
Last event we got and did not yet print because str was NULL (address not yet resolved).
Handle to a message queue.
Definition: mq.c:85
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.
This is just an update about the session, the state did not change.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct PeerResolutionContext * rc_head
DLL: head of resolution entries.
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_TRANSPORT_CoreHandle * handle
Handle to transport service.
struct GNUNET_TIME_Absolute last_validation
Time of last validation.
configuration data
Definition: configuration.c:85
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:373
static struct PeerResolutionContext * rc_tail
DLL: head of resolution entries.
struct GNUNET_HELLO_Address * addrcp
address to resolve
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
An address for communicating with a peer.
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. ...
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_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
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.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
The session was created (first call for each session object).
Entry in list of pending tasks.
Definition: scheduler.c:134
#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...
struct PeerResolutionContext * next
Next in DLL.
struct GNUNET_TRANSPORT_Blacklist * blacklist
Blacklisting handle.
int main(int argc, char *const *argv)
static struct ValidationResolutionContext * vc_head
DLL: head of validation resolution entries.
static unsigned int verbosity
Selected level of verbosity.
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:361
void GNUNET_TRANSPORT_monitor_plugins_cancel(struct GNUNET_TRANSPORT_PluginMonitor *pm)
Cancel monitoring the plugin session state.
Context for address resolution by plugin_monitoring_cb().
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:331
Header for all communications.
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
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:353
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_TRANSPORT_AddressToStringContext * asc
transport conversiion context
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
Handle for the transport service (includes all of the state for the transport service).
static void do_send(void *cls)
Function called to notify a client about the socket begin ready to queue more data.
struct GNUNET_HELLO_Address * address
The address to convert.
static char * address
GNS address for this phone.
static unsigned long long traffic_sent
Number of bytes of traffic we sent so far.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static int destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function called to release data stored in the monitored_peers map.
#define GNUNET_HELLO_address_free(addr)
Free an address.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
#define gettext_noop(String)
Definition: gettext.h:69
Context to store name resolutions for valiation.
static int monitor_connects
Option -c.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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.