JML

net.sf.jqql.packets
Class DiskOutPacket

java.lang.Object
  extended by net.sf.jqql.packets.Packet
      extended by net.sf.jqql.packets.OutPacket
          extended by net.sf.jqql.packets.DiskOutPacket
Direct Known Subclasses:
ApplyPacket, AuthenticatePacket, CreatePacket, DeletePacket, DiskDebugPacket, DownloadPacket, FinalizePacket, GetServerListPacket, GetSharedDiskPacket, GetShareListPacket, GetSizePacket, ListMyDiskDirPacket, ListSharedDiskDirPacket, MovePacket, PasswordOpPacket, PreparePacket, RenamePacket, SetShareListPacket, UnknownDiskOutPacket, UploadFilePacket

public abstract class DiskOutPacket
extends OutPacket

QQ disk protocol family output packet 1. packet length, 4 byte, exclusive 2. version sign, 2 byte 3. unknown 2 byte 4. command 2 byte 5. unknown 60 byte 6. my ip string form, 15 byte, not enough write 0 7. unknown 69 byte 8. packet body Note: this protocol family packet body doesn't encrypt, and only use in TCP connect

 QQ硬盘协议族输出包
 1. 包长,4字节,exclusive
 2. 版本标识,2字节
 3. 未知的2字节
 4. 命令,2字节
 5. 未知的60字节
 6. 我的ip的字符串形式,15字节,不足填0
 7. 未知的69字节
 8. 包体
 
 Note: 此协议族包体不加密,并且只用于TCP连接
 

Author:
luma

Field Summary
 
Fields inherited from class net.sf.jqql.packets.OutPacket
ack, key, resendCountDown, sendCount, seq, timeout
 
Fields inherited from class net.sf.jqql.packets.Packet
bodyBuf, bodyDecrypted, command, crypter, ds, duplicated, header, log, sequence, source, user
 
Constructor Summary
DiskOutPacket(ByteBuffer buf, int length, QQUser user)
           
DiskOutPacket(char command, QQUser user)
           
 
Method Summary
protected  byte[] decryptBody(byte[] body, int offset, int length)
          decrypt packet body 解密包体
protected  byte[] encryptBody(byte[] b, int offset, int length)
          encrypt packet body 加密包体
 boolean equals(Object obj)
           
protected  byte[] getBodyBytes(ByteBuffer buf, int length)
          get byte array of packet body 得到包体的字节数组
protected  int getCryptographStart()
           
 int getFamily()
           
protected  int getHeadLength()
           
protected  int getLength(int bodyLength)
          get total length of UDP form packet, rule out TCP form 得到UDP形式包的总长度,不考虑TCP形式
 String getLocalIp()
           
protected  int getTailLength()
           
 int hashCode()
          make up sequence number and command as hash code.
protected  void parseHeader(ByteBuffer buf)
          parse packet header from current position of buf 从buf的当前位置解析包头
protected  void parseTail(ByteBuffer buf)
          parse packet tail from current position of buf 从buf的当前未知解析包尾
protected  void postFill(ByteBuffer buf, int startPos)
          backfill, some field must fill whole packet to make sure its content, for example length field, then this method will be used after tail filling.
protected  void putHead(ByteBuffer buf)
          change packet header to byte stream, and write into appointed ByteBuffer object.
protected  void putTail(ByteBuffer buf)
          change packet tail to byte stream, and write into appointed ByteBuffer object.
 void setLocalIp(String localIp)
           
protected  boolean validateHeader()
          checkout header 校验头部
 
Methods inherited from class net.sf.jqql.packets.OutPacket
dump, fill, getKey, getNextSeq, getPacketName, getSendCount, getTimeout, needAck, needResend, parseBody, setKey, setSendCount, setTimeout
 
Methods inherited from class net.sf.jqql.packets.Packet
getCommand, getHeader, getSequence, getSource, hash, isDuplicated, putBody, setDuplicated, setHeader, setSequence
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiskOutPacket

public DiskOutPacket(ByteBuffer buf,
                     int length,
                     QQUser user)
              throws PacketParseException
Throws:
PacketParseException

DiskOutPacket

public DiskOutPacket(char command,
                     QQUser user)
Method Detail

postFill

protected void postFill(ByteBuffer buf,
                        int startPos)
Description copied from class: OutPacket
backfill, some field must fill whole packet to make sure its content, for example length field, then this method will be used after tail filling. 回填,有些字段必须填完整个包才能确定其内容,比如长度字段,那么这个方法将在 尾部填充之后调用

