www.pudn.com > mysee.zip > Protocol.h


/* 
 *  Openmysee 
 * 
 *  This program is free software; you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation; either version 2 of the License, or 
 *  (at your option) any later version. 
 * 
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 * 
 *  You should have received a copy of the GNU General Public License 
 *  along with this program; if not, write to the Free Software 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 * 
 */ 
 
// 协议的说明和定义 
 
#ifndef __PROTOCOL_DEFINE_H__ 
#define __PROTOCOL_DEFINE_H__ 
 
// Capture Server = CS; Super Peer = SP; Cache Peer = CP;  
// Tracker Server = TS; Normal Peer = NP; 
 
// 所有不传输Block的连接都基于UDP 
// CP<------UDP------>TS 
// NP<------UDP------>TS 
// 所有传输Block的连接都基于TCP 
// CS<------TCP------>SP 
// SP<------TCP------>CP 
// CP<------TCP------>NP 
// NP<------TCP------>NP 
 
// 协议格式,新的协议的目标是更加精炼,更加安全 
// |msg size(UINT32)|msg type(BYTE)|msg content(...)| 
// |<-----------msg size是全部数据的长度----------->| 
// 注意小写的bool值,大小是一个字节 
 
// **************************************************************************** 
// **************************************************************************** 
enum CSandSP { 
// |size of channel name(UINT8)|channel name(...)| 
// |userid(UINT32)|md5 password(MD5_LEN)| 
// |max blocksize(UINT32)|channel bitRate(float)| 
// |size of CHANNEL DATA(UINT16)|CHANNEL DATA(...)| 
CS2SP_REGISTER    = 0, // 注册到SP 
// |channel bitRate(float)| 
CS2SP_UPDATE      = 1, // 发送更新给SP 
// |block id(UINT32)|block size(UINT32)| 
// |block data(...)| 
CS2SP_BLOCK       = 2, // 发送一个block到SP 
// |media data length(UINT32)媒体数据长度|media data媒体数据(...)| 
CS2SP_MEDIA_TYPE  = 3, // 发送新的编码类型 
 
// |start block ID(UINT32)| 
SP2CS_WELCOME     = 100, // 让CS从某个块开始发送,因为可能是续传 
// |err msg type(UINT16)|should quit(bool)| 
SP2CS_MSG         = 101, // 发送(错误)消息 
}; 
// **************************************************************************** 
// **************************************************************************** 
enum CPandTS { 
// |userID(UINT32)|md5 password(MD5_LEN)|port for NP(USHORT)| 
// |type(UINT8)|type param(...)| // see CP_TYPE 
CP2TS_REGISTER    = 0, // 注册到TS 
// |---CHECK DIGITS(7 BYTEs)---| 
// |resource number(UINT32)|connection number(UINT16)|bandwidth usage(float)| 
// |exceed max connection(bool)| 
CP2TS_UPDATE      = 1, // 统计信息 
// |---CHECK DIGITS(7 BYTEs)---|RESOURCE MD5(MD5_LEN)| 
CP2TS_NEED_PEERS  = 2, // ECP发送。请求GCP和一些接近GCP的Peer地址 
// |---CHECK DIGITS(7 BYTEs)---| 
CP2TS_LOGOUT      = 3, // 退出登录 
 
// |---CHECK DIGITS(7 BYTEs)---| 
TS2CP_WELCOME     = 100, // 返回校验码 
// |RESOURCE MD5(32)|CP list size(UINT8)|first CP addr(NormalAddress)| 
// |peer list size(UINT8)|peer1(PeerInfoWithAddr)|...| 
TS2CP_PEERS       = 101, // 返回GCP和一些接近GCP的Peer地址给ECP 
// |err msg type(UINT16)|should quit(bool)| 
TS2CP_MSG         = 102, // 发送(错误)消息 
}; 
// **************************************************************************** 
// **************************************************************************** 
enum NPandTS { 
// |login id(UINT32)|md5 password(MD5_LEN)| 
// |version of client(float)|listening port(USHORT)| 
// |size of local ip list(UINT8)|first ip addr(in_addr)|...| 
NP2TS_LOGIN       = 0, // 登录,提交本机全部IP,让TS判断 
// |---CHECK DIGITS(7 BYTEs)---| 
// |resource list size(UINT8)| 
// |RESOURCE MD5(MD5_LEN)|Interval count(UINT8)|first BlockInterval|...| 
NP2TS_RES_LIST    = 1, // NP上所有资源的列表 
// |---CHECK DIGITS(7 BYTEs)---| 
// |RESOURCE MD5(MD5_LEN)|Interval count(UINT8)|first BlockInterval|...| 
// |current block(UINT32)|need CP(bool)| 
NP2TS_REQ_RES     = 2, // 加入一个资源 
// |---CHECK DIGITS(7 BYTEs)---|RESOURCE MD5(MD5_LEN)| 
NP2TS_DEL_RES     = 3, // 删除一个资源 
// |---CHECK DIGITS(7 BYTEs)---| 
// |info of peer(CorePeerInfo)|refresh(bool)| 
// |Interval count(UINT8)|first BlockInterval|...| 
// |Transfer Info(TransferInfo)| 
NP2TS_REPORT      = 4, // 报告自身状况 
// |---CHECK DIGITS(7 BYTEs)---|need CP(bool)| 
// |current block(UINT32)|layer(UINT8)| 
NP2TS_NEED_PEERS  = 5, // 需要其他NP的地址 
// |---CHECK DIGITS(7 BYTEs)---|res count(UINT8)|RESOURCE MD5(MD5_LEN)|...| 
NP2TS_QUERY_RES   = 6, // 查询资源的信息 
// |---CHECK DIGITS(7 BYTEs)---| 
NP2TS_LOGOUT      = 7, // 退出登录 
// |---CHECK DIGITS(7 BYTEs)---| 
// |playing block(UINT32)|Current Buffering Time(UINT16)|Buffered Count(UINT16)|Buffered Time(UINT16)| 
// |Connect Fail Count(UINT16)|Incoming Connection Count(UINT16)|Outgoing Connection Count(UINT16)| 
// |Avg Incoming Connection Elapsed Time(UINT16)|Avg OutgoingConnection Elapsed Time(UINT16)| 
// |Message Percent(float)|Transfer Info(TransferInfo)| 
NP2TS_REPORT2     = 8, // NP更多的状态信息 
 
// |---CHECK DIGITS(7 BYTEs)---|ip of peer(P2PAddress)| 
TS2NP_WELCOME     = 100, // 返回NP的地址 
// |CP list size(UINT8)|first CP addr(NormalAddress)|..| 
// |peer list size(UINT8)|peer1(PeerInfoWithAddr)|...| 
TS2NP_PEERS       = 101, // 返回NP需要的地址列表 
// |target addr(P2PAddress)|connect for free?(bool)| 
TS2NP_CONNECT_TO  = 102, // 让NP去连接其他NP 
// |res count(UINT8)|RESOURCE MD5(MD5_LEN)|NP count(UINT16)|...| 
TS2NP_RESINFO     = 103, // 某个资源的信息 
// |err msg type(UINT16)|should quit(bool)| 
TS2NP_MSG         = 104, // 发送(错误)消息 
}; 
// **************************************************************************** 
// **************************************************************************** 
enum NPandNP { 
// |NP version(float)| 
// |RESOURCE MD5(MD5_LEN)|Passive Connection(bool)| 
// |info of peer(PeerInfoWithAddr)| 
// if NP2CP, add |(SPlist size(UINT8)|NormalAddress|...|)| 
P2P_HELLO         = 0, // 相互通报请求的资源 
// if SP2CP, add |RESOURCE MD5(MD5_LEN)| 
// |SP update info(SPUpdate)| 
// if NP2NP, |SP Update sum(BYTE)| 
P2P_SPUPDATE      = 1, // SP更新 
// |info of peer(CorePeerInfo)|refresh(bool)| 
// |Interval count(UINT8)|first BlockInterval|...| 
P2P_REPORT        = 2, // Peer更新 
// |peer list size(UINT8)|first peer(PeerInfoWithAddr)|...| 
P2P_NEAR_PEERS    = 3, // 发送对方可能需要的Peer信息 
// if CP2SP, add |RESOURCE MD5(MD5_LEN)| 
// |refresh(bool)|block count(UINT8)|first blockid(UINT32)|...| 
P2P_PUSHLIST      = 4, // 发送PushList 
// if SP2CP, add |RESOURCE MD5(MD5_LEN)| 
// |block ID(UINT32))|block size(UINT32)|block data(...)| 
P2P_RESPONSE      = 5, // 发送Block 
// |err msg type(UINT16)|should quit(bool)| 
P2P_MSG           = 6, // 发送(错误)消息 
// |block ID(UINT32)| 
P2P_REQMEDIA      = 7, // 请求blockID对应的media数据 
// if SP2CP, add |RESOURCE MD5(MD5_LEN)| 
// |startid(UINT32)|length(UINT32)|media data length(UINT32)媒体数据长度|media data媒体数据(...)| 
// |program name size(UINT8)|program name(...)|program time in seconds(UINT32)|channel name size(UINT8)|channel name(...)| 
P2P_MEDIATYPE     = 8, // 返回blockID所在区间对应的media数据 
}; 
// **************************************************************************** 
// **************************************************************************** 
 
#endif