#include "gnunet_transport_service.h"
#include "gnunet_transport_plugin.h"
-#define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING
+#define LOG(kind,...) GNUNET_log_from (kind, "transport-template",__VA_ARGS__)
/**
* After how long do we expire an address that we
*/
#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6)
+#define PLUGIN_NAME "template"
/**
* Encapsulation of all of the state of the plugin.
};
+GNUNET_NETWORK_STRUCT_BEGIN
+
+struct TemplateAddress
+{
+ /**
+ * Address options in NBO
+ */
+ uint32_t options GNUNET_PACKED;
+
+ /* Add address here */
+};
+
+GNUNET_NETWORK_STRUCT_END
+
/**
* Encapsulation of all of the state of the plugin.
*/
*/
struct Session *sessions;
+ /**
+ * Options in HBO to be used with addresses
+ */
+
};
}
+/**
+ * Function obtain the network type for a session
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param session the session
+ * @return the network type in HBO or GNUNET_SYSERR
+ */
+static enum GNUNET_ATS_Network_Type
+template_plugin_get_network (void *cls,
+ struct Session *session)
+{
+ GNUNET_assert (NULL != session);
+ return GNUNET_ATS_NET_UNSPECIFIED; /* Change to correct network type */
+}
+
+
/**
* Convert the transports address to a nice, human-readable
* format.
GNUNET_TRANSPORT_AddressStringCallback
asc, void *asc_cls)
{
+ if (0 == addrlen)
+ {
+ asc (asc_cls, TRANSPORT_SESSION_INBOUND_STRING);
+ }
+
asc (asc_cls, NULL);
}
{
/* struct Plugin *plugin = cls; */
- /* check if the address is plausible; if so,
- * add it to our list! */
+ /* check if the address is belonging to the plugin*/
return GNUNET_OK;
}
static const char *
template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
{
+ /*
+ * Print address in format template.options.address
+ */
+
+ if (0 == addrlen)
+ {
+ return TRANSPORT_SESSION_INBOUND_STRING;
+ }
+
GNUNET_break (0);
return NULL;
}
+/**
+ * Function called to convert a string address to
+ * a binary address.
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param addr string address
+ * @param addrlen length of the address
+ * @param buf location to store the buffer
+ * @param added location to store the number of bytes in the buffer.
+ * If the function returns GNUNET_SYSERR, its contents are undefined.
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+static int
+template_plugin_string_to_address (void *cls, const char *addr, uint16_t addrlen,
+ void **buf, size_t *added)
+{
+
+ /*
+ * Parse string in format template.options.address
+ */
+
+
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+}
+
+/**
+ * Create a new session to transmit data to the target
+ * This session will used to send data to this peer and the plugin will
+ * notify us by calling the env->session_end function
+ *
+ * @param cls closure
+ * @param address pointer to the GNUNET_HELLO_Address
+ * @return the session if the address is valid, NULL otherwise
+ */
+static struct Session *
+template_plugin_get_session (void *cls,
+ const struct GNUNET_HELLO_Address *address)
+{
+ GNUNET_break (0);
+ return NULL;
+}
/**
* Entry point for the plugin.
*/
void *
-gnunet_plugin_transport_template_init (void *cls)
+libgnunet_plugin_transport_template_init (void *cls)
{
struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
struct GNUNET_TRANSPORT_PluginFunctions *api;
struct Plugin *plugin;
+ if (NULL == env->receive)
+ {
+ /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
+ initialze the plugin or the API */
+ api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
+ api->cls = NULL;
+ api->address_to_string = &template_plugin_address_to_string;
+ api->string_to_address = &template_plugin_string_to_address;
+ api->address_pretty_printer = &template_plugin_address_pretty_printer;
+ return api;
+ }
+
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->env = env;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->address_pretty_printer = &template_plugin_address_pretty_printer;
api->check_address = &template_plugin_address_suggested;
api->address_to_string = &template_plugin_address_to_string;
+ api->string_to_address = &template_plugin_string_to_address;
+ api->get_session = &template_plugin_get_session;
+ api->get_network = &template_plugin_get_network;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
return api;
}
* Exit point from the plugin.
*/
void *
-gnunet_plugin_transport_template_done (void *cls)
+libgnunet_plugin_transport_template_done (void *cls)
{
struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
struct Plugin *plugin = api->cls;