Based partially on work from Rafał Leśniak.
* Initial support for generating a tinc-up script from an invitation.
* Many small fixes, documentation updates.
-Thanks to Etienne Dechamps, thorkill, Vittorio Gambaletta, Martin Weinelt,
+Thanks to Etienne Dechamps, Rafał Leśniak, Vittorio Gambaletta, Martin Weinelt,
Sven-Haegar Koch, Florian Klink, LunnarShadow, Dato Simó, Jo-Philipp Wich,
Jochen Voss, Nathan Stratton Treadway, Pierre Emeriaud, xentec, Samuel
Thibault and Michael Tokarev for their contributions to this version of tinc.
* Sven-Haegar Koch
* Teemu Kiviniemi
* Thomas Tsiakalakis
-* thorkill
* Timothy Redaelli
* Tomasz Fortuna
* Tomislav Čohar
and we are not already trying to make one, create an
outgoing connection to this node.
*/
- int r = rand() % (node_tree->count - 1);
- int i = 0;
-
+ int count = 0;
for splay_each(node_t, n, node_tree) {
- if(n == myself)
+ if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
continue;
+ count++;
+ }
- if(i++ != r)
+ if(!count)
+ goto end;
+
+ int r = rand() % count;
+
+ for splay_each(node_t, n, node_tree) {
+ if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
continue;
- if(n->connection)
- break;
+ if(r--)
+ continue;
bool found = false;
list_insert_tail(outgoing_list, outgoing);
setup_outgoing_connection(outgoing);
}
+
break;
}
} else if(nc > 3) {
}
}
+end:
timeout_set(data, &(struct timeval){5, rand() % 100000});
}
for splay_each(subnet_t, subnet, subnet_tree)
if (subnet->owner)
subnet->expires = 1;
+ }
+
+ for splay_each(node_t, n, node_tree)
+ n->status.has_address = false;
- load_all_subnets();
+ load_all_nodes();
+ if(strictsubnets) {
for splay_each(subnet_t, subnet, subnet_tree) {
if (!subnet->owner)
continue;
extern void purge(void);
extern void retry(void);
extern int reload_configuration(void);
-extern void load_all_subnets(void);
extern void load_all_nodes(void);
extern void try_tx(struct node_t *n, bool);
n->status.validkey_in = false;
}
-/*
- Read Subnets from all host config files
-*/
-void load_all_subnets(void) {
+void load_all_nodes(void) {
DIR *dir;
struct dirent *ent;
char dname[PATH_MAX];
continue;
node_t *n = lookup_node(ent->d_name);
- #ifdef _DIRENT_HAVE_D_TYPE
- //if(ent->d_type != DT_REG)
- // continue;
- #endif
splay_tree_t *config_tree;
init_configuration(&config_tree);
node_add(n);
}
- for(config_t *cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
- subnet_t *s, *s2;
+ if(strictsubnets) {
+ for(config_t *cfg = lookup_config(config_tree, "Subnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) {
+ subnet_t *s, *s2;
- if(!get_config_subnet(cfg, &s))
- continue;
+ if(!get_config_subnet(cfg, &s))
+ continue;
- if((s2 = lookup_subnet(n, s))) {
- s2->expires = -1;
- free(s);
- } else {
- subnet_add(n, s);
+ if((s2 = lookup_subnet(n, s))) {
+ s2->expires = -1;
+ free(s);
+ } else {
+ subnet_add(n, s);
+ }
}
}
- exit_configuration(&config_tree);
- }
-
- closedir(dir);
-}
-
-void load_all_nodes(void) {
- DIR *dir;
- struct dirent *ent;
- char dname[PATH_MAX];
-
- snprintf(dname, sizeof dname, "%s" SLASH "hosts", confbase);
- dir = opendir(dname);
- if(!dir) {
- logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", dname, strerror(errno));
- return;
- }
+ if(lookup_config(config_tree, "Address"))
+ n->status.has_address = true;
- while((ent = readdir(dir))) {
- if(!check_id(ent->d_name))
- continue;
-
- node_t *n = lookup_node(ent->d_name);
- if(n)
- continue;
-
- n = new_node();
- n->name = xstrdup(ent->d_name);
- node_add(n);
+ exit_configuration(&config_tree);
}
closedir(dir);
}
-
char *get_name(void) {
char *name = NULL;
char *returned_name;
graph();
- if(strictsubnets)
- load_all_subnets();
- else if(autoconnect)
- load_all_nodes();
+ load_all_nodes();
/* Open device */
unsigned int send_locally:1; /* 1 if the next UDP packet should be sent on the local network */
unsigned int udppacket:1; /* 1 if the most recently received packet was UDP */
unsigned int validkey_in:1; /* 1 if we have sent a valid key to him */
- unsigned int unused:21;
+ unsigned int has_address:1; /* 1 if we know an external address for this node */
+ unsigned int unused:20;
} node_status_t;
typedef struct node_t {