JML

net.sf.jqql.obsolete
Class FileAgentPacket

java.lang.Object
  extended by net.sf.jqql.obsolete.FileAgentPacket

public class FileAgentPacket
extends Object

 file transfer packet, the format of the packet are different from FilePacket's subclass format, thus it's a independent class.
     it need to use FileDataPacket, for it's transfer packet, it contain transfer data. When it's not used to transfer data, it has
     his own format:
    file transfer request packet(send from client), begin with 0x04, content is:
 1. 0x04
 2. client version number, 2 byte
 3. the whole packet length, 2 byte
 4. command, 2 byte
 5. sequence, 2 byte
 6. my QQ number, 4 byte
 7. unknown 8 byte, no rules
 8. different command has different content:
     a. If the command is 0x0001, it means apply transfter service, format:
        i. authenticate token length, 2 byte
        ii. authenticate token
        iii. unknown 2 byte, 0x07D0, decimal value 2000(begin to encode from this field)
        iv. file transfter target's QQ number, 4 byte

 文件中转包,这个包的格式和FilePacket的子类格式相同甚少,因此是一个独立的类,它
 需要使用FileDataPacket,因为它是中转包,会包含中转数据。当它不用来中转数据时,
 也有自己的格式。具体格式如下:
 
 文件中转请求包(从客户端发出)以0x04开头,内容如下:
 1. 0x04
 2. 客户端版本号,2字节
 3. 整个的包长,2字节
 4. 命令,2字节
 5. 序号,2字节
 6. 我的QQ号,4字节
 7. 未知的8字节,无规律
 8. 根据命令的不同,后面的内容不同:
    a. 如果命令是0x0001时,表示请求中转服务,格式为
        i.   认证令牌长度,2字节
        ii.  认证令牌
        iii. 未知2字节,0x07D0,十进制值2000 (从这个字段开始加密)
           iv.  文件传输另一方的QQ号,4字节

    b. If the command is 0x0002, it means receiveer reports to transfer server, format:
        i. file session ID, 4 byte
        ii, authenticate token length, 2 byte(begin to encode from here)
        iii. authenticate token
    c. If the command is 0x0003, it's thepacket to wrap file data, format is:
        i. file session ID, 4 byte
        ii, unknwon 4 byte
        iii. length of data packet to be wrapped, 2 byte
        iv, data packet, same format as FileDataPacket.
    d. If the command is 0x0004, it's transfter finished packet, format is:
        i. file session ID, 4 byte
        ii. my QQ number(begin to encode from this field)
        iii. unknown 2 byte, often 0, maybe to indicate success.
    e. I fthe command is 0x0005, it's the reply to the server 0x0005.  And part 7 are all 0. Format is:
        i.file session ID, 4 byte
        ii, unknown 4 byte, all 9(encoded)
    f. If the command is 0x0006, part 6 is all 0. Format is:
        i. file session ID, 4 byte
        ii. unknown 2 byte, all 0( encoded)
 9. tail 0x3
 
       b. 如果命令是0x0002,表示接收者向中转服务器报到,格式为:
           i.   文件会话ID,4字节
        ii.  认证令牌长度,2字节(从这里开始加密)
        iii. 认证令牌
    c. 如果命令是0x0003,为封装文件数据的包,格式为(均不加密)
        i.   文件会话ID,4字节
        ii.  未知的4字节
        iii. 被封装的数据包长度,2字节
        iv.  数据包,也就是FileDataPacket的格式
    d.  如果命令是0x0004,为中转结束包,格式为:
        i.   文件会话ID,4字节
        ii.  我的QQ号 (从这个字段开始加密)
        iii. 未知的两字节,一般为全0,可能表示成功
    e.  如果命令是0x0005,是对服务器0x0005的回复,其中7部分全0。格式为:
        i.   文件会话ID,4字节
        ii.  未知的4字节,全0 (加密)
    f.  如果命令是0x0006,6部分全0。格式为:
        i.   文件会话ID,4字节
        ii.  未知的2字节,全0 (加密)
 9. 尾部0x3
 
 file transfer reply packet(send from server), begin with 0x04, format is:
 1. 0x4
 2. transfer server version number
 3. the while packet length, 2 byte
 4. command, 2 byte
 5. sequence, 2 byte
 6. my QQ number, 4 byte
 7. unknown 8 byte, no rule
 8. different command has different content:
    A. If the command is 0x0001, it's the reply to the transfer request, and the part 6 is same as the one of request. format (encoded)is :
        a, response code, 2 byte, different code, different content
            I, If it's 0x0000, means accept transfer requst, format behind is :
                i. transfer server IP, little-endian format, 4 byte
                ii. transfer server port, 2 byte
                iii. file session ID, 4 byte
                iv, 4 byte redirect IP, all 0
                v. 2 byte redirect port, all 0
                vi. unknown 2 byte, all 0
        II. If it's 0x0001, means redirection, format is:
                i. transfer server IP,all 0
                ii. transfer server port, 2 byte, all 0
                iii. file session ID, 4 byte, all 0
                iv, 4 byte redirect IP, little-endian format
                v. 2 byte redirect port
                vi. unknown 2 byte, all 0
 文件中转回复包(从服务器端发出)以0x04开头,格式为:
 1. 0x04
 2. 中转服务器版本号
 3. 整个的包长,2字节
 4. 命令,2字节
 5. 序号,2字节
 6. 我的QQ号,4字节
 7. 未知的8字节,无规律
 8. 根据命令的不同,后面的内容不同:
    A.  如果命令是0x0001,表示对中转请求的回应,且6部分和请求相同。格式为(加密):
          a.   应答码,2字节,根据应答码不同,内容不同
            I. 如果是0x0000,表示接受中转请求,后面的格式为:
                 i.   中转服务器IP,little-endian格式,4字节
                 ii.  中转服务器端口,2字节
                 iii. 文件会话ID,4字节 
                 iv.  4字节重定向IP,全0
                 v.   2字节重定向端口,全0
                 vi.  未知的两字节,全0
            II. 如果是0x0001,表示重定向,格式为
                 i.   中转服务器IP,4字节,全0
                 ii.  中转服务器端口,2字节,全0
                 iii. 文件会话ID,4字节,全0
                 iv.  4字节重定向IP,little-endian格式
                 v.   2字节重定向端口
                 vi.  未知的两字节,全0
    B. If the command is 0x0002, mean reply from transfer server to receiver, format is :
        a. file session ID, 4 byte
        b. unknown 4 byte, all 0(encoding begins here)
    C. If the command is 0x0003, mean data to transfer, formate is ( not encode)
        a. file session ID, 4 byte
        b. unknown 4 byte,
        c. length of data packet to wrap, 2 byte
    D. If the command is 0x0005, means notify the client to begin to send data, format is :
        a. file session ID, 4 byte
        b. count of file sent, two byte, (encoding begins here)
        c. length of message behind, 2 byte
        d. message, often "it's time for transfering data"
    E. If the command is )x0006, it's the reply to client 0x0005. Part 7 are all 0, format is:
        a. file session ID, 4 byte
        b. unknown 2 byte, all 0
        c. unknown 4 byte, 0x00013880, decimal 80000
        d. unknown 2 byte, 0x003C, decimal 60
        e. unknown 4 byte, all 0

 9. tail, 0x3

      B.  如果命令是0x0002,表示中转服务器对接收者报到的应答,格式为:
          a.  文件会话ID,4字节
          b.  未知的4字节,全0(从这里开始加密)
    C.  如果命令是0x0003,表示中转的数据,格式为(均不加密):
        a.  文件会话ID,4字节
        b.  未知的4字节
        c.  被封装的数据包长度,2字节
        d.  数据包,也就是FileDataPacket的格式
    D.  如果命令是0x0005,则是通知客户端可以开始传送数据,格式为:
        a.  文件会话ID,4字节
        b.  已经传送完成的文件数,两字节 (从这个字段开始加密)
        c.  后面的消息长度,2字节
        d.  消息,一般是"it's time for transfering data"
    E.  如果命令是0x0006,则是对客户端0x0006的回复,7部分全0,格式为:
        a.  文件会话ID,4字节
        b.  未知的两字节,全0
        c.  未知的4字节,0x00013880,十进制值80000 
        d.  未知的2字节,0x003C,十进制值60
        e.  未知的4字节,全0
 9. 尾部,0x3            
 

