aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesh/Makefile.am6
-rw-r--r--src/mesh/gnunet-service-mesh.c22
-rw-r--r--src/mesh/mesh.h12
-rw-r--r--src/mesh/mesh_api.c16
-rw-r--r--src/mesh/mesh_common.c185
5 files changed, 221 insertions, 20 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index 68ae729c9..cabf5c1e5 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -42,7 +42,7 @@ libgnunet_plugin_block_mesh_la_DEPENDENCIES = \
42 $(top_builddir)/src/util/libgnunetutil.la 42 $(top_builddir)/src/util/libgnunetutil.la
43 43
44libgnunetmesh_la_SOURCES = \ 44libgnunetmesh_la_SOURCES = \
45 mesh_api.c mesh.h mesh_protocol.h 45 mesh_api.c mesh_common.c
46libgnunetmesh_la_LIBADD = \ 46libgnunetmesh_la_LIBADD = \
47 $(top_builddir)/src/util/libgnunetutil.la \ 47 $(top_builddir)/src/util/libgnunetutil.la \
48 $(XLIB) \ 48 $(XLIB) \
@@ -63,7 +63,9 @@ libgnunetmeshblock_la_LDFLAGS = \
63 63
64gnunet_service_mesh_SOURCES = \ 64gnunet_service_mesh_SOURCES = \
65 gnunet-service-mesh.c \ 65 gnunet-service-mesh.c \
66 mesh_tunnel_tree.c mesh_tunnel_tree.h 66 mesh_tunnel_tree.c \
67 mesh_common.c
68gnunet_service_mesh_CFLAGS = $(AM_CFLAGS)
67gnunet_service_mesh_LDADD = \ 69gnunet_service_mesh_LDADD = \
68 $(top_builddir)/src/util/libgnunetutil.la \ 70 $(top_builddir)/src/util/libgnunetutil.la \
69 $(top_builddir)/src/core/libgnunetcore.la \ 71 $(top_builddir)/src/core/libgnunetcore.la \
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index b48a94ee4..6a2ae46af 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1981,7 +1981,8 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg,
1981 1981
1982 type = ntohs (payload->type); 1982 type = ntohs (payload->type);
1983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending to clients...\n"); 1983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending to clients...\n");
1984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "message of type %u\n", type); 1984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "message of type %s\n",
1985 GNUNET_MESH_DEBUG_M2S (type));
1985 1986
1986 memcpy (cbuf, msg, sizeof (cbuf)); 1987 memcpy (cbuf, msg, sizeof (cbuf));
1987 switch (htons (msg->type)) 1988 switch (htons (msg->type))
@@ -4327,14 +4328,15 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
4327 mc = (struct GNUNET_MESH_Multicast *) mh; 4328 mc = (struct GNUNET_MESH_Multicast *) mh;
4328 mh = (struct GNUNET_MessageHeader *) &mc[1]; 4329 mh = (struct GNUNET_MessageHeader *) &mc[1];
4329 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4330 " multicast, payload type %u\n", ntohs (mh->type)); 4331 " multicast, payload type %s\n",
4332 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
4331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4332 " multicast, payload size %u\n", ntohs (mh->size)); 4334 " multicast, payload size %u\n", ntohs (mh->size));
4333 } 4335 }
4334 else 4336 else
4335 { 4337 {
4336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type %u\n", 4338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " type %s\n",
4337 ntohs (mh->type)); 4339 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
4338 } 4340 }
4339 } 4341 }
4340#endif 4342#endif
@@ -5041,8 +5043,8 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5041 return GNUNET_OK; 5043 return GNUNET_OK;
5042 } 5044 }
5043 msg = (struct GNUNET_MESH_Unicast *) message; 5045 msg = (struct GNUNET_MESH_Unicast *) message;
5044 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %u\n", 5046 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %s\n",
5045 ntohs (msg[1].header.type)); 5047 GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
5046 /* Check tunnel */ 5048 /* Check tunnel */
5047 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 5049 t = tunnel_get (&msg->oid, ntohl (msg->tid));
5048 if (NULL == t) 5050 if (NULL == t)
@@ -5233,8 +5235,8 @@ handle_mesh_data_to_orig (void *cls, const struct GNUNET_PeerIdentity *peer,
5233 return GNUNET_OK; 5235 return GNUNET_OK;
5234 } 5236 }
5235 msg = (struct GNUNET_MESH_ToOrigin *) message; 5237 msg = (struct GNUNET_MESH_ToOrigin *) message;
5236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %u\n", 5238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %s\n",
5237 ntohs (msg[1].header.type)); 5239 GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
5238 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 5240 t = tunnel_get (&msg->oid, ntohl (msg->tid));
5239 5241
5240 if (NULL == t) 5242 if (NULL == t)
@@ -5305,8 +5307,8 @@ handle_mesh_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
5305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n", 5307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n",
5306 GNUNET_i2s (peer)); 5308 GNUNET_i2s (peer));
5307 msg = (struct GNUNET_MESH_ACK *) message; 5309 msg = (struct GNUNET_MESH_ACK *) message;
5308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %u\n", 5310 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " of type %s\n",
5309 ntohs (msg[1].header.type)); 5311 GNUNET_MESH_DEBUG_M2S (ntohs (msg[1].header.type)));
5310 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 5312 t = tunnel_get (&msg->oid, ntohl (msg->tid));
5311 5313
5312 if (NULL == t) 5314 if (NULL == t)
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index 30d1acefa..f67a25d5f 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -310,5 +310,17 @@ enum MeshPeerState
310}; 310};
311 311
312 312
313/**
314 * Convert a message type into a string to help debug
315 * Generated with:
316 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
317 * REPLACE: " case \2: return "\1"; break;"
318 *
319 * @param m Message type.
320 *
321 * @return Human readable string description.
322 */
323const char *
324GNUNET_MESH_DEBUG_M2S (uint16_t m);
313 325
314#endif 326#endif
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index cfabd4c0c..da233c00d 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -1291,8 +1291,8 @@ send_callback (void *cls, size_t size, void *buf)
1291 GNUNET_assert (size >= th->size); 1291 GNUNET_assert (size >= th->size);
1292 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)]; 1292 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
1293 psize = th->notify (th->notify_cls, size - sizeof (to), mh); 1293 psize = th->notify (th->notify_cls, size - sizeof (to), mh);
1294 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin, type %u\n", 1294 LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin, type %s\n",
1295 ntohs (mh->type)); 1295 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
1296 if (psize > 0) 1296 if (psize > 0)
1297 { 1297 {
1298 psize += sizeof (to); 1298 psize += sizeof (to);
@@ -1315,8 +1315,8 @@ send_callback (void *cls, size_t size, void *buf)
1315 GNUNET_assert (size >= th->size); 1315 GNUNET_assert (size >= th->size);
1316 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)]; 1316 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
1317 psize = th->notify (th->notify_cls, size - sizeof (mc), mh); 1317 psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
1318 LOG (GNUNET_ERROR_TYPE_DEBUG, " multicast, type %u\n", 1318 LOG (GNUNET_ERROR_TYPE_DEBUG, " multicast, type %s\n",
1319 ntohs (mh->type)); 1319 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
1320 if (psize > 0) 1320 if (psize > 0)
1321 { 1321 {
1322 psize += sizeof (mc); 1322 psize += sizeof (mc);
@@ -1339,8 +1339,8 @@ send_callback (void *cls, size_t size, void *buf)
1339 GNUNET_assert (size >= th->size); 1339 GNUNET_assert (size >= th->size);
1340 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)]; 1340 mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
1341 psize = th->notify (th->notify_cls, size - sizeof (uc), mh); 1341 psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
1342 LOG (GNUNET_ERROR_TYPE_DEBUG, " unicast, type %u\n", 1342 LOG (GNUNET_ERROR_TYPE_DEBUG, " unicast, type %s\n",
1343 ntohs (mh->type)); 1343 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
1344 if (psize > 0) 1344 if (psize > 0)
1345 { 1345 {
1346 psize += sizeof (uc); 1346 psize += sizeof (uc);
@@ -1360,8 +1360,8 @@ send_callback (void *cls, size_t size, void *buf)
1360 { 1360 {
1361 struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1]; 1361 struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1];
1362 1362
1363 LOG (GNUNET_ERROR_TYPE_DEBUG, " mesh traffic, type %u\n", 1363 LOG (GNUNET_ERROR_TYPE_DEBUG, " mesh traffic, type %s\n",
1364 ntohs (mh->type)); 1364 GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
1365 memcpy (cbuf, &th[1], th->size); 1365 memcpy (cbuf, &th[1], th->size);
1366 psize = th->size; 1366 psize = th->size;
1367 } 1367 }
diff --git a/src/mesh/mesh_common.c b/src/mesh/mesh_common.c
new file mode 100644
index 000000000..cfc2f00ce
--- /dev/null
+++ b/src/mesh/mesh_common.c
@@ -0,0 +1,185 @@
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.c
23 * @brief MESH helper functions
24 * @author Bartlomiej Polot
25 */
26
27#include "mesh.h"
28
29#if !defined(GNUNET_CULL_LOGGING)
30const char *
31GNUNET_MESH_DEBUG_M2S (uint16_t m)
32{
33 static char buf[32];
34 switch (m)
35 {
36 /**
37 * Request the creation of a path
38 */
39 case 256: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE"; break;
40
41 /**
42 * Request the modification of an existing path
43 */
44 case 257: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGE"; break;
45
46 /**
47 * Notify that a connection of a path is no longer valid
48 */
49 case 258: return "GNUNET_MESSAGE_TYPE_MESH_PATH_BROKEN"; break;
50
51 /**
52 * At some point, the route will spontaneously change
53 */
54 case 259: return "GNUNET_MESSAGE_TYPE_MESH_PATH_CHANGED"; break;
55
56 /**
57 * Transport data in the mesh (origin->end) unicast
58 */
59 case 260: return "GNUNET_MESSAGE_TYPE_MESH_UNICAST"; break;
60
61 /**
62 * Transport data to all peers in a tunnel
63 */
64 case 261: return "GNUNET_MESSAGE_TYPE_MESH_MULTICAST"; break;
65
66 /**
67 * Transport data back in the mesh (end->origin)
68 */
69 case 262: return "GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN"; break;
70
71 /**
72 * Send origin an ACK that the path is complete
73 */
74 case 263: return "GNUNET_MESSAGE_TYPE_MESH_PATH_ACK"; break;
75
76 /**
77 * Avoid path timeouts
78 */
79 case 264: return "GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE"; break;
80
81 /**
82 * Request the destuction of a path
83 */
84 case 265: return "GNUNET_MESSAGE_TYPE_MESH_PATH_DESTROY"; break;
85
86 /**
87 * Request the destruction of a whole tunnel
88 */
89 case 266: return "GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY"; break;
90
91 /**
92 * ACK for a data packet.
93 */
94 case 267: return "GNUNET_MESSAGE_TYPE_MESH_ACK"; break;
95
96 /**
97 * Connect to the mesh service, specifying subscriptions
98 */
99 case 272: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT"; break;
100
101 /**
102 * Ask the mesh service to create a new tunnel
103 */
104 case 273: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE"; break;
105
106 /**
107 * Ask the mesh service to destroy a tunnel
108 */
109 case 274: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY"; break;
110
111 /**
112 * Ask the mesh service to add a peer to an existing tunnel
113 */
114 case 275: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD"; break;
115
116 /**
117 * Ask the mesh service to remove a peer from a tunnel
118 */
119 case 276: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL"; break;
120
121 /**
122 * Ask the mesh service to add a peer offering a service to an existing tunnel
123 */
124 case 277: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_TYPE"; break;
125
126 /**
127 * Ask the mesh service to add a peer described by a service string
128 */
129 case 278: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX"; break;
130
131 /**
132 * Ask the mesh service to add a peer described by a service string
133 */
134 case 279: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING"; break;
135
136 /**
137 * Ask the mesh service to add a peer to the blacklist of an existing tunnel
138 */
139 case 280: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_BLACKLIST"; break;
140
141 /**
142 * Ask the mesh service to remove a peer from the blacklist of a tunnel
143 */
144 case 281: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST"; break;
145
146 /**
147 * Set tunnel speed to slowest peer
148 */
149 case 282: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN"; break;
150
151 /**
152 * Set tunnel speed to fastest peer
153 */
154 case 283: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX"; break;
155
156 /**
157 * Set tunnel buffering on.
158 */
159 case 284: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER"; break;
160
161 /**
162 * Set tunnel buffering off.
163 */
164 case 285: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER"; break;
165
166 /**
167 * Local ACK for data.
168 */
169 case 286: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK"; break;
170
171 /**
172 * 640kb should be enough for everybody
173 */
174 case 299: return "GNUNET_MESSAGE_TYPE_MESH_RESERVE_END"; break;
175 }
176 sprintf(buf, "%u (UNKNOWN TYPE)", m);
177 return buf;
178}
179#else
180const char *
181GNUNET_MESH_DEBUG_M2S (uint16_t m)
182{
183 return "";
184}
185#endif