GNUnet  0.20.0
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
162 static void
164  struct GNUNET_ATS_Session *session,
166 {
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
291 template_plugin_get_network (void *cls,
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
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 
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  initialize the plugin or the API */
521  api->cls = NULL;
522  api->address_to_string = &template_plugin_address_to_string;
523  api->string_to_address = &template_plugin_string_to_address;
524  api->address_pretty_printer = &template_plugin_address_pretty_printer;
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;
533  api->disconnect_peer = &template_plugin_disconnect_peer;
534  api->disconnect_session = &template_plugin_disconnect_session;
535  api->query_keepalive_factor = &template_plugin_query_keepalive_factor;
536  api->address_pretty_printer = &template_plugin_address_pretty_printer;
537  api->check_address = &template_plugin_address_suggested;
538  api->address_to_string = &template_plugin_address_to_string;
539  api->string_to_address = &template_plugin_string_to_address;
540  api->get_session = &template_plugin_get_session;
541  api->get_network = &template_plugin_get_network;
542  api->get_network_for_address = &template_plugin_get_network_for_address;
543  api->update_session_timeout = &template_plugin_update_session_timeout;
544  api->setup_monitor = &template_plugin_setup_monitor;
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 
560  GNUNET_free (api);
561  return NULL;
562 }
563 
564 
565 /* end of plugin_transport_template.c */
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
struct TestcasePlugin * plugin
The process handle to the testbed service.
static char * address
GNS address for this phone.
static char * value
Value of the record to add/remove.
enum State state
current state of profiling
#define info
static char buf[2048]
static int numeric
Option -n.
Constants for network protocols.
API to create, modify and access statistics.
Transport service plugin API.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:39
@ GNUNET_NT_WAN
Wide area network (i.e.
Definition: gnunet_nt_lib.h:58
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:43
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 ...
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".
#define TRANSPORT_SESSION_INBOUND_STRING
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_SessionState
Possible states of a session in a plugin.
@ GNUNET_TRANSPORT_SS_UP
Session is fully UP.
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.
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.
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.
static enum GNUNET_NetworkType template_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
Function obtain the network type for a session.
static void template_plugin_update_session_timeout(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
static void template_plugin_setup_monitor(void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
Begin monitoring sessions of a plugin.
void * libgnunet_plugin_transport_template_done(void *cls)
Exit point from the 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...
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.
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...
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.
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 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 ...
void * libgnunet_plugin_transport_template_init(void *cls)
Entry point for the plugin.
static unsigned int template_plugin_query_keepalive_factor(void *cls)
Function that is called to get the keepalive factor.
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.
#define LOG(kind,...)
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.
Session handle for connections.
struct Plugin * plugin
Pointer to the global plugin struct.
uint64_t last_received
How many bytes have we received since the last_quota_update timestamp?
void * transmit_cont_cls
Closure for transmit_cont.
struct GNUNET_PeerIdentity sender
To whom are we talking to (set to our identity if we are still waiting for the welcome message)
struct GNUNET_ATS_Session * next
Stored in a linked list.
uint32_t quota
Number of bytes per ms that this peer is allowed to send to us.
GNUNET_TRANSPORT_TransmitContinuation transmit_cont
The client (used to identify this connection)
struct GNUNET_TIME_Absolute last_quota_update
At what time did we reset last_received last?
void * cls
Closure for all of the callbacks.
An address for communicating with a peer.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
The transport service will pass a pointer to a struct of this type as the first and only argument to ...
void * cls
Closure for the various callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
void * cls
Closure for all of the callbacks.
Information about a plugin's session.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
void * sic_cls
Closure for sic.
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
uint32_t options
Address options in NBO.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.