]> git.meshlink.io Git - meshlink/blobdiff - src/libmeshlink.c
Remove support for control connections.
[meshlink] / src / libmeshlink.c
index f4932cc38aebd6b539ea88da4143381dcdb7dd86..d6e199fd6c0ad9538af21abb84573cddbfa04ebb 100644 (file)
@@ -39,7 +39,6 @@ static bool do_mlock = false;
 */
 bool setup_meshlink_network(void) {
        init_connections();
-       init_subnets();
        init_nodes();
        init_edges();
        init_requests();
@@ -63,13 +62,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;
 }
 
@@ -548,8 +540,59 @@ end:
 
 bool tinc_stop();
 
+bool route_meshlink(node_t *source,vpn_packet_t *packet) {
+
+       printf("data %s\n",packet->data);
+       printf("data 11%s\n",packet->data+11);
+       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(node_t *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,hdr,32);
+       memcpy(packet.data+32,buf,len);
+
+        myself->in_packets++;
+        myself->in_bytes += packet.len;
+        route_meshlink(myself, &packet);
+
+return true;
+}
 
 // handler runs in tinc thread and should return immediately
 bool tinc_set_packet_receive_handler(void (*handler)(const char* sender, const char* buf, unsigned int len));
@@ -558,7 +601,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);