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
55 {
61 
65  struct GNUNET_ATS_Session *next;
66 
70  struct Plugin *plugin;
71 
75  /* void *client; */
76 
83 
88 
93 
98  uint64_t last_received;
99 
104  uint32_t quota;
105 
106 };
107 
109 
111 {
116 
117  /* Add address here */
118 };
119 
121 
125 struct Plugin
126 {
131 
136 
141 
145  void *sic_cls;
146 
151 };
152 
153 
154 #if 0
155 
163 static void
165  struct GNUNET_ATS_Session *session,
167 {
168  struct GNUNET_TRANSPORT_SessionInfo info;
169 
170  if (NULL == plugin->sic)
171  return;
172  memset (&info, 0, sizeof (info));
173  info.state = state;
174  info.is_inbound = GNUNET_SYSERR; /* FIXME */
175  // info.num_msg_pending =
176  // info.num_bytes_pending =
177  // info.receive_delay =
178  // info.session_timeout = session->timeout;
179  // info.address = session->address;
180  plugin->sic (plugin->sic_cls,
181  session,
182  &info);
183 }
184 #endif
185 
186 
214 static ssize_t
216  struct GNUNET_ATS_Session *session,
217  const char *msgbuf,
218  size_t msgbuf_size,
219  unsigned int priority,
220  struct GNUNET_TIME_Relative to,
222  void *cont_cls)
223 {
224  /* struct Plugin *plugin = cls; */
225  ssize_t bytes_sent = 0;
226 
227  return bytes_sent;
228 }
229 
230 
239 static void
241  const struct GNUNET_PeerIdentity *target)
242 {
243  // struct Plugin *plugin = cls;
244  // FIXME
245 }
246 
247 
257 static int
259  struct GNUNET_ATS_Session *session)
260 {
261  // struct Plugin *plugin = cls;
262  // FIXME
263  return GNUNET_SYSERR;
264 }
265 
266 
275 static unsigned int
277 {
278  return 3;
279 }
280 
281 
289 static enum GNUNET_NetworkType
291  struct GNUNET_ATS_Session *session)
292 {
293  GNUNET_assert (NULL != session);
294  return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */
295 }
296 
297 
305 static enum GNUNET_NetworkType
307  const struct GNUNET_HELLO_Address *address)
308 {
309  return GNUNET_NT_WAN; /* FOR NOW */
310 }
311 
312 
327 static void
329  const void *addr, size_t addrlen,
330  int numeric,
333  asc, void *asc_cls)
334 {
335  asc (asc_cls, "converted address", GNUNET_OK); /* return address */
336  asc (asc_cls, NULL, GNUNET_OK); /* done */
337 }
338 
339 
340 
353 static int
354 template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
355 {
356  /* struct Plugin *plugin = cls; */
357 
358  /* check if the address is belonging to the plugin*/
359  return GNUNET_OK;
360 }
361 
362 
374 static const char *
375 template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
376 {
377  /*
378  * Print address in format template.options.address
379  */
380 
381  if (0 == addrlen)
382  {
384  }
385 
386  GNUNET_break (0);
387  return NULL;
388 }
389 
390 
403 static int
405  const char *addr,
406  uint16_t addrlen,
407  void **buf, size_t *added)
408 {
409  /*
410  * Parse string in format template.options.address
411  */
412  GNUNET_break (0);
413  return GNUNET_SYSERR;
414 }
415 
416 
426 static struct GNUNET_ATS_Session *
428  const struct GNUNET_HELLO_Address *address)
429 {
430  GNUNET_break (0);
431  return NULL;
432 }
433 
434 
435 static void
437  const struct GNUNET_PeerIdentity *peer,
438  struct GNUNET_ATS_Session *session)
439 {
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 #endif
468 
469 
482 static void
485  void *sic_cls)
486 {
487  struct Plugin *plugin = cls;
488 
489  plugin->sic = sic;
490  plugin->sic_cls = sic_cls;
491  if (NULL != sic)
492  {
493 #if 0
494  GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */,
496  plugin);
497 #endif
498  /* signal end of first iteration */
499  sic (sic_cls, NULL, NULL);
500  }
501 }
502 
503 
507 void *
509 {
512  struct Plugin *plugin;
513 
514  if (NULL == env->receive)
515  {
516  /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
517  initialze the plugin or the API */
519  api->cls = NULL;
523  return api;
524  }
525 
526  plugin = GNUNET_new (struct Plugin);
527  plugin->env = env;
529  api->cls = plugin;
530  api->send = &template_plugin_send;
543  LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
544  return api;
545 }
546 
547 
551 void *
553 {
555  struct Plugin *plugin = api->cls;
556 
557  GNUNET_free (plugin);
558  GNUNET_free (api);
559  return NULL;
560 }
561 
562 /* 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:78
#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)...
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:79
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