- stop using message types of payload on service side
[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 void
56 GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h)
57 {
58   *(unsigned int *) h = i;
59 }
60
61
62 #if !defined(GNUNET_CULL_LOGGING)
63 const char *
64 GNUNET_MESH_DEBUG_M2S (uint16_t m)
65 {
66   static char buf[32];
67   switch (m)
68     {
69       /**
70        * Request the creation of a path
71        */
72     case 256: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE";
73
74       /**
75        * Request the modification of an existing path
76        */
77     case 257: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGE";
78
79       /**
80        * Notify that a connection of a path is no longer valid
81        */
82     case 258: return "GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN";
83
84       /**
85        * At some point, the route will spontaneously change
86        */
87     case 259: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGED";
88
89       /**
90        * Transport data in the mesh (origin->end) unicast
91        */
92     case 260: return "GNUNET_MESSAGE_TYPE_MESH_UNICAST";
93
94       /**
95        * Transport data to all peers in a tunnel
96        */
97     case 261: return "GNUNET_MESSAGE_TYPE_MESH_MULTICAST";
98
99       /**
100        * Transport data back in the mesh (end->origin)
101        */
102     case 262: return "GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN";
103
104       /**
105        * Send origin an ACK that the path is complete
106        */
107     case 263: return "GNUNET_MESSAGE_TYPE_MESH_PATH_ACK";
108
109       /**
110        * Avoid path timeouts
111        */
112     case 264: return "GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE";
113
114       /**
115        * Request the destuction of a path
116        */
117     case 265: return "GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY";
118
119       /**
120        * Request the destruction of a whole tunnel
121        */
122     case 266: return "GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY";
123
124       /**
125        * ACK for a data packet.
126        */
127     case 267: return "GNUNET_MESSAGE_TYPE_MESH_ACK";
128
129       /**
130        * POLL for ACK.
131        */
132     case 268: return "GNUNET_MESSAGE_TYPE_MESH_POLL";
133
134       /**
135        * Connect to the mesh service, specifying subscriptions
136        */
137     case 272: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT";
138
139       /**
140        * Ask the mesh service to create a new tunnel
141        */
142     case 273: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE";
143
144       /**
145        * Ask the mesh service to destroy a tunnel
146        */
147     case 274: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY";
148
149       /**
150        * Ask the mesh service to add a peer to an existing tunnel
151        */
152     case 275: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD";
153
154       /**
155        * Ask the mesh service to remove a peer from a tunnel
156        */
157     case 276: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL";
158
159       /**
160        * Ask the mesh service to add a peer offering a service to an existing tunnel
161        */
162     case 277: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE";
163
164       /**
165        * Ask the mesh service to add a peer described by a service string
166        */
167     case 278: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX";
168
169       /**
170        * Ask the mesh service to add a peer described by a service string
171        */
172     case 279: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING";
173
174       /**
175        * Ask the mesh service to add a peer to the blacklist of an existing tunnel
176        */
177     case 280: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_BLACKLIST";
178
179       /**
180        * Ask the mesh service to remove a peer from the blacklist of a tunnel
181        */
182     case 281: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST";
183
184       /**
185        * Set tunnel speed to slowest peer
186        */
187     case 282: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN";
188
189       /**
190        * Set tunnel speed to fastest peer
191        */
192     case 283: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX";
193
194       /**
195        * Set tunnel buffering on.
196        */
197     case 284: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER";
198
199       /**
200        * Set tunnel buffering off.
201        */
202     case 285: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER";
203
204       /**
205        * Local ACK for data.
206        */
207     case 286: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK";
208
209       /**
210        * Local monitoring of service.
211        */
212     case 287: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR";
213
214       /**
215        * Local monitoring of service of a specific tunnel.
216        */
217     case 288: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_MONITOR_TUNNEL";
218
219       /**
220        * 640kb should be enough for everybody
221        */
222     case 299: return "GNUNET_MESSAGE_TYPE_MESH_RESERVE_END";
223     }
224   sprintf(buf, "%u (UNKNOWN TYPE)", m);
225   return buf;
226 }
227 #else
228 const char *
229 GNUNET_MESH_DEBUG_M2S (uint16_t m)
230 {
231   return "";
232 }
233 #endif