summaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_template.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_template.c')
-rw-r--r--src/transport/plugin_transport_template.c188
1 files changed, 91 insertions, 97 deletions
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index 8ec2c3992..7977590b0 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_template.c 22 * @file transport/plugin_transport_template.c
@@ -31,14 +31,14 @@
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "gnunet_transport_plugin.h" 32#include "gnunet_transport_plugin.h"
33 33
34#define LOG(kind,...) GNUNET_log_from (kind, "transport-template",__VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log_from(kind, "transport-template", __VA_ARGS__)
35 35
36/** 36/**
37 * After how long do we expire an address that we 37 * After how long do we expire an address that we
38 * learned from another peer if it is not reconfirmed 38 * learned from another peer if it is not reconfirmed
39 * by anyone? 39 * by anyone?
40 */ 40 */
41#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) 41#define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6)
42 42
43#define PLUGIN_NAME "template" 43#define PLUGIN_NAME "template"
44 44
@@ -51,8 +51,7 @@ struct Plugin;
51/** 51/**
52 * Session handle for connections. 52 * Session handle for connections.
53 */ 53 */
54struct GNUNET_ATS_Session 54struct GNUNET_ATS_Session {
55{
56 /** 55 /**
57 * To whom are we talking to (set to our identity 56 * To whom are we talking to (set to our identity
58 * if we are still waiting for the welcome message) 57 * if we are still waiting for the welcome message)
@@ -102,13 +101,11 @@ struct GNUNET_ATS_Session
102 * to send to us. 101 * to send to us.
103 */ 102 */
104 uint32_t quota; 103 uint32_t quota;
105
106}; 104};
107 105
108GNUNET_NETWORK_STRUCT_BEGIN 106GNUNET_NETWORK_STRUCT_BEGIN
109 107
110struct TemplateAddress 108struct TemplateAddress {
111{
112 /** 109 /**
113 * Address options in NBO 110 * Address options in NBO
114 */ 111 */
@@ -122,8 +119,7 @@ GNUNET_NETWORK_STRUCT_END
122/** 119/**
123 * Encapsulation of all of the state of the plugin. 120 * Encapsulation of all of the state of the plugin.
124 */ 121 */
125struct Plugin 122struct Plugin {
126{
127 /** 123 /**
128 * Our environment. 124 * Our environment.
129 */ 125 */
@@ -147,7 +143,6 @@ struct Plugin
147 /** 143 /**
148 * Options in HBO to be used with addresses 144 * Options in HBO to be used with addresses
149 */ 145 */
150
151}; 146};
152 147
153 148
@@ -161,15 +156,15 @@ struct Plugin
161 * @param state new state of the session 156 * @param state new state of the session
162 */ 157 */
163static void 158static void
164notify_session_monitor (struct Plugin *plugin, 159notify_session_monitor(struct Plugin *plugin,
165 struct GNUNET_ATS_Session *session, 160 struct GNUNET_ATS_Session *session,
166 enum GNUNET_TRANSPORT_SessionState state) 161 enum GNUNET_TRANSPORT_SessionState state)
167{ 162{
168 struct GNUNET_TRANSPORT_SessionInfo info; 163 struct GNUNET_TRANSPORT_SessionInfo info;
169 164
170 if (NULL == plugin->sic) 165 if (NULL == plugin->sic)
171 return; 166 return;
172 memset (&info, 0, sizeof (info)); 167 memset(&info, 0, sizeof(info));
173 info.state = state; 168 info.state = state;
174 info.is_inbound = GNUNET_SYSERR; /* FIXME */ 169 info.is_inbound = GNUNET_SYSERR; /* FIXME */
175 // info.num_msg_pending = 170 // info.num_msg_pending =
@@ -177,9 +172,9 @@ notify_session_monitor (struct Plugin *plugin,
177 // info.receive_delay = 172 // info.receive_delay =
178 // info.session_timeout = session->timeout; 173 // info.session_timeout = session->timeout;
179 // info.address = session->address; 174 // info.address = session->address;
180 plugin->sic (plugin->sic_cls, 175 plugin->sic(plugin->sic_cls,
181 session, 176 session,
182 &info); 177 &info);
183} 178}
184#endif 179#endif
185 180
@@ -212,14 +207,14 @@ notify_session_monitor (struct Plugin *plugin,
212 * and does NOT mean that the message was not transmitted (DV) 207 * and does NOT mean that the message was not transmitted (DV)
213 */ 208 */
214static ssize_t 209static ssize_t
215template_plugin_send (void *cls, 210template_plugin_send(void *cls,
216 struct GNUNET_ATS_Session *session, 211 struct GNUNET_ATS_Session *session,
217 const char *msgbuf, 212 const char *msgbuf,
218 size_t msgbuf_size, 213 size_t msgbuf_size,
219 unsigned int priority, 214 unsigned int priority,
220 struct GNUNET_TIME_Relative to, 215 struct GNUNET_TIME_Relative to,
221 GNUNET_TRANSPORT_TransmitContinuation cont, 216 GNUNET_TRANSPORT_TransmitContinuation cont,
222 void *cont_cls) 217 void *cont_cls)
223{ 218{
224 /* struct Plugin *plugin = cls; */ 219 /* struct Plugin *plugin = cls; */
225 ssize_t bytes_sent = 0; 220 ssize_t bytes_sent = 0;
@@ -237,8 +232,8 @@ template_plugin_send (void *cls,
237 * @param target peer from which to disconnect 232 * @param target peer from which to disconnect
238 */ 233 */
239static void 234static void
240template_plugin_disconnect_peer (void *cls, 235template_plugin_disconnect_peer(void *cls,
241 const struct GNUNET_PeerIdentity *target) 236 const struct GNUNET_PeerIdentity *target)
242{ 237{
243 // struct Plugin *plugin = cls; 238 // struct Plugin *plugin = cls;
244 // FIXME 239 // FIXME
@@ -255,8 +250,8 @@ template_plugin_disconnect_peer (void *cls,
255 * @return #GNUNET_OK on success 250 * @return #GNUNET_OK on success
256 */ 251 */
257static int 252static int
258template_plugin_disconnect_session (void *cls, 253template_plugin_disconnect_session(void *cls,
259 struct GNUNET_ATS_Session *session) 254 struct GNUNET_ATS_Session *session)
260{ 255{
261 // struct Plugin *plugin = cls; 256 // struct Plugin *plugin = cls;
262 // FIXME 257 // FIXME
@@ -273,7 +268,7 @@ template_plugin_disconnect_session (void *cls,
273 * @return keepalive factor 268 * @return keepalive factor
274 */ 269 */
275static unsigned int 270static unsigned int
276template_plugin_query_keepalive_factor (void *cls) 271template_plugin_query_keepalive_factor(void *cls)
277{ 272{
278 return 3; 273 return 3;
279} 274}
@@ -287,10 +282,10 @@ template_plugin_query_keepalive_factor (void *cls)
287 * @return the network type in HBO or #GNUNET_SYSERR 282 * @return the network type in HBO or #GNUNET_SYSERR
288 */ 283 */
289static enum GNUNET_NetworkType 284static enum GNUNET_NetworkType
290template_plugin_get_network (void *cls, 285template_plugin_get_network(void *cls,
291 struct GNUNET_ATS_Session *session) 286 struct GNUNET_ATS_Session *session)
292{ 287{
293 GNUNET_assert (NULL != session); 288 GNUNET_assert(NULL != session);
294 return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */ 289 return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */
295} 290}
296 291
@@ -303,8 +298,8 @@ template_plugin_get_network (void *cls,
303 * @return the network type 298 * @return the network type
304 */ 299 */
305static enum GNUNET_NetworkType 300static enum GNUNET_NetworkType
306template_plugin_get_network_for_address (void *cls, 301template_plugin_get_network_for_address(void *cls,
307 const struct GNUNET_HELLO_Address *address) 302 const struct GNUNET_HELLO_Address *address)
308{ 303{
309 return GNUNET_NT_WAN; /* FOR NOW */ 304 return GNUNET_NT_WAN; /* FOR NOW */
310} 305}
@@ -325,15 +320,15 @@ template_plugin_get_network_for_address (void *cls,
325 * @param asc_cls closure for @a asc 320 * @param asc_cls closure for @a asc
326 */ 321 */
327static void 322static void
328template_plugin_address_pretty_printer (void *cls, const char *type, 323template_plugin_address_pretty_printer(void *cls, const char *type,
329 const void *addr, size_t addrlen, 324 const void *addr, size_t addrlen,
330 int numeric, 325 int numeric,
331 struct GNUNET_TIME_Relative timeout, 326 struct GNUNET_TIME_Relative timeout,
332 GNUNET_TRANSPORT_AddressStringCallback 327 GNUNET_TRANSPORT_AddressStringCallback
333 asc, void *asc_cls) 328 asc, void *asc_cls)
334{ 329{
335 asc (asc_cls, "converted address", GNUNET_OK); /* return address */ 330 asc(asc_cls, "converted address", GNUNET_OK); /* return address */
336 asc (asc_cls, NULL, GNUNET_OK); /* done */ 331 asc(asc_cls, NULL, GNUNET_OK); /* done */
337} 332}
338 333
339 334
@@ -351,7 +346,7 @@ template_plugin_address_pretty_printer (void *cls, const char *type,
351 * and transport 346 * and transport
352 */ 347 */
353static int 348static int
354template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) 349template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
355{ 350{
356 /* struct Plugin *plugin = cls; */ 351 /* struct Plugin *plugin = cls; */
357 352
@@ -372,18 +367,18 @@ template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
372 * @return string representing the same address 367 * @return string representing the same address
373 */ 368 */
374static const char * 369static const char *
375template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 370template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
376{ 371{
377 /* 372 /*
378 * Print address in format template.options.address 373 * Print address in format template.options.address
379 */ 374 */
380 375
381 if (0 == addrlen) 376 if (0 == addrlen)
382 { 377 {
383 return TRANSPORT_SESSION_INBOUND_STRING; 378 return TRANSPORT_SESSION_INBOUND_STRING;
384 } 379 }
385 380
386 GNUNET_break (0); 381 GNUNET_break(0);
387 return NULL; 382 return NULL;
388} 383}
389 384
@@ -401,15 +396,15 @@ template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
401 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 396 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
402 */ 397 */
403static int 398static int
404template_plugin_string_to_address (void *cls, 399template_plugin_string_to_address(void *cls,
405 const char *addr, 400 const char *addr,
406 uint16_t addrlen, 401 uint16_t addrlen,
407 void **buf, size_t *added) 402 void **buf, size_t *added)
408{ 403{
409 /* 404 /*
410 * Parse string in format template.options.address 405 * Parse string in format template.options.address
411 */ 406 */
412 GNUNET_break (0); 407 GNUNET_break(0);
413 return GNUNET_SYSERR; 408 return GNUNET_SYSERR;
414} 409}
415 410
@@ -424,20 +419,19 @@ template_plugin_string_to_address (void *cls,
424 * @return the session if the address is valid, NULL otherwise 419 * @return the session if the address is valid, NULL otherwise
425 */ 420 */
426static struct GNUNET_ATS_Session * 421static struct GNUNET_ATS_Session *
427template_plugin_get_session (void *cls, 422template_plugin_get_session(void *cls,
428 const struct GNUNET_HELLO_Address *address) 423 const struct GNUNET_HELLO_Address *address)
429{ 424{
430 GNUNET_break (0); 425 GNUNET_break(0);
431 return NULL; 426 return NULL;
432} 427}
433 428
434 429
435static void 430static void
436template_plugin_update_session_timeout (void *cls, 431template_plugin_update_session_timeout(void *cls,
437 const struct GNUNET_PeerIdentity *peer, 432 const struct GNUNET_PeerIdentity *peer,
438 struct GNUNET_ATS_Session *session) 433 struct GNUNET_ATS_Session *session)
439{ 434{
440
441} 435}
442 436
443 437
@@ -452,16 +446,16 @@ template_plugin_update_session_timeout (void *cls,
452 * @return #GNUNET_OK (continue to iterate) 446 * @return #GNUNET_OK (continue to iterate)
453 */ 447 */
454static int 448static int
455send_session_info_iter (void *cls, 449send_session_info_iter(void *cls,
456 const struct GNUNET_PeerIdentity *peer, 450 const struct GNUNET_PeerIdentity *peer,
457 void *value) 451 void *value)
458{ 452{
459 struct Plugin *plugin = cls; 453 struct Plugin *plugin = cls;
460 struct GNUNET_ATS_Session *session = value; 454 struct GNUNET_ATS_Session *session = value;
461 455
462 notify_session_monitor (plugin, 456 notify_session_monitor(plugin,
463 session, 457 session,
464 GNUNET_TRANSPORT_SS_UP); 458 GNUNET_TRANSPORT_SS_UP);
465 return GNUNET_OK; 459 return GNUNET_OK;
466} 460}
467#endif 461#endif
@@ -480,24 +474,24 @@ send_session_info_iter (void *cls,
480 * @param sic_cls closure for @a sic 474 * @param sic_cls closure for @a sic
481 */ 475 */
482static void 476static void
483template_plugin_setup_monitor (void *cls, 477template_plugin_setup_monitor(void *cls,
484 GNUNET_TRANSPORT_SessionInfoCallback sic, 478 GNUNET_TRANSPORT_SessionInfoCallback sic,
485 void *sic_cls) 479 void *sic_cls)
486{ 480{
487 struct Plugin *plugin = cls; 481 struct Plugin *plugin = cls;
488 482
489 plugin->sic = sic; 483 plugin->sic = sic;
490 plugin->sic_cls = sic_cls; 484 plugin->sic_cls = sic_cls;
491 if (NULL != sic) 485 if (NULL != sic)
492 { 486 {
493#if 0 487#if 0
494 GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */, 488 GNUNET_CONTAINER_multipeermap_iterate(NULL /* FIXME */,
495 &send_session_info_iter, 489 &send_session_info_iter,
496 plugin); 490 plugin);
497#endif 491#endif
498 /* signal end of first iteration */ 492 /* signal end of first iteration */
499 sic (sic_cls, NULL, NULL); 493 sic(sic_cls, NULL, NULL);
500 } 494 }
501} 495}
502 496
503 497
@@ -505,27 +499,27 @@ template_plugin_setup_monitor (void *cls,
505 * Entry point for the plugin. 499 * Entry point for the plugin.
506 */ 500 */
507void * 501void *
508libgnunet_plugin_transport_template_init (void *cls) 502libgnunet_plugin_transport_template_init(void *cls)
509{ 503{
510 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 504 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
511 struct GNUNET_TRANSPORT_PluginFunctions *api; 505 struct GNUNET_TRANSPORT_PluginFunctions *api;
512 struct Plugin *plugin; 506 struct Plugin *plugin;
513 507
514 if (NULL == env->receive) 508 if (NULL == env->receive)
515 { 509 {
516 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 510 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
517 initialze the plugin or the API */ 511 initialze the plugin or the API */
518 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 512 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
519 api->cls = NULL; 513 api->cls = NULL;
520 api->address_to_string = &template_plugin_address_to_string; 514 api->address_to_string = &template_plugin_address_to_string;
521 api->string_to_address = &template_plugin_string_to_address; 515 api->string_to_address = &template_plugin_string_to_address;
522 api->address_pretty_printer = &template_plugin_address_pretty_printer; 516 api->address_pretty_printer = &template_plugin_address_pretty_printer;
523 return api; 517 return api;
524 } 518 }
525 519
526 plugin = GNUNET_new (struct Plugin); 520 plugin = GNUNET_new(struct Plugin);
527 plugin->env = env; 521 plugin->env = env;
528 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 522 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
529 api->cls = plugin; 523 api->cls = plugin;
530 api->send = &template_plugin_send; 524 api->send = &template_plugin_send;
531 api->disconnect_peer = &template_plugin_disconnect_peer; 525 api->disconnect_peer = &template_plugin_disconnect_peer;
@@ -540,7 +534,7 @@ libgnunet_plugin_transport_template_init (void *cls)
540 api->get_network_for_address = &template_plugin_get_network_for_address; 534 api->get_network_for_address = &template_plugin_get_network_for_address;
541 api->update_session_timeout = &template_plugin_update_session_timeout; 535 api->update_session_timeout = &template_plugin_update_session_timeout;
542 api->setup_monitor = &template_plugin_setup_monitor; 536 api->setup_monitor = &template_plugin_setup_monitor;
543 LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); 537 LOG(GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
544 return api; 538 return api;
545} 539}
546 540
@@ -549,13 +543,13 @@ libgnunet_plugin_transport_template_init (void *cls)
549 * Exit point from the plugin. 543 * Exit point from the plugin.
550 */ 544 */
551void * 545void *
552libgnunet_plugin_transport_template_done (void *cls) 546libgnunet_plugin_transport_template_done(void *cls)
553{ 547{
554 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 548 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
555 struct Plugin *plugin = api->cls; 549 struct Plugin *plugin = api->cls;
556 550
557 GNUNET_free (plugin); 551 GNUNET_free(plugin);
558 GNUNET_free (api); 552 GNUNET_free(api);
559 return NULL; 553 return NULL;
560} 554}
561 555