#include <MyTcpSocket.h>
Public Member Functions | |
MyTcpSocket (ISocketHandler &) | |
~MyTcpSocket () | |
void | InitSSLServer () |
Protected Member Functions | |
void | OnLine (const std::string &) |
Definition at line 33 of file MyTcpSocket.h.
|
Definition at line 49 of file MyTcpSocket.cpp.
00050 :TcpSocket(h)
00051 {
00052 SetLineProtocol(); // we want the OnLine callback
00053 }
|
|
Definition at line 56 of file MyTcpSocket.cpp.
00057 { 00058 } |
|
Definition at line 150 of file MyTcpSocket.cpp.
00151 { 00152 InitializeContext("comb.pem",""); 00153 } |
|
Definition at line 61 of file MyTcpSocket.cpp.
00062 { 00063 std::string cmd; 00064 std::string app; 00065 std::string id; 00066 std::string host; 00067 Parse pa(Utility::base64d(line),"_:"); 00068 pa.getword(cmd); // 'Hello' / 'Goodbye' 00069 app = Utility::base64d(pa.getword()); 00070 pa.getword(id); 00071 pa.getword(host); // host 00072 port_t port = pa.getvalue(); 00073 unsigned long hid_from_host = pa.getvalue(); 00074 long extra_info = pa.getvalue(); 00075 00076 if (cmd != "Hello" && cmd != "Goodbye") 00077 { 00078 SetCloseAndDelete(true); 00079 return; 00080 } 00081 00082 // get ip sent to us by the minion 00083 ipaddr_t ip; 00084 Utility::u2ip(host,ip); 00085 00086 // we ignore whatever ip the minion sends us 00087 // we only use the ip from the connection endpoint 00088 ipaddr_t ip2 = GetRemoteIP4(); 00089 DEB( printf("Incoming: id '%s' %s:%d cmd '%s'\n",id.c_str(),GetRemoteAddress().c_str(),port,cmd.c_str());) 00090 if (cmd == "Goodbye") 00091 { 00092 static_cast<MyHandler&>(Handler()).unreg_host(app, id, ip2, port, ip); 00093 SetCloseAndDelete(true); 00094 return; 00095 } 00096 unsigned long host_id = 0; 00097 HOST *h = static_cast<MyHandler&>(Handler()).reg_host(app, id, ip2, port, ip, host_id, hid_from_host); 00098 h -> extra_information = extra_info; 00099 { 00100 std::string str; 00101 std::string msg; 00102 std::string ipstr; 00103 00104 str = "You_" + id + ":" + GetRemoteAddress() + ":" + Utility::l2string(port) + ":" + Utility::l2string(host_id); 00105 msg = Utility::base64(str) + "\n"; 00106 00107 if (config[app + "/dbname"].size()) 00108 { 00109 str = "Database_" + config[app + "/dbname"]; 00110 msg += Utility::base64(str) + "\n"; 00111 } 00112 00113 if (config[app + "/update_host"].size() && 00114 config[app + "/update_port"].size() && 00115 config[app + "/update_url"].size() ) 00116 { 00117 str = "Update_" + config[app + "/update_host"]; 00118 str += ":" + config[app + "/update_port"]; 00119 str += ":" + config[app + "/update_url"]; 00120 msg += Utility::base64(str) + "\n"; 00121 } 00122 00123 static_cast<MyHandler&>(Handler()).reset_sent(app); 00124 for (int i = 0; i < 20; i++) 00125 { 00126 HOST *p = static_cast<MyHandler&>(Handler()).GetRandomHOST(app); 00127 if (!p -> sent) 00128 { 00129 Utility::l2ip(p -> ip,ipstr); 00130 str = "Minion_" + p -> id + ":" + ipstr + ":" + Utility::l2string(p -> port); 00131 str += ":" + Utility::l2string(p -> host_id); 00132 msg += Utility::base64(str) + "\n"; 00133 p -> sent = true; 00134 } 00135 } 00136 msg += Utility::base64("End") + "\n"; 00137 Send(msg); 00138 } 00139 00140 if (app == "viawww" && !h -> connectable) // try again 00141 { 00142 TestSocket *t = new TestSocket(Handler(),h -> connectable); 00143 t -> Open(ip2, h -> extra_information); 00144 t -> SetDeleteByHandler(); 00145 Handler().Add(t); 00146 } 00147 } |