diff options
Diffstat (limited to 'src/transport/transport_api_manipulation.c')
-rw-r--r-- | src/transport/transport_api_manipulation.c | 131 |
1 files changed, 69 insertions, 62 deletions
diff --git a/src/transport/transport_api_manipulation.c b/src/transport/transport_api_manipulation.c index c4bc96aef..4f4ccc4a0 100644 --- a/src/transport/transport_api_manipulation.c +++ b/src/transport/transport_api_manipulation.c | |||
@@ -32,14 +32,15 @@ | |||
32 | #include "gnunet_transport_service.h" | 32 | #include "gnunet_transport_service.h" |
33 | #include "transport.h" | 33 | #include "transport.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-api", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api", __VA_ARGS__) |
36 | 36 | ||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Handle for the transport service (includes all of the | 39 | * Handle for the transport service (includes all of the |
40 | * state for the transport service). | 40 | * state for the transport service). |
41 | */ | 41 | */ |
42 | struct GNUNET_TRANSPORT_ManipulationHandle { | 42 | struct GNUNET_TRANSPORT_ManipulationHandle |
43 | { | ||
43 | /** | 44 | /** |
44 | * My client connection to the transport service. | 45 | * My client connection to the transport service. |
45 | */ | 46 | */ |
@@ -74,7 +75,8 @@ struct GNUNET_TRANSPORT_ManipulationHandle { | |||
74 | * @param h transport service to reconnect | 75 | * @param h transport service to reconnect |
75 | */ | 76 | */ |
76 | static void | 77 | static void |
77 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h); | 78 | disconnect_and_schedule_reconnect (struct |
79 | GNUNET_TRANSPORT_ManipulationHandle *h); | ||
78 | 80 | ||
79 | 81 | ||
80 | /** | 82 | /** |
@@ -87,15 +89,15 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) | |||
87 | * @param error error code | 89 | * @param error error code |
88 | */ | 90 | */ |
89 | static void | 91 | static void |
90 | mq_error_handler(void *cls, | 92 | mq_error_handler (void *cls, |
91 | enum GNUNET_MQ_Error error) | 93 | enum GNUNET_MQ_Error error) |
92 | { | 94 | { |
93 | struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; | 95 | struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; |
94 | 96 | ||
95 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 97 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
96 | "Error receiving from transport service, disconnecting temporarily.\n"); | 98 | "Error receiving from transport service, disconnecting temporarily.\n"); |
97 | h->reconnecting = GNUNET_YES; | 99 | h->reconnecting = GNUNET_YES; |
98 | disconnect_and_schedule_reconnect(h); | 100 | disconnect_and_schedule_reconnect (h); |
99 | } | 101 | } |
100 | 102 | ||
101 | 103 | ||
@@ -105,31 +107,31 @@ mq_error_handler(void *cls, | |||
105 | * @param cls the handle to the transport service | 107 | * @param cls the handle to the transport service |
106 | */ | 108 | */ |
107 | static void | 109 | static void |
108 | reconnect(void *cls) | 110 | reconnect (void *cls) |
109 | { | 111 | { |
110 | struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; | 112 | struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; |
111 | struct GNUNET_MQ_MessageHandler handlers[] = { | 113 | struct GNUNET_MQ_MessageHandler handlers[] = { |
112 | GNUNET_MQ_handler_end() | 114 | GNUNET_MQ_handler_end () |
113 | }; | 115 | }; |
114 | struct GNUNET_MQ_Envelope *env; | 116 | struct GNUNET_MQ_Envelope *env; |
115 | struct StartMessage *s; | 117 | struct StartMessage *s; |
116 | 118 | ||
117 | h->reconnect_task = NULL; | 119 | h->reconnect_task = NULL; |
118 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 120 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
119 | "Connecting to transport service.\n"); | 121 | "Connecting to transport service.\n"); |
120 | GNUNET_assert(NULL == h->mq); | 122 | GNUNET_assert (NULL == h->mq); |
121 | h->reconnecting = GNUNET_NO; | 123 | h->reconnecting = GNUNET_NO; |
122 | h->mq = GNUNET_CLIENT_connect(h->cfg, | 124 | h->mq = GNUNET_CLIENT_connect (h->cfg, |
123 | "transport", | 125 | "transport", |
124 | handlers, | 126 | handlers, |
125 | &mq_error_handler, | 127 | &mq_error_handler, |
126 | h); | 128 | h); |
127 | if (NULL == h->mq) | 129 | if (NULL == h->mq) |
128 | return; | 130 | return; |
129 | env = GNUNET_MQ_msg(s, | 131 | env = GNUNET_MQ_msg (s, |
130 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 132 | GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
131 | GNUNET_MQ_send(h->mq, | 133 | GNUNET_MQ_send (h->mq, |
132 | env); | 134 | env); |
133 | } | 135 | } |
134 | 136 | ||
135 | 137 | ||
@@ -140,19 +142,20 @@ reconnect(void *cls) | |||
140 | * @param h transport service to reconnect | 142 | * @param h transport service to reconnect |
141 | */ | 143 | */ |
142 | static void | 144 | static void |
143 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) | 145 | disconnect_and_schedule_reconnect (struct |
146 | GNUNET_TRANSPORT_ManipulationHandle *h) | ||
144 | { | 147 | { |
145 | GNUNET_assert(NULL == h->reconnect_task); | 148 | GNUNET_assert (NULL == h->reconnect_task); |
146 | if (NULL != h->mq) | 149 | if (NULL != h->mq) |
147 | { | 150 | { |
148 | GNUNET_MQ_destroy(h->mq); | 151 | GNUNET_MQ_destroy (h->mq); |
149 | h->mq = NULL; | 152 | h->mq = NULL; |
150 | } | 153 | } |
151 | h->reconnect_task = | 154 | h->reconnect_task = |
152 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, | 155 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, |
153 | &reconnect, | 156 | &reconnect, |
154 | h); | 157 | h); |
155 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); | 158 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); |
156 | } | 159 | } |
157 | 160 | ||
158 | 161 | ||
@@ -169,27 +172,28 @@ disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h) | |||
169 | * with one message delay. | 172 | * with one message delay. |
170 | */ | 173 | */ |
171 | void | 174 | void |
172 | GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *handle, | 175 | GNUNET_TRANSPORT_manipulation_set (struct |
173 | const struct GNUNET_PeerIdentity *peer, | 176 | GNUNET_TRANSPORT_ManipulationHandle *handle, |
174 | const struct GNUNET_ATS_Properties *prop, | 177 | const struct GNUNET_PeerIdentity *peer, |
175 | struct GNUNET_TIME_Relative delay_in, | 178 | const struct GNUNET_ATS_Properties *prop, |
176 | struct GNUNET_TIME_Relative delay_out) | 179 | struct GNUNET_TIME_Relative delay_in, |
180 | struct GNUNET_TIME_Relative delay_out) | ||
177 | { | 181 | { |
178 | struct GNUNET_MQ_Envelope *env; | 182 | struct GNUNET_MQ_Envelope *env; |
179 | struct TrafficMetricMessage *msg; | 183 | struct TrafficMetricMessage *msg; |
180 | 184 | ||
181 | if (NULL == handle->mq) | 185 | if (NULL == handle->mq) |
182 | return; | 186 | return; |
183 | env = GNUNET_MQ_msg(msg, | 187 | env = GNUNET_MQ_msg (msg, |
184 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); | 188 | GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); |
185 | msg->reserved = htonl(0); | 189 | msg->reserved = htonl (0); |
186 | msg->peer = *peer; | 190 | msg->peer = *peer; |
187 | GNUNET_ATS_properties_hton(&msg->properties, | 191 | GNUNET_ATS_properties_hton (&msg->properties, |
188 | prop); | 192 | prop); |
189 | msg->delay_in = GNUNET_TIME_relative_hton(delay_in); | 193 | msg->delay_in = GNUNET_TIME_relative_hton (delay_in); |
190 | msg->delay_out = GNUNET_TIME_relative_hton(delay_out); | 194 | msg->delay_out = GNUNET_TIME_relative_hton (delay_out); |
191 | GNUNET_MQ_send(handle->mq, | 195 | GNUNET_MQ_send (handle->mq, |
192 | env); | 196 | env); |
193 | } | 197 | } |
194 | 198 | ||
195 | 199 | ||
@@ -201,20 +205,21 @@ GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *ha | |||
201 | * @return NULL on error | 205 | * @return NULL on error |
202 | */ | 206 | */ |
203 | struct GNUNET_TRANSPORT_ManipulationHandle * | 207 | struct GNUNET_TRANSPORT_ManipulationHandle * |
204 | GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | 208 | GNUNET_TRANSPORT_manipulation_connect (const struct |
209 | GNUNET_CONFIGURATION_Handle *cfg) | ||
205 | { | 210 | { |
206 | struct GNUNET_TRANSPORT_ManipulationHandle *h; | 211 | struct GNUNET_TRANSPORT_ManipulationHandle *h; |
207 | 212 | ||
208 | h = GNUNET_new(struct GNUNET_TRANSPORT_ManipulationHandle); | 213 | h = GNUNET_new (struct GNUNET_TRANSPORT_ManipulationHandle); |
209 | h->cfg = cfg; | 214 | h->cfg = cfg; |
210 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 215 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
211 | "Connecting to transport service.\n"); | 216 | "Connecting to transport service.\n"); |
212 | reconnect(h); | 217 | reconnect (h); |
213 | if (NULL == h->mq) | 218 | if (NULL == h->mq) |
214 | { | 219 | { |
215 | GNUNET_free(h); | 220 | GNUNET_free (h); |
216 | return NULL; | 221 | return NULL; |
217 | } | 222 | } |
218 | return h; | 223 | return h; |
219 | } | 224 | } |
220 | 225 | ||
@@ -225,17 +230,19 @@ GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle * | |||
225 | * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect() | 230 | * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect() |
226 | */ | 231 | */ |
227 | void | 232 | void |
228 | GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle) | 233 | GNUNET_TRANSPORT_manipulation_disconnect (struct |
234 | GNUNET_TRANSPORT_ManipulationHandle * | ||
235 | handle) | ||
229 | { | 236 | { |
230 | if (NULL == handle->reconnect_task) | 237 | if (NULL == handle->reconnect_task) |
231 | disconnect_and_schedule_reconnect(handle); | 238 | disconnect_and_schedule_reconnect (handle); |
232 | /* and now we stop trying to connect again... */ | 239 | /* and now we stop trying to connect again... */ |
233 | if (NULL != handle->reconnect_task) | 240 | if (NULL != handle->reconnect_task) |
234 | { | 241 | { |
235 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); | 242 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); |
236 | handle->reconnect_task = NULL; | 243 | handle->reconnect_task = NULL; |
237 | } | 244 | } |
238 | GNUNET_free(handle); | 245 | GNUNET_free (handle); |
239 | } | 246 | } |
240 | 247 | ||
241 | 248 | ||