Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Numerous changes to improve reliability of connection to server

[ARMT] Added communication check before entering loop
[HTTP] Added return of HTTP response code for checking
[DNS] Removed OpenDNS as it returns false records for non-existing domains
  • Loading branch information...
commit 31c874888c45738903cde661f40b64d293068231 1 parent a3159fa
@gnif authored
View
33 armt.cc
@@ -145,10 +145,8 @@ int main(int argc, char *argv[])
CCommon::Initialize(argc, argv);
/* DNS resolver must be setup next so the wrapper works */
- DNS.AddResolver("8.8.8.8" ); /* Google */
- DNS.AddResolver("8.8.4.4" ); /* Google */
- DNS.AddResolver("208.67.222.222"); /* OpenDNS */
- DNS.AddResolver("208.67.222.220"); /* OpenDNS */
+ DNS.AddResolver("8.8.8.8"); /* Google */
+ DNS.AddResolver("8.8.4.4"); /* Google */
std::string armthost;
unsigned int armtport;
@@ -169,9 +167,21 @@ int main(int argc, char *argv[])
return -1;
}
-
+ /* send an AUTH message to verify the remote host */
+ int result = 0;
CMessageBuilder msg(armthost, armtport);
- CScheduler s;
+ msg.AppendSegment("AUTH", NULL);
+ if (!msg.Send(result))
+ {
+ fprintf(stderr, "Failed to communicate with the ARMT server\n");
+ return -1;
+ }
+
+ if (result != 202)
+ {
+ fprintf(stderr, "Failed to authenticate with the ARMT server\n");
+ return -1;
+ }
/* calculate the GMT time for midnight tonight in the server's timezone */
tzset();
@@ -180,7 +190,8 @@ int main(int argc, char *argv[])
midnight += 86400;
midnight += timezone - (daylight * 3600);
- /* add the jobs to the scheduler */
+ /* create and add the jobs to the scheduler */
+ CScheduler s;
s.AddJob(new CMSGJob(midnight , 86400, &msg, "FSCHECK" , &FSCHECK ));
s.AddJob(new CMSGJob(time(NULL), 60 , &msg, "DISKCHECK", &DISKCHECK));
@@ -188,7 +199,13 @@ int main(int argc, char *argv[])
{
msg.Reset();
if (s.Run())
- msg.Send();
+ {
+ result = 0;
+ if (!msg.Send(result))
+ fprintf(stderr, "Failed to communicate with the ARMT server\n");
+ else if (result != 202)
+ fprintf(stderr, "Error in communication with the ARMT server, result = %d\n", result);
+ }
sleep(1);
}
View
2  common/CHTTP.cc
@@ -203,7 +203,7 @@ bool CHTTP::Read(std::stringstream &buffer)
}
}
-bool CHTTP::PerformRequest(const char *method, const std::string &uri, uint16_t &error, HeaderMap &headers, std::string &body)
+bool CHTTP::PerformRequest(const char *method, const std::string &uri, int &error, HeaderMap &headers, std::string &body)
{
error = 0;
headers.clear();
View
2  common/CHTTP.h
@@ -54,7 +54,7 @@ class CHTTP
* @param body This is input and output, input will be the body of the request, output will be the body of the reply
* @return True if valid HTTP communication was established with the server, not if error == 200.
*/
- bool PerformRequest(const char *method, const std::string &uri, uint16_t &error, HeaderMap &headers, std::string &body);
+ bool PerformRequest(const char *method, const std::string &uri, int &error, HeaderMap &headers, std::string &body);
private:
bool m_connected;
View
13 common/CMessageBuilder.cc
@@ -191,7 +191,7 @@ void CMessageBuilder::PackString(std::ostream &ss, const std::string &value)
ss << value;
}
-bool CMessageBuilder::Send()
+bool CMessageBuilder::Send(int &result)
{
std::string body;
{
@@ -204,7 +204,7 @@ bool CMessageBuilder::Send()
/* get the data */
std::stringstream ss;
- if (!segment->second(ss))
+ if (segment->second && !segment->second(ss))
continue;
uint32_t datalen = ss.tellp();
@@ -255,14 +255,11 @@ bool CMessageBuilder::Send()
m_http.SetHeader("Content-Length", CCommon::IntToStr(body.length()));
/* send the message */
- uint16_t error;
CHTTP::HeaderMap headers;
- if (!m_http.PerformRequest("POST", "/", error, headers, body))
+ if (!m_http.PerformRequest("POST", "/", result, headers, body))
return false;
- printf("%d\n", error);
- printf("%s\n", body.c_str());
-
- return error == 202;
+ /* return true as we performed the request, result code needs to be checked for 202 still however */
+ return true;
}
View
2  common/CMessageBuilder.h
@@ -45,7 +45,7 @@ class CMessageBuilder
void AppendSegment(const std::string &name, SegmentFn fn);
void Reset();
- bool Send();
+ bool Send(int &result);
static void PackString(std::ostream &ss, const std::string &value);
private:

0 comments on commit 31c8748

Please sign in to comment.
Something went wrong with that request. Please try again.