GNUnet  0.10.x
plugin_transport_template.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet
3  Copyright (C) 2002-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_protocols.h"
33 
34 #define LOG(kind, ...) GNUNET_log_from(kind, "transport-template", __VA_ARGS__)
35 
41 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6)
42 
43 #define PLUGIN_NAME "template"
44 
48 struct Plugin;
49 
50 
54 struct GNUNET_ATS_Session {
60 
64  struct GNUNET_ATS_Session *next;
65 
69  struct Plugin *plugin;
70 
74  /* void *client; */
75 
82 
87 
92 
97  uint64_t last_received;
98 
103  uint32_t quota;
104 };
105 
107 
113 
114  /* Add address here */
115 };
116 
118 
122 struct Plugin {
127 
132 
137 
141  void *sic_cls;
142 
146 };
147 
148 
149 #if 0
150 
158 static void
160  struct GNUNET_ATS_Session *session,
162 {
163  struct GNUNET_TRANSPORT_SessionInfo info;
164 
165  if (NULL == plugin->sic)
166  return;
167  memset(&info, 0, sizeof(info));
168  info.state = state;
169  info.is_inbound = GNUNET_SYSERR; /* FIXME */
170  // info.num_msg_pending =
171  // info.num_bytes_pending =
172  // info.receive_delay =
173  // info.session_timeout = session->timeout;
174  // info.address = session->address;
175  plugin->sic(plugin->sic_cls,
176  session,
177  &info);
178 }
179 #endif
180 
181 
209 static ssize_t
211  struct GNUNET_ATS_Session *session,
212  const char *msgbuf,
213  size_t msgbuf_size,
214  unsigned int priority,
215  struct GNUNET_TIME_Relative to,
217  void *cont_cls)
218 {
219  /* struct Plugin *plugin = cls; */
220  ssize_t bytes_sent = 0;
221 
222  return bytes_sent;
223 }
224 
225 
234 static void
236  const struct GNUNET_PeerIdentity *target)
237 {
238  // struct Plugin *plugin = cls;
239  // FIXME
240 }
241 
242 
252 static int
254  struct GNUNET_ATS_Session *session)
255 {
256  // struct Plugin *plugin = cls;
257  // FIXME
258  return GNUNET_SYSERR;
259 }
260 
261 
270 static unsigned int
272 {
273  return 3;
274 }
275 
276 
284 static enum GNUNET_NetworkType
286  struct GNUNET_ATS_Session *session)
287 {
288  GNUNET_assert(NULL != session);
289  return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */
290 }
291 
292 
300 static enum GNUNET_NetworkType
302  const struct GNUNET_HELLO_Address *address)
303 {
304  return GNUNET_NT_WAN; /* FOR NOW */
305 }
306 
307 
322 static void
324  const void *addr, size_t addrlen,
325  int numeric,
328  asc, void *asc_cls)
329 {
330  asc(asc_cls, "converted address", GNUNET_OK); /* return address */
331  asc(asc_cls, NULL, GNUNET_OK); /* done */
332 }
333 
334 
335 
348 static int
349 template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
350 {
351  /* struct Plugin *plugin = cls; */
352 
353  /* check if the address is belonging to the plugin*/
354  return GNUNET_OK;
355 }
356 
357 
369 static const char *
370 template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
371 {
372  /*
373  * Print address in format template.options.address
374  */
375 
376  if (0 == addrlen)
377  {
379  }
380 
381  GNUNET_break(0);
382  return NULL;
383 }
384 
385 
398 static int
400  const char *addr,
401  uint16_t addrlen,
402  void **buf, size_t *added)
403 {
404  /*
405  * Parse string in format template.options.address
406  */
407  GNUNET_break(0);
408  return GNUNET_SYSERR;
409 }
410 
411 
421 static struct GNUNET_ATS_Session *
423  const struct GNUNET_HELLO_Address *address)
424 {
425  GNUNET_break(0);
426  return NULL;
427 }
428 
429 
430 static void
432  const struct GNUNET_PeerIdentity *peer,
433  struct GNUNET_ATS_Session *session)
434 {
435 }
436 
437 
438 #if 0
439 
448 static int
449 send_session_info_iter(void *cls,
450  const struct GNUNET_PeerIdentity *peer,
451  void *value)
452 {
453  struct Plugin *plugin = cls;
454  struct GNUNET_ATS_Session *session = value;
455 
456  notify_session_monitor(plugin,
457  session,
459  return GNUNET_OK;
460 }
461 #endif
462 
463 
476 static void
479  void *sic_cls)
480 {
481  struct Plugin *plugin = cls;
482 
483  plugin->sic = sic;
484  plugin->sic_cls = sic_cls;
485  if (NULL != sic)
486  {
487 #if 0
488  GNUNET_CONTAINER_multipeermap_iterate(NULL /* FIXME */,
490  plugin);
491 #endif
492  /* signal end of first iteration */
493  sic(sic_cls, NULL, NULL);
494  }
495 }
496 
497 
501 void *
503 {
506  struct Plugin *plugin;
507 
508  if (NULL == env->receive)
509  {
510  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
511  initialze the plugin or the API */
513  api->cls = NULL;
517  return api;
518  }
519 
520  plugin = GNUNET_new(struct Plugin);
521  plugin->env = env;
523  api->cls = plugin;
524  api->send = &template_plugin_send;
537  LOG(GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
538  return api;
539 }
540 
541 
545 void *
547 {
549  struct Plugin *plugin = api->cls;
550 
551  GNUNET_free(plugin);
552  GNUNET_free(api);
553  return NULL;
554 }
555 
556 /* end of plugin_transport_template.c */
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
static int template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
Another peer has suggested an address for this peer and transport plugin.
static int template_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
GNUNET_TRANSPORT_AddressToString address_to_string
Function that will be called to convert a binary address to a string (numeric conversion only)...
size_t addrlen
Address length.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_ATS_Session * next
Stored in a linked list.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
GNUNET_TRANSPORT_DisconnectPeerFunction disconnect_peer
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
static void template_plugin_setup_monitor(void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
Begin monitoring sessions of a plugin.
int is_inbound
GNUNET_YES if this is an inbound connection, GNUNET_NO if this is an outbound connection, GNUNET_SYSERR if connections of this plugin are so fundamentally bidirectional that they have no &#39;initiator&#39;
enum GNUNET_TRANSPORT_SessionState state
New state of the session.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int send_session_info_iter(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Return information about the given session to the monitor callback.
GNUNET_TRANSPORT_DisconnectSessionFunction disconnect_session
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_TRANSPORT_SessionMonitorSetup setup_monitor
Function to monitor the sessions managed by the plugin.
void * libgnunet_plugin_transport_template_done(void *cls)
Exit point from the plugin.
static void template_plugin_disconnect_peer(void *cls, const struct GNUNET_PeerIdentity *target)
Function that can be used to force the plugin to disconnect from the given peer and cancel all previo...
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define TRANSPORT_SESSION_INBOUND_STRING
Wide area network (i.e.
Definition: gnunet_nt_lib.h:54
static int numeric
Option -n.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HELLO_Address * address
Address.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static int template_plugin_string_to_address(void *cls, const char *addr, uint16_t addrlen, void **buf, size_t *added)
Function called to convert a string address to a binary address.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32.
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:46
void * transmit_cont_cls
Closure for transmit_cont.
GNUNET_TRANSPORT_PluginReceiveCallback receive
Function that should be called by the transport plugin whenever a message is received.
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...
Information about a plugin&#39;s session.
static void notify_session_monitor(struct HTTP_Client_Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
#define LOG(kind,...)
void * cls
Closure for the various callbacks.
enum State state
current state of profiling
void * cls
Closure for all of the callbacks.
static char * value
Value of the record to add/remove.
void(* GNUNET_TRANSPORT_AddressStringCallback)(void *cls, const char *address, int res)
Function called by the pretty printer for the resolved address for each human-readable address obtain...
GNUNET_TRANSPORT_StringToAddress string_to_address
Function that will be called to convert a string address to binary (numeric conversion only)...
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
GNUNET_TRANSPORT_GetNetworkType get_network
Function to obtain the network type for a session.
struct GNUNET_PeerIdentity sender
To whom are we talking to (set to our identity if we are still waiting for the welcome message) ...
static char buf[2048]
uint64_t last_received
How many bytes have we received since the last_quota_update timestamp?
void(* GNUNET_TRANSPORT_SessionInfoCallback)(void *cls, struct GNUNET_ATS_Session *session, const struct GNUNET_TRANSPORT_SessionInfo *info)
Function called by the plugin with information about the current sessions managed by the plugin (for ...
static enum GNUNET_NetworkType template_plugin_get_network_for_address(void *cls, const struct GNUNET_HELLO_Address *address)
Function obtain the network type for an address.
static enum GNUNET_NetworkType template_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
Function obtain the network type for a session.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int template_plugin_query_keepalive_factor(void *cls)
Function that is called to get the keepalive factor.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void(* GNUNET_TRANSPORT_TransmitContinuation)(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
Function called by the GNUNET_TRANSPORT_TransmitFunction upon "completion".
static void template_plugin_update_session_timeout(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
static struct GNUNET_ATS_Session * template_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
Create a new session to transmit data to the target This session will used to send data to this peer ...
static const char * template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
uint32_t quota
Number of bytes per ms that this peer is allowed to send to us.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won&#39;t work on W32;.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
The identity of the host (wraps the signing key of the peer).
static void template_plugin_address_pretty_printer(void *cls, const char *type, const void *addr, size_t addrlen, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
Convert the transports address to a nice, human-readable format.
#define GNUNET_PACKED
gcc-ism to get packed structs.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_TIME_Absolute last_quota_update
At what time did we reset last_received last?
struct GNUNET_PeerIdentity target
To whom are we talking to.
static ssize_t template_plugin_send(void *cls, struct GNUNET_ATS_Session *session, const char *msgbuf, size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Function that can be used by the transport service to transmit a message using the plugin...
An address for communicating with a peer.
void * libgnunet_plugin_transport_template_init(void *cls)
Entry point for the plugin.
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer
Function to pretty-print addresses.
Time for absolute times used by GNUnet, in microseconds.
GNUNET_TRANSPORT_CheckAddress check_address
Function that will be called to check if a binary address for this plugin is well-formed and correspo...
GNUNET_TRANSPORT_SessionState
Possible states of a session in a plugin.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
The client (used to identify this connection)
void * sic_cls
Closure for sic.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
GNUNET_TRANSPORT_GetNetworkTypeForAddress get_network_for_address
Function to obtain the network type for an address.
Category of last resort.
Definition: gnunet_nt_lib.h:39