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