+bool tinc_start(const char* confbaseapi) {
+ pthread_t tincThread;
+ confbase = xstrdup(confbaseapi);
+ pthread_create(&tincThread,NULL,tinc_main_thread,confbase);
+ pthread_detach(tincThread);
+return true;
+}
+
+__attribute__((constructor)) static void meshlink_init(void) {
+ /* Slllluuuuuuurrrrp! */
+
+ gettimeofday(&now, NULL);
+ srand(now.tv_sec + now.tv_usec);
+ crypto_init();
+}
+
+__attribute__((destructor)) static void meshlink_exit(void) {
+ crypto_exit();
+}
+
+
+void *tinc_main_thread(void * in) {
+ static bool status = false;
+ /* If nonzero, write log entries to a separate file. */
+ bool use_logfile = false;
+
+ confbase = (char*) in;
+
+ openlogger("tinc", LOGMODE_STDERR);
+
+ init_configuration(&config_tree);
+
+ if(!read_server_config())
+ return false;
+
+ //char *priority = NULL; //shoud be not needed in libmeshlink
+
+ /* Setup sockets and open device. */
+
+ if(!setup_network())
+ goto end;
+
+ /* Start main loop. It only exits when tinc is killed. */
+
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Ready");
+
+ try_outgoing_connections();
+
+ status = main_loop();
+
+ /* Shutdown properly. */
+
+end:
+ close_network_connections();
+
+ logger(DEBUG_ALWAYS, LOG_NOTICE, "Terminating");
+
+ //free(priority);
+
+ exit_configuration(&config_tree);
+
+ return (void *)status;
+}