-only notify AFTER sending is really close to finished, not before
[oweals/gnunet.git] / src / mesh / mesh_common.c
1 /*
2      This file is part of GNUnet.
3      (C) 2012 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  * @file mesh/mesh_common.c
23  * @brief MESH helper functions
24  * @author Bartlomiej Polot
25  */
26
27 #include "mesh.h"
28
29
30 int
31 GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
32 {
33     return (GNUNET_YES == PID_OVERFLOW (smaller, bigger) ||
34             (bigger > smaller && GNUNET_NO == PID_OVERFLOW (bigger, smaller)));
35 }
36
37
38 uint32_t
39 GMC_max_pid (uint32_t a, uint32_t b)
40 {
41   if (GMC_is_pid_bigger(a, b))
42     return a;
43   return b;
44 }
45
46
47 uint32_t
48 GMC_min_pid (uint32_t a, uint32_t b)
49 {
50   if (GMC_is_pid_bigger(a, b))
51     return b;
52   return a;
53 }
54
55
56 #if !defined(GNUNET_CULL_LOGGING)
57 const char *
58 GNUNET_MESH_DEBUG_M2S (uint16_t m)
59 {
60   static char buf[32];
61   switch (m)
62     {
63       /**
64        * Request the creation of a path
65        */
66     case 256: return "GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE";
67
68       /**
69        * Request the modification of an existing path
70        */
71     case 257: return "GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK";
72
73       /**
74        * Notify that a connection of a path is no longer valid
75        */
76     case 258: return "GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN";
77
78       /**
79        * At some point, the route will spontaneously change
80        */
81     case 259: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGED";
82
83       /**
84        * Transport payload data.
85        */
86     case 260: return "GNUNET_MESSAGE_TYPE_MESH_DATA";
87
88     /**
89      * Confirm receipt of payload data.
90      */
91     case 261: return "GNUNET_MESSAGE_TYPE_MESH_DATA_ACK";
92
93       /**
94        * Key exchange encapsulation.
95        */
96     case 262: return "GNUNET_MESSAGE_TYPE_MESH_KX";
97
98       /**
99        * New ephemeral key.
100        */
101     case 263: return "GNUNET_MESSAGE_TYPE_MESH_KX_EPHEMERAL";
102
103       /**
104        * Challenge to test peer's session key.
105        */
106     case 264: return "GNUNET_MESSAGE_TYPE_MESH_KX_PING";
107
108       /**
109        * Answer to session key challenge.
110        */
111     case 265: return "GNUNET_MESSAGE_TYPE_MESH_KX_PONG";
112
113       /**
114        * Request the destuction of a path
115        */
116     case 266: return "GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY";
117
118       /**
119        * Request the destruction of a whole tunnel
120        */
121     case 267: return "GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY";
122
123       /**
124        * ACK for a data packet.
125        */
126     case 268: return "GNUNET_MESSAGE_TYPE_MESH_ACK";
127
128       /**
129        * POLL for ACK.
130        */
131     case 269: return "GNUNET_MESSAGE_TYPE_MESH_POLL";
132
133       /**
134        * Announce origin is still alive.
135        */
136     case 270: return "GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE";
137
138       /**
139        * Announce destination is still alive.
140        */
141     case 271: return "GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE";
142
143     /**
144        * Connect to the mesh service, specifying subscriptions
145        */
146     case 272: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT";
147
148       /**
149        * Ask the mesh service to create a new tunnel
150        */
151     case 273: return "GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE";
152
153       /**
154        * Ask the mesh service to destroy a tunnel
155        */
156     case 274: return "GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY";
157
158       /**
159        * Confirm the creation of a channel.
160        */
161     case 275: return "GNUNET_MESSAGE_TYPE_MESH_CHANNEL_ACK";
162
163       /**
164        * Confirm the creation of a channel.
165        */
166     case 276: return "GNUNET_MESSAGE_TYPE_MESH_CHANNEL_NACK";
167
168       /**
169        * Encrypted payload.
170        */
171     case 280: return "GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED";
172
173       /**
174        * Local payload traffic
175        */
176     case 285: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA";
177
178       /**
179        * Local ACK for data.
180        */
181     case 286: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK";
182
183       /**
184        * Local monitoring of service.
185        */
186     case 287: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS";
187
188       /**
189        * Local monitoring of service of a specific tunnel.
190        */
191     case 288: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL";
192
193       /**
194        * 640kb should be enough for everybody
195        */
196     case 299: return "GNUNET_MESSAGE_TYPE_MESH_RESERVE_END";
197     }
198   sprintf(buf, "%u (UNKNOWN TYPE)", m);
199   return buf;
200 }
201 #else
202 const char *
203 GNUNET_MESH_DEBUG_M2S (uint16_t m)
204 {
205   return "";
206 }
207 #endif