Add a new failure log level to the HTTP module

Use it for the "determine best masterserver" job, so that we can debug
failures.
This commit is contained in:
heinrich5991 2021-06-15 00:12:06 +02:00
parent df2f66626d
commit c5cd8d354d
5 changed files with 25 additions and 18 deletions

View file

@ -86,7 +86,7 @@ void EscapeUrl(char *pBuf, int Size, const char *pStr)
curl_free(pEsc);
}
CRequest::CRequest(const char *pUrl, CTimeout Timeout, bool LogProgress) :
CRequest::CRequest(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress) :
m_Timeout(Timeout),
m_Size(0),
m_Progress(0),
@ -153,19 +153,19 @@ int CRequest::RunImpl(CURL *pHandle)
return HTTP_ERROR;
}
if(g_Config.m_DbgCurl || m_LogProgress)
if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL)
dbg_msg("http", "fetching %s", m_aUrl);
m_State = HTTP_RUNNING;
int Ret = curl_easy_perform(pHandle);
if(Ret != CURLE_OK)
{
if(g_Config.m_DbgCurl || m_LogProgress)
dbg_msg("http", "task failed. libcurl error: %s", aErr);
if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::FAILURE)
dbg_msg("http", "%s failed. libcurl error: %s", m_aUrl, aErr);
return (Ret == CURLE_ABORTED_BY_CALLBACK) ? HTTP_ABORTED : HTTP_ERROR;
}
else
{
if(g_Config.m_DbgCurl || m_LogProgress)
if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL)
dbg_msg("http", "task done %s", m_aUrl);
return HTTP_DONE;
}
@ -186,7 +186,7 @@ int CRequest::ProgressCallback(void *pUser, double DlTotal, double DlCurr, doubl
return pTask->m_Abort ? -1 : 0;
}
CHead::CHead(const char *pUrl, CTimeout Timeout, bool LogProgress) :
CHead::CHead(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress) :
CRequest(pUrl, Timeout, LogProgress)
{
}
@ -202,7 +202,7 @@ bool CHead::AfterInit(void *pCurl)
return true;
}
CGet::CGet(const char *pUrl, CTimeout Timeout, bool LogProgress) :
CGet::CGet(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress) :
CRequest(pUrl, Timeout, LogProgress),
m_BufferSize(0),
m_BufferLength(0),
@ -275,7 +275,7 @@ size_t CGet::OnData(char *pData, size_t DataSize)
return DataSize;
}
CGetFile::CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, bool LogProgress) :
CGetFile::CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, HTTPLOG LogProgress) :
CRequest(pUrl, Timeout, LogProgress),
m_pStorage(pStorage),
m_File(0),

View file

@ -17,6 +17,13 @@ enum
HTTP_ABORTED,
};
enum class HTTPLOG
{
NONE,
FAILURE,
ALL,
};
struct CTimeout
{
long ConnectTimeoutMs;
@ -42,7 +49,7 @@ class CRequest : public IJob
double m_Size;
double m_Current;
int m_Progress;
bool m_LogProgress;
HTTPLOG m_LogProgress;
std::atomic<int> m_State;
std::atomic<bool> m_Abort;
@ -57,7 +64,7 @@ protected:
virtual int OnCompletion(int State) { return State; }
public:
CRequest(const char *pUrl, CTimeout Timeout, bool LogProgress = true);
CRequest(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress = HTTPLOG::ALL);
double Current() const { return m_Current; }
double Size() const { return m_Size; }
@ -72,7 +79,7 @@ class CHead : public CRequest
virtual bool AfterInit(void *pCurl);
public:
CHead(const char *pUrl, CTimeout Timeout, bool LogProgress = true);
CHead(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress = HTTPLOG::ALL);
~CHead();
};
@ -85,7 +92,7 @@ class CGet : public CRequest
unsigned char *m_pBuffer;
public:
CGet(const char *pUrl, CTimeout Timeout, bool LogProgress = true);
CGet(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress = HTTPLOG::ALL);
~CGet();
size_t ResultSize() const
@ -121,7 +128,7 @@ protected:
virtual int OnCompletion(int State);
public:
CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, bool LogProgress = true);
CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, HTTPLOG LogProgress = HTTPLOG::ALL);
const char *Dest() const { return m_aDest; }
};

View file

@ -137,14 +137,14 @@ void CChooseMaster::CJob::Run()
{
aTimeMs[i] = -1;
const char *pUrl = m_pData->m_aaUrls[aRandomized[i]];
CHead Head(pUrl, Timeout, false);
CHead Head(pUrl, Timeout, HTTPLOG::FAILURE);
IEngine::RunJobBlocking(&Head);
if(Head.State() != HTTP_DONE)
{
continue;
}
int64 StartTime = time_get();
CGet Get(pUrl, Timeout, false);
CGet Get(pUrl, Timeout, HTTPLOG::FAILURE);
IEngine::RunJobBlocking(&Get);
int Time = (time_get() - StartTime) * 1000 / time_freq();
if(Get.State() != HTTP_DONE)

View file

@ -41,7 +41,7 @@ int CSkins::CGetPngFile::OnCompletion(int State)
return State;
}
CSkins::CGetPngFile::CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, bool LogProgress) :
CSkins::CGetPngFile::CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, HTTPLOG LogProgress) :
CGetFile(pStorage, pUrl, pDest, StorageType, Timeout, LogProgress), m_pSkins(pSkins)
{
}
@ -420,7 +420,7 @@ int CSkins::FindImpl(const char *pName)
char aUrl[256];
str_format(aUrl, sizeof(aUrl), "%s%s.png", g_Config.m_ClSkinDownloadUrl, pName);
str_format(Skin.m_aPath, sizeof(Skin.m_aPath), "downloadedskins/%s.%d.tmp", pName, pid());
Skin.m_pTask = std::make_shared<CGetPngFile>(this, Storage(), aUrl, Skin.m_aPath, IStorage::TYPE_SAVE, CTimeout{0, 0, 0}, false);
Skin.m_pTask = std::make_shared<CGetPngFile>(this, Storage(), aUrl, Skin.m_aPath, IStorage::TYPE_SAVE, CTimeout{0, 0, 0}, HTTPLOG::NONE);
m_pClient->Engine()->AddJob(Skin.m_pTask);
m_aDownloadSkins.add(Skin);
return -1;

View file

@ -20,7 +20,7 @@ public:
virtual int OnCompletion(int State);
public:
CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, bool LogProgress = true);
CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, HTTPLOG LogProgress = HTTPLOG::ALL);
CImageInfo m_Info;
};