summaryrefslogtreecommitdiff
path: root/src
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 /src
parenta4f87c40e74cfff2b369958e7f2532ad23b40900 (diff)
Added mesh testing code and configuration files
Diffstat (limited to 'src')
-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
4 files changed, 134 insertions, 73 deletions
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,
/* Create new client structure */
c = GNUNET_malloc(sizeof(struct Client));
c->handle = client;
- c->tunnels_head = NULL;
- c->tunnels_tail = NULL;
if(payload_size != 0) {
c->messages_subscribed = GNUNET_malloc(payload_size);
memcpy(c->messages_subscribed, &message[1], payload_size);
@@ -724,6 +722,7 @@ handle_local_new_client (void *cls,
GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
GNUNET_SERVER_receive_done(client, GNUNET_OK);
+
}
/**
@@ -777,16 +776,6 @@ handle_local_tunnel_create (void *cls,
t = GNUNET_malloc(sizeof(struct MESH_tunnel));
t->tid = ntohl(tunnel_msg->tunnel_id);
t->oid = myid;
- t->peers_ready = 0;
- t->peers_total = 0;
- t->peers_head = NULL;
- t->peers_tail = NULL;
- t->paths_head = NULL;
- t->paths_tail = NULL;
- t->in_head = NULL;
- t->in_tail = NULL;
- t->out_head = NULL;
- t->out_tail = NULL;
t->client = c;
GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
@@ -1319,7 +1308,7 @@ run (void *cls,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 3 ********\n");
GNUNET_SERVER_add_handlers (server, plugin_handlers);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
core_handle = GNUNET_CORE_connect (c, /* Main configuration */
@@ -1334,11 +1323,10 @@ run (void *cls,
NULL, /* Don't notify about all outbound messages */
GNUNET_NO, /* For header-only out notification */
core_handlers); /* Register these handlers */
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 ********\n");
if (core_handle == NULL) {
GNUNET_break(0);
}
-
dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */
if (dht_handle == NULL) {
GNUNET_break(0);
@@ -1356,12 +1344,13 @@ int
main (int argc, char *const *argv)
{
int ret;
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 1 ********\n");
ret = (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
"mesh",
GNUNET_SERVICE_OPTION_NONE,
&run, NULL)) ? 0 : 1;
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 2 ********\n");
return ret;
- }
+}
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) {
int napps;
if(0 == size || buf == NULL) {
- /* TODO treat error / retry */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n");
return 0;
}
if(sizeof(struct GNUNET_MessageHeader) > size) {
- /* TODO treat error / retry */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n");
return 0;
}
+
msg = (struct GNUNET_MESH_ClientConnect *) buf;
h = (struct GNUNET_MESH_Handle *) cls;
msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
+
for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
types[ntypes] = h->message_handlers[ntypes].type;
}
+
for(napps = 0, apps = NULL; h->applications[napps]; napps++) {
apps = GNUNET_realloc(apps,
sizeof(GNUNET_MESH_ApplicationType) *
(napps + 1));
apps[napps] = h->applications[napps];
}
+
msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
sizeof(uint16_t) * ntypes +
sizeof(GNUNET_MESH_ApplicationType) * napps;
@@ -164,14 +168,36 @@ send_connect_packet (void *cls, size_t size, void *buf) {
/* TODO treat error / retry */
return 0;
}
+
memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
apps,
sizeof(GNUNET_MESH_ApplicationType) * napps);
+
return msg->header.size;
}
-
+/**
+ * Type of a function to call when we receive a message
+ * from the service.
+ *
+ * @param cls closure
+ * @param msg message received, NULL on timeout or fatal error
+ */
+void msg_received (void *cls,
+ const struct
+ GNUNET_MessageHeader * msg) {
+ uint16_t t;
+ if(msg != NULL){
+ t = ntohs(msg->type);
+ } else {
+ t = 0;
+ }
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+ "received a message from mesh (of size %d)\n",
+ t);
+ return;
+}
/**
* Connect to the mesh service.
@@ -199,21 +225,23 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
-
h->cleaner = cleaner;
h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
+ GNUNET_CLIENT_receive (h->mesh,
+ &msg_received,
+ h,
+ GNUNET_TIME_UNIT_FOREVER_REL);
if(h->mesh == NULL) {
GNUNET_free(h);
return NULL;
}
+
h->cls = cls;
h->message_handlers = handlers;
h->applications = stypes;
for(h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++);
for(h->n_applications = 0; stypes[h->n_applications]; h->n_applications++);
- h->n_handlers--;
- h->n_applications--;
size = sizeof(struct GNUNET_MESH_ClientConnect);
size += h->n_handlers * sizeof(uint16_t);
@@ -221,8 +249,8 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_CLIENT_notify_transmit_ready(h->mesh,
size,
- GNUNET_TIME_relative_get_forever(),
- GNUNET_YES,
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
+ GNUNET_NO,
&send_connect_packet,
(void *)h);
@@ -236,7 +264,7 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
* @param handle connection to mesh to disconnect
*/
void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) {
-
+
GNUNET_free(handle);
return;
}
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 @@
+[fs]
+AUTOSTART = NO
+
+[resolver]
+AUTOSTART = NO
+
+[mesh]
+DEBUG = YES
+AUTOSTART = YES
+ACCEPT_FROM = 127.0.0.1;
+HOSTNAME = localhost
+PORT = 10511
+
+[dht]
+DEBUG = NO
+AUTOSTART = YES
+ACCEPT_FROM6 = ::1;
+ACCEPT_FROM = 127.0.0.1;
+HOSTNAME = localhost
+PORT = 2100
+
+[block]
+plugins = dht test
+
+[dhtcache]
+QUOTA = 1000000
+DATABASE = sqlite
+
+[transport]
+PLUGINS = tcp
+DEBUG = NO
+ACCEPT_FROM6 = ::1;
+ACCEPT_FROM = 127.0.0.1;
+NEIGHBOUR_LIMIT = 50
+PORT = 12365
+
+[core]
+TOTAL_QUOTA_OUT = 3932160
+TOTAL_QUOTA_IN = 3932160
+PORT = 12092
+
+[arm]
+DEFAULTSERVICES = core
+PORT = 12366
+DEBUG = NO
+
+[transport-tcp]
+TIMEOUT = 300000
+PORT = 12368
+
+[TESTING]
+WEAKRANDOM = YES
+
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
+[PATHS]
+DEFAULTCONFIG = test_mesh.conf
+SERVICEHOME = /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[] = {
{NULL, 0, 0}
};
+
static void
run (void *cls,
char *const *args,
@@ -14,37 +15,30 @@ run (void *cls,
struct GNUNET_OS_Process *arm_pid;
struct GNUNET_MESH_Handle *mesh;
struct GNUNET_DHT_Handle *dht;
-// struct GNUNET_MESH_Tunnel *t;
+ GNUNET_MESH_ApplicationType app;
+ char buffer[2048];
arm_pid = GNUNET_OS_start_process (NULL, NULL,
"gnunet-service-arm",
"gnunet-service-arm",
"-L", "DEBUG",
- "-c", "test_dht_api_data.conf",
+ "-c", "test_mesh.conf",
NULL);
-// sleep(1);
-// printf("%d\n", fopen( "test_mesh.conf", "r"));
-// GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_mesh.conf"));
- //printf("%d\n", GNUNET_CONFIGURATION_load (cfg, NULL));
-// printf("%d\n", GNUNET_CONFIGURATION_load (cfg, "test_dht_api_data.conf"));
dht = GNUNET_DHT_connect(cfg, 100);
if(NULL == dht) {
-// fprintf(stderr, "Couldn't connect to dht :(\n");
-// return 1; // succeed anyway
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
+ } else {
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
+ }
+
+ app = 0;
+ mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
+ if(NULL == mesh) {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
} else {
-// fprintf(stderr, "YAY! CONNECTED TO DHT :D\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
}
-// mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, NULL);
-// if(NULL == mesh) {
-// fprintf(stderr, "Couldn't connect to mesh :(\n");
-// return 1; // succeed anyway
-// } else {
-// fprintf(stderr, "YAY! CONNECTED TO MESH :D\n");
-// }
-// mesh = realloc(mesh, 0); // don't complain about *mesh
-// printf("MESH TEST\n");
-// t = GNUNET_MESH_tunnel_create(mesh, );
/* do real test work here */
if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
@@ -55,33 +49,24 @@ run (void *cls,
return;
}
-static int
-check ()
-{
- int ret;
- char *const argv[] = {"test-mesh-api",
- "-c",
- "test_dht_api_data.conf",
-#if VERBOSE
- "-L", "DEBUG",
-#endif
- NULL
- };
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
- argv, "test-mesh-api", "nohelp",
- options, &run, NULL);
- if (ret != GNUNET_OK)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
- }
- return GNUNET_OK;
-}
+
int main (int argc, char *argv[]) {
- if(GNUNET_OK == check())
- return 0;
- else return 1;
+ int ret;
+ char *const argv2[] = {"test-mesh-api",
+ "-c", "test_mesh.conf",
+ "-L", "DEBUG",
+ NULL
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_END
+ };
+ GNUNET_log_setup ("test-dht-api","DEBUG", NULL);
+ ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
+ argv2, "test-mesh-api", "nohelp",
+ options, &run, NULL);
+ if (ret != GNUNET_OK) {
+ GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with error code %d\n", ret);
+ }
+ return 0;
}