diff options
-rw-r--r-- | src/include/gnunet_mesh_service_new.h | 1 | ||||
-rw-r--r-- | src/mesh/mesh.h | 5 | ||||
-rw-r--r-- | src/mesh/mesh_api.c | 2 | ||||
-rw-r--r-- | src/mesh/mesh_api_new.c | 70 |
4 files changed, 52 insertions, 26 deletions
diff --git a/src/include/gnunet_mesh_service_new.h b/src/include/gnunet_mesh_service_new.h index e85a4814f..1b4faa382 100644 --- a/src/include/gnunet_mesh_service_new.h +++ b/src/include/gnunet_mesh_service_new.h | |||
@@ -196,6 +196,7 @@ typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls, | |||
196 | 196 | ||
197 | /** | 197 | /** |
198 | * Method called whenever a peer has connected to the tunnel. | 198 | * Method called whenever a peer has connected to the tunnel. |
199 | * TODO: change to typedef int? to let client allow the new peer or not | ||
199 | * | 200 | * |
200 | * @param cls closure | 201 | * @param cls closure |
201 | * @param peer peer identity the tunnel was created to, NULL on timeout | 202 | * @param peer peer identity the tunnel was created to, NULL on timeout |
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 41fc13110..4b82b41dc 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h | |||
@@ -118,6 +118,11 @@ struct GNUNET_MESH_TunnelMessage | |||
118 | * ID of a tunnel controlled by this client. | 118 | * ID of a tunnel controlled by this client. |
119 | */ | 119 | */ |
120 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; | 120 | MESH_TunnelNumber tunnel_id GNUNET_PACKED; |
121 | |||
122 | /** | ||
123 | * Peer at the other end, if any | ||
124 | */ | ||
125 | struct GNUNET_PeerIdentity peer; | ||
121 | }; | 126 | }; |
122 | 127 | ||
123 | /** | 128 | /** |
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 615593621..1453f6228 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c | |||
@@ -921,4 +921,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
921 | GNUNET_free (handle); | 921 | GNUNET_free (handle); |
922 | } | 922 | } |
923 | 923 | ||
924 | /* end of mesh_api.c */ \ No newline at end of file | 924 | /* end of mesh_api.c \ No newline at end of file |
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c index fcc515042..73d1eba56 100644 --- a/src/mesh/mesh_api_new.c +++ b/src/mesh/mesh_api_new.c | |||
@@ -372,18 +372,18 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | |||
372 | * @return handle to the required tunnel or NULL if not found | 372 | * @return handle to the required tunnel or NULL if not found |
373 | */ | 373 | */ |
374 | static void | 374 | static void |
375 | destroy_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid) | 375 | destroy_tunnel (struct GNUNET_MESH_Tunnel *t) |
376 | { | 376 | { |
377 | struct GNUNET_MESH_Tunnel *t; | 377 | struct GNUNET_MESH_Handle *h; |
378 | struct GNUNET_PeerIdentity pi; | 378 | struct GNUNET_PeerIdentity pi; |
379 | unsigned int i; | 379 | unsigned int i; |
380 | 380 | ||
381 | t = retrieve_tunnel (h, tid); | ||
382 | if (NULL == t) | 381 | if (NULL == t) |
383 | { | 382 | { |
384 | GNUNET_break (0); | 383 | GNUNET_break (0); |
385 | return; | 384 | return; |
386 | } | 385 | } |
386 | h = t->mesh; | ||
387 | /* TODO remove data packets from queue */ | 387 | /* TODO remove data packets from queue */ |
388 | GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); | 388 | GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t); |
389 | for (i = 0; i < t->npeers; i++) | 389 | for (i = 0; i < t->npeers; i++) |
@@ -439,6 +439,11 @@ add_peer_to_tunnel (struct GNUNET_MESH_Tunnel *t, | |||
439 | struct GNUNET_MESH_Peer *p; | 439 | struct GNUNET_MESH_Peer *p; |
440 | GNUNET_PEER_Id id; | 440 | GNUNET_PEER_Id id; |
441 | 441 | ||
442 | if (0 != t->owner) | ||
443 | { | ||
444 | GNUNET_break (0); | ||
445 | return NULL; | ||
446 | } | ||
442 | id = GNUNET_PEER_intern (pi); | 447 | id = GNUNET_PEER_intern (pi); |
443 | 448 | ||
444 | p = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer)); | 449 | p = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer)); |
@@ -622,6 +627,7 @@ process_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
622 | const struct GNUNET_MESH_TunnelMessage *msg) | 627 | const struct GNUNET_MESH_TunnelMessage *msg) |
623 | { | 628 | { |
624 | struct GNUNET_MESH_Tunnel *t; | 629 | struct GNUNET_MESH_Tunnel *t; |
630 | struct GNUNET_TRANSPORT_ATS_Information atsi; | ||
625 | MESH_TunnelNumber tid; | 631 | MESH_TunnelNumber tid; |
626 | 632 | ||
627 | tid = ntohl (msg->tunnel_id); | 633 | tid = ntohl (msg->tunnel_id); |
@@ -631,8 +637,21 @@ process_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
631 | return; | 637 | return; |
632 | } | 638 | } |
633 | t = create_tunnel (h, tid); | 639 | t = create_tunnel (h, tid); |
640 | t->owner = GNUNET_PEER_intern (&msg->peer); | ||
641 | t->npeers = 1; | ||
642 | t->peers = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer *)); | ||
643 | t->peers[0] = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer)); | ||
644 | t->peers[0]->t = t; | ||
645 | t->peers[0]->connected = 1; | ||
646 | t->peers[0]->id = t->owner; | ||
634 | t->mesh = h; | 647 | t->mesh = h; |
635 | t->tid = tid; | 648 | t->tid = tid; |
649 | if (NULL != h->new_tunnel) | ||
650 | { | ||
651 | atsi.type = 0; | ||
652 | atsi.value = 0; | ||
653 | t->ctx = h->new_tunnel(h->cls, t, &msg->peer, &atsi); | ||
654 | } | ||
636 | GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); | 655 | GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); |
637 | return; | 656 | return; |
638 | } | 657 | } |
@@ -654,10 +673,17 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h, | |||
654 | tid = ntohl (msg->tunnel_id); | 673 | tid = ntohl (msg->tunnel_id); |
655 | t = retrieve_tunnel (h, tid); | 674 | t = retrieve_tunnel (h, tid); |
656 | 675 | ||
657 | t->cls = h->cls; | 676 | if (NULL == t) |
658 | t->mesh = h; | 677 | { |
659 | t->tid = tid; | 678 | GNUNET_break(0); |
660 | GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t); | 679 | return; |
680 | } | ||
681 | if (0 == t->owner) | ||
682 | { | ||
683 | GNUNET_break(0); | ||
684 | } | ||
685 | |||
686 | destroy_tunnel(t); | ||
661 | return; | 687 | return; |
662 | } | 688 | } |
663 | 689 | ||
@@ -687,25 +713,18 @@ process_peer_event (struct GNUNET_MESH_Handle *h, | |||
687 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); | 713 | t = retrieve_tunnel (h, ntohl (msg->tunnel_id)); |
688 | if (NULL == t) | 714 | if (NULL == t) |
689 | { | 715 | { |
690 | t = create_tunnel (h, msg->tunnel_id); | 716 | GNUNET_break(0); |
691 | t->owner = GNUNET_PEER_intern (&msg->peer); | ||
692 | t->npeers = 1; | ||
693 | t->peers = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer *)); | ||
694 | t->peers[0] = GNUNET_malloc (sizeof (struct GNUNET_MESH_Peer)); | ||
695 | t->peers[0]->t = t; | ||
696 | t->peers[0]->connected = 1; | ||
697 | t->peers[0]->id = t->owner; | ||
698 | return; | 717 | return; |
699 | } | 718 | } |
700 | id = GNUNET_PEER_search (&msg->peer); | 719 | id = GNUNET_PEER_search (&msg->peer); |
701 | if ((p = retrieve_peer (t, id)) == NULL) | 720 | if ((p = retrieve_peer (t, id)) == NULL) |
702 | p = add_peer_to_tunnel (t, &msg->peer); | 721 | p = add_peer_to_tunnel (t, &msg->peer); |
703 | atsi.type = 0; | ||
704 | atsi.value = 0; | ||
705 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == msg->header.type) | 722 | if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == msg->header.type) |
706 | { | 723 | { |
707 | if (NULL != t->connect_handler) | 724 | if (NULL != t->connect_handler) |
708 | { | 725 | { |
726 | atsi.type = 0; | ||
727 | atsi.value = 0; | ||
709 | t->connect_handler (t->cls, &msg->peer, &atsi); | 728 | t->connect_handler (t->cls, &msg->peer, &atsi); |
710 | } | 729 | } |
711 | p->connected = 1; | 730 | p->connected = 1; |
@@ -1091,7 +1110,7 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1091 | 1110 | ||
1092 | for (t = handle->tunnels_head; NULL != t; t = t->next) | 1111 | for (t = handle->tunnels_head; NULL != t; t = t->next) |
1093 | { | 1112 | { |
1094 | destroy_tunnel (handle, t->tid); | 1113 | destroy_tunnel (t); |
1095 | } | 1114 | } |
1096 | if (NULL != handle->th) | 1115 | if (NULL != handle->th) |
1097 | { | 1116 | { |
@@ -1144,21 +1163,21 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx, | |||
1144 | * @param tun tunnel handle | 1163 | * @param tun tunnel handle |
1145 | */ | 1164 | */ |
1146 | void | 1165 | void |
1147 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun) | 1166 | GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *t) |
1148 | { | 1167 | { |
1149 | struct GNUNET_MESH_Handle *h; | 1168 | struct GNUNET_MESH_Handle *h; |
1150 | struct GNUNET_MESH_TunnelMessage msg; | 1169 | struct GNUNET_MESH_TunnelMessage msg; |
1151 | 1170 | ||
1152 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); | 1171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n"); |
1153 | h = tun->mesh; | 1172 | h = t->mesh; |
1154 | 1173 | ||
1155 | if (0 != tun->owner) | 1174 | if (0 != t->owner) |
1156 | GNUNET_PEER_change_rc (tun->owner, -1); | 1175 | GNUNET_PEER_change_rc (t->owner, -1); |
1157 | 1176 | ||
1158 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | 1177 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); |
1159 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 1178 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
1160 | msg.tunnel_id = htonl (tun->tid); | 1179 | msg.tunnel_id = htonl (t->tid); |
1161 | destroy_tunnel (h, tun->tid); | 1180 | destroy_tunnel (t); |
1162 | send_packet (h, &msg.header); | 1181 | send_packet (h, &msg.header); |
1163 | } | 1182 | } |
1164 | 1183 | ||
@@ -1191,7 +1210,8 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel, | |||
1191 | return; | 1210 | return; |
1192 | } | 1211 | } |
1193 | } | 1212 | } |
1194 | add_peer_to_tunnel (tunnel, peer); | 1213 | if (NULL == add_peer_to_tunnel (tunnel, peer)) |
1214 | return; | ||
1195 | 1215 | ||
1196 | msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); | 1216 | msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl)); |
1197 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); | 1217 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD); |