aboutsummaryrefslogtreecommitdiff
path: root/src/dv/plugin_transport_dv.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-10-23 09:02:32 +0000
committerChristian Grothoff <christian@grothoff.org>2014-10-23 09:02:32 +0000
commit3a84bbc41f831e5af96cb2678b0eb180dde68eb8 (patch)
treefe98861cd3b1bad6231b1ac637c71667a7bf2685 /src/dv/plugin_transport_dv.c
parent3aef57996c7ee6a730ac500201394cc258348178 (diff)
downloadgnunet-3a84bbc41f831e5af96cb2678b0eb180dde68eb8.tar.gz
gnunet-3a84bbc41f831e5af96cb2678b0eb180dde68eb8.zip
-towards #3452: implement monitoring API in DV
Diffstat (limited to 'src/dv/plugin_transport_dv.c')
-rw-r--r--src/dv/plugin_transport_dv.c129
1 files changed, 124 insertions, 5 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index e5a6b736b..49fe1a4d6 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2002--2013 Christian Grothoff (and other contributing authors) 3 (C) 2002--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
@@ -25,7 +25,6 @@
25 * @author Nathan Evans 25 * @author Nathan Evans
26 * @author Christian Grothoff 26 * @author Christian Grothoff
27 */ 27 */
28
29#include "platform.h" 28#include "platform.h"
30#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
31#include "gnunet_protocols.h" 30#include "gnunet_protocols.h"
@@ -38,7 +37,6 @@
38 37
39#define LOG(kind,...) GNUNET_log_from (kind, "transport-dv",__VA_ARGS__) 38#define LOG(kind,...) GNUNET_log_from (kind, "transport-dv",__VA_ARGS__)
40 39
41#define PLUGIN_NAME "dv"
42 40
43/** 41/**
44 * Encapsulation of all of the state of the plugin. 42 * Encapsulation of all of the state of the plugin.
@@ -111,6 +109,9 @@ struct Session
111 */ 109 */
112 struct PendingRequest *pr_tail; 110 struct PendingRequest *pr_tail;
113 111
112 /**
113 * Address we use for the other peer.
114 */
114 struct GNUNET_HELLO_Address *address; 115 struct GNUNET_HELLO_Address *address;
115 116
116 /** 117 /**
@@ -119,6 +120,18 @@ struct Session
119 struct GNUNET_PeerIdentity sender; 120 struct GNUNET_PeerIdentity sender;
120 121
121 /** 122 /**
123 * Number of bytes waiting for transmission to this peer.
124 * FIXME: not set yet.
125 */
126 unsigned long long bytes_in_queue;
127
128 /**
129 * Number of messages waiting for transmission to this peer.
130 * FIXME: not set yet.
131 */
132 unsigned int msgs_in_queue;
133
134 /**
122 * Current distance to the given peer. 135 * Current distance to the given peer.
123 */ 136 */
124 uint32_t distance; 137 uint32_t distance;
@@ -168,10 +181,51 @@ struct Plugin
168 */ 181 */
169 struct GNUNET_SERVER_MessageStreamTokenizer *mst; 182 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
170 183
184 /**
185 * Function to call about session status changes.
186 */
187 GNUNET_TRANSPORT_SessionInfoCallback sic;
188
189 /**
190 * Closure for @e sic.
191 */
192 void *sic_cls;
171}; 193};
172 194
173 195
174/** 196/**
197 * If a session monitor is attached, notify it about the new
198 * session state.
199 *
200 * @param plugin our plugin
201 * @param session session that changed state
202 * @param state new state of the session
203 */
204static void
205notify_session_monitor (struct Plugin *plugin,
206 struct Session *session,
207 enum GNUNET_TRANSPORT_SessionState state)
208{
209 struct GNUNET_TRANSPORT_SessionInfo info;
210
211 if (NULL == plugin->sic)
212 return;
213 memset (&info, 0, sizeof (info));
214 info.state = state;
215 info.is_inbound = GNUNET_SYSERR; /* hard to say */
216 info.num_msg_pending = session->msgs_in_queue;
217 info.num_bytes_pending = session->bytes_in_queue;
218 /* info.receive_delay remains zero as this is not supported by DV
219 (cannot selectively not receive from 'core') */
220 info.session_timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
221 info.address = session->address;
222 plugin->sic (plugin->sic_cls,
223 session,
224 &info);
225}
226
227
228/**
175 * Notify transport service about the change in distance. 229 * Notify transport service about the change in distance.
176 * 230 *
177 * @param session session where the distance changed 231 * @param session session where the distance changed
@@ -320,7 +374,7 @@ handle_dv_connect (void *cls,
320 } 374 }
321 375
322 session = GNUNET_new (struct Session); 376 session = GNUNET_new (struct Session);
323 session->address = GNUNET_HELLO_address_allocate (peer, PLUGIN_NAME, 377 session->address = GNUNET_HELLO_address_allocate (peer, "dv",
324 NULL, 0, GNUNET_HELLO_ADDRESS_INFO_NONE); 378 NULL, 0, GNUNET_HELLO_ADDRESS_INFO_NONE);
325 session->sender = *peer; 379 session->sender = *peer;
326 session->plugin = plugin; 380 session->plugin = plugin;
@@ -345,6 +399,9 @@ handle_dv_connect (void *cls,
345 session->active = GNUNET_YES; 399 session->active = GNUNET_YES;
346 plugin->env->session_start (plugin->env->cls, session->address, 400 plugin->env->session_start (plugin->env->cls, session->address,
347 session, ats, 2); 401 session, ats, 2);
402 notify_session_monitor (session->plugin,
403 session,
404 GNUNET_TRANSPORT_SS_UP);
348} 405}
349 406
350 407
@@ -406,6 +463,9 @@ free_session (struct Session *session)
406 GNUNET_i2s (&session->sender)); 463 GNUNET_i2s (&session->sender));
407 if (GNUNET_YES == session->active) 464 if (GNUNET_YES == session->active)
408 { 465 {
466 notify_session_monitor (session->plugin,
467 session,
468 GNUNET_TRANSPORT_SS_DOWN);
409 plugin->env->session_end (plugin->env->cls, 469 plugin->env->session_end (plugin->env->cls,
410 session->address, 470 session->address,
411 session); 471 session);
@@ -802,7 +862,7 @@ dv_get_network (void *cls,
802 862
803/** 863/**
804 * Function that is called to get the keepalive factor. 864 * Function that is called to get the keepalive factor.
805 * GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to 865 * #GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to
806 * calculate the interval between keepalive packets. 866 * calculate the interval between keepalive packets.
807 * 867 *
808 * @param cls closure with the `struct Plugin` 868 * @param cls closure with the `struct Plugin`
@@ -816,6 +876,64 @@ dv_plugin_query_keepalive_factor (void *cls)
816 876
817 877
818/** 878/**
879 * Return information about the given session to the
880 * monitor callback.
881 *
882 * @param cls the `struct Plugin` with the monitor callback (`sic`)
883 * @param peer peer we send information about
884 * @param value our `struct Session` to send information about
885 * @return #GNUNET_OK (continue to iterate)
886 */
887static int
888send_session_info_iter (void *cls,
889 const struct GNUNET_PeerIdentity *peer,
890 void *value)
891{
892 struct Plugin *plugin = cls;
893 struct Session *session = value;
894
895 if (GNUNET_YES != session->active)
896 return GNUNET_OK;
897 notify_session_monitor (plugin,
898 session,
899 GNUNET_TRANSPORT_SS_UP);
900 return GNUNET_OK;
901}
902
903
904/**
905 * Begin monitoring sessions of a plugin. There can only
906 * be one active monitor per plugin (i.e. if there are
907 * multiple monitors, the transport service needs to
908 * multiplex the generated events over all of them).
909 *
910 * @param cls closure of the plugin
911 * @param sic callback to invoke, NULL to disable monitor;
912 * plugin will being by iterating over all active
913 * sessions immediately and then enter monitor mode
914 * @param sic_cls closure for @a sic
915 */
916static void
917dv_plugin_setup_monitor (void *cls,
918 GNUNET_TRANSPORT_SessionInfoCallback sic,
919 void *sic_cls)
920{
921 struct Plugin *plugin = cls;
922
923 plugin->sic = sic;
924 plugin->sic_cls = sic_cls;
925 if (NULL != sic)
926 {
927 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions,
928 &send_session_info_iter,
929 plugin);
930 /* signal end of first iteration */
931 sic (sic_cls, NULL, NULL);
932 }
933}
934
935
936/**
819 * Entry point for the plugin. 937 * Entry point for the plugin.
820 * 938 *
821 * @param cls closure with the plugin environment 939 * @param cls closure with the plugin environment
@@ -859,6 +977,7 @@ libgnunet_plugin_transport_dv_init (void *cls)
859 api->get_session = &dv_get_session; 977 api->get_session = &dv_get_session;
860 api->get_network = &dv_get_network; 978 api->get_network = &dv_get_network;
861 api->update_session_timeout = &dv_plugin_update_session_timeout; 979 api->update_session_timeout = &dv_plugin_update_session_timeout;
980 api->setup_monitor = &dv_plugin_setup_monitor;
862 return api; 981 return api;
863} 982}
864 983