aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_template.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-22 22:53:52 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-22 22:53:52 +0000
commit7114c13aa08b9843277f08ce401e23e2a4a75953 (patch)
tree3388b8f84b32f7dae3394491e5b1defd87586fc1 /src/transport/plugin_transport_template.c
parent79c78b7fe41811b2d71f3f4d5853acef6ac9ec2b (diff)
downloadgnunet-7114c13aa08b9843277f08ce401e23e2a4a75953.tar.gz
gnunet-7114c13aa08b9843277f08ce401e23e2a4a75953.zip
-updateing tempalte
Diffstat (limited to 'src/transport/plugin_transport_template.c')
-rw-r--r--src/transport/plugin_transport_template.c156
1 files changed, 130 insertions, 26 deletions
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index a7abca210..b943171b1 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 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
@@ -60,7 +60,7 @@ struct Session
60 struct GNUNET_PeerIdentity sender; 60 struct GNUNET_PeerIdentity sender;
61 61
62 /** 62 /**
63 * Stored in a linked list. 63 * Stored in a linked list (or a peer map, or ...)
64 */ 64 */
65 struct Session *next; 65 struct Session *next;
66 66
@@ -82,17 +82,17 @@ struct Session
82 GNUNET_TRANSPORT_TransmitContinuation transmit_cont; 82 GNUNET_TRANSPORT_TransmitContinuation transmit_cont;
83 83
84 /** 84 /**
85 * Closure for transmit_cont. 85 * Closure for @e transmit_cont.
86 */ 86 */
87 void *transmit_cont_cls; 87 void *transmit_cont_cls;
88 88
89 /** 89 /**
90 * At what time did we reset last_received last? 90 * At what time did we reset @e last_received last?
91 */ 91 */
92 struct GNUNET_TIME_Absolute last_quota_update; 92 struct GNUNET_TIME_Absolute last_quota_update;
93 93
94 /** 94 /**
95 * How many bytes have we received since the "last_quota_update" 95 * How many bytes have we received since the @e last_quota_update
96 * timestamp? 96 * timestamp?
97 */ 97 */
98 uint64_t last_received; 98 uint64_t last_received;
@@ -109,12 +109,12 @@ GNUNET_NETWORK_STRUCT_BEGIN
109 109
110struct TemplateAddress 110struct TemplateAddress
111{ 111{
112 /** 112 /**
113 * Address options in NBO 113 * Address options in NBO
114 */ 114 */
115 uint32_t options GNUNET_PACKED; 115 uint32_t options GNUNET_PACKED;
116 116
117 /* Add address here */ 117 /* Add address here */
118}; 118};
119 119
120GNUNET_NETWORK_STRUCT_END 120GNUNET_NETWORK_STRUCT_END
@@ -130,17 +130,60 @@ struct Plugin
130 struct GNUNET_TRANSPORT_PluginEnvironment *env; 130 struct GNUNET_TRANSPORT_PluginEnvironment *env;
131 131
132 /** 132 /**
133 * List of open sessions. 133 * List of open sessions (or peer map, or...)
134 */ 134 */
135 struct Session *sessions; 135 struct Session *sessions;
136 136
137 /** 137 /**
138 * Function to call about session status changes.
139 */
140 GNUNET_TRANSPORT_SessionInfoCallback sic;
141
142 /**
143 * Closure for @e sic.
144 */
145 void *sic_cls;
146
147 /**
138 * Options in HBO to be used with addresses 148 * Options in HBO to be used with addresses
139 */ 149 */
140 150
141}; 151};
142 152
143 153
154#if 0
155/**
156 * If a session monitor is attached, notify it about the new
157 * session state.
158 *
159 * @param plugin our plugin
160 * @param session session that changed state
161 * @param state new state of the session
162 */
163static void
164notify_session_monitor (struct Plugin *plugin,
165 struct Session *session,
166 enum GNUNET_TRANSPORT_SessionState state)
167{
168 struct GNUNET_TRANSPORT_SessionInfo info;
169
170 if (NULL == plugin->sic)
171 return;
172 memset (&info, 0, sizeof (info));
173 info.state = state;
174 info.is_inbound = GNUNET_SYSERR; /* FIXME */
175 // info.num_msg_pending =
176 // info.num_bytes_pending =
177 // info.receive_delay =
178 // info.session_timeout = session->timeout;
179 // info.address = session->address;
180 plugin->sic (plugin->sic_cls,
181 session,
182 &info);
183}
184#endif
185
186
144/** 187/**
145 * Function that can be used by the transport service to transmit 188 * Function that can be used by the transport service to transmit
146 * a message using the plugin. Note that in the case of a 189 * a message using the plugin. Note that in the case of a
@@ -170,19 +213,17 @@ struct Plugin
170 */ 213 */
171static ssize_t 214static ssize_t
172template_plugin_send (void *cls, 215template_plugin_send (void *cls,
173 struct Session *session, 216 struct Session *session,
174 const char *msgbuf, size_t msgbuf_size, 217 const char *msgbuf,
175 unsigned int priority, 218 size_t msgbuf_size,
176 struct GNUNET_TIME_Relative to, 219 unsigned int priority,
177 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 220 struct GNUNET_TIME_Relative to,
221 GNUNET_TRANSPORT_TransmitContinuation cont,
222 void *cont_cls)
178{ 223{
179 struct Plugin *plugin = cls;
180 int bytes_sent = 0;
181
182 GNUNET_assert (plugin != NULL);
183 GNUNET_assert (session != NULL);
184
185 /* struct Plugin *plugin = cls; */ 224 /* struct Plugin *plugin = cls; */
225 ssize_t bytes_sent = 0;
226
186 return bytes_sent; 227 return bytes_sent;
187} 228}
188 229
@@ -243,7 +284,7 @@ template_plugin_query_keepalive_factor (void *cls)
243 * 284 *
244 * @param cls closure ('struct Plugin*') 285 * @param cls closure ('struct Plugin*')
245 * @param session the session 286 * @param session the session
246 * @return the network type in HBO or GNUNET_SYSERR 287 * @return the network type in HBO or #GNUNET_SYSERR
247 */ 288 */
248static enum GNUNET_ATS_Network_Type 289static enum GNUNET_ATS_Network_Type
249template_plugin_get_network (void *cls, 290template_plugin_get_network (void *cls,
@@ -266,7 +307,7 @@ template_plugin_get_network (void *cls,
266 * @param numeric should (IP) addresses be displayed in numeric form? 307 * @param numeric should (IP) addresses be displayed in numeric form?
267 * @param timeout after how long should we give up? 308 * @param timeout after how long should we give up?
268 * @param asc function to call on each string 309 * @param asc function to call on each string
269 * @param asc_cls closure for asc 310 * @param asc_cls closure for @a asc
270 */ 311 */
271static void 312static void
272template_plugin_address_pretty_printer (void *cls, const char *type, 313template_plugin_address_pretty_printer (void *cls, const char *type,
@@ -375,14 +416,76 @@ template_plugin_get_session (void *cls,
375 return NULL; 416 return NULL;
376} 417}
377 418
419
378static void 420static void
379template_plugin_update_session_timeout (void *cls, 421template_plugin_update_session_timeout (void *cls,
380 const struct GNUNET_PeerIdentity *peer, 422 const struct GNUNET_PeerIdentity *peer,
381 struct Session *session) 423 struct Session *session)
382{ 424{
383 425
384} 426}
385 427
428
429#if 0
430/**
431 * Return information about the given session to the
432 * monitor callback.
433 *
434 * @param cls the `struct Plugin` with the monitor callback (`sic`)
435 * @param peer peer we send information about
436 * @param value our `struct Session` to send information about
437 * @return #GNUNET_OK (continue to iterate)
438 */
439static int
440send_session_info_iter (void *cls,
441 const struct GNUNET_PeerIdentity *peer,
442 void *value)
443{
444 struct Plugin *plugin = cls;
445 struct Session *session = value;
446
447 notify_session_monitor (plugin,
448 session,
449 GNUNET_TRANSPORT_SS_UP);
450 return GNUNET_OK;
451}
452#endif
453
454
455/**
456 * Begin monitoring sessions of a plugin. There can only
457 * be one active monitor per plugin (i.e. if there are
458 * multiple monitors, the transport service needs to
459 * multiplex the generated events over all of them).
460 *
461 * @param cls closure of the plugin
462 * @param sic callback to invoke, NULL to disable monitor;
463 * plugin will being by iterating over all active
464 * sessions immediately and then enter monitor mode
465 * @param sic_cls closure for @a sic
466 */
467static void
468template_plugin_setup_monitor (void *cls,
469 GNUNET_TRANSPORT_SessionInfoCallback sic,
470 void *sic_cls)
471{
472 struct Plugin *plugin = cls;
473
474 plugin->sic = sic;
475 plugin->sic_cls = sic_cls;
476 if (NULL != sic)
477 {
478#if 0
479 GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */,
480 &send_session_info_iter,
481 plugin);
482#endif
483 /* signal end of first iteration */
484 sic (sic_cls, NULL, NULL);
485 }
486}
487
488
386/** 489/**
387 * Entry point for the plugin. 490 * Entry point for the plugin.
388 */ 491 */
@@ -420,6 +523,7 @@ libgnunet_plugin_transport_template_init (void *cls)
420 api->get_session = &template_plugin_get_session; 523 api->get_session = &template_plugin_get_session;
421 api->get_network = &template_plugin_get_network; 524 api->get_network = &template_plugin_get_network;
422 api->update_session_timeout = &template_plugin_update_session_timeout; 525 api->update_session_timeout = &template_plugin_update_session_timeout;
526 api->setup_monitor = &template_plugin_setup_monitor;
423 LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); 527 LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
424 return api; 528 return api;
425} 529}