diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-05 14:17:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-05 14:17:50 +0000 |
commit | 439fed4dda3de557a37de85c08be9ac29746e6b7 (patch) | |
tree | 0a7d0941cd3991fea4aeba26fe9e66d2f456fc8d /src/dv/plugin_transport_dv.c | |
parent | 1f3219c222bb206e02a793e6c7d48ccc3045d604 (diff) | |
download | gnunet-439fed4dda3de557a37de85c08be9ac29746e6b7.tar.gz gnunet-439fed4dda3de557a37de85c08be9ac29746e6b7.zip |
-reworking DV to use new MQ API
Diffstat (limited to 'src/dv/plugin_transport_dv.c')
-rw-r--r-- | src/dv/plugin_transport_dv.c | 157 |
1 files changed, 13 insertions, 144 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 7293d9fb8..0c72cea3f 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c | |||
@@ -45,51 +45,6 @@ struct Plugin; | |||
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * An active request for transmission via DV. | ||
49 | */ | ||
50 | struct PendingRequest | ||
51 | { | ||
52 | |||
53 | /** | ||
54 | * This is a DLL. | ||
55 | */ | ||
56 | struct PendingRequest *next; | ||
57 | |||
58 | /** | ||
59 | * This is a DLL. | ||
60 | */ | ||
61 | struct PendingRequest *prev; | ||
62 | |||
63 | /** | ||
64 | * Continuation function to call once the transmission buffer | ||
65 | * has again space available. NULL if there is no | ||
66 | * continuation to call. | ||
67 | */ | ||
68 | GNUNET_TRANSPORT_TransmitContinuation transmit_cont; | ||
69 | |||
70 | /** | ||
71 | * Closure for @e transmit_cont. | ||
72 | */ | ||
73 | void *transmit_cont_cls; | ||
74 | |||
75 | /** | ||
76 | * Transmission handle from DV client library. | ||
77 | */ | ||
78 | struct GNUNET_DV_TransmitHandle *th; | ||
79 | |||
80 | /** | ||
81 | * Session of this request. | ||
82 | */ | ||
83 | struct GNUNET_ATS_Session *session; | ||
84 | |||
85 | /** | ||
86 | * Number of bytes to transmit. | ||
87 | */ | ||
88 | size_t size; | ||
89 | }; | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Session handle for connections. | 48 | * Session handle for connections. |
94 | */ | 49 | */ |
95 | struct GNUNET_ATS_Session | 50 | struct GNUNET_ATS_Session |
@@ -100,16 +55,6 @@ struct GNUNET_ATS_Session | |||
100 | struct Plugin *plugin; | 55 | struct Plugin *plugin; |
101 | 56 | ||
102 | /** | 57 | /** |
103 | * Head of pending requests. | ||
104 | */ | ||
105 | struct PendingRequest *pr_head; | ||
106 | |||
107 | /** | ||
108 | * Tail of pending requests. | ||
109 | */ | ||
110 | struct PendingRequest *pr_tail; | ||
111 | |||
112 | /** | ||
113 | * Address we use for the other peer. | 58 | * Address we use for the other peer. |
114 | */ | 59 | */ |
115 | struct GNUNET_HELLO_Address *address; | 60 | struct GNUNET_HELLO_Address *address; |
@@ -449,7 +394,6 @@ static void | |||
449 | free_session (struct GNUNET_ATS_Session *session) | 394 | free_session (struct GNUNET_ATS_Session *session) |
450 | { | 395 | { |
451 | struct Plugin *plugin = session->plugin; | 396 | struct Plugin *plugin = session->plugin; |
452 | struct PendingRequest *pr; | ||
453 | 397 | ||
454 | GNUNET_assert (GNUNET_YES == | 398 | GNUNET_assert (GNUNET_YES == |
455 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, | 399 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, |
@@ -470,20 +414,6 @@ free_session (struct GNUNET_ATS_Session *session) | |||
470 | session); | 414 | session); |
471 | session->active = GNUNET_NO; | 415 | session->active = GNUNET_NO; |
472 | } | 416 | } |
473 | while (NULL != (pr = session->pr_head)) | ||
474 | { | ||
475 | GNUNET_CONTAINER_DLL_remove (session->pr_head, | ||
476 | session->pr_tail, | ||
477 | pr); | ||
478 | GNUNET_DV_send_cancel (pr->th); | ||
479 | pr->th = NULL; | ||
480 | if (NULL != pr->transmit_cont) | ||
481 | pr->transmit_cont (pr->transmit_cont_cls, | ||
482 | &session->sender, | ||
483 | GNUNET_SYSERR, | ||
484 | pr->size, 0); | ||
485 | GNUNET_free (pr); | ||
486 | } | ||
487 | GNUNET_HELLO_address_free (session->address); | 417 | GNUNET_HELLO_address_free (session->address); |
488 | GNUNET_free (session); | 418 | GNUNET_free (session); |
489 | } | 419 | } |
@@ -515,31 +445,6 @@ handle_dv_disconnect (void *cls, | |||
515 | 445 | ||
516 | 446 | ||
517 | /** | 447 | /** |
518 | * Function called once the delivery of a message has been successful. | ||
519 | * Clean up the pending request, and call continuations. | ||
520 | * | ||
521 | * @param cls closure | ||
522 | */ | ||
523 | static void | ||
524 | send_finished (void *cls) | ||
525 | { | ||
526 | struct PendingRequest *pr = cls; | ||
527 | struct GNUNET_ATS_Session *session = pr->session; | ||
528 | |||
529 | pr->th = NULL; | ||
530 | GNUNET_CONTAINER_DLL_remove (session->pr_head, | ||
531 | session->pr_tail, | ||
532 | pr); | ||
533 | if (NULL != pr->transmit_cont) | ||
534 | pr->transmit_cont (pr->transmit_cont_cls, | ||
535 | &session->sender, | ||
536 | GNUNET_OK, | ||
537 | pr->size, 0); | ||
538 | GNUNET_free (pr); | ||
539 | } | ||
540 | |||
541 | |||
542 | /** | ||
543 | * Function that can be used by the transport service to transmit | 448 | * Function that can be used by the transport service to transmit |
544 | * a message using the plugin. | 449 | * a message using the plugin. |
545 | * | 450 | * |
@@ -565,10 +470,10 @@ dv_plugin_send (void *cls, | |||
565 | size_t msgbuf_size, | 470 | size_t msgbuf_size, |
566 | unsigned int priority, | 471 | unsigned int priority, |
567 | struct GNUNET_TIME_Relative timeout, | 472 | struct GNUNET_TIME_Relative timeout, |
568 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 473 | GNUNET_TRANSPORT_TransmitContinuation cont, |
474 | void *cont_cls) | ||
569 | { | 475 | { |
570 | struct Plugin *plugin = cls; | 476 | struct Plugin *plugin = cls; |
571 | struct PendingRequest *pr; | ||
572 | const struct GNUNET_MessageHeader *msg; | 477 | const struct GNUNET_MessageHeader *msg; |
573 | struct GNUNET_MessageHeader *box; | 478 | struct GNUNET_MessageHeader *box; |
574 | 479 | ||
@@ -585,20 +490,13 @@ dv_plugin_send (void *cls, | |||
585 | memcpy (&box[1], msgbuf, msgbuf_size); | 490 | memcpy (&box[1], msgbuf, msgbuf_size); |
586 | msg = box; | 491 | msg = box; |
587 | } | 492 | } |
588 | pr = GNUNET_new (struct PendingRequest); | 493 | GNUNET_DV_send (plugin->dvh, |
589 | pr->transmit_cont = cont; | 494 | &session->sender, |
590 | pr->transmit_cont_cls = cont_cls; | 495 | msg); |
591 | pr->session = session; | 496 | cont (cont_cls, |
592 | pr->size = msgbuf_size; | 497 | &session->sender, |
593 | GNUNET_CONTAINER_DLL_insert_tail (session->pr_head, | 498 | GNUNET_OK, |
594 | session->pr_tail, | 499 | msgbuf_size, 0); |
595 | pr); | ||
596 | |||
597 | pr->th = GNUNET_DV_send (plugin->dvh, | ||
598 | &session->sender, | ||
599 | msg, | ||
600 | &send_finished, | ||
601 | pr); | ||
602 | GNUNET_free_non_null (box); | 500 | GNUNET_free_non_null (box); |
603 | return 0; /* DV */ | 501 | return 0; /* DV */ |
604 | } | 502 | } |
@@ -618,26 +516,11 @@ dv_plugin_disconnect_peer (void *cls, | |||
618 | { | 516 | { |
619 | struct Plugin *plugin = cls; | 517 | struct Plugin *plugin = cls; |
620 | struct GNUNET_ATS_Session *session; | 518 | struct GNUNET_ATS_Session *session; |
621 | struct PendingRequest *pr; | ||
622 | 519 | ||
623 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, | 520 | session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions, |
624 | target); | 521 | target); |
625 | if (NULL == session) | 522 | if (NULL == session) |
626 | return; /* nothing to do */ | 523 | return; /* nothing to do */ |
627 | while (NULL != (pr = session->pr_head)) | ||
628 | { | ||
629 | GNUNET_CONTAINER_DLL_remove (session->pr_head, | ||
630 | session->pr_tail, | ||
631 | pr); | ||
632 | GNUNET_DV_send_cancel (pr->th); | ||
633 | pr->th = NULL; | ||
634 | if (NULL != pr->transmit_cont) | ||
635 | pr->transmit_cont (pr->transmit_cont_cls, | ||
636 | &session->sender, | ||
637 | GNUNET_SYSERR, | ||
638 | pr->size, 0); | ||
639 | GNUNET_free (pr); | ||
640 | } | ||
641 | session->active = GNUNET_NO; | 524 | session->active = GNUNET_NO; |
642 | } | 525 | } |
643 | 526 | ||
@@ -655,22 +538,6 @@ static int | |||
655 | dv_plugin_disconnect_session (void *cls, | 538 | dv_plugin_disconnect_session (void *cls, |
656 | struct GNUNET_ATS_Session *session) | 539 | struct GNUNET_ATS_Session *session) |
657 | { | 540 | { |
658 | struct PendingRequest *pr; | ||
659 | |||
660 | while (NULL != (pr = session->pr_head)) | ||
661 | { | ||
662 | GNUNET_CONTAINER_DLL_remove (session->pr_head, | ||
663 | session->pr_tail, | ||
664 | pr); | ||
665 | GNUNET_DV_send_cancel (pr->th); | ||
666 | pr->th = NULL; | ||
667 | if (NULL != pr->transmit_cont) | ||
668 | pr->transmit_cont (pr->transmit_cont_cls, | ||
669 | &session->sender, | ||
670 | GNUNET_SYSERR, | ||
671 | pr->size, 0); | ||
672 | GNUNET_free (pr); | ||
673 | } | ||
674 | session->active = GNUNET_NO; | 541 | session->active = GNUNET_NO; |
675 | return GNUNET_OK; | 542 | return GNUNET_OK; |
676 | } | 543 | } |
@@ -691,9 +558,11 @@ dv_plugin_disconnect_session (void *cls, | |||
691 | * @param asc_cls closure for @a asc | 558 | * @param asc_cls closure for @a asc |
692 | */ | 559 | */ |
693 | static void | 560 | static void |
694 | dv_plugin_address_pretty_printer (void *cls, const char *type, | 561 | dv_plugin_address_pretty_printer (void *cls, |
562 | const char *type, | ||
695 | const void *addr, | 563 | const void *addr, |
696 | size_t addrlen, int numeric, | 564 | size_t addrlen, |
565 | int numeric, | ||
697 | struct GNUNET_TIME_Relative timeout, | 566 | struct GNUNET_TIME_Relative timeout, |
698 | GNUNET_TRANSPORT_AddressStringCallback asc, | 567 | GNUNET_TRANSPORT_AddressStringCallback asc, |
699 | void *asc_cls) | 568 | void *asc_cls) |