JML

net.sf.jqql.obsolete
Class FilePacket

java.lang.Object
  extended by net.sf.jqql.obsolete.FilePacket
Direct Known Subclasses:
FileControlPacket, FileDataPacket

public abstract class FilePacket
extends Object

 base class of sent packet in file transfer, packet header of packet in file transfer in 12 byte, format is 
 1. a byte mean packet type, since control data is 0x00, file data is 0x03
 2. sender QQ version, or server version, this field is same as common-use pakcet of QQ
 3. random cipher code, 1 byte, if this byte is 0x25, then cipher code is 0x23232323, this cipher code is use to encrypt
    sender and receiver QQ number
 4. encrypt form of sender QQ number, 4 byte. encrypt arithmetic: QQ number negate then XOR with cipher code
 5. encrypt form of receiver QQ number, 4 byte
 文件传输时发送的包的基类,文件传送的包的包头为12个字节,格式为
 1. 一个字节表示包的类型,似乎控制数据是0x00,文件数据是0x03
 2. 发送方QQ版本,或者是服务器版本,这个字段和QQ的普通用途包是一样的
 3. 随机密钥,1字节,如果这个字节是0x23,那么密钥就是0x23232323,这个密钥用来加密
    发送者和接受者的QQ号
 4. 发送者QQ号的加密形式,4字节。加密算法: QQ号取反再与密钥异或
 5. 接受者QQ号的加密形式,4字节
 
* @author luma


Field Summary
protected static Crypter crypter
           
protected  int key
           
protected static org.apache.commons.logging.Log log
           
protected static Random random
           
protected  int receiver
           
protected  int sender
           
protected  char source
           
protected  byte tag
           
protected  FileWatcher watcher
           
 
Constructor Summary
protected FilePacket(FileWatcher watcher)
          create a FilePacket 构造一个FilePacket
 
Method Summary
protected  int decryptQQ(int qq, int key)
          decrypt QQ number 解密QQ号
protected  int encryptQQ(int qq, int key)
          encrypt QQ number 加密QQ号
protected  void fill(ByteBuffer out)
           initialize packet content, subclass should overide this method, and first use this method in super class × content of input ByteBuffer will be clear, after complete, buffer position equal to packet length 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法 输入ByteBuffer原来的内容将被清空,完成后,bufferçš„position 等于包长
protected  void fill(ByteBuffer out, int from)
           initialize packet content, subclass should overide this method, and first use this method in super class content of input ByteBuffer won't be clear, new content start fill from from position, after complete, buffer position = packet length + from 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法 输入ByteBuffer的原来内容不被清空,新的内容从from位置开始 填充,完成后,bufferçš„position等于包长加上from
protected  int generateKey(byte b)
          base on seed create a new key, inside key won't be refreshed 根据种子生成一个新的Key,内部的Key不会被刷新
 int getKey()
          method for debugg 调试用方法
 int getReceiver()
           
 int getSender()
           
 char getSource()
           
 byte getTag()
           
protected abstract  void initFixedFields()
          init some fixed field toward fixed type packet 初始化一些对于固定类型的包来说固定值的字段
protected  void parse(ByteBuffer in)
          parse packet header, subclass should overide this method, and first use this method in super class parse start from current position of in, after parse complete, position of in will be after this packet 解析包头,子类应该覆盖该方法,并首先调用父类的这个方法 解析从in的当前位置开始,解析完毕后inçš„position将位于 这个包之后
protected  int refreshKey()
          inside refresh key 内部刷新Key
 void setReceiver(int receiver)
           
 void setSender(int sender)
           
 void setSource(char source)
           
 void setTag(byte type)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

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

source

protected char source

tag

protected byte tag

crypter

protected static Crypter crypter

random

protected static Random random

key

protected int key

sender

protected int sender

receiver

protected int receiver

watcher

protected FileWatcher watcher
Constructor Detail

FilePacket

protected FilePacket(FileWatcher watcher)
create a FilePacket 构造一个FilePacket

Parameters:
watcher - FileWatcher对象 // FileWatcher object
Method Detail

refreshKey

protected int refreshKey()
inside refresh key 内部刷新Key


generateKey

protected int generateKey(byte b)
base on seed create a new key, inside key won't be refreshed 根据种子生成一个新的Key,内部的Key不会被刷新

Parameters:
b - 种子 // seed

parse

protected void parse(ByteBuffer in)
              throws PacketParseException
parse packet header, subclass should overide this method, and first use this method in super class parse start from current position of in, after parse complete, position of in will be after this packet 解析包头,子类应该覆盖该方法,并首先调用父类的这个方法 解析从in的当前位置开始,解析完毕后in的position将位于 这个包之后

Parameters:
in - ByteBuffer对象,做为输入缓冲区 // ByteBuffer object, as input buffer
Throws:
BadQQPacketException - 如果包的长度不对 // if packet length wrong
PacketParseException

fill

protected void fill(ByteBuffer out)
 initialize packet content, subclass should overide this method, and first use this method in super class
     × content of input ByteBuffer will be clear, after complete, buffer position equal to packet length
 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法
 输入ByteBuffer原来的内容将被清空,完成后,buffer的position
 等于包长
 

Parameters:
out - ByteBuffer对象,做为输出缓冲区 // ByteBuffer object, use to output buffer

fill

protected void fill(ByteBuffer out,
                    int from)
 initialize packet content, subclass should overide this method, and first use this method in super class
 content of input ByteBuffer won't be clear, new content start fill from from position, after complete,
 buffer position = packet length + from
 初始化包内容,子类应该覆盖这个方法,并首先调用父类的这个方法
 输入ByteBuffer的原来内容不被清空,新的内容从from位置开始
 填充,完成后,buffer的position等于包长加上from
 

Parameters:
out - ByteBuffer对象,做为输出缓冲区 // ByteBuffer object, use to output buffer
from - 开始填充的位置 //start fill position

initFixedFields

protected abstract void initFixedFields()
init some fixed field toward fixed type packet 初始化一些对于固定类型的包来说固定值的字段


encryptQQ

protected int encryptQQ(int qq,
                        int key)
encrypt QQ number 加密QQ号

Parameters:
qq - QQ号 // QQ number
key - 密钥
Returns:
加密后的QQ号 // encrpyted QQ number

decryptQQ

protected int decryptQQ(int qq,
                        int key)
decrypt QQ number 解密QQ号

Parameters:
qq - QQ号 // QQ number
key - 密钥 // cipher code
Returns:
解密后的QQ号 // decrypt QQ number

getSource

public char getSource()
Returns:
Returns the source.

setSource

public void setSource(char source)
Parameters:
source - The source to set.

getTag

public byte getTag()
Returns:
Returns the type.

setTag

public void setTag(byte type)
Parameters:
type - The type to set.

getKey

public int getKey()
method for debugg 调试用方法

Returns:
随机密钥 random cipher code

getReceiver

public int getReceiver()
Returns:
Returns the receiver.

setReceiver

public void setReceiver(int receiver)
Parameters:
receiver - The receiver to set.

getSender

public int getSender()
Returns:
Returns the sender.

setSender

public void setSender(int sender)
Parameters:
sender - The sender to set.

JML