2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
23 #include "gnunet_util_lib.h"
25 #include "gnunet_statistics_service.h"
28 #include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared
30 #include "gnunet-service-mesh_local.h"
32 #define LOG(level, ...) GNUNET_log_from(level,"mesh-loc",__VA_ARGS__)
34 /******************************************************************************/
35 /******************************** STRUCTS **********************************/
36 /******************************************************************************/
39 * Struct containing information about a client of the service
41 * TODO: add a list of 'waiting' ports
48 struct MeshClient *next;
53 struct MeshClient *prev;
56 * Tunnels that belong to this client, indexed by local id
58 struct GNUNET_CONTAINER_MultiHashMap32 *own_channels;
61 * Tunnels this client has accepted, indexed by incoming local id
63 struct GNUNET_CONTAINER_MultiHashMap32 *incoming_channels;
66 * Channel ID for the next incoming channel.
68 MESH_ChannelNumber next_chid;
71 * Handle to communicate with the client
73 struct GNUNET_SERVER_Client *handle;
76 * Ports that this client has declared interest in.
77 * Indexed by port, contains *Client.
79 struct GNUNET_CONTAINER_MultiHashMap32 *ports;
82 * Whether the client is active or shutting down (don't send confirmations
83 * to a client that is shutting down.
88 * ID of the client, mainly for debug messages
93 /******************************************************************************/
94 /******************************* GLOBALS ***********************************/
95 /******************************************************************************/
98 * Global handle to the statistics service.
100 extern struct GNUNET_STATISTICS_Handle *stats;
103 * Handle to server lib.
105 static struct GNUNET_SERVER_Handle *server_handle;
108 * DLL with all the clients, head.
110 static struct MeshClient *clients_head;
113 * DLL with all the clients, tail.
115 static struct MeshClient *clients_tail;
118 * Next ID to assign to a client.
120 unsigned int next_client_id;
123 * All ports clients of this peer have opened.
125 static struct GNUNET_CONTAINER_MultiHashMap32 *ports;
128 * Notification context, to send messages to local clients.
130 static struct GNUNET_SERVER_NotificationContext *nc;
133 /******************************************************************************/
134 /******************************** STATIC ***********************************/
135 /******************************************************************************/
138 * Remove client's ports from the global hashmap on disconnect.
140 * @param cls Closure (unused).
142 * @param value Client structure.
144 * @return GNUNET_OK, keep iterating.
147 client_release_ports (void *cls,
153 res = GNUNET_CONTAINER_multihashmap32_remove (ports, key, value);
154 if (GNUNET_YES != res)
157 LOG (GNUNET_ERROR_TYPE_WARNING,
158 "Port %u by client %p was not registered.\n",
166 /******************************************************************************/
167 /******************************** HANDLES ***********************************/
168 /******************************************************************************/
172 * Handler for client connection.
174 * @param cls Closure (unused).
175 * @param client Client handler.
178 handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
180 struct MeshClient *c;
184 c = GNUNET_new (struct MeshClient);
186 c->id = next_client_id++; /* overflow not important: just for debug */
187 c->next_chid = GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
188 GNUNET_SERVER_client_keep (client);
189 GNUNET_SERVER_client_set_user_context (client, c);
190 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
195 * Handler for client disconnection
198 * @param client identification of the client; NULL
199 * for the last call when the server is destroyed
202 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
204 struct MeshClient *c;
206 LOG (GNUNET_ERROR_TYPE_DEBUG, "client disconnected: %p\n", client);
209 LOG (GNUNET_ERROR_TYPE_DEBUG, " (SERVER DOWN)\n");
213 c = client_get (client);
216 LOG (GNUNET_ERROR_TYPE_DEBUG, "matching client found (%u, %p)\n",
218 GNUNET_SERVER_client_drop (c->handle);
219 c->shutting_down = GNUNET_YES;
220 if (NULL != c->own_channels)
222 GNUNET_CONTAINER_multihashmap32_iterate (c->own_channels,
223 &channel_destroy_iterator, c);
224 GNUNET_CONTAINER_multihashmap32_destroy (c->own_channels);
227 if (NULL != c->incoming_channels)
229 GNUNET_CONTAINER_multihashmap32_iterate (c->incoming_channels,
230 &channel_destroy_iterator, c);
231 GNUNET_CONTAINER_multihashmap32_destroy (c->incoming_channels);
234 if (NULL != c->ports)
236 GNUNET_CONTAINER_multihashmap32_iterate (c->ports,
237 &client_release_ports, c);
238 GNUNET_CONTAINER_multihashmap32_destroy (c->ports);
240 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
241 GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO);
242 LOG (GNUNET_ERROR_TYPE_DEBUG, " client free (%p)\n", c);
247 LOG (GNUNET_ERROR_TYPE_WARNING, " context NULL!\n");
249 LOG (GNUNET_ERROR_TYPE_DEBUG, "done!\n");
255 * Handler for new clients
258 * @param client identification of the client
259 * @param message the actual message, which includes messages the client wants
262 handle_new_client (void *cls, struct GNUNET_SERVER_Client *client,
263 const struct GNUNET_MessageHeader *message)
265 struct GNUNET_MESH_ClientConnect *cc_msg;
266 struct MeshClient *c;
271 LOG (GNUNET_ERROR_TYPE_DEBUG, "new client connected %p\n", client);
273 /* Check data sanity */
274 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
275 cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
276 if (0 != (size % sizeof (uint32_t)))
279 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
282 size /= sizeof (uint32_t);
284 /* Initialize new client structure */
285 c = GNUNET_SERVER_client_get_user_context (client, struct MeshClient);
286 LOG (GNUNET_ERROR_TYPE_DEBUG, " client id %u\n", c->id);
287 LOG (GNUNET_ERROR_TYPE_DEBUG, " client has %u ports\n", size);
292 p = (uint32_t *) &cc_msg[1];
293 c->ports = GNUNET_CONTAINER_multihashmap32_create (size);
294 for (i = 0; i < size; i++)
297 LOG (GNUNET_ERROR_TYPE_DEBUG, " port: %u\n", u32);
299 /* store in client's hashmap */
300 GNUNET_CONTAINER_multihashmap32_put (c->ports, u32, c,
301 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
302 /* store in global hashmap */
303 /* FIXME only allow one client to have the port open,
304 * have a backup hashmap with waiting clients */
305 GNUNET_CONTAINER_multihashmap32_put (ports, u32, c,
306 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
310 c->own_channels = GNUNET_CONTAINER_multihashmap32_create (32);
311 c->incoming_channels = GNUNET_CONTAINER_multihashmap32_create (32);
312 GNUNET_SERVER_notification_context_add (nc, client);
313 GNUNET_STATISTICS_update (stats, "# clients", 1, GNUNET_NO);
315 GNUNET_SERVER_receive_done (client, GNUNET_OK);
316 LOG (GNUNET_ERROR_TYPE_DEBUG, "new client processed\n");
321 * Handler for requests of new tunnels
323 * @param cls Closure.
324 * @param client Identification of the client.
325 * @param message The actual message.
328 handle_channel_create (void *cls, struct GNUNET_SERVER_Client *client,
329 const struct GNUNET_MessageHeader *message)
331 struct MeshClient *c;
333 LOG (GNUNET_ERROR_TYPE_DEBUG, "new channel requested\n");
335 /* Sanity check for client registration */
336 if (NULL == (c = GML_client_get (client)))
339 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
342 LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
344 /* Message size sanity check */
345 if (sizeof (struct GNUNET_MESH_ChannelMessage) != ntohs (message->size))
348 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
352 GMCH_handle_local_create (c, (struct GNUNET_MESH_ChannelMessage *) message);
354 GNUNET_SERVER_receive_done (client, GNUNET_OK);
360 * Handler for requests of deleting tunnels
363 * @param client identification of the client
364 * @param message the actual message
367 handle_channel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
368 const struct GNUNET_MessageHeader *message)
370 struct GNUNET_MESH_ChannelMessage *msg;
371 struct MeshClient *c;
372 struct MeshChannel *ch;
373 MESH_ChannelNumber chid;
375 LOG (GNUNET_ERROR_TYPE_DEBUG,
376 "Got a DESTROY CHANNEL from client!\n");
378 /* Sanity check for client registration */
379 if (NULL == (c = GML_client_get (client)))
382 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
385 LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
387 /* Message sanity check */
388 if (sizeof (struct GNUNET_MESH_ChannelMessage) != ntohs (message->size))
391 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
395 msg = (struct GNUNET_MESH_ChannelMessage *) message;
397 /* Retrieve tunnel */
398 chid = ntohl (msg->channel_id);
399 ch = GML_channel_get (c, chid);
402 LOG (GNUNET_ERROR_TYPE_ERROR, " channel %X not found\n", chid);
404 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
408 GMCH_handle_local_destroy (ch, c, chid);
410 GNUNET_SERVER_receive_done (client, GNUNET_OK);
416 * Handler for client traffic
419 * @param client identification of the client
420 * @param message the actual message
423 handle_data (void *cls, struct GNUNET_SERVER_Client *client,
424 const struct GNUNET_MessageHeader *message)
426 struct GNUNET_MESH_LocalData *msg;
427 struct MeshClient *c;
428 struct MeshChannel *ch;
429 MESH_ChannelNumber chid;
433 LOG (GNUNET_ERROR_TYPE_DEBUG,
434 "Got data from a client!\n");
436 /* Sanity check for client registration */
437 if (NULL == (c = GML_client_get (client)))
440 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
443 LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
445 msg = (struct GNUNET_MESH_LocalData *) message;
447 /* Sanity check for message size */
448 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_LocalData);
449 if (size < sizeof (struct GNUNET_MessageHeader))
452 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
456 /* Channel exists? */
457 chid = ntohl (msg->id);
458 fwd = chid < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
459 ch = GML_channel_get (c, chid);
463 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
468 GMCH_handle_local_data (ch, c,
469 (struct GNUNET_MessageHeader *)&msg[1], fwd))
471 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
475 LOG (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
476 GNUNET_SERVER_receive_done (client, GNUNET_OK);
483 * Handler for client's ACKs for payload traffic.
485 * @param cls Closure (unused).
486 * @param client Identification of the client.
487 * @param message The actual message.
490 handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
491 const struct GNUNET_MessageHeader *message)
493 struct GNUNET_MESH_LocalAck *msg;
494 struct MeshChannel *ch;
495 struct MeshClient *c;
496 MESH_ChannelNumber chid;
499 LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a local ACK\n");
501 /* Sanity check for client registration */
502 if (NULL == (c = GML_client_get (client)))
505 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
508 LOG (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
510 msg = (struct GNUNET_MESH_LocalAck *) message;
512 /* Channel exists? */
513 chid = ntohl (msg->channel_id);
514 LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X\n", chid);
515 ch = GML_channel_get (c, chid);
516 LOG (GNUNET_ERROR_TYPE_DEBUG, " -- ch %p\n", ch);
520 LOG (GNUNET_ERROR_TYPE_WARNING, "Channel %X unknown.\n", chid);
521 LOG (GNUNET_ERROR_TYPE_WARNING, " for client %u.\n", c->id);
522 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
526 /* If client is root, the ACK is going FWD, therefore this is "BCK". */
527 /* If client is dest, the ACK is going BCK, therefore this is "FWD" */
528 fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
530 GMCH_handle_local_ack (ch, fwd);
531 GNUNET_SERVER_receive_done (client, GNUNET_OK);
538 * Iterator over all tunnels to send a monitoring client info about each tunnel.
540 * @param cls Closure (client handle).
541 * @param key Key (hashed tunnel ID, unused).
542 * @param value Tunnel info.
544 * @return GNUNET_YES, to keep iterating.
547 // monitor_all_tunnels_iterator (void *cls,
548 // const struct GNUNET_HashCode * key,
551 // struct GNUNET_SERVER_Client *client = cls;
552 // struct MeshChannel *ch = value;
553 // struct GNUNET_MESH_LocalMonitor *msg;
555 // msg = GNUNET_malloc (sizeof(struct GNUNET_MESH_LocalMonitor));
556 // msg->channel_id = htonl (ch->gid);
557 // msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
558 // msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
560 // LOG (GNUNET_ERROR_TYPE_INFO,
561 // "* sending info about tunnel %s\n",
562 // GNUNET_i2s (&msg->owner));
564 // GNUNET_SERVER_notification_context_unicast (nc, client,
565 // &msg->header, GNUNET_NO);
566 // return GNUNET_YES;
571 * Handler for client's MONITOR request.
573 * @param cls Closure (unused).
574 * @param client Identification of the client.
575 * @param message The actual message.
578 handle_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
579 const struct GNUNET_MessageHeader *message)
581 struct MeshClient *c;
583 /* Sanity check for client registration */
584 if (NULL == (c = GML_client_get (client)))
587 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
591 LOG (GNUNET_ERROR_TYPE_INFO,
592 "Received get tunnels request from client %u\n",
594 // GNUNET_CONTAINER_multihashmap_iterate (tunnels,
595 // monitor_all_tunnels_iterator,
597 LOG (GNUNET_ERROR_TYPE_INFO,
598 "Get tunnels request from client %u completed\n",
600 GNUNET_SERVER_receive_done (client, GNUNET_OK);
605 * Handler for client's MONITOR_TUNNEL request.
607 * @param cls Closure (unused).
608 * @param client Identification of the client.
609 * @param message The actual message.
612 handle_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
613 const struct GNUNET_MessageHeader *message)
615 const struct GNUNET_MESH_LocalMonitor *msg;
616 struct GNUNET_MESH_LocalMonitor *resp;
617 struct MeshClient *c;
618 struct MeshChannel *ch;
620 /* Sanity check for client registration */
621 if (NULL == (c = GML_client_get (client)))
624 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
628 msg = (struct GNUNET_MESH_LocalMonitor *) message;
629 LOG (GNUNET_ERROR_TYPE_INFO,
630 "Received tunnel info request from client %u for tunnel %s[%X]\n",
633 ntohl (msg->channel_id));
634 // ch = channel_get (&msg->owner, ntohl (msg->channel_id));
638 /* We don't know the tunnel */
639 struct GNUNET_MESH_LocalMonitor warn;
642 GNUNET_SERVER_notification_context_unicast (nc, client,
645 GNUNET_SERVER_receive_done (client, GNUNET_OK);
649 /* Initialize context */
650 resp = GNUNET_malloc (sizeof (struct GNUNET_MESH_LocalMonitor));
652 resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
653 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
654 &resp->header, GNUNET_NO);
657 LOG (GNUNET_ERROR_TYPE_INFO,
658 "Monitor tunnel request from client %u completed\n",
660 GNUNET_SERVER_receive_done (client, GNUNET_OK);
665 * Functions to handle messages from clients
667 static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
668 {&handle_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
669 {&handle_channel_create, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE,
670 sizeof (struct GNUNET_MESH_ChannelMessage)},
671 {&handle_channel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY,
672 sizeof (struct GNUNET_MESH_ChannelMessage)},
673 {&handle_data, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
674 {&handle_ack, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
675 sizeof (struct GNUNET_MESH_LocalAck)},
676 {&handle_get_tunnels, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS,
677 sizeof (struct GNUNET_MessageHeader)},
678 {&handle_show_tunnel, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL,
679 sizeof (struct GNUNET_MESH_LocalMonitor)},
685 /******************************************************************************/
686 /******************************** API ***********************************/
687 /******************************************************************************/
690 * Initialize server subsystem.
692 * @param handle Server handle.
695 GML_init (struct GNUNET_SERVER_Handle *handle)
697 server_handle = handle;
698 GNUNET_SERVER_suspend (server_handle);
699 ports = GNUNET_CONTAINER_multihashmap32_create (32);
704 * Install server (service) handlers and start listening to clients.
709 GNUNET_SERVER_add_handlers (server_handle, client_handlers);
710 GNUNET_SERVER_connect_notify (server_handle, &handle_client_connect, NULL);
711 GNUNET_SERVER_disconnect_notify (server_handle, &handle_client_disconnect,
713 nc = GNUNET_SERVER_notification_context_create (server_handle, 1);
718 GNUNET_SERVER_resume (server_handle);
730 GNUNET_SERVER_notification_context_destroy (nc);
737 * Get a chennel from a client
739 * @param c the client to check
740 * @param chid Channel ID, must be local (> 0x800...)
742 * @return non-NULL if channel exists in the clients lists
745 GML_channel_get (struct MeshClient *c, MESH_ChannelNumber chid)
747 if (0 == (chid & GNUNET_MESH_LOCAL_CHANNEL_ID_CLI))
750 LOG (GNUNET_ERROR_TYPE_DEBUG, "CHID %X not a local chid\n", chid);
753 if (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
754 return GNUNET_CONTAINER_multihashmap32_get (c->incoming_channels, chid);
755 return GNUNET_CONTAINER_multihashmap32_get (c->own_channels, chid);
760 * Add a channel to a client
762 * @param client Client.
763 * @param chid Channel ID.
767 GML_channel_add (struct MeshClient *client,
769 struct MeshChannel *ch)
771 if (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV)
772 GNUNET_CONTAINER_multihashmap32_put (client->incoming_channels, chid, ch,
773 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
774 else if (chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_CLI)
775 GNUNET_CONTAINER_multihashmap32_put (client->own_channels, chid, ch,
776 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
783 * Remove a channel from a client
785 * @param client Client.
786 * @param chid Channel ID.
790 GML_channel_remove (struct MeshClient *client,
792 struct MeshChannel *ch)
794 if (GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid)
795 GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, chid, ch);
796 else if (GNUNET_MESH_LOCAL_CHANNEL_ID_CLI <= chid)
797 GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, chid, ch);
804 * Get the tunnel's next free local channel ID.
808 * @return LID of a channel free to use.
811 GML_get_next_chid (struct MeshClient *c)
813 MESH_ChannelNumber chid;
815 while (NULL != GML_channel_get (c, c->next_chid))
817 LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel %u exists...\n", c->next_chid);
818 c->next_chid = (c->next_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
821 c->next_chid = (c->next_chid + 1) | GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
828 * Check if client has registered with the service and has not disconnected
830 * @param client the client to check
832 * @return non-NULL if client exists in the global DLL
835 GML_client_get (struct GNUNET_SERVER_Client *client)
837 return GNUNET_SERVER_client_get_user_context (client, struct MeshClient);
841 * Find a client that has opened a port
843 * @param port Port to check.
845 * @return non-NULL if a client has the port.
848 GML_client_get_by_port (uint32_t port)
850 return GNUNET_CONTAINER_multihashmap32_get (ports, port);
855 * Deletes a channel from a client (either owner or destination).
857 * @param c Client whose tunnel to delete.
858 * @param ch Channel which should be deleted.
859 * @param id Channel ID.
862 GML_client_delete_channel (struct MeshClient *c,
863 struct MeshChannel *ch,
864 MESH_ChannelNumber id)
868 if (GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= id)
870 res = GNUNET_CONTAINER_multihashmap32_remove (c->incoming_channels,
872 if (GNUNET_YES != res)
873 LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_channel dest KO\n");
875 else if (GNUNET_MESH_LOCAL_CHANNEL_ID_CLI <= id)
877 res = GNUNET_CONTAINER_multihashmap32_remove (c->own_channels,
879 if (GNUNET_YES != res)
880 LOG (GNUNET_ERROR_TYPE_DEBUG, "client_delete_tunnel root KO\n");
889 * Build a local ACK message and send it to a local client, if needed.
891 * If the client was already allowed to send data, do nothing.
893 * @param c Client to whom send the ACK.
894 * @param id Channel ID to use
897 GML_send_ack (struct MeshClient *c, MESH_ChannelNumber id)
899 struct GNUNET_MESH_LocalAck msg;
901 LOG (GNUNET_ERROR_TYPE_DEBUG,
902 "send local %s ack on %X towards %p\n",
903 id < GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? "FWD" : "BCK", id, c);
905 msg.header.size = htons (sizeof (msg));
906 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
907 msg.channel_id = htonl (id);
908 GNUNET_SERVER_notification_context_unicast (nc,
917 * Notify the client that a new incoming channel was created.
919 * @param ch Channel that was created.
922 GML_send_channel_create (struct MeshClient *c,
923 uint32_t id, uint32_t port, uint32_t opt,
924 const struct GNUNET_PeerIdentity *peer)
926 struct GNUNET_MESH_ChannelMessage msg;
928 msg.header.size = htons (sizeof (msg));
929 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
930 msg.channel_id = htonl (id);
931 msg.port = htonl (port);
932 msg.opt = htonl (opt);
934 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
935 &msg.header, GNUNET_NO);
940 * Notify a client that a channel is no longer valid.
943 * @param id ID of the channel that is destroyed.
946 GML_send_channel_destroy (struct MeshClient *c, uint32_t id)
948 struct GNUNET_MESH_ChannelMessage msg;
955 msg.header.size = htons (sizeof (msg));
956 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
957 msg.channel_id = htonl (id);
958 msg.port = htonl (0);
959 memset (&msg.peer, 0, sizeof (msg.peer));
961 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
962 &msg.header, GNUNET_NO);
967 * Modify the mesh message ID from global to local and send to client.
969 * @param c Client to send to.
970 * @param msg Message to modify and send.
971 * @param id Channel ID to use (c can be both owner and client).
974 GML_send_data (struct MeshClient *c,
975 const struct GNUNET_MESH_Data *msg,
976 MESH_ChannelNumber id)
978 struct GNUNET_MESH_LocalData *copy;
979 uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_MESH_Data);
980 char cbuf[size + sizeof (struct GNUNET_MESH_LocalData)];
982 if (size < sizeof (struct GNUNET_MessageHeader))
992 copy = (struct GNUNET_MESH_LocalData *) cbuf;
993 memcpy (©[1], &msg[1], size);
994 copy->header.size = htons (sizeof (struct GNUNET_MESH_LocalData) + size);
995 copy->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA);
996 copy->id = htonl (id);
997 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
998 ©->header, GNUNET_NO);
1003 * Get the static string to represent a client.
1007 * @return Static string for the client.
1010 GML_2s (const struct MeshClient *c)
1012 static char buf[32];
1014 sprintf (buf, "%u", c->id);