aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_local.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-11 10:27:52 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-11 10:27:52 +0000
commit23cd779d3db3edd280ca9f760f1a98efa49e6653 (patch)
tree12586c18d6dae3cc5700989815f214fc16d3f3b9 /src/mesh/gnunet-service-mesh_local.c
parentd254743f5668e69b13b0d82b373699562f3a0738 (diff)
downloadgnunet-23cd779d3db3edd280ca9f760f1a98efa49e6653.tar.gz
gnunet-23cd779d3db3edd280ca9f760f1a98efa49e6653.zip
- migrate handlers to channel.c
- clients shouldn't know about tunnels
Diffstat (limited to 'src/mesh/gnunet-service-mesh_local.c')
-rw-r--r--src/mesh/gnunet-service-mesh_local.c61
1 files changed, 11 insertions, 50 deletions
diff --git a/src/mesh/gnunet-service-mesh_local.c b/src/mesh/gnunet-service-mesh_local.c
index eba5b88de..6ee23e6e0 100644
--- a/src/mesh/gnunet-service-mesh_local.c
+++ b/src/mesh/gnunet-service-mesh_local.c
@@ -28,7 +28,6 @@
28#include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared 28#include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared
29 29
30#include "gnunet-service-mesh_local.h" 30#include "gnunet-service-mesh_local.h"
31#include "gnunet-service-mesh_tunnel.h"
32 31
33#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__) 32#define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__)
34 33
@@ -435,14 +434,13 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
435 struct GNUNET_MESH_ChannelMessage *msg; 434 struct GNUNET_MESH_ChannelMessage *msg;
436 struct MeshClient *c; 435 struct MeshClient *c;
437 struct MeshChannel *ch; 436 struct MeshChannel *ch;
438 struct MeshTunnel2 *t;
439 MESH_ChannelNumber chid; 437 MESH_ChannelNumber chid;
440 438
441 LOG (GNUNET_ERROR_TYPE_DEBUG, 439 LOG (GNUNET_ERROR_TYPE_DEBUG,
442 "Got a DESTROY CHANNEL from client!\n"); 440 "Got a DESTROY CHANNEL from client!\n");
443 441
444 /* Sanity check for client registration */ 442 /* Sanity check for client registration */
445 if (NULL == (c = client_get (client))) 443 if (NULL == (c = GML_client_get (client)))
446 { 444 {
447 GNUNET_break (0); 445 GNUNET_break (0);
448 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 446 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -462,7 +460,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
462 460
463 /* Retrieve tunnel */ 461 /* Retrieve tunnel */
464 chid = ntohl (msg->channel_id); 462 chid = ntohl (msg->channel_id);
465 ch = channel_get_by_local_id (c, chid); 463 ch = GML_channel_get (c, chid);
466 if (NULL == ch) 464 if (NULL == ch)
467 { 465 {
468 LOG (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid); 466 LOG (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid);
@@ -471,27 +469,7 @@ handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
471 return; 469 return;
472 } 470 }
473 471
474 /* Cleanup after the tunnel */ 472 GMCH_handle_local_destroy (ch, c, chid);
475 client_delete_channel (c, ch);
476 if (c == ch->dest && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid)
477 {
478 ch->dest = NULL;
479 }
480 else if (c == ch->root && GNUNET_MESH_LOCAL_CHANNEL_ID_SERV > chid)
481 {
482 ch->root = NULL;
483 }
484 else
485 {
486 LOG (GNUNET_ERROR_TYPE_ERROR,
487 " channel %X client %p (%p, %p)\n",
488 chid, c, ch->root, ch->dest);
489 GNUNET_break (0);
490 }
491
492 t = ch->t;
493 channel_destroy (ch);
494 tunnel_destroy_if_empty (t);
495 473
496 GNUNET_SERVER_receive_done (client, GNUNET_OK); 474 GNUNET_SERVER_receive_done (client, GNUNET_OK);
497 return; 475 return;
@@ -512,7 +490,6 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
512 struct GNUNET_MESH_LocalData *msg; 490 struct GNUNET_MESH_LocalData *msg;
513 struct MeshClient *c; 491 struct MeshClient *c;
514 struct MeshChannel *ch; 492 struct MeshChannel *ch;
515 struct MeshChannelReliability *rel;
516 MESH_ChannelNumber chid; 493 MESH_ChannelNumber chid;
517 size_t size; 494 size_t size;
518 int fwd; 495 int fwd;
@@ -551,30 +528,14 @@ handle_data (void *cls, struct GNUNET_SERVER_Client *client,
551 return; 528 return;
552 } 529 }
553 530
554 rel = fwd ? ch->root_rel : ch->dest_rel; 531 if (GNUNET_OK !=
555 rel->client_ready = GNUNET_NO; 532 GMCH_handle_local_data (ch, c,
556 533 (struct GNUNET_MessageHeader *)&msg[1], fwd))
557 /* Ok, everything is correct, send the message. */
558 { 534 {
559 struct GNUNET_MESH_Data *payload; 535 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
560 uint16_t p2p_size = sizeof(struct GNUNET_MESH_Data) + size; 536 return;
561 unsigned char cbuf[p2p_size];
562
563 payload = (struct GNUNET_MESH_Data *) cbuf;
564 payload->mid = htonl (rel->mid_send);
565 rel->mid_send++;
566 memcpy (&payload[1], &msg[1], size);
567 payload->header.size = htons (p2p_size);
568 payload->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_DATA);
569 payload->chid = htonl (ch->gid);
570 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
571 send_prebuilt_message_channel (&payload->header, ch, fwd);
572
573 if (GNUNET_YES == ch->reliable)
574 channel_save_copy (ch, &payload->header, fwd);
575 } 537 }
576 if (tunnel_get_buffer (ch->t, fwd) > 0) 538
577 send_local_ack (ch, fwd);
578 LOG (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n"); 539 LOG (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
579 GNUNET_SERVER_receive_done (client, GNUNET_OK); 540 GNUNET_SERVER_receive_done (client, GNUNET_OK);
580 541
@@ -630,8 +591,8 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
630 /* If client is dest, the ACK is going BCK, therefore this is "FWD" */ 591 /* If client is dest, the ACK is going BCK, therefore this is "FWD" */
631 fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV; 592 fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
632 593
633 GNUNET_SERVER_receive_done (client, GNUNET_OK);
634 GMCH_handle_local_ack (ch, fwd); 594 GMCH_handle_local_ack (ch, fwd);
595 GNUNET_SERVER_receive_done (client, GNUNET_OK);
635 596
636 return; 597 return;
637} 598}
@@ -955,7 +916,7 @@ GML_client_get_by_port (uint32_t port)
955 916
956 917
957/** 918/**
958 * Deletes a tunnel from a client (either owner or destination). 919 * Deletes a channel from a client (either owner or destination).
959 * 920 *
960 * @param c Client whose tunnel to delete. 921 * @param c Client whose tunnel to delete.
961 * @param ch Channel which should be deleted. 922 * @param ch Channel which should be deleted.