00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _MINION_MinderHandler_H
00024 #define _MINION_MinderHandler_H
00025 #include "sockets-config.h"
00026 #ifdef HAVE_OPENSSL
00027
00028
00029
00030 #include "SocketHandler.h"
00031 #include "MinionSocket.h"
00032
00033 #include "Base64.h"
00034
00035 #ifdef SOCKETS_NAMESPACE
00036 namespace SOCKETS_NAMESPACE {
00037 #endif
00038
00039
00040 class MinderSocket;
00041
00045 class MinderHandler : public SocketHandler
00046 {
00049 struct SEEN {
00050 SEEN(unsigned long l1,unsigned long l2) : m_hid(l1),m_mid(l2),m_t(time(NULL)) {}
00051 bool Eq(unsigned long l1,unsigned long l2) {
00052 return l1 == m_hid && l2 == m_mid;
00053 }
00054 unsigned long m_hid;
00055 unsigned long m_mid;
00056 bool m_temp;
00057 time_t m_t;
00058 };
00059 typedef std::vector<SEEN *> seen_v;
00061 struct STORE {
00062 STORE(long x,long y,const std::string& msg) : m_hid(x),m_mid(y),m_message(msg),m_t(time(NULL)) {}
00063 long m_hid;
00064 long m_mid;
00065 std::string m_message;
00066 time_t m_t;
00067 };
00068 typedef std::vector<STORE *> store_v;
00071 struct HOSTS {
00072 HOSTS(ipaddr_t a,port_t p,const std::string& k,long r) : ip(a),port(p),key(k),remote_host_id(r) {}
00073 ipaddr_t ip;
00074 port_t port;
00075 std::string key;
00076 long remote_host_id;
00077 };
00078 typedef std::vector<HOSTS *> hosts_v;
00079 public:
00080 MinderHandler();
00081 ~MinderHandler();
00082
00083 void GenerateID();
00084 const std::string& GetID();
00085
00086 void SetExternalAddress(const std::string& str) { m_external_ip = str; }
00087 void SetLocalPort(port_t s) { m_local_port = s; }
00088 port_t GetLocalPort() { return m_local_port; }
00089
00090 void SetHostId(unsigned long id) { m_host_id = id; }
00091 unsigned long GetHostId() { return m_host_id; }
00092
00093 void SendMessage(const std::string&,short ttl = 30);
00094 void SendMessage(const std::string&,const std::string&,short,const std::string&,std::list<std::string>&,ulong_v&);
00095
00096 bool Seen(unsigned long,unsigned long,bool = false);
00097
00098 void SendConnectList();
00099
00100 void KeepAlive();
00101
00102
00103 bool MinderSockets();
00104 bool FindMinion(const std::string& );
00105 int Count();
00106
00107 void Store(long,long,const std::string& );
00108 bool StoreGet(long,long,std::string& );
00109
00110 void SetDebug(bool x = true) { m_bDebug = x; }
00111 bool Debug() { return m_bDebug; }
00112
00113 void AddHost(ipaddr_t,port_t,const std::string&,long);
00114 bool GetHost(ipaddr_t&,port_t&,std::string&,long&);
00115 void SetMyIpPort(ipaddr_t a,port_t p) { my_ip = a; my_port = p; }
00116 void GetMyIpPort(ipaddr_t& a,port_t& p) { a = my_ip; p = my_port; }
00117
00118 void SendTop(const std::string& );
00119 void Tops(FILE *);
00120
00121 time_t GetMinderTime() { return m_tMinder; }
00122 void SetMinderTime(time_t x) { m_tMinder = x; }
00123
00124 virtual std::string GetVersion() = 0;
00125 virtual unsigned char *GetKey_m2minion() = 0;
00126
00127 protected:
00128 Base64 m_b;
00129
00130 private:
00131 MinderHandler(const MinderHandler& ) {}
00132 MinderHandler& operator=(const MinderHandler& ) { return *this; }
00133 std::string m_id;
00134 std::string m_external_ip;
00135 unsigned long m_message_id;
00136 port_t m_local_port;
00137 unsigned long m_host_id;
00138 seen_v m_seen;
00139 store_v m_store;
00140 bool m_bDebug;
00141 hosts_v m_hosts;
00142 ipaddr_t my_ip;
00143 port_t my_port;
00144 time_t m_tMinder;
00145 };
00146
00147
00148
00149 #ifdef SOCKETS_NAMESPACE
00150 }
00151 #endif
00152
00153 #endif // HAVE_OPENSSL
00154 #endif // _MINION_MinderHandler_H