GNUnet  0.11.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 ( \
42  GNUNET_TIME_UNIT_HOURS, 6)
43 
44 #define PLUGIN_NAME "template"
45 
49 struct Plugin;
50 
51 
55 struct GNUNET_ATS_Session
56 {
62 
66  struct GNUNET_ATS_Session *next;
67 
71  struct Plugin *plugin;
72 
76  /* void *client; */
77 
84 
89 
94 
99  uint64_t last_received;
100 
105  uint32_t quota;
106 };
107 
109 
111 {
116 
117  /* Add address here */
118 };
119 
121 
125 struct Plugin
126 {
131 
136 
141 
145  void *sic_cls;
146 
150 };
151 
152 
153 #if 0
154 
162 static void
164  struct GNUNET_ATS_Session *session,
166 {
167  struct GNUNET_TRANSPORT_SessionInfo info;
168 
169  if (NULL == plugin->sic)
170  return;
171  memset (&info, 0, sizeof(info));
172  info.state = state;
173  info.is_inbound = GNUNET_SYSERR; /* FIXME */
174  // info.num_msg_pending =
175  // info.num_bytes_pending =
176  // info.receive_delay =
177  // info.session_timeout = session->timeout;
178  // info.address = session->address;
179  plugin->sic (plugin->sic_cls,
180  session,
181  &info);
182 }
183 
184 
185 #endif
186 
187 
215 static ssize_t
217  struct GNUNET_ATS_Session *session,
218  const char *msgbuf,
219  size_t msgbuf_size,
220  unsigned int priority,
221  struct GNUNET_TIME_Relative to,
223  void *cont_cls)
224 {
225  /* struct Plugin *plugin = cls; */
226  ssize_t bytes_sent = 0;
227 
228  return bytes_sent;
229 }
230 
231 
240 static void
242  const struct GNUNET_PeerIdentity *target)
243 {
244  // struct Plugin *plugin = cls;
245  // FIXME
246 }
247 
248 
258 static int
260  struct GNUNET_ATS_Session *session)
261 {
262  // struct Plugin *plugin = cls;
263  // FIXME
264  return GNUNET_SYSERR;
265 }
266 
267 
276 static unsigned int
278 {
279  return 3;
280 }
281 
282 
290 static enum GNUNET_NetworkType
292  struct GNUNET_ATS_Session *session)
293 {
294  GNUNET_assert (NULL != session);
295  return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */
296 }
297 
298 
306 static enum GNUNET_NetworkType
308  const struct
310 {
311  return GNUNET_NT_WAN; /* FOR NOW */
312 }
313 
314 
329 static void
331  const void *addr, size_t addrlen,
332  int numeric,
335  asc, void *asc_cls)
336 {
337  asc (asc_cls, "converted address", GNUNET_OK); /* return address */
338  asc (asc_cls, NULL, GNUNET_OK); /* done */
339 }
340 
341 
354 static int
355 template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
356 {
357  /* struct Plugin *plugin = cls; */
358 
359  /* check if the address is belonging to the plugin*/
360  return GNUNET_OK;
361 }
362 
363 
375 static const char *
376 template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
377 {
378  /*
379  * Print address in format template.options.address
380  */
381 
382  if (0 == addrlen)
383  {
385  }
386 
387  GNUNET_break (0);
388  return NULL;
389 }
390 
391 
404 static int
406  const char *addr,
407  uint16_t addrlen,
408  void **buf, size_t *added)
409 {
410  /*
411  * Parse string in format template.options.address
412  */
413  GNUNET_break (0);
414  return GNUNET_SYSERR;
415 }
416 
417 
427 static struct GNUNET_ATS_Session *
429  const struct GNUNET_HELLO_Address *address)
430 {
431  GNUNET_break (0);
432  return NULL;
433 }
434 
435 
436 static void
438  const struct GNUNET_PeerIdentity *peer,
439  struct GNUNET_ATS_Session *session)
440 {
441 }
442 
443 
444 #if 0
445 
454 static int
455 send_session_info_iter (void *cls,
456  const struct GNUNET_PeerIdentity *peer,
457  void *value)
458 {
459  struct Plugin *plugin = cls;
460  struct GNUNET_ATS_Session *session = value;
461 
462  notify_session_monitor (plugin,
463  session,
465  return GNUNET_OK;
466 }
467 
468 
469 #endif
470 
471 
484 static void
487  void *sic_cls)
488 {
489  struct Plugin *plugin = cls;
490 
491  plugin->sic = sic;
492  plugin->sic_cls = sic_cls;
493  if (NULL != sic)
494  {
495 #if 0
496  GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */,
498  plugin);
499 #endif
500  /* signal end of first iteration */
501  sic (sic_cls, NULL, NULL);
502  }
503 }
504 
505 
509 void *
511 {
514  struct Plugin *plugin;
515 
516  if (NULL == env->receive)
517  {
518  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
519  initialze the plugin or the API */
521  api->cls = NULL;
525  return api;
526  }
527 
528  plugin = GNUNET_new (struct Plugin);
529  plugin->env = env;
531  api->cls = plugin;
532  api->send = &template_plugin_send;
545  LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
546  return api;
547 }
548 
549 
553 void *
555 {
557  struct Plugin *plugin = api->cls;
558 
559  GNUNET_free (plugin);
560  GNUNET_free (api);
561  return NULL;
562 }
563 
564 
565 /* 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:55
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:47
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)...
Session handle for connections.
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:40