The following commit has been merged in the master branch: commit 405b1ae52cd64e53aaeb95455dd57761086c7a18 Author: Marek Lindner lindner_marek@yahoo.de Date: Thu Oct 19 23:40:36 2006 +0200
ignore gateway if recent connection attempts were unsuccessful
diff --git a/batman.c b/batman.c index a3ee37c..6a6ba59 100755 --- a/batman.c +++ b/batman.c @@ -193,6 +193,10 @@ static void choose_gw()
gw_node = list_entry(pos, struct gw_node, list);
+ /* ignore this gateway if recent connection attempts were unsuccessful */ + if ( ( gw_node->unavail_factor * gw_node->unavail_factor * 30000 ) + gw_node->last_failure > get_time() ) + continue; + switch ( routing_class ) {
case 1: /* fast connection */ @@ -400,6 +404,9 @@ static void update_gw_list( struct orig_node *orig_node, unsigned char new_gwfla INIT_LIST_HEAD(&gw_node->list);
gw_node->orig_node = orig_node; + gw_node->unavail_factor = 0; + gw_node->last_failure = get_time(); + list_add_tail(&gw_node->list, &gw_list);
choose_gw(); diff --git a/batman.h b/batman.h index b9b9826..00d5fae 100755 --- a/batman.h +++ b/batman.h @@ -110,6 +110,8 @@ struct gw_node { struct list_head list; struct orig_node *orig_node; + int unavail_factor; + int last_failure; };
struct batman_if diff --git a/posix.c b/posix.c index 8292664..936cb93 100644 --- a/posix.c +++ b/posix.c @@ -143,6 +143,10 @@ void *client_to_gw_tun( void *arg ) {
do_log( "Error - can't connect to gateway: %s\n", strerror(errno) ); close( curr_gateway_tcp_sock ); + + gw_node->last_failure = get_time(); + gw_node->unavail_factor++; + curr_gateway = NULL; return NULL;
@@ -205,9 +209,15 @@ void *client_to_gw_tun( void *arg ) { server_keep_alive_timeout = get_time();
if ( write( curr_gateway_tcp_sock, keep_alive_string, sizeof( keep_alive_string ) ) < 0 ) { + if ( debug_level == 1 ) printf( "server_keepalive failed: no connect to server\n" ); + + gw_node->last_failure = get_time(); + gw_node->unavail_factor++; + break; + }
} @@ -244,6 +254,9 @@ void *client_to_gw_tun( void *arg ) { if ( debug_level == 1 ) printf( "Gateway closed connection - timeout ?\n" );
+ gw_node->last_failure = get_time(); + gw_node->unavail_factor++; + break;
}