From ad7a06950759257627c0ecd05f70c184cac7040e Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Tue, 12 Jun 2007 16:51:18 +0000 Subject: [PATCH] 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. --- CASA-auth-token/client/library/engine.c | 43 ++++++++++++++++--------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/CASA-auth-token/client/library/engine.c b/CASA-auth-token/client/library/engine.c index 573e55dd..0fd2fb07 100644 --- a/CASA-auth-token/client/library/engine.c +++ b/CASA-auth-token/client/library/engine.c @@ -29,7 +29,9 @@ //===[ Type definitions ]================================================== -#define DEFAULT_RETRY_LIFETIME 300 // seconds +#define DEFAULT_RETRY_LIFETIME 300 // seconds + +#define BAD_CACHE_TRIGER_TIME 30 // seconds #define DEFAULT_ATS_PORT 2645 @@ -661,8 +663,8 @@ ObtainAuthTokenInt( bool setupHostEntries = true; char *pHostNameAnd443 = NULL; char *pHostNameAnd2645 = NULL; - ATSHostEntry serviceHostEntry443 = {NULL, NULL, NULL, NULL, 0}; - ATSHostEntry serviceHostEntry2645 = {NULL, NULL, NULL, NULL, 0}; + ATSHostEntry serviceHostEntry443 = {{NULL, NULL}, NULL, NULL, 0}; + ATSHostEntry serviceHostEntry2645 = {{NULL, NULL}, NULL, NULL, 0}; LIST_ENTRY *pListEntry; ATSHostEntry *pHostEntryInUse; @@ -734,6 +736,7 @@ ObtainAuthTokenInt( // Initialize to retry in case of failure int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME; bool advisedToRetry; + DWORD opStartTime = GetTickCount(); // Cache entry created, now try to obtain auth token from the CASA Server pToken = NULL; @@ -760,23 +763,31 @@ ObtainAuthTokenInt( &advisedToRetry); } - // Add the entry to the cache if we did not fail due to authentication - // failure. + // Try to add the entry to the cache if we did not fail due + // to authentication failure. if (CasaStatusCode(retStatus) != CASA_STATUS_AUTHENTICATION_FAILURE) { - pCacheEntry = CreateAuthTokenCacheEntry(pServiceName, - pNormalizedHostName, - pHostEntryInUse, - retStatus, - pToken, - cacheEntryLifetime, - pCredStoreScope); - if (pCacheEntry) + 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))) { - // Release the cache entry if the resulting status is not successful - if (!CASA_SUCCESS(retStatus)) + pCacheEntry = CreateAuthTokenCacheEntry(pServiceName, + pNormalizedHostName, + pHostEntryInUse, + retStatus, + pToken, + cacheEntryLifetime, + pCredStoreScope); + if (pCacheEntry) { - FreeAuthCacheEntry(pCacheEntry); + // Release the cache entry if the resulting status is not successful + if (!CASA_SUCCESS(retStatus)) + { + FreeAuthCacheEntry(pCacheEntry); + } } } }