]> git.meshlink.io Git - meshlink/blobdiff - src/libmeshlink.c
Remove everything GPL that is not copyright Guus Sliepen, update copyright statements.
[meshlink] / src / libmeshlink.c
index 80f18a22e341187a192125ba7f8a32a072d8c518..a1fef4cc784320326dea481e1fb0aa7919347661 100644 (file)
@@ -1,6 +1,6 @@
 /*
     libmeshlink.h -- Tincd Library
-    Copyright (C) 2014 Guus Sliepen <guus@tinc-vpn.org> Saverio Proto <zioproto@gmail.com>
+    Copyright (C) 2014 Guus Sliepen <guus@meshlink.io> Saverio Proto <zioproto@gmail.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -18,7 +18,6 @@
 */
 
 #include "libmeshlink.h"
-#include LZO1X_H
 #ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
 #endif
@@ -39,7 +38,6 @@ static bool do_mlock = false;
 */
 bool setup_meshlink_network(void) {
        init_connections();
-       init_subnets();
        init_nodes();
        init_edges();
        init_requests();
@@ -63,13 +61,6 @@ bool setup_meshlink_network(void) {
        if(!setup_myself())
                return false;
 
-       if(!init_control())
-               return false;
-
-       /* Run subnet-up scripts for our own subnets */
-
-       subnet_update(myself, NULL, true);
-
        return true;
 }
 
@@ -388,8 +379,7 @@ int check_port(char *name) {
 }
 //tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script.
 bool tinc_setup(const char* confbaseapi, const char* name) {
-       confbase = confbaseapi;
-       make_names();
+       confbase = xstrdup(confbaseapi);
         xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
         xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
        if(!access(tinc_conf, F_OK)) {
@@ -402,11 +392,6 @@ bool tinc_setup(const char* confbaseapi, const char* name) {
                return false;
        }
 
-       if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) {
-               fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno));
-               return false;
-       }
-
        if(mkdir(confbase, 0777) && errno != EEXIST) {
                fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
                return false;
@@ -445,15 +430,14 @@ return true;
 }
 
 bool tinc_main_thread(void * in) {
+       static bool status = false;
 
-static bool status = false;
+       /* If nonzero, write log entries to a separate file. */
+       bool use_logfile = false;
 
-/* If nonzero, write log entries to a separate file. */
-bool use_logfile = false;
+       confbase = (char*) in;
 
-confbase = (char*) in;
-
-       openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);
+       openlogger("tinc", LOGMODE_STDERR);
 
        init_configuration(&config_tree);
 
@@ -466,13 +450,6 @@ confbase = (char*) in;
        if(!read_server_config())
                return false;
 
-#ifdef HAVE_LZO
-       if(lzo_init() != LZO_E_OK) {
-               logger(DEBUG_ALWAYS, LOG_ERR, "Error initializing LZO compressor!");
-               return false;
-       }
-#endif
-
        //char *priority = NULL; //shoud be not needed in libmeshlink
 
 #ifdef HAVE_MLOCKALL
@@ -539,8 +516,6 @@ end:
        crypto_exit();
 
        exit_configuration(&config_tree);
-       free(cmdline_conf);
-       free_names();
 
        return status;
 
@@ -548,17 +523,57 @@ end:
 
 bool tinc_stop();
 
+bool route_meshlink(node_t *source,vpn_packet_t *packet) {
+
+       printf("data %s\n",packet->data);
+       printf("data 16%s\n",packet->data+16);
+       printf("data 32%s\n",packet->data+32);
+       node_t* owner = NULL;
+
+       tincpackethdr* hdr = (tincpackethdr*)packet->data;
+       owner = lookup_node(hdr->destination);
+
+       if (owner == NULL) {
+       //Lookup failed
+       printf("NULL\n");
+       return false;
+       }
+       printf("lookupnode %s\n",owner->name);
+
+       if(!owner->status.reachable) {
+       //Do some here
+       return false;
+       }
+
+       //TODO: I skipped here a lot of checks !
+
+       send_packet(owner,packet);
+
+}
 // can be called from any thread
-bool tinc_send_packet(tincremotehost *receiver, const char* buf, unsigned int len) {
+bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) {
 
        vpn_packet_t packet;
+       tincpackethdr* hdr = malloc(sizeof(tincpackethdr));
+
+       if (sizeof(hdr) + len > MAXSIZE) {
+
+       //log something
+       return false;
+       }
+
+       memcpy(hdr->destination,receiver->name,sizeof(hdr->destination));
+       memcpy(hdr->source,myself->name,sizeof(hdr->source));
 
        packet.priority = 0;
-       memcpy(packet.data,buf,len);
+       packet.len = len + 32;
+
+       memcpy(packet.data,hdr,32);
+       memcpy(packet.data+32,buf,len);
 
         myself->in_packets++;
         myself->in_bytes += packet.len;
-        route(myself, &packet);
+        route_meshlink(myself, &packet);
 
 return true;
 }
@@ -570,7 +585,11 @@ bool tinc_set_packet_receive_handler(void (*handler)(const char* sender, const c
 //It might also be a good idea to add the option of looking up hosts by public
 //key (fingerprints) instead of names.
 
-node_t *tinc_get_host(const char *name);
+node_t *tinc_get_host(const char *name) {
+
+
+
+};
 
 bool tinc_get_hosts(node_t** hosts);