projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Only forward SPTPS packets if Forwarding = internal.
[tinc]
/
src
/
autoconnect.c
diff --git
a/src/autoconnect.c
b/src/autoconnect.c
index
e97a33c
..
8adb74f
100644
(file)
--- a/
src/autoconnect.c
+++ b/
src/autoconnect.c
@@
-27,23
+27,29
@@
static void make_new_connection() {
/* Select a random node we haven't connected to yet. */
int count = 0;
static void make_new_connection() {
/* Select a random node we haven't connected to yet. */
int count = 0;
+
for splay_each(node_t, n, node_tree) {
for splay_each(node_t, n, node_tree) {
- if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
+ if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
{
continue;
continue;
+ }
+
count++;
}
count++;
}
- if(!count)
+ if(!count)
{
return;
return;
+ }
int r = rand() % count;
for splay_each(node_t, n, node_tree) {
int r = rand() % count;
for splay_each(node_t, n, node_tree) {
- if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
+ if(n == myself || n->connection || !(n->status.has_address || n->status.reachable))
{
continue;
continue;
+ }
- if(r--)
+ if(r--)
{
continue;
continue;
+ }
bool found = false;
bool found = false;
@@
-77,17
+83,20
@@
static void connect_to_unreachable() {
int r = rand() % node_tree->count;
for splay_each(node_t, n, node_tree) {
int r = rand() % node_tree->count;
for splay_each(node_t, n, node_tree) {
- if(r--)
+ if(r--)
{
continue;
continue;
+ }
/* Is it unreachable and do we know an address for it? If not, return. */
/* Is it unreachable and do we know an address for it? If not, return. */
- if(n == myself || n->connection || n->status.reachable || !n->status.has_address)
+ if(n == myself || n->connection || n->status.reachable || !n->status.has_address)
{
return;
return;
+ }
/* Are we already trying to make an outgoing connection to it? If not, return. */
for list_each(outgoing_t, outgoing, outgoing_list)
/* Are we already trying to make an outgoing connection to it? If not, return. */
for list_each(outgoing_t, outgoing, outgoing_list)
- if(!strcmp(outgoing->name, n->name))
+ if(!strcmp(outgoing->name, n->name))
{
return;
return;
+ }
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
outgoing_t *outgoing = xzalloc(sizeof(*outgoing));
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
outgoing_t *outgoing = xzalloc(sizeof(*outgoing));
@@
-102,23
+111,29
@@
static void connect_to_unreachable() {
static void drop_superfluous_outgoing_connection() {
/* Choose a random outgoing connection to a node that has at least one other connection. */
int count = 0;
static void drop_superfluous_outgoing_connection() {
/* Choose a random outgoing connection to a node that has at least one other connection. */
int count = 0;
+
for list_each(connection_t, c, connection_list) {
for list_each(connection_t, c, connection_list) {
- if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2)
+ if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2)
{
continue;
continue;
+ }
+
count++;
}
count++;
}
- if(!count)
+ if(!count)
{
return;
return;
+ }
int r = rand() % count;
for list_each(connection_t, c, connection_list) {
int r = rand() % count;
for list_each(connection_t, c, connection_list) {
- if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2)
+ if(!c->edge || !c->outgoing || !c->node || c->node->edge_tree->count < 2)
{
continue;
continue;
-
- if(r--)
+ }
+
+ if(r--) {
continue;
continue;
+ }
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autodisconnecting from %s", c->name);
list_delete(outgoing_list, c->outgoing);
logger(DEBUG_CONNECTIONS, LOG_INFO, "Autodisconnecting from %s", c->name);
list_delete(outgoing_list, c->outgoing);
@@
-132,6
+147,7
@@
static void drop_superfluous_pending_connections() {
for list_each(outgoing_t, o, outgoing_list) {
/* Only look for connections that are waiting to be retried later. */
bool found = false;
for list_each(outgoing_t, o, outgoing_list) {
/* Only look for connections that are waiting to be retried later. */
bool found = false;
+
for list_each(connection_t, c, connection_list) {
if(c->outgoing == o) {
found = true;
for list_each(connection_t, c, connection_list) {
if(c->outgoing == o) {
found = true;
@@
-139,8
+155,9
@@
static void drop_superfluous_pending_connections() {
}
}
}
}
- if(found)
+ if(found)
{
continue;
continue;
+ }
logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->name);
list_delete_node(outgoing_list, node);
logger(DEBUG_CONNECTIONS, LOG_INFO, "Cancelled outgoing connection to %s", o->name);
list_delete_node(outgoing_list, node);
@@
-150,9
+167,11
@@
static void drop_superfluous_pending_connections() {
void do_autoconnect() {
/* Count number of active connections. */
int nc = 0;
void do_autoconnect() {
/* Count number of active connections. */
int nc = 0;
+
for list_each(connection_t, c, connection_list) {
for list_each(connection_t, c, connection_list) {
- if(c->edge)
+ if(c->edge)
{
nc++;
nc++;
+ }
}
/* Less than 3 connections? Eagerly try to make a new one. */
}
/* Less than 3 connections? Eagerly try to make a new one. */
@@
-160,10
+179,11
@@
void do_autoconnect() {
make_new_connection();
return;
}
make_new_connection();
return;
}
-
+
/* More than 3 connections? See if we can get rid of a superfluous one. */
/* More than 3 connections? See if we can get rid of a superfluous one. */
- if(nc > 3)
+ if(nc > 3)
{
drop_superfluous_outgoing_connection();
drop_superfluous_outgoing_connection();
+ }
/* Check if there are unreachable nodes that we should try to connect to. */
/* Check if there are unreachable nodes that we should try to connect to. */