diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/transport_api2_monitor.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/transport_api2_monitor.c')
-rw-r--r-- | src/transport/transport_api2_monitor.c | 127 |
1 files changed, 64 insertions, 63 deletions
diff --git a/src/transport/transport_api2_monitor.c b/src/transport/transport_api2_monitor.c index 74624326c..f358051b6 100644 --- a/src/transport/transport_api2_monitor.c +++ b/src/transport/transport_api2_monitor.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Opaque handle to the transport service for monitors. | 34 | * Opaque handle to the transport service for monitors. |
35 | */ | 35 | */ |
36 | struct GNUNET_TRANSPORT_MonitorContext { | 36 | struct GNUNET_TRANSPORT_MonitorContext |
37 | { | ||
37 | /** | 38 | /** |
38 | * Our configuration. | 39 | * Our configuration. |
39 | */ | 40 | */ |
@@ -72,7 +73,7 @@ struct GNUNET_TRANSPORT_MonitorContext { | |||
72 | * @param mc handle to reconnect | 73 | * @param mc handle to reconnect |
73 | */ | 74 | */ |
74 | static void | 75 | static void |
75 | reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc); | 76 | reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc); |
76 | 77 | ||
77 | 78 | ||
78 | /** | 79 | /** |
@@ -82,17 +83,17 @@ reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc); | |||
82 | * @param ai address to delete | 83 | * @param ai address to delete |
83 | */ | 84 | */ |
84 | static void | 85 | static void |
85 | send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc) | 86 | send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc) |
86 | { | 87 | { |
87 | struct GNUNET_MQ_Envelope *env; | 88 | struct GNUNET_MQ_Envelope *env; |
88 | struct GNUNET_TRANSPORT_MonitorStart *smm; | 89 | struct GNUNET_TRANSPORT_MonitorStart *smm; |
89 | 90 | ||
90 | if (NULL == mc->mq) | 91 | if (NULL == mc->mq) |
91 | return; | 92 | return; |
92 | env = GNUNET_MQ_msg(smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); | 93 | env = GNUNET_MQ_msg (smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); |
93 | smm->one_shot = htonl((uint32_t)mc->one_shot); | 94 | smm->one_shot = htonl ((uint32_t) mc->one_shot); |
94 | smm->peer = mc->peer; | 95 | smm->peer = mc->peer; |
95 | GNUNET_MQ_send(mc->mq, env); | 96 | GNUNET_MQ_send (mc->mq, env); |
96 | } | 97 | } |
97 | 98 | ||
98 | 99 | ||
@@ -102,11 +103,11 @@ send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc) | |||
102 | * @param mc service to disconnect from | 103 | * @param mc service to disconnect from |
103 | */ | 104 | */ |
104 | static void | 105 | static void |
105 | disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) | 106 | disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) |
106 | { | 107 | { |
107 | if (NULL == mc->mq) | 108 | if (NULL == mc->mq) |
108 | return; | 109 | return; |
109 | GNUNET_MQ_destroy(mc->mq); | 110 | GNUNET_MQ_destroy (mc->mq); |
110 | mc->mq = NULL; | 111 | mc->mq = NULL; |
111 | } | 112 | } |
112 | 113 | ||
@@ -118,16 +119,16 @@ disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) | |||
118 | * @param error what error happened? | 119 | * @param error what error happened? |
119 | */ | 120 | */ |
120 | static void | 121 | static void |
121 | error_handler(void *cls, enum GNUNET_MQ_Error error) | 122 | error_handler (void *cls, enum GNUNET_MQ_Error error) |
122 | { | 123 | { |
123 | struct GNUNET_TRANSPORT_MonitorContext *mc = cls; | 124 | struct GNUNET_TRANSPORT_MonitorContext *mc = cls; |
124 | 125 | ||
125 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 126 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
126 | "MQ failure %d, reconnecting to transport service.\n", | 127 | "MQ failure %d, reconnecting to transport service.\n", |
127 | error); | 128 | error); |
128 | disconnect(mc); | 129 | disconnect (mc); |
129 | /* TODO: maybe do this with exponential backoff/delay */ | 130 | /* TODO: maybe do this with exponential backoff/delay */ |
130 | reconnect(mc); | 131 | reconnect (mc); |
131 | } | 132 | } |
132 | 133 | ||
133 | 134 | ||
@@ -140,10 +141,10 @@ error_handler(void *cls, enum GNUNET_MQ_Error error) | |||
140 | * @return #GNUNET_OK if @a smt is well-formed | 141 | * @return #GNUNET_OK if @a smt is well-formed |
141 | */ | 142 | */ |
142 | static int | 143 | static int |
143 | check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) | 144 | check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) |
144 | { | 145 | { |
145 | (void)cls; | 146 | (void) cls; |
146 | GNUNET_MQ_check_zero_termination(md); | 147 | GNUNET_MQ_check_zero_termination (md); |
147 | return GNUNET_OK; | 148 | return GNUNET_OK; |
148 | } | 149 | } |
149 | 150 | ||
@@ -155,21 +156,21 @@ check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) | |||
155 | * @param md monitor data | 156 | * @param md monitor data |
156 | */ | 157 | */ |
157 | static void | 158 | static void |
158 | handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) | 159 | handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) |
159 | { | 160 | { |
160 | struct GNUNET_TRANSPORT_MonitorContext *mc = cls; | 161 | struct GNUNET_TRANSPORT_MonitorContext *mc = cls; |
161 | struct GNUNET_TRANSPORT_MonitorInformation mi; | 162 | struct GNUNET_TRANSPORT_MonitorInformation mi; |
162 | 163 | ||
163 | mi.address = (const char *)&md[1]; | 164 | mi.address = (const char *) &md[1]; |
164 | mi.nt = (enum GNUNET_NetworkType)ntohl(md->nt); | 165 | mi.nt = (enum GNUNET_NetworkType) ntohl (md->nt); |
165 | mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(md->cs); | 166 | mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (md->cs); |
166 | mi.num_msg_pending = ntohl(md->num_msg_pending); | 167 | mi.num_msg_pending = ntohl (md->num_msg_pending); |
167 | mi.num_bytes_pending = ntohl(md->num_bytes_pending); | 168 | mi.num_bytes_pending = ntohl (md->num_bytes_pending); |
168 | mi.last_validation = GNUNET_TIME_absolute_ntoh(md->last_validation); | 169 | mi.last_validation = GNUNET_TIME_absolute_ntoh (md->last_validation); |
169 | mi.valid_until = GNUNET_TIME_absolute_ntoh(md->valid_until); | 170 | mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until); |
170 | mi.next_validation = GNUNET_TIME_absolute_ntoh(md->next_validation); | 171 | mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation); |
171 | mi.rtt = GNUNET_TIME_relative_ntoh(md->rtt); | 172 | mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt); |
172 | mc->cb(mc->cb_cls, &md->peer, &mi); | 173 | mc->cb (mc->cb_cls, &md->peer, &mi); |
173 | } | 174 | } |
174 | 175 | ||
175 | 176 | ||
@@ -180,19 +181,19 @@ handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) | |||
180 | * @param me end message | 181 | * @param me end message |
181 | */ | 182 | */ |
182 | static void | 183 | static void |
183 | handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me) | 184 | handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me) |
184 | { | 185 | { |
185 | struct GNUNET_TRANSPORT_MonitorContext *mc = cls; | 186 | struct GNUNET_TRANSPORT_MonitorContext *mc = cls; |
186 | 187 | ||
187 | if (GNUNET_YES != mc->one_shot) | 188 | if (GNUNET_YES != mc->one_shot) |
188 | { | 189 | { |
189 | GNUNET_break(0); | 190 | GNUNET_break (0); |
190 | disconnect(mc); | 191 | disconnect (mc); |
191 | reconnect(mc); | 192 | reconnect (mc); |
192 | return; | 193 | return; |
193 | } | 194 | } |
194 | mc->cb(mc->cb_cls, NULL, NULL); | 195 | mc->cb (mc->cb_cls, NULL, NULL); |
195 | GNUNET_TRANSPORT_monitor_cancel(mc); | 196 | GNUNET_TRANSPORT_monitor_cancel (mc); |
196 | } | 197 | } |
197 | 198 | ||
198 | 199 | ||
@@ -202,24 +203,24 @@ handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me) | |||
202 | * @param mc handle to reconnect | 203 | * @param mc handle to reconnect |
203 | */ | 204 | */ |
204 | static void | 205 | static void |
205 | reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) | 206 | reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) |
206 | { | 207 | { |
207 | struct GNUNET_MQ_MessageHandler handlers[] = | 208 | struct GNUNET_MQ_MessageHandler handlers[] = |
208 | { GNUNET_MQ_hd_var_size(monitor_data, | 209 | { GNUNET_MQ_hd_var_size (monitor_data, |
209 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, | 210 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, |
210 | struct GNUNET_TRANSPORT_MonitorData, | 211 | struct GNUNET_TRANSPORT_MonitorData, |
211 | mc), | 212 | mc), |
212 | GNUNET_MQ_hd_fixed_size(monitor_end, | 213 | GNUNET_MQ_hd_fixed_size (monitor_end, |
213 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, | 214 | GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END, |
214 | struct GNUNET_MessageHeader, | 215 | struct GNUNET_MessageHeader, |
215 | mc), | 216 | mc), |
216 | GNUNET_MQ_handler_end() }; | 217 | GNUNET_MQ_handler_end () }; |
217 | 218 | ||
218 | mc->mq = | 219 | mc->mq = |
219 | GNUNET_CLIENT_connect(mc->cfg, "transport", handlers, &error_handler, mc); | 220 | GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc); |
220 | if (NULL == mc->mq) | 221 | if (NULL == mc->mq) |
221 | return; | 222 | return; |
222 | send_start_monitor(mc); | 223 | send_start_monitor (mc); |
223 | } | 224 | } |
224 | 225 | ||
225 | 226 | ||
@@ -250,27 +251,27 @@ reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc) | |||
250 | * @param cb_cls closure for @a mc | 251 | * @param cb_cls closure for @a mc |
251 | */ | 252 | */ |
252 | struct GNUNET_TRANSPORT_MonitorContext * | 253 | struct GNUNET_TRANSPORT_MonitorContext * |
253 | GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg, | 254 | GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, |
254 | const struct GNUNET_PeerIdentity *peer, | 255 | const struct GNUNET_PeerIdentity *peer, |
255 | int one_shot, | 256 | int one_shot, |
256 | GNUNET_TRANSPORT_MonitorCallback cb, | 257 | GNUNET_TRANSPORT_MonitorCallback cb, |
257 | void *cb_cls) | 258 | void *cb_cls) |
258 | { | 259 | { |
259 | struct GNUNET_TRANSPORT_MonitorContext *mc; | 260 | struct GNUNET_TRANSPORT_MonitorContext *mc; |
260 | 261 | ||
261 | mc = GNUNET_new(struct GNUNET_TRANSPORT_MonitorContext); | 262 | mc = GNUNET_new (struct GNUNET_TRANSPORT_MonitorContext); |
262 | mc->cfg = cfg; | 263 | mc->cfg = cfg; |
263 | if (NULL != peer) | 264 | if (NULL != peer) |
264 | mc->peer = *peer; | 265 | mc->peer = *peer; |
265 | mc->one_shot = one_shot; | 266 | mc->one_shot = one_shot; |
266 | mc->cb = cb; | 267 | mc->cb = cb; |
267 | mc->cb_cls = cb_cls; | 268 | mc->cb_cls = cb_cls; |
268 | reconnect(mc); | 269 | reconnect (mc); |
269 | if (NULL == mc->mq) | 270 | if (NULL == mc->mq) |
270 | { | 271 | { |
271 | GNUNET_free(mc); | 272 | GNUNET_free (mc); |
272 | return NULL; | 273 | return NULL; |
273 | } | 274 | } |
274 | return mc; | 275 | return mc; |
275 | } | 276 | } |
276 | 277 | ||
@@ -281,10 +282,10 @@ GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
281 | * @param pmc handle for the request to cancel | 282 | * @param pmc handle for the request to cancel |
282 | */ | 283 | */ |
283 | void | 284 | void |
284 | GNUNET_TRANSPORT_monitor_cancel(struct GNUNET_TRANSPORT_MonitorContext *mc) | 285 | GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc) |
285 | { | 286 | { |
286 | disconnect(mc); | 287 | disconnect (mc); |
287 | GNUNET_free(mc); | 288 | GNUNET_free (mc); |
288 | } | 289 | } |
289 | 290 | ||
290 | /* end of transport_api2_monitor.c */ | 291 | /* end of transport_api2_monitor.c */ |