📄 packetfactory.java
字号:
* <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x51</td> * <td>The value of the OP_HASHSETREQUEST * opcode</td> * </tr> * <tr> * <td>File ID</td> * <td>16</td> * <td> NA</td> * <td>The file ID of the requested file</td> * </tr> * </tbody> * </table> */ public static Packet getRequestPartHashSetPacket(FileHash fileHash){ Packet packet=new StandardPacket(16); packet.setCommand(OP_HASHSETREQUEST); packet.insertData(fileHash.getHash()); return packet; } /** * Get Slot release packet, sended when download is finished/canceled. * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x56</td> * <td>The value of the OP_ CANCELTRANSFER * opcode * * </td> * </tr> * </tbody> * </table> */ public static Packet getSlotReleasePacket(){ Packet packet = new StandardPacket(0); packet.setCommand(OP_SLOTRELEASE); return packet; } /** * End of Download Packet. * @param fileHash * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x49</td> * <td>The value of the OP END OF DOWNLOAD * opcode * </td> * </tr> * <tr> * <td>File ID</td> * <td> 16</td> * <td> NA</td> * <td>The file ID</td> * </tr> * </tbody> * </table> */ public static Packet getEndOfDownloadPacket(FileHash fileHash){ Packet packet = new StandardPacket(16); packet.setCommand(OP_END_OF_DOWNLOAD); packet.insertData(fileHash.getHash()); return packet; } /** * File request answer packet. * @param fileHash * @param fName * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x59</td> * <td>The value of the OP FILEREQANSWER opcode</td> * </tr> * <tr> * <td>File ID</td> * <td>16</td> * <td>NA</td> * <td>Unique file ID</td> * </tr> * <tr> * <td>Name length</td> * <td>2</td> * <td>NA</td> * <td>Optional, sent if the extended request version * indicated in the eMule info message is greater * than zero. The file significance is explained in * this section * </td> * </tr> * <tr> * <td>Filename</td> * <td>Varies</td> * <td>NA</td> * <td>Optional, sent if the extended request version * indicated in the eMule info message is greater * than one. Indicated the current number of * sources for this file * </td> * </tr> * </tbody> * </table> */ public static Packet getFileRequestAnswerPacket(FileHash fileHash, String fName){ Packet packet = new StandardPacket( 16+2+fName.length() ); packet.setCommand(OP_FILEREQANSWER); packet.insertData(fileHash.getHash()); packet.insertData(Convert.intToShort(fName.length())); packet.insertData(fName.getBytes()); return packet; } /** * File Status reply. * @param fSet * @param fileSize * @param fileGapList * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x50</td> * <td>The value of the OP FILESTATUS opcode</td> * </tr> * <tr> * <td>File ID</td> * <td>16</td> * <td>NA</td> * <td>The ID of the file</td> * </tr> * <tr> * <td>Part count</td> * <td>2</td> * <td>NA</td> * <td>File parts count</td> * </tr> * <tr> * <td>Part status</td> * <td> </td> * <td>NA</td> * <td>bit array with parts status : 1 - completed part ; 0 - uncompleted part</td> * </tr> * </tbody> * </table> * </table> */ public static Packet getFileStatusReplyPacket(PartHashSet fSet,long fileSize, GapList fileGapList){ JMuleBitSet bitSet = fileGapList.getBitSet(fileSize); byte [] bitSetArray = bitSet.getAsByteArray(); Packet packet = new StandardPacket(16+2+bitSetArray.length); packet.setCommand(OP_FILESTATUS); packet.insertData(fSet.getFileHash().getHash()); packet.insertData((short)fSet.size()); packet.insertData(bitSetArray); return packet; } /** * File hash set answer packet. * @param fSet * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x51</td> * <td>The value of the OP_HASHSETREQUEST opcode</td> * </tr> * <tr> * <td>File Hash</td> * <td>16</td> * <td> NA</td> * <td>The hash extracted from all the file</td> * </tr> * <tr> * <td>Part Count</td> * <td>2</td> * <td>NA</td> * <td>The number of parts in the file</td> * </tr> * <tr> * <td>Part Hashes</td> * <td>Varies</td> * <td>NA</td> * <td>A hash for each file part - the size of each hash * is 16 bytes * </td> * </tr> * </tbody> * </table> * </table> */ public static Packet getFileHashReplyPacket(PartHashSet fSet){ Packet packet = new StandardPacket(16+2+16*fSet.size()); packet.setCommand(OP_HASHSETANSWER); packet.insertData(fSet.getFileHash().getHash()); packet.insertData(Convert.intToShort(fSet.size())); for(int i = 0 ; i<fSet.size() ; i++) packet.insertData(fSet.get(i)); return packet; } /** * Accept upload packet. * @param fileHash * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields</td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x55</td> * <td>The value of the OP_ACCEPTUPLOADREQ opcode * </td> * </tr> * </tbody> * </table> * </table> */ public static Packet getAcceptUploadPacket(FileHash fileHash){ Packet packet = new StandardPacket(16); packet.setCommand(OP_SLOTGIVEN); packet.insertData(fileHash.getHash()); return packet; } /** * File part sending packet. * @param fileHash * @param fileChunk * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x46</td> * <td>The value of the OP SENDINGPART opcode</td> * </tr> * <tr> * <td>File ID</td> * <td> 16</td> * <td> NA</td> * <td>A unique file ID calculated by hashing the * file’s data * </td> * </tr> * <tr> * <td>Start Pos</td> * <td>4</td> * <td>NA</td> * <td>The start position of the downloaded data</td> * </tr> * <tr> * <td>End Pos</td> * <td>4</td> * <td>NA</td> * <td>The end position of the downloaded data</td> * </tr> * <tr> * <td>Data</td> * <td> </td> * <td> </td> * <td>The actual downloaded data. This data may * be compressed. * </td> * </tr> * </tbody> * </table> * </table> */ public static Packet getFilePartSendingPacket(FileHash fileHash,FileChunk fileChunk){ Packet packet = new StandardPacket(16+4+4+fileChunk.getChunkData().capacity()); packet.setCommand(OP_SENDINGPART); packet.insertData(fileHash.getHash()); packet.insertData(Convert.longToInt(fileChunk.getChunkStart())); packet.insertData(Convert.longToInt(fileChunk.getChunkEnd())); packet.insertData(fileChunk.getChunkData().array()); return packet; } /** * File not found packet. * @param fileHash * @return * <table cellspacing="0" border="1" cellpadding="0"> * <thead> * <tr> * <th>Name</th> * <th>Size in bytes</th> * <th>Default value</th> * <th>Comment</th> * </tr> * </thead> * <tbody> * <tr> * <td>Protocol</td> * <td>1</td> * <td>0xE3</td> * <td>-</td> * </tr> * <tr> * <td>Size</td> * <td>4</td> * <td>-</td> * <td>The size of the message in bytes not including * the header and size fields * </td> * </tr> * <tr> * <td>Type</td> * <td>1</td> * <td>0x48</td> * <td>The value of the OP FILEREQANSNOFIL * opcode</td> * </tr> * <tr> * <td>File ID</td> * <td>16</td> * <td>NA</td> * <td>The non existent file ID</td> * </tr> * </tbody> * </table> * </table> */ public static Packet getFileNotFoundPacket(FileHash fileHash){ Packet packet = new StandardPacket(16); packet.setCommand(OP_FILEREQANSNOFILE); packet.insertData(fileHash.getHash()); return packet; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -