00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _MYHANDLER_H
00023 #define _MYHANDLER_H
00024
00025 #include <map>
00026 #include <string>
00027 #include "MinderHandler.h"
00028 #include <libxml/tree.h>
00029 #include <vector>
00030 #include <stdint.h>
00031 #include <Utility.h>
00032 #include "Configuration.h"
00033 #include "key.h"
00034 #include "MyMinionSocket.h"
00035 #include "TrackerSock.h"
00036
00037
00038 class MyHandler : public MinderHandler
00039 {
00040 public:
00041 struct PEER {
00042 PEER(const std::string& id,const std::string& address,port_t p)
00043 :escaped_peer_id(id),ip(address),port(p)
00044 ,uploaded(0),downloaded(0),left(0)
00045 ,updated(true),completed(false),stopped(false)
00046 ,last_contact(time(NULL))
00047 {
00048 for (size_t i = 0; i < id.size(); i += 3)
00049 {
00050 int x;
00051 sscanf( (char *)id.substr(i + 1,2).c_str(),"%02X",&x);
00052 peer_id[i / 3] = x;
00053 }
00054 }
00055 void update(const std::string& u,const std::string& d,const std::string& l) {
00056 uploaded = Utility::atoi64(u);
00057 downloaded = Utility::atoi64(d);
00058 left = Utility::atoi64(l);
00059 updated = true;
00060 }
00061 void stop() {
00062 if (!stopped)
00063 updated = true;
00064 stopped = true;
00065 }
00066 void complete() {
00067 if (!completed)
00068 updated = true;
00069 completed = true;
00070 }
00071 std::string escaped_peer_id;
00072 unsigned char peer_id[20];
00073 std::string ip;
00074 port_t port;
00075 uint64_t uploaded;
00076 uint64_t downloaded;
00077 uint64_t left;
00078 bool updated;
00079 bool completed;
00080 bool stopped;
00081 time_t last_contact;
00082 };
00083 typedef std::vector<PEER *> peer_v;
00084 typedef std::map<std::string,peer_v> peer_m;
00085 public:
00086 MyHandler(const std::string& );
00087 ~MyHandler();
00088
00089 std::string GetVersion() {
00090
00091 return GetString("server/identity");
00092 }
00093 unsigned char *GetKey_m2minion() { return k1; }
00094
00095 int GetInt(const std::string& );
00096 std::string GetString(const std::string& );
00097 bool GetBoolean(const std::string& );
00098
00099 std::string escape(const std::string& );
00100
00101 PEER *reg_peer(const std::string& hash,
00102 const std::string& peer_id,
00103 const std::string& ip,
00104 port_t port);
00105
00106 void CreatePeers(TcpSocket *,const std::string& hash,size_t);
00107 void SendList();
00108 void CheckDropped();
00109 void SendInit(MyMinionSocket *);
00110 size_t MapSize();
00111 void HtmlReport(TrackerSock *);
00112
00113 private:
00114 Configuration m_config;
00115 peer_m m_peers;
00116 };
00117
00118
00119 #endif // _MYHANDLER_H