diff options
Diffstat (limited to 'src/mesh/mesh_api_new.c')
-rw-r--r-- | src/mesh/mesh_api_new.c | 498 |
1 files changed, 248 insertions, 250 deletions
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index 0540c765b..e6e6fdaa8 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -22,7 +22,7 @@ | |||
22 | * @file mesh/mesh_api_new.c | 22 | * @file mesh/mesh_api_new.c |
23 | * @brief mesh api: client implementation of mesh service | 23 | * @brief mesh api: client implementation of mesh service |
24 | * @author Bartlomiej Polot | 24 | * @author Bartlomiej Polot |
25 | * | 25 | * |
26 | * STRUCTURE: | 26 | * STRUCTURE: |
27 | * - CONSTANTS | 27 | * - CONSTANTS |
28 | * - DATA STRUCTURES | 28 | * - DATA STRUCTURES |
@@ -193,7 +193,7 @@ retrieve_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | |||
193 | 193 | ||
194 | /** | 194 | /** |
195 | * Process the new tunnel notification and add it to the tunnels in the handle | 195 | * Process the new tunnel notification and add it to the tunnels in the handle |
196 | * | 196 | * |
197 | * @param h The mesh handle | 197 | * @param h The mesh handle |
198 | * @param msg A message with the details of the new incoming tunnel | 198 | * @param msg A message with the details of the new incoming tunnel |
199 | */ | 199 | */ |
@@ -201,30 +201,30 @@ static void | |||
201 | process_tunnel_create (struct GNUNET_MESH_Handle *h, | 201 | process_tunnel_create (struct GNUNET_MESH_Handle *h, |
202 | const struct GNUNET_MESH_TunnelMessage *msg) | 202 | const struct GNUNET_MESH_TunnelMessage *msg) |
203 | { | 203 | { |
204 | struct GNUNET_MESH_Tunnel *t; | 204 | struct GNUNET_MESH_Tunnel *t; |
205 | MESH_TunnelNumber tid; | 205 | MESH_TunnelNumber tid; |
206 | 206 | ||
207 | tid = ntohl (msg->tunnel_id); | 207 | tid = ntohl (msg->tunnel_id); |
208 | if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK) | 208 | if (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK) |
209 | { | 209 | { |
210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
211 | "MESH: received an incoming tunnel with tid in local range (%X)\n", | 211 | "MESH: received an incoming tunnel with tid in local range (%X)\n", |
212 | tid); | 212 | tid); |
213 | GNUNET_break_op (0); | 213 | GNUNET_break_op (0); |
214 | return; //FIXME abort? reconnect? | 214 | return; //FIXME abort? reconnect? |
215 | } | 215 | } |
216 | t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); | 216 | t = GNUNET_malloc (sizeof (struct GNUNET_MESH_Tunnel)); |
217 | t->cls = h->cls; | 217 | t->cls = h->cls; |
218 | t->mesh = h; | 218 | t->mesh = h; |
219 | t->tid = tid; | 219 | t->tid = tid; |
220 | 220 | ||
221 | return; | 221 | return; |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | /** | 225 | /** |
226 | * Process the new peer event and notify the upper level of it | 226 | * Process the new peer event and notify the upper level of it |
227 | * | 227 | * |
228 | * @param h The mesh handle | 228 | * @param h The mesh handle |
229 | * @param msg A message with the details of the peer event | 229 | * @param msg A message with the details of the peer event |
230 | */ | 230 | */ |
@@ -232,41 +232,41 @@ static void | |||
232 | process_peer_event (struct GNUNET_MESH_Handle *h, | 232 | process_peer_event (struct GNUNET_MESH_Handle *h, |
233 | const struct GNUNET_MESH_PeerControl *msg) | 233 | const struct GNUNET_MESH_PeerControl *msg) |
234 | { | 234 | { |
235 | struct GNUNET_MESH_Tunnel *t; | 235 | struct GNUNET_MESH_Tunnel *t; |
236 | uint16_t size; | 236 | uint16_t size; |
237 | 237 | ||
238 | size = ntohs (msg->header.size); | 238 | size = ntohs (msg->header.size); |
239 | if (size != sizeof (struct GNUNET_MESH_PeerControl)) | 239 | if (size != sizeof (struct GNUNET_MESH_PeerControl)) |
240 | { | 240 | { |
241 | GNUNET_break_op (0); | 241 | GNUNET_break_op (0); |
242 | return; | 242 | return; |
243 | } | 243 | } |
244 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); | 244 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); |
245 | if (NULL == t) | 245 | if (NULL == t) |
246 | { | 246 | { |
247 | GNUNET_break_op (0); | 247 | GNUNET_break_op (0); |
248 | return; | 248 | return; |
249 | } | 249 | } |
250 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type) | 250 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED == msg->header.type) |
251 | { | ||
252 | if (NULL != t->connect_handler) | ||
251 | { | 253 | { |
252 | if (NULL != t->connect_handler) | 254 | t->connect_handler (t->cls, &msg->peer, NULL); /* FIXME atsi */ |
253 | { | ||
254 | t->connect_handler (t->cls, &msg->peer, NULL); /* FIXME atsi */ | ||
255 | } | ||
256 | } | 255 | } |
257 | else | 256 | } |
257 | else | ||
258 | { | ||
259 | if (NULL != t->disconnect_handler) | ||
258 | { | 260 | { |
259 | if (NULL != t->disconnect_handler) | 261 | t->disconnect_handler (t->cls, &msg->peer); |
260 | { | ||
261 | t->disconnect_handler (t->cls, &msg->peer); | ||
262 | } | ||
263 | } | 262 | } |
263 | } | ||
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | /** | 267 | /** |
268 | * Process the incoming data packets | 268 | * Process the incoming data packets |
269 | * | 269 | * |
270 | * @param h The mesh handle | 270 | * @param h The mesh handle |
271 | * @param msh A message encapsulating the data | 271 | * @param msh A message encapsulating the data |
272 | */ | 272 | */ |
@@ -274,66 +274,66 @@ static void | |||
274 | process_incoming_data (struct GNUNET_MESH_Handle *h, | 274 | process_incoming_data (struct GNUNET_MESH_Handle *h, |
275 | const struct GNUNET_MessageHeader *message) | 275 | const struct GNUNET_MessageHeader *message) |
276 | { | 276 | { |
277 | const struct GNUNET_MessageHeader *payload; | 277 | const struct GNUNET_MessageHeader *payload; |
278 | const struct GNUNET_MESH_MessageHandler *handler; | 278 | const struct GNUNET_MESH_MessageHandler *handler; |
279 | const struct GNUNET_PeerIdentity *peer; | 279 | const struct GNUNET_PeerIdentity *peer; |
280 | struct GNUNET_MESH_Unicast *ucast; | 280 | struct GNUNET_MESH_Unicast *ucast; |
281 | struct GNUNET_MESH_Multicast *mcast; | 281 | struct GNUNET_MESH_Multicast *mcast; |
282 | struct GNUNET_MESH_ToOrigin *to_orig; | 282 | struct GNUNET_MESH_ToOrigin *to_orig; |
283 | struct GNUNET_MESH_Tunnel *t; | 283 | struct GNUNET_MESH_Tunnel *t; |
284 | uint16_t type; | 284 | uint16_t type; |
285 | int i; | 285 | int i; |
286 | 286 | ||
287 | type = ntohs (message->type); | 287 | type = ntohs (message->type); |
288 | switch (type) | 288 | switch (type) |
289 | { | 289 | { |
290 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 290 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: |
291 | ucast = (struct GNUNET_MESH_Unicast *) message; | 291 | ucast = (struct GNUNET_MESH_Unicast *) message; |
292 | t = retrieve_tunnel (h, ntohl (ucast->tid)); | 292 | t = retrieve_tunnel (h, ntohl (ucast->tid)); |
293 | payload = (struct GNUNET_MessageHeader *) &ucast[1]; | 293 | payload = (struct GNUNET_MessageHeader *) &ucast[1]; |
294 | peer = &ucast->oid; | 294 | peer = &ucast->oid; |
295 | break; | 295 | break; |
296 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | 296 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: |
297 | mcast = (struct GNUNET_MESH_Multicast *) message; | 297 | mcast = (struct GNUNET_MESH_Multicast *) message; |
298 | t = retrieve_tunnel (h, ntohl (mcast->tid)); | 298 | t = retrieve_tunnel (h, ntohl (mcast->tid)); |
299 | payload = (struct GNUNET_MessageHeader *) &mcast[1]; | 299 | payload = (struct GNUNET_MessageHeader *) &mcast[1]; |
300 | peer = &mcast->oid; | 300 | peer = &mcast->oid; |
301 | break; | 301 | break; |
302 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | 302 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: |
303 | to_orig = (struct GNUNET_MESH_ToOrigin *) message; | 303 | to_orig = (struct GNUNET_MESH_ToOrigin *) message; |
304 | t = retrieve_tunnel (h, ntohl (to_orig->tid)); | 304 | t = retrieve_tunnel (h, ntohl (to_orig->tid)); |
305 | payload = (struct GNUNET_MessageHeader *) &to_orig[1]; | 305 | payload = (struct GNUNET_MessageHeader *) &to_orig[1]; |
306 | peer = &to_orig->sender; | 306 | peer = &to_orig->sender; |
307 | break; | 307 | break; |
308 | default: | 308 | default: |
309 | GNUNET_break_op (0); | 309 | GNUNET_break_op (0); |
310 | return; | 310 | return; |
311 | } | 311 | } |
312 | if (NULL == t) | 312 | if (NULL == t) |
313 | { | 313 | { |
314 | GNUNET_break_op (0); | 314 | GNUNET_break_op (0); |
315 | return; | 315 | return; |
316 | } | 316 | } |
317 | for (i = 0; i < h->n_handlers; i++) | 317 | for (i = 0; i < h->n_handlers; i++) |
318 | { | ||
319 | handler = &h->message_handlers[i]; | ||
320 | if (handler->type == type) | ||
318 | { | 321 | { |
319 | handler = &h->message_handlers[i]; | 322 | if (GNUNET_OK == handler->callback (h->cls, t, NULL, /* FIXME ctx */ |
320 | if (handler->type == type) | 323 | peer, payload, NULL)) /* FIXME atsi */ |
321 | { | 324 | { |
322 | if (GNUNET_OK == handler->callback (h->cls, t, NULL, /* FIXME ctx */ | 325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
323 | peer, payload, NULL)) /* FIXME atsi */ | 326 | "MESH: callback completed successfully\n"); |
324 | { | 327 | } |
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 328 | else |
326 | "MESH: callback completed successfully\n"); | 329 | { |
327 | } | 330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
328 | else | 331 | "MESH: callback caused disconnection\n"); |
329 | { | 332 | GNUNET_MESH_disconnect (h); |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 333 | } |
331 | "MESH: callback caused disconnection\n"); | ||
332 | GNUNET_MESH_disconnect (h); | ||
333 | } | ||
334 | } | ||
335 | } | 334 | } |
336 | return; | 335 | } |
336 | return; | ||
337 | } | 337 | } |
338 | 338 | ||
339 | 339 | ||
@@ -346,44 +346,43 @@ process_incoming_data (struct GNUNET_MESH_Handle *h, | |||
346 | static void | 346 | static void |
347 | msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | 347 | msg_received (void *cls, const struct GNUNET_MessageHeader *msg) |
348 | { | 348 | { |
349 | struct GNUNET_MESH_Handle *h = cls; | 349 | struct GNUNET_MESH_Handle *h = cls; |
350 | 350 | ||
351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 351 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: received a message from MESH\n"); |
352 | "mesh: received a message from MESH\n"); | 352 | if (msg == NULL) |
353 | if (msg == NULL) | 353 | { |
354 | { | 354 | GNUNET_break_op (0); |
355 | GNUNET_break_op (0); | 355 | return; |
356 | return; | 356 | } |
357 | } | ||
358 | 357 | ||
359 | switch (ntohs (msg->type)) | 358 | switch (ntohs (msg->type)) |
360 | { | 359 | { |
361 | /* Notify of a new incoming tunnel */ | 360 | /* Notify of a new incoming tunnel */ |
362 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: | 361 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE: |
363 | process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg); | 362 | process_tunnel_create (h, (struct GNUNET_MESH_TunnelMessage *) msg); |
364 | break; | 363 | break; |
365 | /* Notify of a new peer or a peer disconnect in the tunnel */ | 364 | /* Notify of a new peer or a peer disconnect in the tunnel */ |
366 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED: | 365 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_CONNECTED: |
367 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED: | 366 | case GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED: |
368 | process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg); | 367 | process_peer_event (h, (struct GNUNET_MESH_PeerControl *) msg); |
369 | break; | 368 | break; |
370 | /* Notify of a new data packet in the tunnel */ | 369 | /* Notify of a new data packet in the tunnel */ |
371 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: | 370 | case GNUNET_MESSAGE_TYPE_MESH_UNICAST: |
372 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: | 371 | case GNUNET_MESSAGE_TYPE_MESH_MULTICAST: |
373 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: | 372 | case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: |
374 | process_incoming_data (h, msg); | 373 | process_incoming_data (h, msg); |
375 | break; | 374 | break; |
376 | /* We shouldn't get any other packages, log and ignore */ | 375 | /* We shouldn't get any other packages, log and ignore */ |
377 | default: | 376 | default: |
378 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
379 | "MESH: unsolicited message form service (type %d)\n", | 378 | "MESH: unsolicited message form service (type %d)\n", |
380 | ntohs (msg->type)); | 379 | ntohs (msg->type)); |
381 | } | 380 | } |
382 | 381 | ||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n"); | 382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n"); |
384 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | 383 | GNUNET_CLIENT_receive (h->client, &msg_received, h, |
385 | GNUNET_TIME_UNIT_FOREVER_REL); | 384 | GNUNET_TIME_UNIT_FOREVER_REL); |
386 | return; | 385 | return; |
387 | } | 386 | } |
388 | 387 | ||
389 | 388 | ||
@@ -406,66 +405,65 @@ msg_received (void *cls, const struct GNUNET_MessageHeader *msg) | |||
406 | static size_t | 405 | static size_t |
407 | send_connect_packet (void *cls, size_t size, void *buf) | 406 | send_connect_packet (void *cls, size_t size, void *buf) |
408 | { | 407 | { |
409 | struct GNUNET_MESH_Handle *h = cls; | 408 | struct GNUNET_MESH_Handle *h = cls; |
410 | struct GNUNET_MESH_ClientConnect *msg; | 409 | struct GNUNET_MESH_ClientConnect *msg; |
411 | GNUNET_MESH_ApplicationType *apps; | 410 | GNUNET_MESH_ApplicationType *apps; |
412 | uint16_t napps; | 411 | uint16_t napps; |
413 | uint16_t *types; | 412 | uint16_t *types; |
414 | uint16_t ntypes; | 413 | uint16_t ntypes; |
415 | 414 | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send connect packet()\n", size); |
417 | "mesh: Send connect packet()\n", size); | 416 | h->th = NULL; |
418 | h->th = NULL; | 417 | if (0 == size || NULL == buf) |
419 | if (0 == size || NULL == buf) | 418 | { |
420 | { | 419 | // FIXME: disconnect, reconnect, retry? |
421 | // FIXME: disconnect, reconnect, retry? | 420 | return 0; |
422 | return 0; | 421 | } |
423 | } | 422 | if (sizeof (struct GNUNET_MessageHeader) > size) |
424 | if (sizeof (struct GNUNET_MessageHeader) > size) | 423 | { |
425 | { | 424 | GNUNET_break (0); |
426 | GNUNET_break(0); | 425 | // FIXME: disconnect, reconnect, retry! |
427 | // FIXME: disconnect, reconnect, retry! | 426 | return 0; |
428 | return 0; | 427 | } |
429 | } | 428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 429 | "mesh: Send connect packet: %lu bytes buffer\n", size); |
431 | "mesh: Send connect packet: %lu bytes buffer\n", size); | 430 | msg = (struct GNUNET_MESH_ClientConnect *) buf; |
432 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | 431 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); |
433 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | ||
434 | |||
435 | for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++) | ||
436 | { | ||
437 | types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1)); | ||
438 | types[ntypes] = h->message_handlers[ntypes].type; | ||
439 | } | ||
440 | 432 | ||
441 | for (napps = 0, apps = NULL; napps < h->n_applications; napps++) | 433 | for (ntypes = 0, types = NULL; ntypes < h->n_handlers; ntypes++) |
442 | { | 434 | { |
443 | apps = | 435 | types = GNUNET_realloc (types, sizeof (uint16_t) * (ntypes + 1)); |
444 | GNUNET_realloc (apps, | 436 | types[ntypes] = h->message_handlers[ntypes].type; |
445 | sizeof (GNUNET_MESH_ApplicationType) * (napps + 1)); | 437 | } |
446 | apps[napps] = h->applications[napps]; | ||
447 | } | ||
448 | 438 | ||
449 | msg->header.size = | 439 | for (napps = 0, apps = NULL; napps < h->n_applications; napps++) |
450 | htons (sizeof (struct GNUNET_MESH_ClientConnect) + | 440 | { |
451 | sizeof (uint16_t) * ntypes + | 441 | apps = |
452 | sizeof (GNUNET_MESH_ApplicationType) * napps); | 442 | GNUNET_realloc (apps, |
453 | memcpy (&msg[1], types, sizeof (uint16_t) * ntypes); | 443 | sizeof (GNUNET_MESH_ApplicationType) * (napps + 1)); |
454 | types = (uint16_t *) &msg[1]; | 444 | apps[napps] = h->applications[napps]; |
455 | memcpy (&types[ntypes], apps, sizeof (GNUNET_MESH_ApplicationType) * napps); | 445 | } |
456 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
457 | "mesh: Sent %lu bytes long message %d types and %d apps\n", | ||
458 | ntohs (msg->header.size), ntypes, napps); | ||
459 | msg->applications = htons (napps); | ||
460 | msg->types = htons (ntypes); | ||
461 | |||
462 | /* start listening */ | ||
463 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
464 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
465 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
466 | "mesh: Send connect packet() END\n", size); | ||
467 | 446 | ||
468 | return ntohs (msg->header.size); | 447 | msg->header.size = |
448 | htons (sizeof (struct GNUNET_MESH_ClientConnect) + | ||
449 | sizeof (uint16_t) * ntypes + | ||
450 | sizeof (GNUNET_MESH_ApplicationType) * napps); | ||
451 | memcpy (&msg[1], types, sizeof (uint16_t) * ntypes); | ||
452 | types = (uint16_t *) & msg[1]; | ||
453 | memcpy (&types[ntypes], apps, sizeof (GNUNET_MESH_ApplicationType) * napps); | ||
454 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
455 | "mesh: Sent %lu bytes long message %d types and %d apps\n", | ||
456 | ntohs (msg->header.size), ntypes, napps); | ||
457 | msg->applications = htons (napps); | ||
458 | msg->types = htons (ntypes); | ||
459 | |||
460 | /* start listening */ | ||
461 | GNUNET_CLIENT_receive (h->client, &msg_received, h, | ||
462 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
463 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send connect packet() END\n", | ||
464 | size); | ||
465 | |||
466 | return ntohs (msg->header.size); | ||
469 | } | 467 | } |
470 | 468 | ||
471 | 469 | ||
@@ -496,7 +494,7 @@ send_tunnel_create_packet (void *cls, size_t size, void *buf) | |||
496 | } | 494 | } |
497 | if (sizeof (struct GNUNET_MESH_TunnelMessage) > size) | 495 | if (sizeof (struct GNUNET_MESH_TunnelMessage) > size) |
498 | { | 496 | { |
499 | GNUNET_break(0); | 497 | GNUNET_break (0); |
500 | // FIXME: disconnect, reconnect, retry? | 498 | // FIXME: disconnect, reconnect, retry? |
501 | return 0; | 499 | return 0; |
502 | } | 500 | } |
@@ -529,35 +527,35 @@ send_tunnel_create_packet (void *cls, size_t size, void *buf) | |||
529 | static size_t | 527 | static size_t |
530 | send_tunnel_destroy_packet (void *cls, size_t size, void *buf) | 528 | send_tunnel_destroy_packet (void *cls, size_t size, void *buf) |
531 | { | 529 | { |
532 | struct GNUNET_MESH_Tunnel *t = cls; | 530 | struct GNUNET_MESH_Tunnel *t = cls; |
533 | struct GNUNET_MESH_Handle *h; | 531 | struct GNUNET_MESH_Handle *h; |
534 | struct GNUNET_MESH_TunnelMessage *msg; | 532 | struct GNUNET_MESH_TunnelMessage *msg; |
535 | 533 | ||
536 | h = t->mesh; | 534 | h = t->mesh; |
537 | h->th = NULL; | 535 | h->th = NULL; |
538 | if (0 == size || buf == NULL) | 536 | if (0 == size || buf == NULL) |
539 | { | 537 | { |
540 | return 0; | 538 | return 0; |
541 | } | 539 | } |
542 | if (sizeof (struct GNUNET_MESH_TunnelMessage) > size) | 540 | if (sizeof (struct GNUNET_MESH_TunnelMessage) > size) |
543 | { | 541 | { |
544 | GNUNET_break(0); | 542 | GNUNET_break (0); |
545 | // FIXME: disconnect, reconnect, retry! | 543 | // FIXME: disconnect, reconnect, retry! |
546 | return 0; | 544 | return 0; |
547 | } | 545 | } |
548 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
549 | "Send tunnel destroy packet: %lu bytes buffer\n", size); | 547 | "Send tunnel destroy packet: %lu bytes buffer\n", size); |
550 | msg = (struct GNUNET_MESH_TunnelMessage *) buf; | 548 | msg = (struct GNUNET_MESH_TunnelMessage *) buf; |
551 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | 549 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); |
552 | 550 | ||
553 | msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 551 | msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
554 | msg->tunnel_id = htonl (t->tid); | 552 | msg->tunnel_id = htonl (t->tid); |
555 | 553 | ||
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n", | 554 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %lu bytes long message\n", |
557 | ntohs (msg->header.size)); | 555 | ntohs (msg->header.size)); |
558 | GNUNET_free(t); | 556 | GNUNET_free (t); |
559 | 557 | ||
560 | return sizeof (struct GNUNET_MESH_TunnelMessage); | 558 | return sizeof (struct GNUNET_MESH_TunnelMessage); |
561 | } | 559 | } |
562 | 560 | ||
563 | 561 | ||
@@ -577,7 +575,7 @@ send_tunnel_destroy_packet (void *cls, size_t size, void *buf) | |||
577 | * inbound messages if the client does not process them fast | 575 | * inbound messages if the client does not process them fast |
578 | * enough (for this notification type, a bounded queue is used) | 576 | * enough (for this notification type, a bounded queue is used) |
579 | * @param stypes Application Types the client claims to offer | 577 | * @param stypes Application Types the client claims to offer |
580 | * @return handle to the mesh service | 578 | * @return handle to the mesh service |
581 | * NULL on error (in this case, init is never called) | 579 | * NULL on error (in this case, init is never called) |
582 | */ | 580 | */ |
583 | struct GNUNET_MESH_Handle * | 581 | struct GNUNET_MESH_Handle * |
@@ -586,8 +584,8 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
586 | const struct GNUNET_MESH_MessageHandler *handlers, | 584 | const struct GNUNET_MESH_MessageHandler *handlers, |
587 | const GNUNET_MESH_ApplicationType *stypes) | 585 | const GNUNET_MESH_ApplicationType *stypes) |
588 | { | 586 | { |
589 | struct GNUNET_MESH_Handle *h; | 587 | struct GNUNET_MESH_Handle *h; |
590 | size_t size; | 588 | size_t size; |
591 | 589 | ||
592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); | 590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n"); |
593 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); | 591 | h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle)); |
@@ -596,7 +594,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
596 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); | 594 | h->client = GNUNET_CLIENT_connect ("mesh", cfg); |
597 | if (h->client == NULL) | 595 | if (h->client == NULL) |
598 | { | 596 | { |
599 | GNUNET_break(0); | 597 | GNUNET_break (0); |
600 | GNUNET_free (h); | 598 | GNUNET_free (h); |
601 | return NULL; | 599 | return NULL; |
602 | } | 600 | } |
@@ -613,11 +611,11 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
613 | size += h->n_handlers * sizeof (uint16_t); | 611 | size += h->n_handlers * sizeof (uint16_t); |
614 | size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); | 612 | size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType); |
615 | 613 | ||
616 | if (NULL != h->th) { | 614 | if (NULL != h->th) |
617 | /* FIXME implement queue system instead */ | 615 | { |
618 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 616 | /* FIXME implement queue system instead */ |
619 | "mesh: overwriting th of mesh\n"); | 617 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mesh: overwriting th of mesh\n"); |
620 | GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); | 618 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
621 | } | 619 | } |
622 | h->th = | 620 | h->th = |
623 | GNUNET_CLIENT_notify_transmit_ready (h->client, size, | 621 | GNUNET_CLIENT_notify_transmit_ready (h->client, size, |
@@ -676,11 +674,11 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
676 | tunnel->mesh = h; | 674 | tunnel->mesh = h; |
677 | tunnel->tid = h->next_tid++; | 675 | tunnel->tid = h->next_tid++; |
678 | h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range | 676 | h->next_tid |= GNUNET_MESH_LOCAL_TUNNEL_ID_MARK; // keep in range |
679 | if (NULL != h->th) { | 677 | if (NULL != h->th) |
680 | /* FIXME implement queue system instead */ | 678 | { |
681 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 679 | /* FIXME implement queue system instead */ |
682 | "mesh: overwriting th of mesh\n"); | 680 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mesh: overwriting th of mesh\n"); |
683 | GNUNET_CLIENT_notify_transmit_ready_cancel(h->th); | 681 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); |
684 | } | 682 | } |
685 | h->th = | 683 | h->th = |
686 | GNUNET_CLIENT_notify_transmit_ready (h->client, | 684 | GNUNET_CLIENT_notify_transmit_ready (h->client, |
@@ -703,21 +701,21 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
703 | void | 701 | void |
704 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun) | 702 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun) |
705 | { | 703 | { |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); | 704 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); |
707 | if (NULL != tun->mesh->th) { | 705 | if (NULL != tun->mesh->th) |
708 | /* FIXME implement queue system instead */ | 706 | { |
709 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 707 | /* FIXME implement queue system instead */ |
710 | "mesh: overwriting th of mesh\n"); | 708 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "mesh: overwriting th of mesh\n"); |
711 | GNUNET_CLIENT_notify_transmit_ready_cancel(tun->mesh->th); | 709 | GNUNET_CLIENT_notify_transmit_ready_cancel (tun->mesh->th); |
712 | } | 710 | } |
713 | tun->mesh->th = GNUNET_CLIENT_notify_transmit_ready ( | 711 | tun->mesh->th = |
714 | tun->mesh->client, | 712 | GNUNET_CLIENT_notify_transmit_ready (tun->mesh->client, |
715 | sizeof (struct | 713 | sizeof (struct |
716 | GNUNET_MESH_TunnelMessage), | 714 | GNUNET_MESH_TunnelMessage), |
717 | GNUNET_TIME_UNIT_FOREVER_REL, | 715 | GNUNET_TIME_UNIT_FOREVER_REL, |
718 | GNUNET_YES, | 716 | GNUNET_YES, |
719 | &send_tunnel_destroy_packet, | 717 | &send_tunnel_destroy_packet, |
720 | (void *) tun); | 718 | (void *) tun); |
721 | } | 719 | } |
722 | 720 | ||
723 | 721 | ||
@@ -792,7 +790,7 @@ GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel, | |||
792 | * @param priority how important is the message? | 790 | * @param priority how important is the message? |
793 | * @param maxdelay how long can the message wait? | 791 | * @param maxdelay how long can the message wait? |
794 | * @param target destination for the message, | 792 | * @param target destination for the message, |
795 | * NULL for multicast to all tunnel targets | 793 | * NULL for multicast to all tunnel targets |
796 | * @param notify_size how many bytes of buffer space does notify want? | 794 | * @param notify_size how many bytes of buffer space does notify want? |
797 | * @param notify function to call when buffer space is available; | 795 | * @param notify function to call when buffer space is available; |
798 | * will be called with NULL on timeout or if the overall queue | 796 | * will be called with NULL on timeout or if the overall queue |