diff options
Diffstat (limited to 'src/transport/transport_api_offer_hello.c')
-rw-r--r-- | src/transport/transport_api_offer_hello.c | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/src/transport/transport_api_offer_hello.c b/src/transport/transport_api_offer_hello.c index 0abce2d62..951ab9ba4 100644 --- a/src/transport/transport_api_offer_hello.c +++ b/src/transport/transport_api_offer_hello.c | |||
@@ -23,31 +23,23 @@ | |||
23 | * @brief library to offer HELLOs to transport service | 23 | * @brief library to offer HELLOs to transport service |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_hello_lib.h" | ||
29 | #include "gnunet_protocols.h" | ||
30 | #include "gnunet_transport_service.h" | ||
31 | |||
26 | 32 | ||
27 | /** | 33 | /** |
28 | * Entry in linked list for all offer-HELLO requests. | 34 | * Entry in linked list for all offer-HELLO requests. |
29 | */ | 35 | */ |
30 | struct GNUNET_TRANSPORT_OfferHelloHandle | 36 | struct GNUNET_TRANSPORT_OfferHelloHandle |
31 | { | 37 | { |
32 | /** | ||
33 | * For the DLL. | ||
34 | */ | ||
35 | struct GNUNET_TRANSPORT_OfferHelloHandle *prev; | ||
36 | |||
37 | /** | ||
38 | * For the DLL. | ||
39 | */ | ||
40 | struct GNUNET_TRANSPORT_OfferHelloHandle *next; | ||
41 | 38 | ||
42 | /** | 39 | /** |
43 | * Transport service handle we use for transmission. | 40 | * Transport service handle we use for transmission. |
44 | */ | 41 | */ |
45 | struct GNUNET_TRANSPORT_Handle *th; | 42 | struct GNUNET_MQ_Handle *mq; |
46 | |||
47 | /** | ||
48 | * Transmission handle for this request. | ||
49 | */ | ||
50 | struct GNUNET_TRANSPORT_TransmitHandle *tth; | ||
51 | 43 | ||
52 | /** | 44 | /** |
53 | * Function to call once we are done. | 45 | * Function to call once we are done. |
@@ -59,20 +51,31 @@ struct GNUNET_TRANSPORT_OfferHelloHandle | |||
59 | */ | 51 | */ |
60 | void *cls; | 52 | void *cls; |
61 | 53 | ||
62 | /** | ||
63 | * The HELLO message to be transmitted. | ||
64 | */ | ||
65 | struct GNUNET_MessageHeader *msg; | ||
66 | }; | 54 | }; |
67 | 55 | ||
68 | 56 | ||
57 | /** | ||
58 | * Done sending HELLO message to the service, notify application. | ||
59 | * | ||
60 | * @param cls the handle for the operation | ||
61 | */ | ||
62 | static void | ||
63 | finished_hello (void *cls) | ||
64 | { | ||
65 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls; | ||
66 | |||
67 | if (NULL != ohh->cont) | ||
68 | ohh->cont (ohh->cls); | ||
69 | GNUNET_TRANSPORT_offer_hello_cancel (ohh); | ||
70 | } | ||
71 | |||
69 | 72 | ||
70 | /** | 73 | /** |
71 | * Offer the transport service the HELLO of another peer. Note that | 74 | * Offer the transport service the HELLO of another peer. Note that |
72 | * the transport service may just ignore this message if the HELLO is | 75 | * the transport service may just ignore this message if the HELLO is |
73 | * malformed or useless due to our local configuration. | 76 | * malformed or useless due to our local configuration. |
74 | * | 77 | * |
75 | * @param handle connection to transport service | 78 | * @param cfg configuration |
76 | * @param hello the hello message | 79 | * @param hello the hello message |
77 | * @param cont continuation to call when HELLO has been sent, | 80 | * @param cont continuation to call when HELLO has been sent, |
78 | * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail | 81 | * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail |
@@ -83,46 +86,43 @@ struct GNUNET_TRANSPORT_OfferHelloHandle | |||
83 | * | 86 | * |
84 | */ | 87 | */ |
85 | struct GNUNET_TRANSPORT_OfferHelloHandle * | 88 | struct GNUNET_TRANSPORT_OfferHelloHandle * |
86 | GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | 89 | GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg, |
87 | const struct GNUNET_MessageHeader *hello, | 90 | const struct GNUNET_MessageHeader *hello, |
88 | GNUNET_SCHEDULER_TaskCallback cont, | 91 | GNUNET_SCHEDULER_TaskCallback cont, |
89 | void *cont_cls) | 92 | void *cont_cls) |
90 | { | 93 | { |
91 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh; | 94 | struct GNUNET_TRANSPORT_OfferHelloHandle *ohh |
92 | struct GNUNET_MessageHeader *msg; | 95 | = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle); |
96 | struct GNUNET_MQ_Envelope *env; | ||
93 | struct GNUNET_PeerIdentity peer; | 97 | struct GNUNET_PeerIdentity peer; |
94 | uint16_t size; | ||
95 | 98 | ||
96 | if (NULL == handle->mq) | ||
97 | return NULL; | ||
98 | GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); | ||
99 | size = ntohs (hello->size); | ||
100 | GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader)); | ||
101 | if (GNUNET_OK != | 99 | if (GNUNET_OK != |
102 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, | 100 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, |
103 | &peer)) | 101 | &peer)) |
104 | { | 102 | { |
105 | GNUNET_break (0); | 103 | GNUNET_break (0); |
104 | GNUNET_free (ohh); | ||
105 | return NULL; | ||
106 | } | ||
107 | ohh->mq = GNUNET_CLIENT_connecT (cfg, | ||
108 | "transport", | ||
109 | NULL, | ||
110 | NULL, | ||
111 | ohh); | ||
112 | if (NULL == ohh->mq) | ||
113 | { | ||
114 | GNUNET_free (ohh); | ||
106 | return NULL; | 115 | return NULL; |
107 | } | 116 | } |
108 | |||
109 | msg = GNUNET_malloc (size); | ||
110 | memcpy (msg, hello, size); | ||
111 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
112 | "Offering HELLO message of `%s' to transport for validation.\n", | ||
113 | GNUNET_i2s (&peer)); | ||
114 | ohh = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle); | ||
115 | ohh->th = handle; | ||
116 | ohh->cont = cont; | 117 | ohh->cont = cont; |
117 | ohh->cls = cont_cls; | 118 | ohh->cls = cont_cls; |
118 | ohh->msg = msg; | 119 | GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); |
119 | ohh->tth = schedule_control_transmit (handle, | 120 | env = GNUNET_MQ_msg_copy (hello); |
120 | size, | 121 | GNUNET_MQ_notify_sent (env, |
121 | &send_hello, | 122 | &finished_hello, |
122 | ohh); | 123 | ohh); |
123 | GNUNET_CONTAINER_DLL_insert (handle->oh_head, | 124 | GNUNET_MQ_send (ohh->mq, |
124 | handle->oh_tail, | 125 | env); |
125 | ohh); | ||
126 | return ohh; | 126 | return ohh; |
127 | } | 127 | } |
128 | 128 | ||
@@ -135,13 +135,7 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
135 | void | 135 | void |
136 | GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh) | 136 | GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh) |
137 | { | 137 | { |
138 | struct GNUNET_TRANSPORT_Handle *th = ohh->th; | 138 | GNUNET_MQ_destroy (ohh->mq); |
139 | |||
140 | cancel_control_transmit (ohh->th, ohh->tth); | ||
141 | GNUNET_CONTAINER_DLL_remove (th->oh_head, | ||
142 | th->oh_tail, | ||
143 | ohh); | ||
144 | GNUNET_free (ohh->msg); | ||
145 | GNUNET_free (ohh); | 139 | GNUNET_free (ohh); |
146 | } | 140 | } |
147 | 141 | ||