#include <MyHandler.h>
Public Member Functions | |
| MyHandler () | |
| ~MyHandler () | |
| void | CheckTimeout () |
| HOST * | reg_host (const std::string &map, const std::string &, ipaddr_t, port_t, ipaddr_t, unsigned long &, long) |
| void | unreg_host (const std::string &map, const std::string &, ipaddr_t, port_t, ipaddr_t) |
| HOST * | GetRandomHOST (const std::string &map, bool must_be_connectable=false) |
| void | reset_sent (const std::string &map) |
| void | ViewHosts () |
Private Attributes | |
| app_m | m_app |
|
|
Definition at line 41 of file MyHandler.cpp.
00042 :SocketHandler()
00043 {
00044 }
|
|
|
Definition at line 47 of file MyHandler.cpp.
00048 {
00049 }
|
|
|
Definition at line 52 of file MyHandler.cpp. References m_app, and unreg_host(). Referenced by main().
00053 {
00054 bool ok = true;
00055 for (app_m::iterator it = m_app.begin(); it != m_app.end() && ok; it++)
00056 for (host_v::iterator i2 = (*it).second.begin(); i2 != (*it).second.end() && ok; i2++)
00057 {
00058 HOST *p = *i2;
00059 if (p)
00060 {
00061 if (time(NULL) - p -> t > 15 * 60 + 10)
00062 {
00063 unreg_host( (*it).first, p -> id,p -> ip,p -> port,p -> ip);
00064 ok = false;
00065 }
00066 }
00067 }
00068 }
|
|
||||||||||||
|
Definition at line 119 of file MyHandler.cpp. References m_app.
00120 {
00121 if (must)
00122 {
00123 int q = 0;
00124 for (host_v::iterator it = m_app[app].begin(); it != m_app[app].end(); it++)
00125 {
00126 HOST *p = *it;
00127 if (p -> connectable)
00128 {
00129 q++;
00130 break;
00131 }
00132 }
00133 if (q)
00134 {
00135 #ifdef _WIN32
00136 int x = rand() % m_app[app].size();
00137 #else
00138 int x = random() % m_app[app].size();
00139 #endif
00140 HOST *p = m_app[app][x];
00141 while (!p -> connectable)
00142 {
00143 #ifdef _WIN32
00144 x = rand() % m_app[app].size();
00145 #else
00146 x = random() % m_app[app].size();
00147 #endif
00148 p = m_app[app][x];
00149 }
00150 return p;
00151 }
00152 }
00153 else
00154 {
00155 if (m_app[app].size())
00156 {
00157 #ifdef _WIN32
00158 return m_app[app][rand() % m_app[app].size()];
00159 #else
00160 return m_app[app][random() % m_app[app].size()];
00161 #endif
00162 }
00163 }
00164 return NULL;
00165 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 71 of file MyHandler.cpp. References config, m_app, ViewHosts(), and write_config().
00072 {
00073 for (host_v::iterator it = m_app[app].begin(); it != m_app[app].end(); it++)
00074 {
00075 HOST *p = *it;
00076 if (!strcmp(id.c_str(),p -> id.c_str()) && p -> ip == ip && p -> port == port)
00077 {
00078 hostid = p -> host_id;
00079 p -> t = time(NULL);
00080 return p;
00081 }
00082 }
00083 HOST *p = new HOST(id,ip,port);
00084 if (hid_from_host)
00085 {
00086 p -> host_id = hostid = hid_from_host;
00087 }
00088 else
00089 {
00090 p -> host_id = hostid = atol(config["next_host_id"].c_str()); //m_host_id++;
00091 config["next_host_id"] = Utility::l2string(hostid + 1);
00092 write_config();
00093 }
00094 p -> t = time(NULL);
00095 if (ip != ip_minion)
00096 p -> behind_firewall = true;
00097 m_app[app].push_back(p);
00098 ViewHosts();
00099 return p;
00100 }
|
|
|
Definition at line 168 of file MyHandler.cpp. References m_app.
|
|
||||||||||||||||||||||||
|
Definition at line 103 of file MyHandler.cpp. References m_app, and ViewHosts(). Referenced by CheckTimeout().
00104 {
00105 for (host_v::iterator it = m_app[app].begin(); it != m_app[app].end(); it++)
00106 {
00107 HOST *p = *it;
00108 if (!strcmp(id.c_str(),p -> id.c_str()) && p -> ip == ip && p -> port == port)
00109 {
00110 delete p;
00111 m_app[app].erase(it);
00112 ViewHosts();
00113 break;
00114 }
00115 }
00116 }
|
|
|
Definition at line 180 of file MyHandler.cpp. Referenced by reg_host(), and unreg_host().
00181 {
00182 DEB( printf("Current minion list\n");)
00183 for (app_m::iterator it = m_app.begin(); it != m_app.end(); it++)
00184 {
00185 DEB( printf(" %s\n",(*it).first.c_str());)
00186 for (host_v::iterator i2 = (*it).second.begin(); i2 != (*it).second.end(); i2++)
00187 {
00188 HOST *p = *i2;
00189 DEB( printf(" %ld %08x:%d %s%s%s\n",
00190 p -> host_id,p -> ip,p -> port,p -> id.c_str(),
00191 p -> behind_firewall ? " (nat)" : "",
00192 p -> connectable ? " Connectable" : "");)
00193 }
00194 }
00195 }
|
|
|
Definition at line 69 of file MyHandler.h. Referenced by CheckTimeout(), GetRandomHOST(), reg_host(), reset_sent(), unreg_host(), and ViewHosts(). |
1.3.6