PeerSim进行BitTorrent仿真(二)—— BitTorrent变量
程序员文章站
2022-03-04 23:28:28
...
public class BitTorrent implements EDProtocol {
/**
* 配置文件中读取的文件大小
* @config
*/
private static final String PAR_SIZE="file_size";
/**
* The Transport used by the the protocol.
* @config
*/
private static final String PAR_TRANSPORT="transport";
/**
* 配置文件中读取一个节点虽多能拥有的邻居数
* @config
*/
private static final String PAR_SWARM="max_swarm_size";
/**
* tracker向普通节点返回的一个子集,用于交换bitfield成为邻居
* @config
*/
private static final String PAR_PEERSET_SIZE="peerset_size";
/**
* 当前网络最多能动态增加的节点数
* @config
*/
private static final String PAR_MAX_GROWTH="max_growth";
/**
* 单个request能向多少个节点同时发送
* @config
*/
private static final String PAR_DUP_REQ = "duplicated_requests";
/**
* KEEP_ALIVE message.
* @see SimpleEvent#type "Event types"
*/
private static final int KEEP_ALIVE = 1;
/**
* CHOKE message.
* @see SimpleEvent#type "Event types"
*/
private static final int CHOKE = 2;
/**
* UNCHOKE message.
* @see SimpleEvent#type "Event types"
*/
private static final int UNCHOKE = 3;
/**
* INTERESTED message.
* @see SimpleEvent#type "Event types"
*/
private static final int INTERESTED = 4;
/**
* NOT_INTERESTED message.
* @see SimpleEvent#type "Event types"
*/
private static final int NOT_INTERESTED = 5;
/**
* HAVE message.
* @see SimpleEvent#type "Event types"
*/
private static final int HAVE = 6;
/**
* BITFIELD message.
* @see SimpleEvent#type "Event types"
*/
private static final int BITFIELD = 7;
/**
* REQUEST message.
* @see SimpleEvent#type "Event types"
*/
private static final int REQUEST = 8;
/**
* PIECE message.
* @see SimpleEvent#type "Event types"
*/
private static final int PIECE = 9;
/**
* CANCEL message.
* @see SimpleEvent#type "Event types"
*/
private static final int CANCEL = 10;
/**
* TRACKER message.
* @see SimpleEvent#type "Event types"
*/
private static final int TRACKER = 11;
/**
* PEERSET message.
* @see SimpleEvent#type "Event types"
*/
private static final int PEERSET = 12;
/**
* CHOKE_TIME event.
* @see SimpleEvent#type "Event types"
*/
private static final int CHOKE_TIME = 13;
/**
* OPTUNCHK_TIME event.
* @see SimpleEvent#type "Event types"
*/
private static final int OPTUNCHK_TIME = 14;
/**
* ANTISNUB_TIME event.
* @see SimpleEvent#type "Event types"
*/
private static final int ANTISNUB_TIME = 15;
/**
* CHECKALIVE_TIME event.
* @see SimpleEvent#type "Event types"
*/
private static final int CHECKALIVE_TIME = 16;
/**
* TRACKERALIVE_TIME event.
* @see SimpleEvent#type "Event types"
*/
private static final int TRACKERALIVE_TIME = 17;
/**
* DOWNLOAD_COMPLETED event.
* @see SimpleEvent#type "Event types"
*/
private static final int DOWNLOAD_COMPLETED = 18;
/**
* 最大带宽
*/
int maxBandwidth;
/**
* 通过节点ID存储的邻居数组
* @see Element
*/
private Element byPeer[];
/**
* 通过带宽排序的邻居数组,用于判断unchoke
*/
private Element byBandwidth[];
/**
* The Neighbors list.
*/
private Neighbor cache[];
/**
* 记录对子集unchoke的节点
*/
private boolean unchokedBy[];
/**
* cache中的邻居节点数
*/
private int nNodes = 0;
/**
* 网络中的最大节点数
*/
private int nMaxNodes;
/**
* 本地节点状态:是否为seed. 0 means that the current peer is a leecher, 1 a seeder.
*/
private int peerStatus;
/**
* Defines how much the network can grow with respect to the <tt>network.size</tt>
* when {@link NetworkDynamics} is used.
*/
public int maxGrowth;
/**
* File status of the local node. Contains the blocks owned by the local node.
*/
private int status[];
/**
* 向多少个节点发送了BitField消息
*/
private int nBitfieldSent = 0;
/**
* 当前正在上传的Piece数
*/
public int nPiecesUp = 0;
/**
* 正在下载的Piece数
*/
public int nPiecesDown = 0;
/**
* 当前完成下载的Piece数
*/
private int nPieceCompleted = 0;
/**
* 正在下载哪个Piece。 the previous lastInterested piece.
*/
int currentPiece = -1;
/**
* Used to compute the average download rates in choking algorithm. Stores the
* number of <tt>CHOKE</tt> events.
* 记录被choke的次数,用于计算平均下载速率。
*/
int n_choke_time = 0;
/**
* Used to send the <tt>TRACKER</tt> message when the local node has 20 neighbors
* for the first time.
*/
boolean lock = false;
/**
* Number of peers interested to my pieces.
* 对自己interest的节点数
*/
int numInterestedPeers = 0;
/**
* Last piece for which the local node sent an <tt>INTERESTED</tt> message.
* 本节点上一个感兴趣的Piece
*/
int lastInterested = -1;
/**
* 存储本Piece的block状态。均为1的时候说明整个Piece下载完成
*/
private int pieceStatus[];
/**
* 当前File有多少个Piece
*/
int nPieces;
/**
* 相当于neighbor的Piece状态:BitField消息
*/
int [][]swarm;
/**
* local rarest piece
*/
int rarestPieceSet[];
/**
* 五个待解决的block请求.
*/
int pendingRequest[];
/**
* 邻居列表最多多少个
*/
int swarmSize;
/**
* peerset大小
*/
int peersetSize;
/**
* 当前nodeId
*/
private long thisNodeID;
/**
* 同时向多少个节点发送request
* @see BitTorrent#PAR_DUP_REQ
*/
private int numberOfDuplicatedRequests;
/**
* T向自己发送过的请求队列
*/
Queue requestToServe = null;
/**
* 等待处理的Pieces
*/
Queue incomingPieces = null;
/**
* The Transport ID.
* @see BitTorrent#PAR_TRANSPORT
*/
int tid;
/**
* The reference to the tracker node. If equals to <tt>null</tt>, the local
* node is the tracker.
*/
private Node tracker = null;
上一篇: P2P网络概念的背景和基础认识
下一篇: android image文件编译