aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-10-23 10:59:15 +0000
committerChristian Grothoff <christian@grothoff.org>2014-10-23 10:59:15 +0000
commit1a45b968a48a82e57696ce618e1e77141b738182 (patch)
treec42bbd986f0df598621d88859362082549ce4fde /src/transport/gnunet-service-transport_clients.c
parent1aa2d5f160da455dd68c3d8be6f6e9ebf5b46d98 (diff)
downloadgnunet-1a45b968a48a82e57696ce618e1e77141b738182.tar.gz
gnunet-1a45b968a48a82e57696ce618e1e77141b738182.zip
implementing monitoring functionality in transport service
Diffstat (limited to 'src/transport/gnunet-service-transport_clients.c')
-rw-r--r--src/transport/gnunet-service-transport_clients.c100
1 files changed, 98 insertions, 2 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;
220static struct GNUNET_SERVER_NotificationContext *val_nc; 220static struct GNUNET_SERVER_NotificationContext *val_nc;
221 221
222/** 222/**
223 * Notification context, to send updates on changes to active plugin
224 * connections.
225 */
226static 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 */
1281static void 1287static void
1282clients_handle_monitor_validation (void *cls, struct GNUNET_SERVER_Client *client, 1288clients_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 */
1364static void
1365plugin_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 */
1419static void
1420clients_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