Completed incoming tunnel handling, refactored destroy tunnel
[oweals/gnunet.git] / src / mesh / mesh.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @author Bartlomiej Polot
23  * @file mesh/mesh.h
24  */
25
26 #ifndef MESH_H_
27 #define MESH_H_
28 #include <stdint.h>
29
30 #include <gnunet_mesh_service_new.h>
31 #include "gnunet_common.h"
32
33 /******************************************************************************/
34 /********************        MESH LOCAL MESSAGES      *************************/
35 /******************************************************************************/
36 /*  Any API call should be documented in the folowing table under API CALL.
37  *  Also, any message type should be documented in the following table, with the
38  * associated event.
39  *
40  * API CALL (GNUNET_MESH_*)             MESSAGE USED
41  * ------------------------             ------------
42  * connect                              GNUNET_MESH_ClientConnect
43  * disconnect                           None (network level disconnect)
44  *
45  * tunnel_create                        GNUNET_MESH_TunnelMessage
46  * tunnel_destroy                       GNUNET_MESH_TunnelMessage
47  *
48  * peer_request_connect_add             GNUNET_MESH_PeerControl
49  * peer_request_connect_del             GNUNET_MESH_PeerControl
50  * peer_request_connect_by_type         GNUNET_MESH_ConnectPeerByType
51  *
52  * notify_transmit_ready                *GNUNET_MESH_TransmitReady?*
53  * notify_transmit_ready_cancel         None (clear of internal data structures)
54  *
55  *
56  *
57  * EVENT                                MESSAGE USED
58  * -----                                ------------
59  * data                                 GNUNET_MESH_Data OR
60  *                                      GNUNET_MESH_DataBroadcast
61  * new incoming tunnel                  GNUNET_MESH_PeerControl
62  * peer connects to a tunnel            GNUNET_MESH_PeerControl
63  * peer disconnects from a tunnel       GNUNET_MESH_PeerControl
64  */
65
66 /******************************************************************************/
67 /**************************       CONSTANTS      ******************************/
68 /******************************************************************************/
69
70 #define GNUNET_MESH_LOCAL_TUNNEL_ID_CLI 0x80000000
71 #define GNUNET_MESH_LOCAL_TUNNEL_ID_SERV 0xB0000000
72
73
74 /******************************************************************************/
75 /**************************        MESSAGES      ******************************/
76 /******************************************************************************/
77
78 /**
79  * Message for a client to register to the service
80  */
81 struct GNUNET_MESH_ClientConnect
82 {
83     /**
84      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT
85      *
86      * Size: sizeof(struct GNUNET_MESH_ClientConnect) +
87      *       sizeof(uint16_t) * types +
88      *       sizeof(MESH_ApplicationType) * applications
89      */
90   struct GNUNET_MessageHeader header;
91   uint16_t types GNUNET_PACKED;
92   uint16_t applications GNUNET_PACKED;
93   /* uint16_t                 list_types[types]           */
94   /* uint16_t                 list_apps[applications]     */
95 };
96
97
98 /**
99  * Type for tunnel numbering.
100  * - Local tunnel numbers are >= 0x80000000
101  * - Global tunnel numbers are < 0x80000000
102  */
103 typedef uint32_t MESH_TunnelNumber;
104
105 /**
106  * Message for a client to create and destroy tunnels.
107  */
108 struct GNUNET_MESH_TunnelMessage
109 {
110     /**
111      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_[CREATE|DESTROY]
112      *
113      * Size: sizeof(struct GNUNET_MESH_TunnelMessage)
114      */
115   struct GNUNET_MessageHeader header;
116
117     /**
118      * ID of a tunnel controlled by this client.
119      */
120   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
121
122     /**
123      * Peer at the other end, if any
124      */
125   struct GNUNET_PeerIdentity peer;
126 };
127
128 /**
129  * Message for:
130  * - request adding and deleting peers from a tunnel
131  * - notify the client that peers have connected:
132  *   -- requested
133  *   -- unrequested (new incoming tunnels)
134  * - notify the client that peers have disconnected
135  */
136 struct GNUNET_MESH_PeerControl
137 {
138
139   /**
140    * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_[ADD|DEL]
141    *       (client to service, client created tunnel)
142    *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_[CONNECTED|DISCONNECTED]
143    *       (service to client)
144    *
145    * Size: sizeof(struct GNUNET_MESH_PeerControl)
146    */
147   struct GNUNET_MessageHeader header;
148
149   /**
150    * ID of a tunnel controlled by this client.
151    */
152   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
153
154   /**
155    * Peer to connect/disconnect.
156    */
157   struct GNUNET_PeerIdentity peer;
158 };
159
160
161 /**
162  * Message for connecting to peers offering a certain service.
163  */
164 struct GNUNET_MESH_ConnectPeerByType
165 {
166     /**
167      * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE |
168      *       GNUNET_MESSAGE_TYPE_MESH_LOCAL_DISCONNECT_PEER_BY_TYPE
169      */
170   struct GNUNET_MessageHeader header;
171
172   /**
173    * ID of a tunnel controlled by this client.
174    */
175   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
176
177   /**
178    * Type specification
179    */
180   GNUNET_MESH_ApplicationType type GNUNET_PACKED;
181 };
182
183 #endif