From 59937eff76975b16e667f35827aafb0a6451b954 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 12 Nov 2013 16:34:02 +0100 Subject: [SERVER] Add "client only" flag for alt servers --- src/server/altservers.c | 12 ++++++++---- src/server/altservers.h | 2 +- src/server/globals.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/server/altservers.c b/src/server/altservers.c index 2cb5061..44a4b85 100644 --- a/src/server/altservers.c +++ b/src/server/altservers.c @@ -67,9 +67,11 @@ int altservers_load() while ( !feof( fp ) ) { if ( fgets( buffer, 1000, fp ) == NULL ) break; int isPrivate = FALSE; - for (line = buffer;;) { // Trim left and scan for "-" prefix + int isClientOnly = FALSE; + for (line = buffer; *line != '\0'; ) { // Trim left and scan for "-" prefix if ( *line == '-' ) isPrivate = TRUE; - else if ( *line != ' ' || *line != '\t' ) break; + else if ( *line == '+' ) isClientOnly = TRUE; + else if ( *line != ' ' && *line != '\t' ) break; line++; } trim_right( line ); @@ -80,14 +82,14 @@ int altservers_load() memlogf( "[WARNING] Invalid entry in alt-servers file ignored: '%s'", line ); continue; } - if ( altservers_add( &host, space, isPrivate ) ) ++count; + if ( altservers_add( &host, space, isPrivate, isClientOnly ) ) ++count; } fclose( fp ); printf( "[DEBUG] Added %d alt servers\n", count ); return count; } -int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate) +int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate, const int isClientOnly) { int i, freeSlot = -1; spin_lock( &_alts_lock ); @@ -109,6 +111,7 @@ int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate) } _alt_servers[freeSlot].host = *host; _alt_servers[freeSlot].isPrivate = isPrivate; + _alt_servers[freeSlot].isClientOnly = isClientOnly; if ( comment != NULL ) snprintf( _alt_servers[freeSlot].comment, COMMENT_LENGTH, "%s", comment ); spin_unlock( &_alts_lock ); return TRUE; @@ -225,6 +228,7 @@ int altservers_get(dnbd3_host_t *output, int size) for (i = 0; i < _num_alts; ++i) { if ( _alt_servers[i].host.type == 0 ) continue; if ( _proxyPrivateOnly && !_alt_servers[i].isPrivate ) continue; + if ( _alt_servers[i].isClientOnly ) continue; if ( _alt_servers[i].numFails > SERVER_MAX_UPLINK_FAILS && now - _alt_servers[i].lastFail > SERVER_BAD_UPLINK_IGNORE ) continue; _alt_servers[i].numFails = 0; output[count++] = _alt_servers[i].host; diff --git a/src/server/altservers.h b/src/server/altservers.h index e07afce..de7643c 100644 --- a/src/server/altservers.h +++ b/src/server/altservers.h @@ -7,7 +7,7 @@ void altservers_init(); int altservers_load(); -int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate); +int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate, const int isClientOnly); void altservers_findUplink(dnbd3_connection_t *uplink); diff --git a/src/server/globals.h b/src/server/globals.h index a15678b..e2de1fb 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -73,7 +73,7 @@ typedef struct dnbd3_host_t host; int rtt[SERVER_RTT_PROBES]; int rttIndex; - int isPrivate; + int isPrivate, isClientOnly; time_t lastFail; int numFails; } dnbd3_alt_server_t; -- cgit v1.2.3-55-g7522