Specified by:
postFill in class OutPacket
Parameters:
buf - ByteBuffer
startPos - packet initial position 包起始位置

getLength

protected int getLength(int bodyLength)
Description copied from class: Packet
get total length of UDP form packet, rule out TCP form 得到UDP形式包的总长度,不考虑TCP形式

Specified by:
getLength in class Packet
Parameters:
bodyLength - packet body length 包体长度
Returns:
packet length 包长度

validateHeader

protected boolean validateHeader()
Description copied from class: Packet
checkout header 校验头部

Specified by:
validateHeader in class Packet
Returns:
true means header usable true表示头部有效

getHeadLength

protected int getHeadLength()
Specified by:
getHeadLength in class Packet
Returns:
packet header length 包头长度

getTailLength

protected int getTailLength()
Specified by:
getTailLength in class Packet
Returns:
packet tail length 包尾长度

putHead

protected void putHead(ByteBuffer buf)
Description copied from class: Packet
change packet header to byte stream, and write into appointed ByteBuffer object. 将包头部转化为字节流, 写入指定的ByteBuffer对象.

Specified by:
putHead in class Packet
Parameters:
buf - ByteBuffer object whicn packet need to write into 写入的ByteBuffer对象.

getBodyBytes

protected byte[] getBodyBytes(ByteBuffer buf,
                              int length)
Description copied from class: Packet
get byte array of packet body 得到包体的字节数组

Specified by:
getBodyBytes in class Packet
Parameters:
buf - ByteBuffer
length - packet total length 包总长度
Returns:
byte array of packet body 包体字节数组

getFamily

public int getFamily()
Specified by:
getFamily in class Packet
Returns:
sign this packet belong which protocol family 标识这个包属于哪个协议族

putTail

protected void putTail(ByteBuffer buf)
Description copied from class: Packet
change packet tail to byte stream, and write into appointed ByteBuffer object. 将包尾部转化为字节流, 写入指定的ByteBuffer对象.

Specified by:
putTail in class Packet
Parameters:
buf - ByteBuffer object whicn packet need to write into 写入的ByteBuffer对象.

encryptBody

protected byte[] encryptBody(byte[] b,
                             int offset,
                             int length)
Description copied from class: Packet
encrypt packet body 加密包体

Specified by:
encryptBody in class Packet
Parameters:
b - unencrypt byte array 未加密的字节数组
offset - offset of packet body begin 包体开始的偏移
length - packet body length 包体长度
Returns:
encrypted packet body 加密的包体

decryptBody

protected byte[] decryptBody(byte[] body,
                             int offset,
                             int length)
Description copied from class: Packet
decrypt packet body 解密包体

Specified by:
decryptBody in class Packet
Parameters:
body - byte array of packet body 包体字节数组
offset - offset of packet body begin 包体开始偏移
length - packet length 包体长度
Returns:
解密的包体字节数组 // byte array of decrypted packet body

getCryptographStart

protected int getCryptographStart()
Specified by:
getCryptographStart in class Packet
Returns:
start position of cryptograph, relative to the first byte of packet body. if this packet is unknown packet, return -1, this method only available to some protocol family. 密文的起始位置,这个位置是相对于包体的第一个字节来说的,如果这个包是未知包, 返回-1,这个方法只对某些协议族有意义

parseHeader

protected void parseHeader(ByteBuffer buf)
                    throws PacketParseException
Description copied from class: Packet
parse packet header from current position of buf 从buf的当前位置解析包头

Specified by:
parseHeader in class Packet
Parameters:
buf - ByteBuffer
Throws:
PacketParseException - if parse error 如果解析出错

parseTail

protected void parseTail(ByteBuffer buf)
                  throws PacketParseException
Description copied from class: Packet
parse packet tail from current position of buf 从buf的当前未知解析包尾

Specified by:
parseTail in class Packet
Parameters:
buf - ByteBuffer
Throws:
PacketParseException - if parse error 如果解析出错

hashCode

public int hashCode()
Description copied from class: Packet
make up sequence number and command as hash code. for avoid different packet have the same command, header join in 把序列号和命令拼起来作为哈希码. 为了避免不同header的包有相同的命令,Header也参与进来

Overrides:
hashCode in class Packet

getLocalIp

public String getLocalIp()
Returns:
the localIp

setLocalIp

public void setLocalIp(String localIp)
Parameters:
localIp - the localIp to set

equals

public boolean equals(Object obj)
Overrides:
equals in class Packet

JML