Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Geoffrey McRae authored
33 armt.cc
@@ -145,10 +145,8 @@ int main(int argc, char *argv[])
145 145 CCommon::Initialize(argc, argv);
146 146
147 147 /* DNS resolver must be setup next so the wrapper works */
148   - DNS.AddResolver("8.8.8.8" ); /* Google */
149   - DNS.AddResolver("8.8.4.4" ); /* Google */
150   - DNS.AddResolver("208.67.222.222"); /* OpenDNS */
151   - DNS.AddResolver("208.67.222.220"); /* OpenDNS */
  148 + DNS.AddResolver("8.8.8.8"); /* Google */
  149 + DNS.AddResolver("8.8.4.4"); /* Google */
152 150
153 151 std::string armthost;
154 152 unsigned int armtport;
@@ -169,9 +167,21 @@ int main(int argc, char *argv[])
169 167 return -1;
170 168 }
171 169
172   -
  170 + /* send an AUTH message to verify the remote host */
  171 + int result = 0;
173 172 CMessageBuilder msg(armthost, armtport);
174   - CScheduler s;
  173 + msg.AppendSegment("AUTH", NULL);
  174 + if (!msg.Send(result))
  175 + {
  176 + fprintf(stderr, "Failed to communicate with the ARMT server\n");
  177 + return -1;
  178 + }
  179 +
  180 + if (result != 202)
  181 + {
  182 + fprintf(stderr, "Failed to authenticate with the ARMT server\n");
  183 + return -1;
  184 + }
175 185
176 186 /* calculate the GMT time for midnight tonight in the server's timezone */
177 187 tzset();
@@ -180,7 +190,8 @@ int main(int argc, char *argv[])
180 190 midnight += 86400;
181 191 midnight += timezone - (daylight * 3600);
182 192
183   - /* add the jobs to the scheduler */
  193 + /* create and add the jobs to the scheduler */
  194 + CScheduler s;
184 195 s.AddJob(new CMSGJob(midnight , 86400, &msg, "FSCHECK" , &FSCHECK ));
185 196 s.AddJob(new CMSGJob(time(NULL), 60 , &msg, "DISKCHECK", &DISKCHECK));
186 197
@@ -188,7 +199,13 @@ int main(int argc, char *argv[])
188 199 {
189 200 msg.Reset();
190 201 if (s.Run())
191   - msg.Send();
  202 + {
  203 + result = 0;
  204 + if (!msg.Send(result))
  205 + fprintf(stderr, "Failed to communicate with the ARMT server\n");
  206 + else if (result != 202)
  207 + fprintf(stderr, "Error in communication with the ARMT server, result = %d\n", result);
  208 + }
192 209 sleep(1);
193 210 }
194 211
2  common/CHTTP.cc
@@ -203,7 +203,7 @@ bool CHTTP::Read(std::stringstream &buffer)
203 203 }
204 204 }
205 205
206   -bool CHTTP::PerformRequest(const char *method, const std::string &uri, uint16_t &error, HeaderMap &headers, std::string &body)
  206 +bool CHTTP::PerformRequest(const char *method, const std::string &uri, int &error, HeaderMap &headers, std::string &body)
207 207 {
208 208 error = 0;
209 209 headers.clear();
2  common/CHTTP.h
@@ -54,7 +54,7 @@ class CHTTP
54 54 * @param body This is input and output, input will be the body of the request, output will be the body of the reply
55 55 * @return True if valid HTTP communication was established with the server, not if error == 200.
56 56 */
57   - bool PerformRequest(const char *method, const std::string &uri, uint16_t &error, HeaderMap &headers, std::string &body);
  57 + bool PerformRequest(const char *method, const std::string &uri, int &error, HeaderMap &headers, std::string &body);
58 58
59 59 private:
60 60 bool m_connected;
13 common/CMessageBuilder.cc
@@ -191,7 +191,7 @@ void CMessageBuilder::PackString(std::ostream &ss, const std::string &value)
191 191 ss << value;
192 192 }
193 193
194   -bool CMessageBuilder::Send()
  194 +bool CMessageBuilder::Send(int &result)
195 195 {
196 196 std::string body;
197 197 {
@@ -204,7 +204,7 @@ bool CMessageBuilder::Send()
204 204
205 205 /* get the data */
206 206 std::stringstream ss;
207   - if (!segment->second(ss))
  207 + if (segment->second && !segment->second(ss))
208 208 continue;
209 209
210 210 uint32_t datalen = ss.tellp();
@@ -255,14 +255,11 @@ bool CMessageBuilder::Send()
255 255 m_http.SetHeader("Content-Length", CCommon::IntToStr(body.length()));
256 256
257 257 /* send the message */
258   - uint16_t error;
259 258 CHTTP::HeaderMap headers;
260   - if (!m_http.PerformRequest("POST", "/", error, headers, body))
  259 + if (!m_http.PerformRequest("POST", "/", result, headers, body))
261 260 return false;
262 261
263   - printf("%d\n", error);
264   - printf("%s\n", body.c_str());
265   -
266   - return error == 202;
  262 + /* return true as we performed the request, result code needs to be checked for 202 still however */
  263 + return true;
267 264 }
268 265
2  common/CMessageBuilder.h
@@ -45,7 +45,7 @@ class CMessageBuilder
45 45
46 46 void AppendSegment(const std::string &name, SegmentFn fn);
47 47 void Reset();
48   - bool Send();
  48 + bool Send(int &result);
49 49
50 50 static void PackString(std::ostream &ss, const std::string &value);
51 51 private:

0 comments on commit 31c8748

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