⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bttracker.h

📁 模拟P2P各种网络环境的,适合新手们的学习,不错的源码.
💻 H
字号:
#ifndef __BTTRACKER_H__
#define __BTTRACKER_H__
#include <list>
#include <string>
#include <iostream>
#include <map>
#include<vector>
#include "Agent.h"
using namespace std;
class BTEvent;
class BTTorrent;
class BTPeer;
class BTTracker: public Agent{
typedef struct{
	BTTorrent* mTorrent;
	vector<BTPeer*> mPeerList;
	unsigned int mDownloadTimes;
	vector<BTPeer*> mComPeerList;
	bool		    mEspWork;
}BTDocRecord;

	public:
		map<string, BTDocRecord*>	 mDocDB;
		vector<BTTorrent*>	mDocList;
		
	public:
		BTTracker(void){
			mDocDB.clear();
			mDocList.clear();
	      };
		BTTracker(int i):Agent(i){
			mDocDB.clear();
			mDocList.clear();
		};
		~BTTracker(void);

		BTTorrent* getTTorrent(string key);
		BTTorrent* getRandomTorrent(void);
		bool addTorrent(BTTorrent* tt);
		bool addNodeAssociateWithDoc(string key, BTPeer* peer);
		bool addComNode( string , BTPeer*);
		unsigned int getComNum( string );
		void handler(SimEvent*);
		void handleGetRequest(BTEvent*);
		unsigned int getDocDownloadSize(string key){
			map<string, BTDocRecord*>::iterator aIt = mDocDB.find( key );
			if( aIt == mDocDB.end())
				return 0;
			else
				return aIt->second->mPeerList.size();

		}
		unsigned int getDocDownloadNum(string key){
			map<string, BTDocRecord*>::iterator aIt = mDocDB.find( key );
			if( aIt == mDocDB.end())
				return 0;
			else
				return aIt->second->mDownloadTimes;
		};
		void sendEspRetire( string );
		void sendEspRecover( string );
		bool ifEspRetire( string);
		unsigned int getPeerNumSince( string, float);
		void setEspSate(string, bool);
		string toString(void);
private: 
		list<BTPeer*>* selectPeers( BTDocRecord*);

};
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -