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