aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-05-11 15:38:25 +0000
committerBart Polot <bart@net.in.tum.de>2011-05-11 15:38:25 +0000
commit3117911a77e121fb729411d29c4929332934ba42 (patch)
tree573c11f40bdffeb711ab78acdf6e1f60523dcb51
parenta4f87c40e74cfff2b369958e7f2532ad23b40900 (diff)
downloadgnunet-3117911a77e121fb729411d29c4929332934ba42.tar.gz
gnunet-3117911a77e121fb729411d29c4929332934ba42.zip
Added mesh testing code and configuration files
-rw-r--r--contrib/defaults.conf13
-rw-r--r--src/mesh/gnunet-service-mesh.c23
-rw-r--r--src/mesh/mesh_api_new.c46
-rw-r--r--src/mesh/test_mesh.conf59
-rw-r--r--src/mesh/test_mesh_api.c79
5 files changed, 147 insertions, 73 deletions
diff --git a/contrib/defaults.conf b/contrib/defaults.conf
index f0ee4e3e0..dd6a29e45 100644
--- a/contrib/defaults.conf
+++ b/contrib/defaults.conf
@@ -354,3 +354,16 @@ QUOTA = 1024000
354 354
355[block] 355[block]
356PLUGINS = fs dht test 356PLUGINS = fs dht test
357
358[mesh]
359AUTOSTART = YES
360PORT = 10511
361HOSTNAME = localhost
362HOME = $SERVICEHOME
363CONFIG = $DEFAULTCONFIG
364BINARY = gnunet-service-mesh
365ACCEPT_FROM = 127.0.0.1;
366ACCEPT_FROM6 = ::1;
367UNIXPATH = /tmp/gnunet-service-mesh.sock
368UNIX_MATCH_UID = YES
369UNIX_MATCH_GID = YES
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 2769793f9..d545d8dd3 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -710,8 +710,6 @@ handle_local_new_client (void *cls,
710 /* Create new client structure */ 710 /* Create new client structure */
711 c = GNUNET_malloc(sizeof(struct Client)); 711 c = GNUNET_malloc(sizeof(struct Client));
712 c->handle = client; 712 c->handle = client;
713 c->tunnels_head = NULL;
714 c->tunnels_tail = NULL;
715 if(payload_size != 0) { 713 if(payload_size != 0) {
716 c->messages_subscribed = GNUNET_malloc(payload_size); 714 c->messages_subscribed = GNUNET_malloc(payload_size);
717 memcpy(c->messages_subscribed, &message[1], payload_size); 715 memcpy(c->messages_subscribed, &message[1], payload_size);
@@ -724,6 +722,7 @@ handle_local_new_client (void *cls,
724 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); 722 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
725 723
726 GNUNET_SERVER_receive_done(client, GNUNET_OK); 724 GNUNET_SERVER_receive_done(client, GNUNET_OK);
725
727} 726}
728 727
729/** 728/**
@@ -777,16 +776,6 @@ handle_local_tunnel_create (void *cls,
777 t = GNUNET_malloc(sizeof(struct MESH_tunnel)); 776 t = GNUNET_malloc(sizeof(struct MESH_tunnel));
778 t->tid = ntohl(tunnel_msg->tunnel_id); 777 t->tid = ntohl(tunnel_msg->tunnel_id);
779 t->oid = myid; 778 t->oid = myid;
780 t->peers_ready = 0;
781 t->peers_total = 0;
782 t->peers_head = NULL;
783 t->peers_tail = NULL;
784 t->paths_head = NULL;
785 t->paths_tail = NULL;
786 t->in_head = NULL;
787 t->in_tail = NULL;
788 t->out_head = NULL;
789 t->out_tail = NULL;
790 t->client = c; 779 t->client = c;
791 780
792 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t); 781 GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
@@ -1319,7 +1308,7 @@ run (void *cls,
1319 struct GNUNET_SERVER_Handle *server, 1308 struct GNUNET_SERVER_Handle *server,
1320 const struct GNUNET_CONFIGURATION_Handle *c) 1309 const struct GNUNET_CONFIGURATION_Handle *c)
1321{ 1310{
1322 1311GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 3 ********\n");
1323 GNUNET_SERVER_add_handlers (server, plugin_handlers); 1312 GNUNET_SERVER_add_handlers (server, plugin_handlers);
1324 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 1313 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
1325 core_handle = GNUNET_CORE_connect (c, /* Main configuration */ 1314 core_handle = GNUNET_CORE_connect (c, /* Main configuration */
@@ -1334,11 +1323,10 @@ run (void *cls,
1334 NULL, /* Don't notify about all outbound messages */ 1323 NULL, /* Don't notify about all outbound messages */
1335 GNUNET_NO, /* For header-only out notification */ 1324 GNUNET_NO, /* For header-only out notification */
1336 core_handlers); /* Register these handlers */ 1325 core_handlers); /* Register these handlers */
1337 1326GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 ********\n");
1338 if (core_handle == NULL) { 1327 if (core_handle == NULL) {
1339 GNUNET_break(0); 1328 GNUNET_break(0);
1340 } 1329 }
1341
1342 dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */ 1330 dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */
1343 if (dht_handle == NULL) { 1331 if (dht_handle == NULL) {
1344 GNUNET_break(0); 1332 GNUNET_break(0);
@@ -1356,12 +1344,13 @@ int
1356main (int argc, char *const *argv) 1344main (int argc, char *const *argv)
1357{ 1345{
1358 int ret; 1346 int ret;
1359 1347GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 1 ********\n");
1360 ret = (GNUNET_OK == 1348 ret = (GNUNET_OK ==
1361 GNUNET_SERVICE_run (argc, 1349 GNUNET_SERVICE_run (argc,
1362 argv, 1350 argv,
1363 "mesh", 1351 "mesh",
1364 GNUNET_SERVICE_OPTION_NONE, 1352 GNUNET_SERVICE_OPTION_NONE,
1365 &run, NULL)) ? 0 : 1; 1353 &run, NULL)) ? 0 : 1;
1354GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 2 ********\n");
1366 return ret; 1355 return ret;
1367 } 1356}
diff --git a/src/mesh/mesh_api_new.c b/src/mesh/mesh_api_new.c
index d68408a3b..ca68279ed 100644
--- a/src/mesh/mesh_api_new.c
+++ b/src/mesh/mesh_api_new.c
@@ -137,26 +137,30 @@ send_connect_packet (void *cls, size_t size, void *buf) {
137 int napps; 137 int napps;
138 138
139 if(0 == size || buf == NULL) { 139 if(0 == size || buf == NULL) {
140 /* TODO treat error / retry */ 140 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n");
141 return 0; 141 return 0;
142 } 142 }
143 if(sizeof(struct GNUNET_MessageHeader) > size) { 143 if(sizeof(struct GNUNET_MessageHeader) > size) {
144 /* TODO treat error / retry */ 144 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n");
145 return 0; 145 return 0;
146 } 146 }
147
147 msg = (struct GNUNET_MESH_ClientConnect *) buf; 148 msg = (struct GNUNET_MESH_ClientConnect *) buf;
148 h = (struct GNUNET_MESH_Handle *) cls; 149 h = (struct GNUNET_MESH_Handle *) cls;
149 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT; 150 msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
151
150 for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) { 152 for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
151 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1)); 153 types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
152 types[ntypes] = h->message_handlers[ntypes].type; 154 types[ntypes] = h->message_handlers[ntypes].type;
153 } 155 }
156
154 for(napps = 0, apps = NULL; h->applications[napps]; napps++) { 157 for(napps = 0, apps = NULL; h->applications[napps]; napps++) {
155 apps = GNUNET_realloc(apps, 158 apps = GNUNET_realloc(apps,
156 sizeof(GNUNET_MESH_ApplicationType) * 159 sizeof(GNUNET_MESH_ApplicationType) *
157 (napps + 1)); 160 (napps + 1));
158 apps[napps] = h->applications[napps]; 161 apps[napps] = h->applications[napps];
159 } 162 }
163
160 msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) + 164 msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
161 sizeof(uint16_t) * ntypes + 165 sizeof(uint16_t) * ntypes +
162 sizeof(GNUNET_MESH_ApplicationType) * napps; 166 sizeof(GNUNET_MESH_ApplicationType) * napps;
@@ -164,14 +168,36 @@ send_connect_packet (void *cls, size_t size, void *buf) {
164 /* TODO treat error / retry */ 168 /* TODO treat error / retry */
165 return 0; 169 return 0;
166 } 170 }
171
167 memcpy(&msg[1], types, sizeof(uint16_t) * ntypes); 172 memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
168 memcpy(&msg[1] + sizeof(uint16_t) * ntypes, 173 memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
169 apps, 174 apps,
170 sizeof(GNUNET_MESH_ApplicationType) * napps); 175 sizeof(GNUNET_MESH_ApplicationType) * napps);
176
171 return msg->header.size; 177 return msg->header.size;
172} 178}
173 179
174 180/**
181 * Type of a function to call when we receive a message
182 * from the service.
183 *
184 * @param cls closure
185 * @param msg message received, NULL on timeout or fatal error
186 */
187void msg_received (void *cls,
188 const struct
189 GNUNET_MessageHeader * msg) {
190 uint16_t t;
191 if(msg != NULL){
192 t = ntohs(msg->type);
193 } else {
194 t = 0;
195 }
196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
197 "received a message from mesh (of size %d)\n",
198 t);
199 return;
200}
175 201
176/** 202/**
177 * Connect to the mesh service. 203 * Connect to the mesh service.
@@ -199,21 +225,23 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
199 225
200 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle)); 226 h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
201 227
202
203 h->cleaner = cleaner; 228 h->cleaner = cleaner;
204 h->mesh = GNUNET_CLIENT_connect("mesh", cfg); 229 h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
230 GNUNET_CLIENT_receive (h->mesh,
231 &msg_received,
232 h,
233 GNUNET_TIME_UNIT_FOREVER_REL);
205 if(h->mesh == NULL) { 234 if(h->mesh == NULL) {
206 GNUNET_free(h); 235 GNUNET_free(h);
207 return NULL; 236 return NULL;
208 } 237 }
238
209 h->cls = cls; 239 h->cls = cls;
210 h->message_handlers = handlers; 240 h->message_handlers = handlers;
211 h->applications = stypes; 241 h->applications = stypes;
212 242
213 for(h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++); 243 for(h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++);
214 for(h->n_applications = 0; stypes[h->n_applications]; h->n_applications++); 244 for(h->n_applications = 0; stypes[h->n_applications]; h->n_applications++);
215 h->n_handlers--;
216 h->n_applications--;
217 245
218 size = sizeof(struct GNUNET_MESH_ClientConnect); 246 size = sizeof(struct GNUNET_MESH_ClientConnect);
219 size += h->n_handlers * sizeof(uint16_t); 247 size += h->n_handlers * sizeof(uint16_t);
@@ -221,8 +249,8 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
221 249
222 GNUNET_CLIENT_notify_transmit_ready(h->mesh, 250 GNUNET_CLIENT_notify_transmit_ready(h->mesh,
223 size, 251 size,
224 GNUNET_TIME_relative_get_forever(), 252 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
225 GNUNET_YES, 253 GNUNET_NO,
226 &send_connect_packet, 254 &send_connect_packet,
227 (void *)h); 255 (void *)h);
228 256
@@ -236,7 +264,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
236 * @param handle connection to mesh to disconnect 264 * @param handle connection to mesh to disconnect
237 */ 265 */
238void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) { 266void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) {
239 267
240 GNUNET_free(handle); 268 GNUNET_free(handle);
241 return; 269 return;
242} 270}
diff --git a/src/mesh/test_mesh.conf b/src/mesh/test_mesh.conf
new file mode 100644
index 000000000..49da05129
--- /dev/null
+++ b/src/mesh/test_mesh.conf
@@ -0,0 +1,59 @@
1[fs]
2AUTOSTART = NO
3
4[resolver]
5AUTOSTART = NO
6
7[mesh]
8DEBUG = YES
9AUTOSTART = YES
10ACCEPT_FROM = 127.0.0.1;
11HOSTNAME = localhost
12PORT = 10511
13
14[dht]
15DEBUG = NO
16AUTOSTART = YES
17ACCEPT_FROM6 = ::1;
18ACCEPT_FROM = 127.0.0.1;
19HOSTNAME = localhost
20PORT = 2100
21
22[block]
23plugins = dht test
24
25[dhtcache]
26QUOTA = 1000000
27DATABASE = sqlite
28
29[transport]
30PLUGINS = tcp
31DEBUG = NO
32ACCEPT_FROM6 = ::1;
33ACCEPT_FROM = 127.0.0.1;
34NEIGHBOUR_LIMIT = 50
35PORT = 12365
36
37[core]
38TOTAL_QUOTA_OUT = 3932160
39TOTAL_QUOTA_IN = 3932160
40PORT = 12092
41
42[arm]
43DEFAULTSERVICES = core
44PORT = 12366
45DEBUG = NO
46
47[transport-tcp]
48TIMEOUT = 300000
49PORT = 12368
50
51[TESTING]
52WEAKRANDOM = YES
53
54[gnunetd]
55HOSTKEY = $SERVICEHOME/.hostkey
56
57[PATHS]
58DEFAULTCONFIG = test_mesh.conf
59SERVICEHOME = /tmp/test-mesh/
diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c
index 4383d3133..00212eb49 100644
--- a/src/mesh/test_mesh_api.c
+++ b/src/mesh/test_mesh_api.c
@@ -7,6 +7,7 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
7 {NULL, 0, 0} 7 {NULL, 0, 0}
8}; 8};
9 9
10
10static void 11static void
11run (void *cls, 12run (void *cls,
12 char *const *args, 13 char *const *args,
@@ -14,37 +15,30 @@ run (void *cls,
14 struct GNUNET_OS_Process *arm_pid; 15 struct GNUNET_OS_Process *arm_pid;
15 struct GNUNET_MESH_Handle *mesh; 16 struct GNUNET_MESH_Handle *mesh;
16 struct GNUNET_DHT_Handle *dht; 17 struct GNUNET_DHT_Handle *dht;
17// struct GNUNET_MESH_Tunnel *t; 18 GNUNET_MESH_ApplicationType app;
19 char buffer[2048];
18 20
19 21
20 arm_pid = GNUNET_OS_start_process (NULL, NULL, 22 arm_pid = GNUNET_OS_start_process (NULL, NULL,
21 "gnunet-service-arm", 23 "gnunet-service-arm",
22 "gnunet-service-arm", 24 "gnunet-service-arm",
23 "-L", "DEBUG", 25 "-L", "DEBUG",
24 "-c", "test_dht_api_data.conf", 26 "-c", "test_mesh.conf",
25 NULL); 27 NULL);
26// sleep(1);
27// printf("%d\n", fopen( "test_mesh.conf", "r"));
28// GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_mesh.conf"));
29 //printf("%d\n", GNUNET_CONFIGURATION_load (cfg, NULL));
30// printf("%d\n", GNUNET_CONFIGURATION_load (cfg, "test_dht_api_data.conf"));
31 dht = GNUNET_DHT_connect(cfg, 100); 28 dht = GNUNET_DHT_connect(cfg, 100);
32 if(NULL == dht) { 29 if(NULL == dht) {
33// fprintf(stderr, "Couldn't connect to dht :(\n"); 30 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
34// return 1; // succeed anyway 31 } else {
32 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
33 }
34
35 app = 0;
36 mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
37 if(NULL == mesh) {
38 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
35 } else { 39 } else {
36// fprintf(stderr, "YAY! CONNECTED TO DHT :D\n"); 40 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
37 } 41 }
38// mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, NULL);
39// if(NULL == mesh) {
40// fprintf(stderr, "Couldn't connect to mesh :(\n");
41// return 1; // succeed anyway
42// } else {
43// fprintf(stderr, "YAY! CONNECTED TO MESH :D\n");
44// }
45// mesh = realloc(mesh, 0); // don't complain about *mesh
46// printf("MESH TEST\n");
47// t = GNUNET_MESH_tunnel_create(mesh, );
48 42
49 /* do real test work here */ 43 /* do real test work here */
50 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) 44 if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
@@ -55,33 +49,24 @@ run (void *cls,
55 return; 49 return;
56} 50}
57 51
58static int 52
59check ()
60{
61 int ret;
62 char *const argv[] = {"test-mesh-api",
63 "-c",
64 "test_dht_api_data.conf",
65#if VERBOSE
66 "-L", "DEBUG",
67#endif
68 NULL
69 };
70 struct GNUNET_GETOPT_CommandLineOption options[] = {
71 GNUNET_GETOPT_OPTION_END
72 };
73 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
74 argv, "test-mesh-api", "nohelp",
75 options, &run, NULL);
76 if (ret != GNUNET_OK)
77 {
78 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
79 }
80 return GNUNET_OK;
81}
82 53
83int main (int argc, char *argv[]) { 54int main (int argc, char *argv[]) {
84 if(GNUNET_OK == check()) 55 int ret;
85 return 0; 56 char *const argv2[] = {"test-mesh-api",
86 else return 1; 57 "-c", "test_mesh.conf",
58 "-L", "DEBUG",
59 NULL
60 };
61 struct GNUNET_GETOPT_CommandLineOption options[] = {
62 GNUNET_GETOPT_OPTION_END
63 };
64 GNUNET_log_setup ("test-dht-api","DEBUG", NULL);
65 ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
66 argv2, "test-mesh-api", "nohelp",
67 options, &run, NULL);
68 if (ret != GNUNET_OK) {
69 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
70 }
71 return 0;
87} 72}