[block]
PLUGINS = fs dht test
+
+[mesh]
+AUTOSTART = YES
+PORT = 10511
+HOSTNAME = localhost
+HOME = $SERVICEHOME
+CONFIG = $DEFAULTCONFIG
+BINARY = gnunet-service-mesh
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/gnunet-service-mesh.sock
+UNIX_MATCH_UID = YES
+UNIX_MATCH_GID = YES
/* 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);
GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
GNUNET_SERVER_receive_done(client, GNUNET_OK);
+
}
/**
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);
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 */
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);
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;
- }
+}
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;
/* 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.
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);
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);
* @param handle connection to mesh to disconnect
*/
void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) {
-
+
GNUNET_free(handle);
return;
}
--- /dev/null
+[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/
{NULL, 0, 0}
};
+
static void
run (void *cls,
char *const *args,
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))
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;
}