diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-10-23 10:59:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-10-23 10:59:15 +0000 |
commit | 1a45b968a48a82e57696ce618e1e77141b738182 (patch) | |
tree | c42bbd986f0df598621d88859362082549ce4fde /src | |
parent | 1aa2d5f160da455dd68c3d8be6f6e9ebf5b46d98 (diff) | |
download | gnunet-1a45b968a48a82e57696ce618e1e77141b738182.tar.gz gnunet-1a45b968a48a82e57696ce618e1e77141b738182.zip |
implementing monitoring functionality in transport service
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 100 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 86 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.h | 11 | ||||
-rw-r--r-- | src/transport/transport.h | 18 |
4 files changed, 175 insertions, 40 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index af15023df..b67d432c5 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -220,6 +220,12 @@ static struct GNUNET_SERVER_NotificationContext *peer_nc; | |||
220 | static struct GNUNET_SERVER_NotificationContext *val_nc; | 220 | static struct GNUNET_SERVER_NotificationContext *val_nc; |
221 | 221 | ||
222 | /** | 222 | /** |
223 | * Notification context, to send updates on changes to active plugin | ||
224 | * connections. | ||
225 | */ | ||
226 | static struct GNUNET_SERVER_NotificationContext *plugin_nc; | ||
227 | |||
228 | /** | ||
223 | * Find the internal handle associated with the given client handle | 229 | * Find the internal handle associated with the given client handle |
224 | * | 230 | * |
225 | * @param client server's client handle to look up | 231 | * @param client server's client handle to look up |
@@ -1279,8 +1285,9 @@ clients_handle_monitor_peers (void *cls, struct GNUNET_SERVER_Client *client, | |||
1279 | * @param message the peer address information request | 1285 | * @param message the peer address information request |
1280 | */ | 1286 | */ |
1281 | static void | 1287 | static void |
1282 | clients_handle_monitor_validation (void *cls, struct GNUNET_SERVER_Client *client, | 1288 | clients_handle_monitor_validation (void *cls, |
1283 | const struct GNUNET_MessageHeader *message) | 1289 | struct GNUNET_SERVER_Client *client, |
1290 | const struct GNUNET_MessageHeader *message) | ||
1284 | { | 1291 | { |
1285 | static struct GNUNET_PeerIdentity all_zeros; | 1292 | static struct GNUNET_PeerIdentity all_zeros; |
1286 | struct GNUNET_SERVER_TransmitContext *tc; | 1293 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -1341,6 +1348,86 @@ clients_handle_monitor_validation (void *cls, struct GNUNET_SERVER_Client *clien | |||
1341 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 1348 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
1342 | } | 1349 | } |
1343 | 1350 | ||
1351 | |||
1352 | /** | ||
1353 | * Function called by the plugin with information about the | ||
1354 | * current sessions managed by the plugin (for monitoring). | ||
1355 | * | ||
1356 | * @param cls closure | ||
1357 | * @param session session handle this information is about, | ||
1358 | * NULL to indicate that we are "in sync" (initial | ||
1359 | * iteration complete) | ||
1360 | * @param info information about the state of the session, | ||
1361 | * NULL if @a session is also NULL and we are | ||
1362 | * merely signalling that the initial iteration is over | ||
1363 | */ | ||
1364 | static void | ||
1365 | plugin_session_info_cb (void *cls, | ||
1366 | struct Session *session, | ||
1367 | const struct GNUNET_TRANSPORT_SessionInfo *info) | ||
1368 | { | ||
1369 | struct TransportPluginMonitorMessage *msg; | ||
1370 | size_t size; | ||
1371 | size_t slen; | ||
1372 | uint16_t alen; | ||
1373 | char *name; | ||
1374 | char *addr; | ||
1375 | |||
1376 | if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc)) | ||
1377 | { | ||
1378 | GST_plugins_monitor_subscribe (NULL, NULL); | ||
1379 | return; | ||
1380 | } | ||
1381 | slen = strlen (info->address->transport_name) + 1; | ||
1382 | alen = info->address->address_length; | ||
1383 | size = sizeof (struct TransportPluginMonitorMessage) + slen + alen; | ||
1384 | if (size > UINT16_MAX) | ||
1385 | { | ||
1386 | GNUNET_break (0); | ||
1387 | return; | ||
1388 | } | ||
1389 | msg = GNUNET_malloc (size); | ||
1390 | msg->header.size = htons (size); | ||
1391 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); | ||
1392 | msg->session_state = htons ((uint16_t) info->state); | ||
1393 | msg->is_inbound = htons ((int16_t) info->is_inbound); | ||
1394 | msg->msgs_pending = htonl (info->num_msg_pending); | ||
1395 | msg->bytes_pending = htonl (info->num_bytes_pending); | ||
1396 | msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout); | ||
1397 | msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay); | ||
1398 | msg->peer = info->address->peer; | ||
1399 | msg->plugin_name_len = htons (slen); | ||
1400 | msg->plugin_address_len = htons (alen); | ||
1401 | name = (char *) &msg[1]; | ||
1402 | memcpy (name, info->address->transport_name, slen); | ||
1403 | addr = &name[slen + 1]; | ||
1404 | memcpy (addr, info->address->address, alen); | ||
1405 | GNUNET_SERVER_notification_context_broadcast (plugin_nc, | ||
1406 | &msg->header, | ||
1407 | GNUNET_NO); | ||
1408 | GNUNET_free (msg); | ||
1409 | } | ||
1410 | |||
1411 | |||
1412 | /** | ||
1413 | * Client asked to obtain information about all plugin connections. | ||
1414 | * | ||
1415 | * @param cls unused | ||
1416 | * @param client the client | ||
1417 | * @param message the peer address information request | ||
1418 | */ | ||
1419 | static void | ||
1420 | clients_handle_monitor_plugins (void *cls, | ||
1421 | struct GNUNET_SERVER_Client *client, | ||
1422 | const struct GNUNET_MessageHeader *message) | ||
1423 | { | ||
1424 | GNUNET_SERVER_disable_receive_done_warning (client); | ||
1425 | if (0 == GNUNET_SERVER_notification_context_get_size (plugin_nc)) | ||
1426 | GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL); | ||
1427 | GNUNET_SERVER_notification_context_add (plugin_nc, client); | ||
1428 | } | ||
1429 | |||
1430 | |||
1344 | /** | 1431 | /** |
1345 | * Start handling requests from clients. | 1432 | * Start handling requests from clients. |
1346 | * | 1433 | * |
@@ -1375,10 +1462,14 @@ GST_clients_start (struct GNUNET_SERVER_Handle *server) | |||
1375 | sizeof (struct BlacklistMessage)}, | 1462 | sizeof (struct BlacklistMessage)}, |
1376 | {&GST_manipulation_set_metric, NULL, | 1463 | {&GST_manipulation_set_metric, NULL, |
1377 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0}, | 1464 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 0}, |
1465 | {&clients_handle_monitor_plugins, NULL, | ||
1466 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT, | ||
1467 | sizeof (struct GNUNET_MessageHeader) }, | ||
1378 | {NULL, NULL, 0, 0} | 1468 | {NULL, NULL, 0, 0} |
1379 | }; | 1469 | }; |
1380 | peer_nc = GNUNET_SERVER_notification_context_create (server, 0); | 1470 | peer_nc = GNUNET_SERVER_notification_context_create (server, 0); |
1381 | val_nc = GNUNET_SERVER_notification_context_create (server, 0); | 1471 | val_nc = GNUNET_SERVER_notification_context_create (server, 0); |
1472 | plugin_nc = GNUNET_SERVER_notification_context_create (server, 0); | ||
1382 | GNUNET_SERVER_add_handlers (server, handlers); | 1473 | GNUNET_SERVER_add_handlers (server, handlers); |
1383 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, | 1474 | GNUNET_SERVER_disconnect_notify (server, &client_disconnect_notification, |
1384 | NULL); | 1475 | NULL); |
@@ -1409,6 +1500,11 @@ GST_clients_stop () | |||
1409 | GNUNET_SERVER_notification_context_destroy (val_nc); | 1500 | GNUNET_SERVER_notification_context_destroy (val_nc); |
1410 | val_nc = NULL; | 1501 | val_nc = NULL; |
1411 | } | 1502 | } |
1503 | if (NULL != plugin_nc) | ||
1504 | { | ||
1505 | GNUNET_SERVER_notification_context_destroy (plugin_nc); | ||
1506 | plugin_nc = NULL; | ||
1507 | } | ||
1412 | } | 1508 | } |
1413 | 1509 | ||
1414 | 1510 | ||
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index 846461a4c..e43b7057a 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c | |||
@@ -1,21 +1,21 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2010-2014 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
@@ -302,13 +302,14 @@ GST_plugins_unload () | |||
302 | struct GNUNET_TRANSPORT_PluginFunctions * | 302 | struct GNUNET_TRANSPORT_PluginFunctions * |
303 | GST_plugins_find (const char *name) | 303 | GST_plugins_find (const char *name) |
304 | { | 304 | { |
305 | struct TransportPlugin *head = plugins_head; | 305 | struct TransportPlugin *pos; |
306 | 306 | ||
307 | while ((head != NULL) && (0 != strcmp (name, head->short_name))) | 307 | for (pos = plugins_head; NULL != pos; pos = pos->next) |
308 | head = head->next; | 308 | if (0 == strcmp (name, pos->short_name)) |
309 | if (NULL == head) | 309 | break; |
310 | if (NULL == pos) | ||
310 | return NULL; | 311 | return NULL; |
311 | return head->api; | 312 | return pos->api; |
312 | } | 313 | } |
313 | 314 | ||
314 | 315 | ||
@@ -325,23 +326,19 @@ GST_plugins_find (const char *name) | |||
325 | struct GNUNET_TRANSPORT_PluginFunctions * | 326 | struct GNUNET_TRANSPORT_PluginFunctions * |
326 | GST_plugins_printer_find (const char *name) | 327 | GST_plugins_printer_find (const char *name) |
327 | { | 328 | { |
328 | struct TransportPlugin *head = plugins_head; | 329 | struct TransportPlugin *pos; |
329 | |||
330 | char *stripped = GNUNET_strdup (name); | 330 | char *stripped = GNUNET_strdup (name); |
331 | char *sep = strchr (stripped, '_'); | 331 | char *sep = strchr (stripped, '_'); |
332 | |||
332 | if (NULL != sep) | 333 | if (NULL != sep) |
333 | sep[0] = '\0'; | 334 | sep[0] = '\0'; |
334 | 335 | for (pos = plugins_head; NULL != pos; pos = pos->next) | |
335 | while (head != NULL) | 336 | if (pos->short_name == strstr (pos->short_name, stripped)) |
336 | { | ||
337 | if (head->short_name == strstr (head->short_name, stripped)) | ||
338 | break; | 337 | break; |
339 | head = head->next; | ||
340 | } | ||
341 | GNUNET_free (stripped); | 338 | GNUNET_free (stripped); |
342 | if (NULL == head) | 339 | if (NULL == pos) |
343 | return NULL; | 340 | return NULL; |
344 | return head->api; | 341 | return pos->api; |
345 | } | 342 | } |
346 | 343 | ||
347 | 344 | ||
@@ -359,9 +356,9 @@ GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) | |||
359 | static char unable_to_show[1024]; | 356 | static char unable_to_show[1024]; |
360 | static const char *s; | 357 | static const char *s; |
361 | 358 | ||
362 | if (address == NULL) | 359 | if (NULL == address) |
363 | { | 360 | { |
364 | GNUNET_break (0); /* a HELLO address cannot be NULL */ | 361 | GNUNET_break (0); /* a HELLO address cannot be NULL */ |
365 | return "<invalid>"; | 362 | return "<invalid>"; |
366 | } | 363 | } |
367 | if (0 == address->address_length) | 364 | if (0 == address->address_length) |
@@ -382,4 +379,25 @@ GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) | |||
382 | } | 379 | } |
383 | 380 | ||
384 | 381 | ||
382 | /** | ||
383 | * Register callback with all plugins to monitor their status. | ||
384 | * | ||
385 | * @param cb callback to register, NULL to unsubscribe | ||
386 | * @param cb_cls closure for @a cb | ||
387 | */ | ||
388 | void | ||
389 | GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb, | ||
390 | void *cb_cls) | ||
391 | { | ||
392 | struct TransportPlugin *pos; | ||
393 | |||
394 | for (pos = plugins_head; NULL != pos; pos = pos->next) | ||
395 | if (NULL == pos->api->setup_monitor) | ||
396 | GNUNET_break (0); | ||
397 | else | ||
398 | pos->api->setup_monitor (pos->api->cls, | ||
399 | cb, cb_cls); | ||
400 | } | ||
401 | |||
402 | |||
385 | /* end of file gnunet-service-transport_plugins.c */ | 403 | /* end of file gnunet-service-transport_plugins.c */ |
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h index 15d8463fb..766ebaa66 100644 --- a/src/transport/gnunet-service-transport_plugins.h +++ b/src/transport/gnunet-service-transport_plugins.h | |||
@@ -100,5 +100,16 @@ const char * | |||
100 | GST_plugins_a2s (const struct GNUNET_HELLO_Address *address); | 100 | GST_plugins_a2s (const struct GNUNET_HELLO_Address *address); |
101 | 101 | ||
102 | 102 | ||
103 | /** | ||
104 | * Register callback with all plugins to monitor their status. | ||
105 | * | ||
106 | * @param cb callback to register, NULL to unsubscribe | ||
107 | * @param cb_cls closure for @a cb | ||
108 | */ | ||
109 | void | ||
110 | GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb, | ||
111 | void *cb_cls); | ||
112 | |||
113 | |||
103 | #endif | 114 | #endif |
104 | /* end of file gnunet-service-transport_plugins.h */ | 115 | /* end of file gnunet-service-transport_plugins.h */ |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 87bfeb386..df45cd657 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -606,7 +606,17 @@ struct TransportPluginMonitorMessage | |||
606 | /** | 606 | /** |
607 | * An `enum GNUNET_TRANSPORT_SessionState` in NBO. | 607 | * An `enum GNUNET_TRANSPORT_SessionState` in NBO. |
608 | */ | 608 | */ |
609 | int32_t session_state GNUNET_PACKED; | 609 | uint16_t session_state GNUNET_PACKED; |
610 | |||
611 | /** | ||
612 | * #GNUNET_YES if this is an inbound connection, | ||
613 | * #GNUNET_NO if this is an outbound connection, | ||
614 | * #GNUNET_SYSERR if connections of this plugin | ||
615 | * are so fundamentally bidirectional | ||
616 | * that they have no 'initiator' | ||
617 | * Value given in NBO. | ||
618 | */ | ||
619 | int16_t is_inbound GNUNET_PACKED; | ||
610 | 620 | ||
611 | /** | 621 | /** |
612 | * Number of messages waiting transmission. | 622 | * Number of messages waiting transmission. |
@@ -624,9 +634,9 @@ struct TransportPluginMonitorMessage | |||
624 | struct GNUNET_TIME_AbsoluteNBO timeout; | 634 | struct GNUNET_TIME_AbsoluteNBO timeout; |
625 | 635 | ||
626 | /** | 636 | /** |
627 | * What is the expected latency? | 637 | * Until how long is this plugin currently blocked from reading? |
628 | */ | 638 | */ |
629 | struct GNUNET_TIME_RelativeNBO delay; | 639 | struct GNUNET_TIME_AbsoluteNBO delay; |
630 | 640 | ||
631 | /** | 641 | /** |
632 | * Which peer is this connection for? | 642 | * Which peer is this connection for? |
@@ -634,7 +644,7 @@ struct TransportPluginMonitorMessage | |||
634 | struct GNUNET_PeerIdentity peer; | 644 | struct GNUNET_PeerIdentity peer; |
635 | 645 | ||
636 | /** | 646 | /** |
637 | * Length of the plugin name in bytes, excluding 0-termination. | 647 | * Length of the plugin name in bytes, including 0-termination. |
638 | */ | 648 | */ |
639 | uint16_t plugin_name_len GNUNET_PACKED; | 649 | uint16_t plugin_name_len GNUNET_PACKED; |
640 | 650 | ||