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

📄 btpeermessage.java

📁 p2p仿真
💻 JAVA
字号:
/*
 * @(#)BTPeerMessage.java	ver 1.2  6/20/2005
 *
 * Copyright 2005 Weishuai Yang (wyang@cs.binghamton.edu). 
 * All rights reserved.
 * 
 */

package gps.protocol.BT.param;
import gps.protocol.BT.BTSocket;

/**
 * includes message contents between peers.
 * 
 * @author  Weishuai Yang
 * @version 1.2,  6/20/2005
 */
public class BTPeerMessage {
	/**
	 * choke
	 */
	public static final int CHOKE=0;
	/**
	 * unchoke
	 */
	public static final int UNCHOKE=1;
	/**
	 * interested
	 */
	public static final int INTERESTED=2;
	/**
	 * not interested
	 */
	public static final int NOT_INTERESTED=3;
	/**
	 * finished downloading a piece
	 */
	public static final int HAVE=4;
	/**
	 * bit field
	 */
	public static final int BITFIELD=5;
	/**
	 * request a block
	 */
	public static final int REQUEST=6;
	/**
	 * sending a block in a piece
	 */
	public static final int PIECE=7;
	/**
	 * cancel a request
	 */
	public static final int CANCEL=8;
	/**
	 * keep alive
	 */
	public static final int KEEP_ALIVE=9;
	/**
	 * hand shaking
	 */
	public static final int HAND_SHAKING=10;
	/**
	 * document hash key
	 */
	public String mDocHashKey=null;	
	/**
	 * bit field
	 */
	public boolean mBitfield[]=null;
	/**
	 * piece index
	 */
	public int mIndex=0;
		
	/**
	 * byte offset within the indexed piece to begin with
	 */
	public int mBegin=0;
	/**
	 * byte length
	 */
	public int mLength=0;
	/**
	 * message type
	 */
	public int mType=-1;
	
	/** 
	 * add an additional mInterested here only for simplicity
	 * when a handshaking is sent, bitfield is also sent,
	 * interested or not is piggybacked in the replying bitfield
	 * using this additional field.
	 */
	
	public boolean mInterested=false;
	
	/** 
	 * only used in the bitfiled message to 
	 * set up connections to each other
	 */
	public BTSocket mConnection=null;
	
	/** 
	 * add an additional mDownloadBandwidth to cooperate with the 
	 * PIECE message to let the downloader know the bandwidth.
	 */
	public double mDownloadBandwidth=0;
	/**
	 * dummy constructor
	 *
	 */
	public BTPeerMessage(){}
	/**
	 * constructs a message of a type
	 * @param t type
	 */
	public BTPeerMessage(int t){mType = t;}
	
	/**
	 * gets string description of message
	 * @return string description
	 */
	public String messageToString(){
		switch(mType){
			case CHOKE: return "CHOKE";
			case UNCHOKE: return "UNCHOKE";
			case INTERESTED: return "INTERESTED";
			case NOT_INTERESTED: return "NOT_INTERESTED";
			case HAVE: return "HAVE";
			case BITFIELD: return "BITFIELD";
			case REQUEST: return "REQUEST";
			case PIECE: return "PIECE";
			case CANCEL: return "CANCEL";
			case KEEP_ALIVE: return "KEEP_ALIVE";
			case HAND_SHAKING: return "HAND_SHAKING";
		}
		return "UNKNOWN";
	}
	/**
	 * gets string description of message
	 * @return string description
	 */
	public String toString(){
		return messageToString();
	}
}

⌨️ 快捷键说明

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