From 7114c13aa08b9843277f08ce401e23e2a4a75953 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 22 Jun 2014 22:53:52 +0000 Subject: -updateing tempalte --- src/transport/plugin_transport_template.c | 156 +++++++++++++++++++++++++----- src/transport/plugin_transport_unix.c | 109 +++++++++++---------- 2 files changed, 186 insertions(+), 79 deletions(-) (limited to 'src') 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 @@ /* This file is part of GNUnet - (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) + (C) 2002-2014 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -60,7 +60,7 @@ struct Session struct GNUNET_PeerIdentity sender; /** - * Stored in a linked list. + * Stored in a linked list (or a peer map, or ...) */ struct Session *next; @@ -82,17 +82,17 @@ struct Session GNUNET_TRANSPORT_TransmitContinuation transmit_cont; /** - * Closure for transmit_cont. + * Closure for @e transmit_cont. */ void *transmit_cont_cls; /** - * At what time did we reset last_received last? + * At what time did we reset @e last_received last? */ struct GNUNET_TIME_Absolute last_quota_update; /** - * How many bytes have we received since the "last_quota_update" + * How many bytes have we received since the @e last_quota_update * timestamp? */ uint64_t last_received; @@ -109,12 +109,12 @@ GNUNET_NETWORK_STRUCT_BEGIN struct TemplateAddress { - /** - * Address options in NBO - */ - uint32_t options GNUNET_PACKED; + /** + * Address options in NBO + */ + uint32_t options GNUNET_PACKED; - /* Add address here */ + /* Add address here */ }; GNUNET_NETWORK_STRUCT_END @@ -130,10 +130,20 @@ struct Plugin struct GNUNET_TRANSPORT_PluginEnvironment *env; /** - * List of open sessions. + * List of open sessions (or peer map, or...) */ struct Session *sessions; + /** + * Function to call about session status changes. + */ + GNUNET_TRANSPORT_SessionInfoCallback sic; + + /** + * Closure for @e sic. + */ + void *sic_cls; + /** * Options in HBO to be used with addresses */ @@ -141,6 +151,39 @@ struct Plugin }; +#if 0 +/** + * If a session monitor is attached, notify it about the new + * session state. + * + * @param plugin our plugin + * @param session session that changed state + * @param state new state of the session + */ +static void +notify_session_monitor (struct Plugin *plugin, + struct Session *session, + enum GNUNET_TRANSPORT_SessionState state) +{ + struct GNUNET_TRANSPORT_SessionInfo info; + + if (NULL == plugin->sic) + return; + memset (&info, 0, sizeof (info)); + info.state = state; + info.is_inbound = GNUNET_SYSERR; /* FIXME */ + // info.num_msg_pending = + // info.num_bytes_pending = + // info.receive_delay = + // info.session_timeout = session->timeout; + // info.address = session->address; + plugin->sic (plugin->sic_cls, + session, + &info); +} +#endif + + /** * Function that can be used by the transport service to transmit * a message using the plugin. Note that in the case of a @@ -170,19 +213,17 @@ struct Plugin */ static ssize_t template_plugin_send (void *cls, - struct Session *session, - const char *msgbuf, size_t msgbuf_size, - unsigned int priority, - struct GNUNET_TIME_Relative to, - GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) + struct Session *session, + const char *msgbuf, + size_t msgbuf_size, + unsigned int priority, + struct GNUNET_TIME_Relative to, + GNUNET_TRANSPORT_TransmitContinuation cont, + void *cont_cls) { - struct Plugin *plugin = cls; - int bytes_sent = 0; - - GNUNET_assert (plugin != NULL); - GNUNET_assert (session != NULL); - /* struct Plugin *plugin = cls; */ + ssize_t bytes_sent = 0; + return bytes_sent; } @@ -243,7 +284,7 @@ template_plugin_query_keepalive_factor (void *cls) * * @param cls closure ('struct Plugin*') * @param session the session - * @return the network type in HBO or GNUNET_SYSERR + * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_ATS_Network_Type template_plugin_get_network (void *cls, @@ -266,7 +307,7 @@ template_plugin_get_network (void *cls, * @param numeric should (IP) addresses be displayed in numeric form? * @param timeout after how long should we give up? * @param asc function to call on each string - * @param asc_cls closure for asc + * @param asc_cls closure for @a asc */ static void template_plugin_address_pretty_printer (void *cls, const char *type, @@ -375,14 +416,76 @@ template_plugin_get_session (void *cls, return NULL; } + static void template_plugin_update_session_timeout (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct Session *session) + const struct GNUNET_PeerIdentity *peer, + struct Session *session) { } + +#if 0 +/** + * Return information about the given session to the + * monitor callback. + * + * @param cls the `struct Plugin` with the monitor callback (`sic`) + * @param peer peer we send information about + * @param value our `struct Session` to send information about + * @return #GNUNET_OK (continue to iterate) + */ +static int +send_session_info_iter (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *value) +{ + struct Plugin *plugin = cls; + struct Session *session = value; + + notify_session_monitor (plugin, + session, + GNUNET_TRANSPORT_SS_UP); + return GNUNET_OK; +} +#endif + + +/** + * Begin monitoring sessions of a plugin. There can only + * be one active monitor per plugin (i.e. if there are + * multiple monitors, the transport service needs to + * multiplex the generated events over all of them). + * + * @param cls closure of the plugin + * @param sic callback to invoke, NULL to disable monitor; + * plugin will being by iterating over all active + * sessions immediately and then enter monitor mode + * @param sic_cls closure for @a sic + */ +static void +template_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) +{ + struct Plugin *plugin = cls; + + plugin->sic = sic; + plugin->sic_cls = sic_cls; + if (NULL != sic) + { +#if 0 + GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */, + &send_session_info_iter, + plugin); +#endif + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } +} + + /** * Entry point for the plugin. */ @@ -420,6 +523,7 @@ libgnunet_plugin_transport_template_init (void *cls) api->get_session = &template_plugin_get_session; api->get_network = &template_plugin_get_network; api->update_session_timeout = &template_plugin_update_session_timeout; + api->setup_monitor = &template_plugin_setup_monitor; LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); return api; } diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 7dff9587f..6c0c12065 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c @@ -382,9 +382,9 @@ notify_session_monitor (struct Plugin *plugin, * @return string representing the same address */ static const char * -unix_address_to_string (void *cls, - const void *addr, - size_t addrlen) +unix_plugin_address_to_string (void *cls, + const void *addr, + size_t addrlen) { static char rbuf[1024]; struct UnixAddress *ua = (struct UnixAddress *) addr; @@ -442,8 +442,8 @@ unix_address_to_string (void *cls, * @return #GNUNET_OK on success */ static int -unix_session_disconnect (void *cls, - struct Session *session) +unix_plugin_session_disconnect (void *cls, + struct Session *session) { struct Plugin *plugin = cls; struct UNIXMessageWrapper *msgw; @@ -452,9 +452,9 @@ unix_session_disconnect (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting session for peer `%s' `%s'\n", GNUNET_i2s (&session->target), - unix_address_to_string (NULL, - session->address->address, - session->address->address_length)); + unix_plugin_address_to_string (NULL, + session->address->address, + session->address->address_length)); plugin->env->session_end (plugin->env->cls, session->address, session); @@ -538,7 +538,7 @@ session_timeout (void *cls, session, GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_YES)); - unix_session_disconnect (session->plugin, session); + unix_plugin_session_disconnect (session->plugin, session); } @@ -662,7 +662,7 @@ lookup_session (struct Plugin *plugin, * @return keepalive factor */ static unsigned int -unix_query_keepalive_factor (void *cls) +unix_plugin_query_keepalive_factor (void *cls) { return 3; } @@ -808,8 +808,8 @@ resend: * @return the network type in HBO or #GNUNET_SYSERR */ static enum GNUNET_ATS_Network_Type -unix_get_network (void *cls, - struct Session *session) +unix_plugin_get_network (void *cls, + struct Session *session) { GNUNET_assert (NULL != session); return GNUNET_ATS_NET_LOOPBACK; @@ -875,9 +875,9 @@ unix_plugin_get_session (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p for address `%s'\n", session, - unix_address_to_string (NULL, - address->address, - address->address_length)); + unix_plugin_address_to_string (NULL, + address->address, + address->address_length)); return session; } @@ -892,9 +892,9 @@ unix_plugin_get_session (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating a new session %p for address `%s'\n", session, - unix_address_to_string (NULL, - address->address, - address->address_length)); + unix_plugin_address_to_string (NULL, + address->address, + address->address_length)); (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, &address->peer, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); @@ -959,7 +959,7 @@ unix_demultiplexer (struct Plugin *plugin, GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n", - unix_address_to_string (NULL, ua, ua_len)); + unix_plugin_address_to_string (NULL, ua, ua_len)); GNUNET_STATISTICS_update (plugin->env->stats, "# bytes received via UNIX", ntohs (currhdr->size), @@ -1321,9 +1321,9 @@ unix_plugin_send (void *cls, LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session for peer `%s' `%s'\n", GNUNET_i2s (&session->target), - unix_address_to_string(NULL, - session->address->address, - session->address->address_length)); + unix_plugin_address_to_string (NULL, + session->address->address, + session->address->address_length)); GNUNET_break (0); return GNUNET_SYSERR; } @@ -1331,9 +1331,9 @@ unix_plugin_send (void *cls, "Sending %u bytes with session for peer `%s' `%s'\n", msgbuf_size, GNUNET_i2s (&session->target), - unix_address_to_string (NULL, - session->address->address, - session->address->address_length)); + unix_plugin_address_to_string (NULL, + session->address->address, + session->address->address_length)); ssize = sizeof (struct UNIXMessage) + msgbuf_size; message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); message->header.size = htons (ssize); @@ -1452,9 +1452,9 @@ unix_transport_server_start (void *cls) * */ static int -unix_check_address (void *cls, - const void *addr, - size_t addrlen) +unix_plugin_check_address (void *cls, + const void *addr, + size_t addrlen) { struct Plugin* plugin = cls; const struct UnixAddress *ua = addr; @@ -1513,9 +1513,9 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, const char *ret; if ( (NULL != addr) && (addrlen > 0)) - ret = unix_address_to_string (NULL, - addr, - addrlen); + ret = unix_plugin_address_to_string (NULL, + addr, + addrlen); else ret = NULL; asc (asc_cls, @@ -1538,10 +1538,10 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ static int -unix_string_to_address (void *cls, - const char *addr, - uint16_t addrlen, - void **buf, size_t *added) +unix_plugin_string_to_address (void *cls, + const char *addr, + uint16_t addrlen, + void **buf, size_t *added) { struct UnixAddress *ua; char *address; @@ -1661,9 +1661,9 @@ get_session_delete_it (void *cls, void *value) { struct Plugin *plugin = cls; - struct Session *s = value; + struct Session *session = value; - unix_session_disconnect (plugin, s); + unix_plugin_session_disconnect (plugin, session); return GNUNET_YES; } @@ -1676,12 +1676,11 @@ get_session_delete_it (void *cls, * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed */ static void -unix_peer_disconnect (void *cls, - const struct GNUNET_PeerIdentity *target) +unix_plugin_peer_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; - GNUNET_assert (NULL != plugin); GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, target, &get_session_delete_it, plugin); @@ -1725,18 +1724,22 @@ send_session_info_iter (void *cls, * @param sic_cls closure for @a sic */ static void -unix_setup_monitor (void *cls, - GNUNET_TRANSPORT_SessionInfoCallback sic, - void *sic_cls) +unix_plugin_setup_monitor (void *cls, + GNUNET_TRANSPORT_SessionInfoCallback sic, + void *sic_cls) { struct Plugin *plugin = cls; plugin->sic = sic; plugin->sic_cls = sic_cls; if (NULL != sic) + { GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, &send_session_info_iter, plugin); + /* signal end of first iteration */ + sic (sic_cls, NULL, NULL); + } } @@ -1762,8 +1765,8 @@ libgnunet_plugin_transport_unix_init (void *cls) api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); api->cls = NULL; api->address_pretty_printer = &unix_plugin_address_pretty_printer; - api->address_to_string = &unix_address_to_string; - api->string_to_address = &unix_string_to_address; + api->address_to_string = &unix_plugin_address_to_string; + api->string_to_address = &unix_plugin_string_to_address; return api; } @@ -1797,16 +1800,16 @@ libgnunet_plugin_transport_unix_init (void *cls) api->cls = plugin; api->get_session = &unix_plugin_get_session; api->send = &unix_plugin_send; - api->disconnect_peer = &unix_peer_disconnect; - api->disconnect_session = &unix_session_disconnect; - api->query_keepalive_factor = &unix_query_keepalive_factor; + api->disconnect_peer = &unix_plugin_peer_disconnect; + api->disconnect_session = &unix_plugin_session_disconnect; + api->query_keepalive_factor = &unix_plugin_query_keepalive_factor; api->address_pretty_printer = &unix_plugin_address_pretty_printer; - api->address_to_string = &unix_address_to_string; - api->check_address = &unix_check_address; - api->string_to_address = &unix_string_to_address; - api->get_network = &unix_get_network; + api->address_to_string = &unix_plugin_address_to_string; + api->check_address = &unix_plugin_check_address; + api->string_to_address = &unix_plugin_string_to_address; + api->get_network = &unix_plugin_get_network; api->update_session_timeout = &unix_plugin_update_session_timeout; - api->setup_monitor = &unix_setup_monitor; + api->setup_monitor = &unix_plugin_setup_monitor; sockets_created = unix_transport_server_start (plugin); if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) { -- cgit v1.2.3