Author:
luma

Field Summary
protected static ByteBuffer buffer
           
protected  char command
           
protected static Crypter crypter
           
protected  FileDataPacket fdp
           
protected static org.apache.commons.logging.Log log
           
protected  char sequence
           
 
Constructor Summary
FileAgentPacket(FileWatcher watcher)
          constructor
 
Method Summary
 boolean equals(Object obj)
           
 void fill(ByteBuffer out)
          fill packet content to out, previous content in out will be clear.
 void fill(ByteBuffer out, int from)
          fill packet content to out, previous content in out 填充包内容到out中,out中原来的内容
 char getCommand()
           
 char getSequence()
           
 int hashCode()
           
 void parse(ByteBuffer in)
          parse file transfer packet from current position of in.
 void setCommand(char command)
           
 void setSequence(char sequence)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log

command

protected char command

sequence

protected char sequence

crypter

protected static Crypter crypter

fdp

protected FileDataPacket fdp

buffer

protected static ByteBuffer buffer
Constructor Detail

FileAgentPacket

public FileAgentPacket(FileWatcher watcher)
constructor

Parameters:
watcher - file water 构造函数
watcher - 文件守望者对象
Method Detail

fill

public void fill(ByteBuffer out)
fill packet content to out, previous content in out will be clear. After filled, position of out is equal to length of the packet. 填充包内容到out中,out中原来的内容将被清空,填充完毕后,out的 position等于包长

Parameters:
out - ByteBuffer object
out - ByteBuffer对象

fill

public void fill(ByteBuffer out,
                 int from)
fill packet content to out, previous content in out 填充包内容到out中,out中原来的内容

Parameters:
out -
from -

parse

public void parse(ByteBuffer in)
           throws PacketParseException
parse file transfer packet from current position of in. Position after parsed is behind the packet. 从in的当前位置开始解析文件中转包,解析后的position将位于这个包之后

Parameters:
in -
Throws:
PacketParseException

getCommand

public char getCommand()
Returns:
Returns the command.

setCommand

public void setCommand(char command)
Parameters:
command - The command to set.

getSequence

public char getSequence()
Returns:
Returns the sequence.

setSequence

public void setSequence(char sequence)
Parameters:
sequence - The sequence to set.

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

JML