diff options
Diffstat (limited to 'src/cadet/cadet_api_get_path.c')
-rw-r--r-- | src/cadet/cadet_api_get_path.c | 145 |
1 files changed, 73 insertions, 72 deletions
diff --git a/src/cadet/cadet_api_get_path.c b/src/cadet/cadet_api_get_path.c index 0f18014c3..68070eab2 100644 --- a/src/cadet/cadet_api_get_path.c +++ b/src/cadet/cadet_api_get_path.c | |||
@@ -34,7 +34,8 @@ | |||
34 | /** | 34 | /** |
35 | * Operation handle. | 35 | * Operation handle. |
36 | */ | 36 | */ |
37 | struct GNUNET_CADET_GetPath { | 37 | struct GNUNET_CADET_GetPath |
38 | { | ||
38 | /** | 39 | /** |
39 | * Monitor callback | 40 | * Monitor callback |
40 | */ | 41 | */ |
@@ -81,24 +82,24 @@ struct GNUNET_CADET_GetPath { | |||
81 | * #GNUNET_SYSERR otherwise | 82 | * #GNUNET_SYSERR otherwise |
82 | */ | 83 | */ |
83 | static int | 84 | static int |
84 | check_get_path(void *cls, | 85 | check_get_path (void *cls, |
85 | const struct GNUNET_CADET_LocalInfoPath *message) | 86 | const struct GNUNET_CADET_LocalInfoPath *message) |
86 | { | 87 | { |
87 | size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath); | 88 | size_t msize = sizeof(struct GNUNET_CADET_LocalInfoPath); |
88 | size_t esize; | 89 | size_t esize; |
89 | 90 | ||
90 | (void)cls; | 91 | (void) cls; |
91 | esize = ntohs(message->header.size); | 92 | esize = ntohs (message->header.size); |
92 | if (esize < msize) | 93 | if (esize < msize) |
93 | { | 94 | { |
94 | GNUNET_break(0); | 95 | GNUNET_break (0); |
95 | return GNUNET_SYSERR; | 96 | return GNUNET_SYSERR; |
96 | } | 97 | } |
97 | if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity))) | 98 | if (0 != ((esize - msize) % sizeof(struct GNUNET_PeerIdentity))) |
98 | { | 99 | { |
99 | GNUNET_break(0); | 100 | GNUNET_break (0); |
100 | return GNUNET_SYSERR; | 101 | return GNUNET_SYSERR; |
101 | } | 102 | } |
102 | return GNUNET_OK; | 103 | return GNUNET_OK; |
103 | } | 104 | } |
104 | 105 | ||
@@ -110,19 +111,19 @@ check_get_path(void *cls, | |||
110 | * @param message Message itself. | 111 | * @param message Message itself. |
111 | */ | 112 | */ |
112 | static void | 113 | static void |
113 | handle_get_path(void *cls, | 114 | handle_get_path (void *cls, |
114 | const struct GNUNET_CADET_LocalInfoPath *message) | 115 | const struct GNUNET_CADET_LocalInfoPath *message) |
115 | { | 116 | { |
116 | struct GNUNET_CADET_GetPath *gp = cls; | 117 | struct GNUNET_CADET_GetPath *gp = cls; |
117 | struct GNUNET_CADET_PeerPathDetail ppd; | 118 | struct GNUNET_CADET_PeerPathDetail ppd; |
118 | 119 | ||
119 | ppd.peer = gp->id; | 120 | ppd.peer = gp->id; |
120 | ppd.path = (const struct GNUNET_PeerIdentity *)&message[1]; | 121 | ppd.path = (const struct GNUNET_PeerIdentity *) &message[1]; |
121 | ppd.target_offset = ntohl(message->off); | 122 | ppd.target_offset = ntohl (message->off); |
122 | ppd.path_length = (ntohs(message->header.size) - sizeof(*message)) | 123 | ppd.path_length = (ntohs (message->header.size) - sizeof(*message)) |
123 | / sizeof(struct GNUNET_PeerIdentity); | 124 | / sizeof(struct GNUNET_PeerIdentity); |
124 | gp->path_cb(gp->path_cb_cls, | 125 | gp->path_cb (gp->path_cb_cls, |
125 | &ppd); | 126 | &ppd); |
126 | } | 127 | } |
127 | 128 | ||
128 | 129 | ||
@@ -133,15 +134,15 @@ handle_get_path(void *cls, | |||
133 | * @param message Message itself. | 134 | * @param message Message itself. |
134 | */ | 135 | */ |
135 | static void | 136 | static void |
136 | handle_get_path_end(void *cls, | 137 | handle_get_path_end (void *cls, |
137 | const struct GNUNET_MessageHeader *message) | 138 | const struct GNUNET_MessageHeader *message) |
138 | { | 139 | { |
139 | struct GNUNET_CADET_GetPath *gp = cls; | 140 | struct GNUNET_CADET_GetPath *gp = cls; |
140 | 141 | ||
141 | (void)message; | 142 | (void) message; |
142 | gp->path_cb(gp->path_cb_cls, | 143 | gp->path_cb (gp->path_cb_cls, |
143 | NULL); | 144 | NULL); |
144 | GNUNET_CADET_get_path_cancel(gp); | 145 | GNUNET_CADET_get_path_cancel (gp); |
145 | } | 146 | } |
146 | 147 | ||
147 | 148 | ||
@@ -151,7 +152,7 @@ handle_get_path_end(void *cls, | |||
151 | * @param cls a `struct GNUNET_CADET_GetPath` operation | 152 | * @param cls a `struct GNUNET_CADET_GetPath` operation |
152 | */ | 153 | */ |
153 | static void | 154 | static void |
154 | reconnect(void *cls); | 155 | reconnect (void *cls); |
155 | 156 | ||
156 | 157 | ||
157 | /** | 158 | /** |
@@ -161,18 +162,18 @@ reconnect(void *cls); | |||
161 | * @param error error code from MQ | 162 | * @param error error code from MQ |
162 | */ | 163 | */ |
163 | static void | 164 | static void |
164 | error_handler(void *cls, | 165 | error_handler (void *cls, |
165 | enum GNUNET_MQ_Error error) | 166 | enum GNUNET_MQ_Error error) |
166 | { | 167 | { |
167 | struct GNUNET_CADET_GetPath *gp = cls; | 168 | struct GNUNET_CADET_GetPath *gp = cls; |
168 | 169 | ||
169 | GNUNET_MQ_destroy(gp->mq); | 170 | GNUNET_MQ_destroy (gp->mq); |
170 | gp->mq = NULL; | 171 | gp->mq = NULL; |
171 | gp->backoff = GNUNET_TIME_randomized_backoff(gp->backoff, | 172 | gp->backoff = GNUNET_TIME_randomized_backoff (gp->backoff, |
172 | GNUNET_TIME_UNIT_MINUTES); | 173 | GNUNET_TIME_UNIT_MINUTES); |
173 | gp->reconnect_task = GNUNET_SCHEDULER_add_delayed(gp->backoff, | 174 | gp->reconnect_task = GNUNET_SCHEDULER_add_delayed (gp->backoff, |
174 | &reconnect, | 175 | &reconnect, |
175 | gp); | 176 | gp); |
176 | } | 177 | } |
177 | 178 | ||
178 | 179 | ||
@@ -182,36 +183,36 @@ error_handler(void *cls, | |||
182 | * @param cls a `struct GNUNET_CADET_GetPath` operation | 183 | * @param cls a `struct GNUNET_CADET_GetPath` operation |
183 | */ | 184 | */ |
184 | static void | 185 | static void |
185 | reconnect(void *cls) | 186 | reconnect (void *cls) |
186 | { | 187 | { |
187 | struct GNUNET_CADET_GetPath *gp = cls; | 188 | struct GNUNET_CADET_GetPath *gp = cls; |
188 | struct GNUNET_MQ_MessageHandler handlers[] = { | 189 | struct GNUNET_MQ_MessageHandler handlers[] = { |
189 | GNUNET_MQ_hd_var_size(get_path, | 190 | GNUNET_MQ_hd_var_size (get_path, |
190 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, | 191 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH, |
191 | struct GNUNET_CADET_LocalInfoPath, | 192 | struct GNUNET_CADET_LocalInfoPath, |
192 | gp), | 193 | gp), |
193 | GNUNET_MQ_hd_fixed_size(get_path_end, | 194 | GNUNET_MQ_hd_fixed_size (get_path_end, |
194 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, | 195 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PATH_END, |
195 | struct GNUNET_MessageHeader, | 196 | struct GNUNET_MessageHeader, |
196 | gp), | 197 | gp), |
197 | GNUNET_MQ_handler_end() | 198 | GNUNET_MQ_handler_end () |
198 | }; | 199 | }; |
199 | struct GNUNET_CADET_RequestPathInfoMessage *msg; | 200 | struct GNUNET_CADET_RequestPathInfoMessage *msg; |
200 | struct GNUNET_MQ_Envelope *env; | 201 | struct GNUNET_MQ_Envelope *env; |
201 | 202 | ||
202 | gp->reconnect_task = NULL; | 203 | gp->reconnect_task = NULL; |
203 | gp->mq = GNUNET_CLIENT_connect(gp->cfg, | 204 | gp->mq = GNUNET_CLIENT_connect (gp->cfg, |
204 | "cadet", | 205 | "cadet", |
205 | handlers, | 206 | handlers, |
206 | &error_handler, | 207 | &error_handler, |
207 | gp); | 208 | gp); |
208 | if (NULL == gp->mq) | 209 | if (NULL == gp->mq) |
209 | return; | 210 | return; |
210 | env = GNUNET_MQ_msg(msg, | 211 | env = GNUNET_MQ_msg (msg, |
211 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH); | 212 | GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PATH); |
212 | msg->peer = gp->id; | 213 | msg->peer = gp->id; |
213 | GNUNET_MQ_send(gp->mq, | 214 | GNUNET_MQ_send (gp->mq, |
214 | env); | 215 | env); |
215 | } | 216 | } |
216 | 217 | ||
217 | 218 | ||
@@ -225,29 +226,29 @@ reconnect(void *cls) | |||
225 | * @return NULL on error | 226 | * @return NULL on error |
226 | */ | 227 | */ |
227 | struct GNUNET_CADET_GetPath * | 228 | struct GNUNET_CADET_GetPath * |
228 | GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg, | 229 | GNUNET_CADET_get_path (const struct GNUNET_CONFIGURATION_Handle *cfg, |
229 | const struct GNUNET_PeerIdentity *id, | 230 | const struct GNUNET_PeerIdentity *id, |
230 | GNUNET_CADET_PathCB callback, | 231 | GNUNET_CADET_PathCB callback, |
231 | void *callback_cls) | 232 | void *callback_cls) |
232 | { | 233 | { |
233 | struct GNUNET_CADET_GetPath *gp; | 234 | struct GNUNET_CADET_GetPath *gp; |
234 | 235 | ||
235 | if (NULL == callback) | 236 | if (NULL == callback) |
236 | { | 237 | { |
237 | GNUNET_break(0); | 238 | GNUNET_break (0); |
238 | return NULL; | 239 | return NULL; |
239 | } | 240 | } |
240 | gp = GNUNET_new(struct GNUNET_CADET_GetPath); | 241 | gp = GNUNET_new (struct GNUNET_CADET_GetPath); |
241 | gp->path_cb = callback; | 242 | gp->path_cb = callback; |
242 | gp->path_cb_cls = callback_cls; | 243 | gp->path_cb_cls = callback_cls; |
243 | gp->cfg = cfg; | 244 | gp->cfg = cfg; |
244 | gp->id = *id; | 245 | gp->id = *id; |
245 | reconnect(gp); | 246 | reconnect (gp); |
246 | if (NULL == gp->mq) | 247 | if (NULL == gp->mq) |
247 | { | 248 | { |
248 | GNUNET_free(gp); | 249 | GNUNET_free (gp); |
249 | return NULL; | 250 | return NULL; |
250 | } | 251 | } |
251 | return gp; | 252 | return gp; |
252 | } | 253 | } |
253 | 254 | ||
@@ -259,15 +260,15 @@ GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
259 | * @return closure from #GNUNET_CADET_get_path(). | 260 | * @return closure from #GNUNET_CADET_get_path(). |
260 | */ | 261 | */ |
261 | void * | 262 | void * |
262 | GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp) | 263 | GNUNET_CADET_get_path_cancel (struct GNUNET_CADET_GetPath *gp) |
263 | { | 264 | { |
264 | void *ret = gp->path_cb_cls; | 265 | void *ret = gp->path_cb_cls; |
265 | 266 | ||
266 | if (NULL != gp->mq) | 267 | if (NULL != gp->mq) |
267 | GNUNET_MQ_destroy(gp->mq); | 268 | GNUNET_MQ_destroy (gp->mq); |
268 | if (NULL != gp->reconnect_task) | 269 | if (NULL != gp->reconnect_task) |
269 | GNUNET_SCHEDULER_cancel(gp->reconnect_task); | 270 | GNUNET_SCHEDULER_cancel (gp->reconnect_task); |
270 | GNUNET_free(gp); | 271 | GNUNET_free (gp); |
271 | return ret; | 272 | return ret; |
272 | } | 273 | } |
273 | 274 | ||