Updated to only add non-success authtoken entries to the

cache if the time necessary to process them exceeds 30
seconds. With this change we make sure that non-successful
entries are added to the cache to deal with server
un-available issues.
This commit is contained in:
Juan Carlos Luciani 2007-06-12 16:51:18 +00:00
parent e9551385d0
commit ad7a069507

View File

@ -31,6 +31,8 @@
#define DEFAULT_RETRY_LIFETIME 300 // seconds #define DEFAULT_RETRY_LIFETIME 300 // seconds
#define BAD_CACHE_TRIGER_TIME 30 // seconds
#define DEFAULT_ATS_PORT 2645 #define DEFAULT_ATS_PORT 2645
#define LOG_FILE_NAME "\\casaauthtoken.log" #define LOG_FILE_NAME "\\casaauthtoken.log"
@ -661,8 +663,8 @@ ObtainAuthTokenInt(
bool setupHostEntries = true; bool setupHostEntries = true;
char *pHostNameAnd443 = NULL; char *pHostNameAnd443 = NULL;
char *pHostNameAnd2645 = NULL; char *pHostNameAnd2645 = NULL;
ATSHostEntry serviceHostEntry443 = {NULL, NULL, NULL, NULL, 0}; ATSHostEntry serviceHostEntry443 = {{NULL, NULL}, NULL, NULL, 0};
ATSHostEntry serviceHostEntry2645 = {NULL, NULL, NULL, NULL, 0}; ATSHostEntry serviceHostEntry2645 = {{NULL, NULL}, NULL, NULL, 0};
LIST_ENTRY *pListEntry; LIST_ENTRY *pListEntry;
ATSHostEntry *pHostEntryInUse; ATSHostEntry *pHostEntryInUse;
@ -734,6 +736,7 @@ ObtainAuthTokenInt(
// Initialize to retry in case of failure // Initialize to retry in case of failure
int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME; int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME;
bool advisedToRetry; bool advisedToRetry;
DWORD opStartTime = GetTickCount();
// Cache entry created, now try to obtain auth token from the CASA Server // Cache entry created, now try to obtain auth token from the CASA Server
pToken = NULL; pToken = NULL;
@ -760,9 +763,16 @@ ObtainAuthTokenInt(
&advisedToRetry); &advisedToRetry);
} }
// Add the entry to the cache if we did not fail due to authentication // Try to add the entry to the cache if we did not fail due
// failure. // to authentication failure.
if (CasaStatusCode(retStatus) != CASA_STATUS_AUTHENTICATION_FAILURE) if (CasaStatusCode(retStatus) != CASA_STATUS_AUTHENTICATION_FAILURE)
{
DWORD opEndTime = GetTickCount();
// We only want to cache bad results if the operation took a
// considerable amount of time.
if (CASA_SUCCESS(retStatus)
|| opEndTime >= (opStartTime + (BAD_CACHE_TRIGER_TIME * 1000)))
{ {
pCacheEntry = CreateAuthTokenCacheEntry(pServiceName, pCacheEntry = CreateAuthTokenCacheEntry(pServiceName,
pNormalizedHostName, pNormalizedHostName,
@ -780,6 +790,7 @@ ObtainAuthTokenInt(
} }
} }
} }
}
// Release authentication token if present // Release authentication token if present
if (pToken) if (pToken)