diff options
Diffstat (limited to 'src/mesh/mesh2_api.c')
-rw-r--r-- | src/mesh/mesh2_api.c | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/src/mesh/mesh2_api.c b/src/mesh/mesh2_api.c index 90a216774..31681bec1 100644 --- a/src/mesh/mesh2_api.c +++ b/src/mesh/mesh2_api.c | |||
@@ -117,6 +117,21 @@ struct GNUNET_MESH_Handle | |||
117 | */ | 117 | */ |
118 | const struct GNUNET_MESH_MessageHandler *message_handlers; | 118 | const struct GNUNET_MESH_MessageHandler *message_handlers; |
119 | 119 | ||
120 | /** | ||
121 | * Number of handlers in the handlers array. | ||
122 | */ | ||
123 | unsigned int n_handlers; | ||
124 | |||
125 | /** | ||
126 | * Ports open. | ||
127 | */ | ||
128 | uint32_t *ports; | ||
129 | |||
130 | /** | ||
131 | * Number of ports. | ||
132 | */ | ||
133 | unsigned int n_ports; | ||
134 | |||
120 | /** | 135 | /** |
121 | * Double linked list of the tunnels this client is connected to, head. | 136 | * Double linked list of the tunnels this client is connected to, head. |
122 | */ | 137 | */ |
@@ -163,11 +178,6 @@ struct GNUNET_MESH_Handle | |||
163 | MESH_TunnelNumber next_tid; | 178 | MESH_TunnelNumber next_tid; |
164 | 179 | ||
165 | /** | 180 | /** |
166 | * Number of handlers in the handlers array. | ||
167 | */ | ||
168 | unsigned int n_handlers; | ||
169 | |||
170 | /** | ||
171 | * Have we started the task to receive messages from the service | 181 | * Have we started the task to receive messages from the service |
172 | * yet? We do this after we send the 'MESH_LOCAL_CONNECT' message. | 182 | * yet? We do this after we send the 'MESH_LOCAL_CONNECT' message. |
173 | */ | 183 | */ |
@@ -265,6 +275,11 @@ struct GNUNET_MESH_Tunnel | |||
265 | MESH_TunnelNumber tid; | 275 | MESH_TunnelNumber tid; |
266 | 276 | ||
267 | /** | 277 | /** |
278 | * Port number. | ||
279 | */ | ||
280 | uint32_t port; | ||
281 | |||
282 | /** | ||
268 | * Other end of the tunnel. | 283 | * Other end of the tunnel. |
269 | */ | 284 | */ |
270 | GNUNET_PEER_Id peer; | 285 | GNUNET_PEER_Id peer; |
@@ -633,23 +648,32 @@ send_connect (struct GNUNET_MESH_Handle *h) | |||
633 | char buf[size] GNUNET_ALIGN; | 648 | char buf[size] GNUNET_ALIGN; |
634 | struct GNUNET_MESH_ClientConnect *msg; | 649 | struct GNUNET_MESH_ClientConnect *msg; |
635 | uint16_t *types; | 650 | uint16_t *types; |
636 | uint16_t ntypes; | 651 | uint32_t *ports; |
652 | uint16_t i; | ||
637 | 653 | ||
638 | /* build connection packet */ | 654 | /* build connection packet */ |
639 | msg = (struct GNUNET_MESH_ClientConnect *) buf; | 655 | msg = (struct GNUNET_MESH_ClientConnect *) buf; |
640 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); | 656 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT); |
641 | msg->header.size = htons (size); | 657 | msg->header.size = htons (size); |
642 | types = (uint16_t *) & msg[1]; | 658 | msg->types = htons (h->n_handlers); |
643 | for (ntypes = 0; ntypes < h->n_handlers; ntypes++) | 659 | msg->ports = htons (h->n_ports); |
660 | types = (uint16_t *) &msg[1]; | ||
661 | for (i = 0; i < h->n_handlers; i++) | ||
644 | { | 662 | { |
645 | types[ntypes] = htons (h->message_handlers[ntypes].type); | 663 | types[i] = htons (h->message_handlers[i].type); |
646 | LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n", | 664 | LOG (GNUNET_ERROR_TYPE_DEBUG, " type %u\n", |
647 | h->message_handlers[ntypes].type); | 665 | h->message_handlers[i].type); |
666 | } | ||
667 | ports = (uint32_t *) &types[h->n_handlers]; | ||
668 | for (i = 0; i < h->n_ports; i++) | ||
669 | { | ||
670 | ports[i] = htonl (h->ports[i]); | ||
671 | LOG (GNUNET_ERROR_TYPE_DEBUG, " port %u\n", | ||
672 | h->ports[i]); | ||
648 | } | 673 | } |
649 | msg->types = htons (ntypes); | ||
650 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 674 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
651 | "Sending %lu bytes long message %d types\n", | 675 | "Sending %lu bytes long message %u types and %u ports\n", |
652 | ntohs (msg->header.size), ntypes); | 676 | ntohs (msg->header.size), h->n_handlers, h->n_ports); |
653 | send_packet (h, &msg->header, NULL); | 677 | send_packet (h, &msg->header, NULL); |
654 | } | 678 | } |
655 | } | 679 | } |
@@ -803,12 +827,13 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h, | |||
803 | GNUNET_PEER_change_rc (t->peer, 1); | 827 | GNUNET_PEER_change_rc (t->peer, 1); |
804 | t->mesh = h; | 828 | t->mesh = h; |
805 | t->tid = tid; | 829 | t->tid = tid; |
830 | t->port = ntohl (msg->port); | ||
806 | if ((msg->opt & MESH_TUNNEL_OPT_NOBUFFER) != 0) | 831 | if ((msg->opt & MESH_TUNNEL_OPT_NOBUFFER) != 0) |
807 | t->buffering = GNUNET_NO; | 832 | t->buffering = GNUNET_NO; |
808 | else | 833 | else |
809 | t->buffering = GNUNET_YES; | 834 | t->buffering = GNUNET_YES; |
810 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); | 835 | LOG (GNUNET_ERROR_TYPE_DEBUG, " created tunnel %p\n", t); |
811 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer); | 836 | t->ctx = h->new_tunnel (h->cls, t, &msg->peer, t->port); |
812 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); | 837 | LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); |
813 | } | 838 | } |
814 | else | 839 | else |
@@ -1340,7 +1365,8 @@ struct GNUNET_MESH_Handle * | |||
1340 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | 1365 | GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, |
1341 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, | 1366 | GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel, |
1342 | GNUNET_MESH_TunnelEndHandler cleaner, | 1367 | GNUNET_MESH_TunnelEndHandler cleaner, |
1343 | const struct GNUNET_MESH_MessageHandler *handlers) | 1368 | const struct GNUNET_MESH_MessageHandler *handlers, |
1369 | uint32_t *ports) | ||
1344 | { | 1370 | { |
1345 | struct GNUNET_MESH_Handle *h; | 1371 | struct GNUNET_MESH_Handle *h; |
1346 | 1372 | ||
@@ -1359,6 +1385,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
1359 | } | 1385 | } |
1360 | h->cls = cls; | 1386 | h->cls = cls; |
1361 | h->message_handlers = handlers; | 1387 | h->message_handlers = handlers; |
1388 | h->ports = ports; | ||
1362 | h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; | 1389 | h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; |
1363 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; | 1390 | h->reconnect_time = GNUNET_TIME_UNIT_MILLISECONDS; |
1364 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; | 1391 | h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -1367,6 +1394,9 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, | |||
1367 | for (h->n_handlers = 0; | 1394 | for (h->n_handlers = 0; |
1368 | handlers && handlers[h->n_handlers].type; | 1395 | handlers && handlers[h->n_handlers].type; |
1369 | h->n_handlers++) ; | 1396 | h->n_handlers++) ; |
1397 | for (h->n_ports = 0; | ||
1398 | ports && ports[h->n_ports]; | ||
1399 | h->n_ports++) ; | ||
1370 | send_connect (h); | 1400 | send_connect (h); |
1371 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n"); | 1401 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n"); |
1372 | return h; | 1402 | return h; |
@@ -1455,7 +1485,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
1455 | struct GNUNET_MESH_Tunnel * | 1485 | struct GNUNET_MESH_Tunnel * |
1456 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | 1486 | GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, |
1457 | void *tunnel_ctx, | 1487 | void *tunnel_ctx, |
1458 | const struct GNUNET_PeerIdentity *peer) | 1488 | const struct GNUNET_PeerIdentity *peer, |
1489 | uint32_t port) | ||
1459 | { | 1490 | { |
1460 | struct GNUNET_MESH_Tunnel *t; | 1491 | struct GNUNET_MESH_Tunnel *t; |
1461 | struct GNUNET_MESH_TunnelMessage msg; | 1492 | struct GNUNET_MESH_TunnelMessage msg; |
@@ -1468,6 +1499,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, | |||
1468 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); | 1499 | msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE); |
1469 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | 1500 | msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage)); |
1470 | msg.tunnel_id = htonl (t->tid); | 1501 | msg.tunnel_id = htonl (t->tid); |
1502 | msg.port = htonl (port); | ||
1471 | msg.peer = *peer; | 1503 | msg.peer = *peer; |
1472 | send_packet (h, &msg.header, t); | 1504 | send_packet (h, &msg.header, t); |
1473 | return t; | 1505 | return t; |