summaryrefslogtreecommitdiffstats
path: root/src/server/altservers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/altservers.c')
-rw-r--r--src/server/altservers.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/server/altservers.c b/src/server/altservers.c
index 17e8e4b..8962e15 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( &altServersLock );
@@ -109,6 +111,7 @@ int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate)
}
altServers[freeSlot].host = *host;
altServers[freeSlot].isPrivate = isPrivate;
+ altServers[freeSlot].isClientOnly = isClientOnly;
if ( comment != NULL ) snprintf( altServers[freeSlot].comment, COMMENT_LENGTH, "%s", comment );
spin_unlock( &altServersLock );
return TRUE;
@@ -236,6 +239,7 @@ int altservers_get(dnbd3_host_t *output, int size)
for (i = 0; i < numAltServers; ++i) {
if ( altServers[i].host.type == 0 ) continue; // Slot is empty
if ( _proxyPrivateOnly && !altServers[i].isPrivate ) continue; // Config says to consider private alt-servers only? ignore!
+ if ( altServers[i].isClientOnly ) continue;
if ( altServers[i].numFails > SERVER_MAX_UPLINK_FAILS // server failed X times in a row
&& now - altServers[i].lastFail > SERVER_BAD_UPLINK_IGNORE ) continue; // and last fail was not too long ago? ignore!
// server seems ok, include in output and reset its fail counter