]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Stop using global variable mesh in net_socket.[ch].
[meshlink] / src / meshlink.c
index 4abacb1433afd18b35c2027d7aef64af1ad932a6..124b6e8f649731495a3fb65e9c7b0407e789f315 100644 (file)
@@ -212,6 +212,8 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) {
        meshlink_handle_t *mesh = xzalloc(sizeof *mesh);
        mesh->confbase = xstrdup(confbase);
        mesh->name = xstrdup(name);
+       event_loop_init(&mesh->loop);
+       mesh->loop.data = mesh;
        set_mesh(mesh);
 
        // TODO: should be set by a function.
@@ -236,13 +238,13 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) {
 
        init_configuration(&mesh->config);
 
-       if(!read_server_config())
+       if(!read_server_config(mesh))
                return meshlink_close(mesh), NULL;
 
        // Setup up everything
        // TODO: we should not open listening sockets yet
 
-       if(!setup_network())
+       if(!setup_network(mesh))
                return meshlink_close(mesh), NULL;
 
        return mesh;
@@ -251,7 +253,7 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) {
 void *meshlink_main_loop(void *arg) {
        meshlink_handle_t *mesh = arg;
 
-       try_outgoing_connections();
+       try_outgoing_connections(mesh);
 
        main_loop();
 
@@ -288,7 +290,7 @@ void meshlink_close(meshlink_handle_t *mesh) {
        logger(DEBUG_ALWAYS, LOG_NOTICE, "Terminating");
 
        exit_configuration(&mesh->config);
-
+       event_loop_exit(&mesh->loop);
 }
 
 void meshlink_set_receive_cb(meshlink_handle_t *mesh, meshlink_receive_cb_t cb) {
@@ -363,8 +365,6 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
 }
 
 static void __attribute__((constructor)) meshlink_init(void) {
-       gettimeofday(&now, NULL);
-       srand(now.tv_sec + now.tv_usec);
        crypto_init();
 }