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

📄 connection.h

📁 模拟P2P各种网络环境的,适合新手们的学习,不错的源码.
💻 H
字号:
/*
 * Project		:	P2PSimulator
 *
 * File Name	:	Connection.h
 * 					high level directional connection between agent
 *
 * Author		:	Liu Jiang
 *
 * Date		:	2006-3-27
 *
 * Log		:
 */

#ifndef _Connection_h
#define _Connection_h
#define protect protected

#include "Common.h"

class Topology;
class Link;
class Agent;

class Connection;
ostream &operator<<(ostream &os, const Connection &connecion);

class Connection
{
protect:
	bool mActive; /* active connection or not */	
	bool mLock; /* mLock is true means the bandwidth reaches its limitation */
	
	Agent *mSource; /* source of the connection, ie initiator */
	Agent *mDestination; /* destination of the connection */
		
	vector< pair<bool, Link *> >mLink; /* all the links along the connection, including s-t link and virtual link */
	
	unsigned long mBandwidth; /* bandwidth consumed by this connection */
	unsigned long mBandwidthLock; /* bandwidth limited for this connection */

	static Topology *mTopology; /* single reference to topology */
	static set<Connection *> mConnection; /* all the connections in the system */
	static set<Link *> mLinkAdjust; /* when activate a connection, we put the influenced links in here waiting adjusting for convenience */

	unsigned long minAverageBandwidthA();
	unsigned long minAverageBandwidthB();
	unsigned long minAvailableBandwidth();
public:
	friend ostream &operator<<(ostream &os, const Connection &connection);
	Connection(Agent *agent1, Agent *agent2);
	virtual ~Connection();

	bool isActive();
	unsigned long getBandwidth();
	unsigned long getAvailableBandwidth(bool flag);
	static set<Connection *> getAllConnection();
	
	void addConnection();
	void removeConnection();

	void activate(unsigned long limit = UINT_MAX);
	void inactivate();
	
	virtual long long adjustBandwidth(long long value, bool internal = false);
	void reallocate();

	void check();
};

#endif

⌨️ 快捷键说明

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