]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink_internal.h
Lock meshlink.conf to ensure only one instance can run at a time.
[meshlink] / src / meshlink_internal.h
index 6426f83dcbce397df1065899a421a99ffa09b557..92774c49baf3c9481d4aac62273256156c77d629 100644 (file)
@@ -1,6 +1,9 @@
+#ifndef MESHLINK_INTERNAL_H
+#define MESHLINK_INTERNAL_H
+
 /*
     meshlink_internal.h -- Internal parts of the public API.
-    Copyright (C) 2014 Guus Sliepen <guus@meshlink.io>
+    Copyright (C) 2014, 2017 Guus Sliepen <guus@meshlink.io>
 
     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
     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
-#ifndef MESHLINK_INTERNAL_H
-#define MESHLINK_INTERNAL_H
-
 #include "system.h"
 
 #include "event.h"
+#include "hash.h"
 #include "meshlink.h"
+#include "meshlink_queue.h"
 #include "sockaddr.h"
+#include "sptps.h"
+
+#include <pthread.h>
+
+#define MAXSOCKETS 8    /* Probably overkill... */
+
+static const char meshlink_invitation_label[] = "MeshLink invitation";
+static const char meshlink_tcp_label[] = "MeshLink TCP";
+static const char meshlink_udp_label[] = "MeshLink UDP";
+
+struct CattaServer;
+struct CattaSServiceBrowser;
+struct CattaSimplePoll;
+struct CattaSEntryGroup;
+
+typedef struct listen_socket_t {
+       struct io_t tcp;
+       struct io_t udp;
+       sockaddr_t sa;
+       bool bindto;
+} listen_socket_t;
 
 typedef enum proxytype_t {
        PROXY_NONE = 0,
@@ -32,21 +55,34 @@ typedef enum proxytype_t {
        PROXY_SOCKS4A,
        PROXY_SOCKS5,
        PROXY_HTTP,
-       PROXY_EXEC,
 } proxytype_t;
 
 /// A handle for an instance of MeshLink.
 struct meshlink_handle {
-       char *confbase;
        char *name;
+       void *priv;
+
+       char *appname;
+       dev_class_t devclass;
+
+       char *confbase;
+       FILE *conffile;
 
        meshlink_receive_cb_t receive_cb;
        meshlink_node_status_cb_t node_status_cb;
        meshlink_log_cb_t log_cb;
        meshlink_log_level_t log_level;
 
+       meshlink_channel_accept_cb_t channel_accept_cb;
+       meshlink_node_duplicate_cb_t node_duplicate_cb;
+
        pthread_t thread;
-       struct list_t *sockets;
+       bool threadstarted;
+       pthread_mutex_t mesh_mutex;
+       event_loop_t loop;
+       listen_socket_t listen_socket[MAXSOCKETS];
+       int listen_sockets;
+       signal_t datafromapp;
 
        struct node_t *self;
 
@@ -57,6 +93,11 @@ struct meshlink_handle {
        struct list_t *connections;
        struct list_t *outgoings;
 
+       meshlink_queue_t outpacketqueue;
+
+       struct splay_tree_t *past_request_tree;
+       timeout_t past_request_timeout;
+
        int contradicting_add_edge;
        int contradicting_del_edge;
        int sleeptime;
@@ -72,8 +113,38 @@ struct meshlink_handle {
        char *proxypass;
        proxytype_t proxytype;
 
+       bool discovery;         // Whether Catta is enabled or not
        bool localdiscovery;
        sockaddr_t localdiscovery_address;
+
+       bool default_blacklist;
+
+       hash_t *node_udp_cache;
+       struct connection_t *everyone;
+       struct ecdsa *invitation_key;
+       int invitation_timeout;
+
+       int pinginterval;       /* seconds between pings */
+       int pingtimeout;        /* seconds to wait for response */
+       int maxtimeout;
+
+       int sock;
+       sptps_t sptps;
+       char cookie[18], hash[18];
+       char *data;
+       size_t thedatalen;
+       bool success;
+       char line[4096];
+       char buffer[4096];
+       size_t blen;
+
+       pthread_t discovery_thread;
+       bool discovery_threadstarted;
+       struct CattaServer *catta_server;
+       struct CattaSServiceBrowser *catta_browser;
+       struct CattaSimplePoll *catta_poll;
+       struct CattaSEntryGroup *catta_group;
+       char *catta_servicetype;
 };
 
 /// A handle for a MeshLink node.
@@ -82,10 +153,36 @@ struct meshlink_node {
        void *priv;
 };
 
-// This is a *temporary* global variable which will keep the compiler happy
-// while refactoring the code to get rid of global variables.
-// TODO: remove this when no other global variables remain.
+/// A channel.
+struct meshlink_channel {
+       struct node_t *node;
+       void *priv;
 
-extern meshlink_handle_t *mesh;
+       struct utcp_connection *c;
+       meshlink_channel_receive_cb_t receive_cb;
+       meshlink_channel_poll_cb_t poll_cb;
+};
 
-#endif // MESHLINK_INTERNAL_H
+/// Header for data packets routed between nodes
+typedef struct meshlink_packethdr {
+       uint8_t destination[16];
+       uint8_t source[16];
+} __attribute__((__packed__)) meshlink_packethdr_t;
+
+extern void meshlink_send_from_queue(event_loop_t *el, meshlink_handle_t *mesh);
+extern void update_node_status(meshlink_handle_t *mesh, struct node_t *n);
+extern meshlink_log_level_t global_log_level;
+extern meshlink_log_cb_t global_log_cb;
+extern int check_port(meshlink_handle_t *mesh);
+extern void handle_duplicate_node(meshlink_handle_t *mesh, struct node_t *n);
+
+/// Device class traits
+typedef struct {
+       unsigned int min_connects;
+       unsigned int max_connects;
+       int edge_weight;
+} dev_class_traits_t;
+
+extern dev_class_traits_t dev_class_traits[];
+
+#endif