In particular: confbase, contradicting_add_edge, contradicting_del_edge,
sleeptime, last_config_check, pingtimer, periodictimer.
- xasprintf(&fname, "%s" SLASH "tinc.conf", confbase);
+ xasprintf(&fname, "%s" SLASH "tinc.conf", mesh->confbase);
errno = 0;
x = read_config_file(mesh->config, fname);
errno = 0;
x = read_config_file(mesh->config, fname);
- xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name);
x = read_config_file(config_tree, fname);
free(fname);
x = read_config_file(config_tree, fname);
free(fname);
bool append_config_file(const char *name, const char *key, const char *value) {
char *fname;
bool append_config_file(const char *name, const char *key, const char *value) {
char *fname;
- xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, name);
+ xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, name);
FILE *fp = fopen(fname, "a");
FILE *fp = fopen(fname, "a");
#include "meshlink.h"
/// A handle for an instance of MeshLink.
#include "meshlink.h"
/// A handle for an instance of MeshLink.
struct list_t *connections;
struct list_t *outgoings;
struct list_t *connections;
struct list_t *outgoings;
+
+ int contradicting_add_edge;
+ int contradicting_del_edge;
+ int sleeptime;
+ time_t last_config_check;
+ timeout_t pingtimer;
+ timeout_t periodictimer;
};
/// A handle for a MeshLink node.
};
/// A handle for a MeshLink node.
#include "protocol.h"
#include "xalloc.h"
#include "protocol.h"
#include "xalloc.h"
-int contradicting_add_edge = 0;
-int contradicting_del_edge = 0;
-static int sleeptime = 10;
-time_t last_config_check = 0;
-static timeout_t pingtimer;
-static timeout_t periodictimer;
-
-//TODO: move this to a better place
-char *confbase;
-
/* Purge edges of unreachable nodes. Use carefully. */
// TODO: remove
/* Purge edges of unreachable nodes. Use carefully. */
// TODO: remove
If so, sleep for a short while to prevent a storm of contradicting messages.
*/
If so, sleep for a short while to prevent a storm of contradicting messages.
*/
- if(contradicting_del_edge > 100 && contradicting_add_edge > 100) {
- logger(DEBUG_ALWAYS, LOG_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", sleeptime);
- usleep(sleeptime * 1000000LL);
- sleeptime *= 2;
- if(sleeptime < 0)
- sleeptime = 3600;
+ if(mesh->contradicting_del_edge > 100 && mesh->contradicting_add_edge > 100) {
+ logger(DEBUG_ALWAYS, LOG_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", mesh->sleeptime);
+ usleep(mesh->sleeptime * 1000000LL);
+ mesh->sleeptime *= 2;
+ if(mesh->sleeptime < 0)
+ mesh->sleeptime = 3600;
- sleeptime /= 2;
- if(sleeptime < 10)
- sleeptime = 10;
+ mesh->sleeptime /= 2;
+ if(mesh->sleeptime < 10)
+ mesh->sleeptime = 10;
- contradicting_add_edge = 0;
- contradicting_del_edge = 0;
+ mesh->contradicting_add_edge = 0;
+ mesh->contradicting_del_edge = 0;
/* If AutoConnect is set, check if we need to make or break connections. */
/* If AutoConnect is set, check if we need to make or break connections. */
- xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, mesh->self->name);
+ xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, mesh->self->name);
read_config_file(mesh->config, fname);
free(fname);
read_config_file(mesh->config, fname);
free(fname);
/* Close connections to hosts that have a changed or deleted host config file */
for list_each(connection_t, c, mesh->connections) {
/* Close connections to hosts that have a changed or deleted host config file */
for list_each(connection_t, c, mesh->connections) {
- xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
+ xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, c->name);
- if(stat(fname, &s) || s.st_mtime > last_config_check) {
+ if(stat(fname, &s) || s.st_mtime > mesh->last_config_check) {
logger(DEBUG_CONNECTIONS, LOG_INFO, "Host config file of %s has been changed", c->name);
terminate_connection(c, c->status.active);
}
free(fname);
}
logger(DEBUG_CONNECTIONS, LOG_INFO, "Host config file of %s has been changed", c->name);
terminate_connection(c, c->status.active);
}
free(fname);
}
- last_config_check = now.tv_sec;
+ mesh->last_config_check = now.tv_sec;
}
/* Kick the ping timeout handler */
}
/* Kick the ping timeout handler */
- timeout_set(&pingtimer, &(struct timeval){0, 0});
+ timeout_set(&mesh->pingtimer, &(struct timeval){0, 0});
}
/*
this is where it all happens...
*/
int main_loop(void) {
}
/*
this is where it all happens...
*/
int main_loop(void) {
- timeout_add(&pingtimer, timeout_handler, &pingtimer, &(struct timeval){pingtimeout, rand() % 100000});
- timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){pingtimeout, rand() % 100000});
+ timeout_add(&mesh->pingtimer, timeout_handler, &mesh->pingtimer, &(struct timeval){pingtimeout, rand() % 100000});
+ timeout_add(&mesh->periodictimer, periodic_handler, &mesh->periodictimer, &(struct timeval){pingtimeout, rand() % 100000});
if(!event_loop()) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while waiting for input: %s", strerror(errno));
return 1;
}
if(!event_loop()) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while waiting for input: %s", strerror(errno));
return 1;
}
- timeout_del(&periodictimer);
- timeout_del(&pingtimer);
+ timeout_del(&mesh->periodictimer);
+ timeout_del(&mesh->pingtimer);
extern char *myport;
extern int autoconnect;
extern bool disablebuggypeers;
extern char *myport;
extern int autoconnect;
extern bool disablebuggypeers;
-extern int contradicting_add_edge;
-extern int contradicting_del_edge;
-extern time_t last_config_check;
extern char *proxyhost;
extern char *proxyport;
extern char *proxyhost;
extern char *proxyport;
} proxytype_t;
extern proxytype_t proxytype;
} proxytype_t;
extern proxytype_t proxytype;
-extern char *scriptinterpreter;
-extern char *scriptextension;
-
/* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
#include "connection.h"
#include "node.h"
/* Yes, very strange placement indeed, but otherwise the typedefs get all tangled up */
#include "connection.h"
#include "node.h"
extern CRITICAL_SECTION mutex;
#endif
extern CRITICAL_SECTION mutex;
#endif
-//TODO: move this to a better place
-extern char *confbase;
-
#endif /* __TINC_NET_H__ */
#endif /* __TINC_NET_H__ */
- xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", confbase);
+ xasprintf(&fname, "%s" SLASH "ecdsa_key.priv", mesh->confbase);
fp = fopen(fname, "r");
free(fname);
fp = fopen(fname, "r");
free(fname);
- xasprintf(&fname, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", confbase);
+ xasprintf(&fname, "%s" SLASH "invitations" SLASH "ecdsa_key.priv", mesh->confbase);
struct dirent *ent;
char *dname;
struct dirent *ent;
char *dname;
- xasprintf(&dname, "%s" SLASH "hosts", confbase);
+ xasprintf(&dname, "%s" SLASH "hosts", mesh->confbase);
dir = opendir(dname);
if(!dir) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
dir = opendir(dname);
if(!dir) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
- last_config_check = now.tv_sec;
+ mesh->last_config_check = now.tv_sec;
// Create a new host config file
char filename[PATH_MAX];
// Create a new host config file
char filename[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", confbase, c->name);
+ snprintf(filename, sizeof filename, "%s" SLASH "hosts" SLASH "%s", mesh->confbase, c->name);
if(!access(filename, F_OK)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Host config file for %s (%s) already exists!\n", c->name, c->hostname);
return false;
if(!access(filename, F_OK)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Host config file for %s (%s) already exists!\n", c->name, c->hostname);
return false;
free(fingerprint);
char filename[PATH_MAX], usedname[PATH_MAX];
free(fingerprint);
char filename[PATH_MAX], usedname[PATH_MAX];
- snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookie);
- snprintf(usedname, sizeof usedname, "%s" SLASH "invitations" SLASH "%s.used", confbase, cookie);
+ snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", mesh->confbase, cookie);
+ snprintf(usedname, sizeof usedname, "%s" SLASH "invitations" SLASH "%s.used", mesh->confbase, cookie);
// Atomically rename the invitation file
if(rename(filename, usedname)) {
// Atomically rename the invitation file
if(rename(filename, usedname)) {
} else if(from == mesh->self) {
logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist",
"ADD_EDGE", c->name, c->hostname);
} else if(from == mesh->self) {
logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist",
"ADD_EDGE", c->name, c->hostname);
- contradicting_add_edge++;
+ mesh->contradicting_add_edge++;
e = new_edge();
e->from = from;
e->to = to;
e = new_edge();
e->from = from;
e->to = to;
if(e->from == mesh->self) {
logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself",
"DEL_EDGE", c->name, c->hostname);
if(e->from == mesh->self) {
logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself",
"DEL_EDGE", c->name, c->hostname);
- contradicting_del_edge++;
+ mesh->contradicting_del_edge++;
send_add_edge(c, e); /* Send back a correction */
return true;
}
send_add_edge(c, e); /* Send back a correction */
return true;
}