Packet TypeCode IHAVE DATA 2345 DENIED Table 1: Codes for different packet types 24 4 bytes invalid valid padding Header Len Packet Len Chunk Hash #1(20 bytes) Seq Num Chunk Hash #2 (20 bytes) Ack Num (a)The basic packet header, with each (b) A full WHOHAS request with two (c)A hunk hashes in the request. Note that number of data. both seq num and ack num have no Note that meaning in this packet. Figure 2: Packet headers
15441 1 0 16 60 invalid invalid 2 padding Chunk Hash #1 (20 bytes) Chunk Hash #2 (20 bytes) 15441 1 3 16 1016 24 invalid Chunk Data (1000 bytes) Packet Type Code WHOHAS IHAVE GET DATA ACK DENIED 0 1 2 3 4 5 Table 1: Codes for different packet types. 4 bytes 4 bytes 4 bytes Magic Version Type Header Len Packet Len Seq Num Ack Num (a) The basic packet header, with each header field named. (b) A full WHOHAS request with two Chunk hashes in the request. Note that both seq num and ack num have no meaning in this packet. (c) A full DATA packet, with seq number 24 and 1000 bytes of data. Note that the ack num has no meaning because data-flowis one-way. Figure 2: Packet headers. 6
DATa packet to acknowledge a previous packet and do not send data in a ack packet. This means that for any daTA packet the ACK num will be invalid and for any ACK packet the seQ num field will be invalid. Invalid fields still take up space in the packet header, but their value should be ignored by the peer receiving the packet 4.7 File formats Chunks file: File: <path to the file which needs sharing> Chunks id chunk-hash The master-chunks-file has above format. The first line specifies the file that needs to be shared among the peers The peer should only read the chunks it is provided with in the peer's has-chunks-file parameter. All the chunks have a fixed size of 512KB. If the file size is not a multiple of 5 B then it will be padded appropriately All lines after"Chunks: contain chunk ids and the corresponding hash value of the chunk. The hash is the SHA-1 hash of the chunk, represented as a hexadecimal number(it will not have a starting Ox). The chunk id is a decimal integer, specifying the offset of the chunk in the master data file. If the chunk id is i, then the chunks content starts at an offset of i x 512k bytes into the master data file Has chunk file This file contains a list of the ids and hashes of the chunks a particular peer has, As in the master chunk file, the ids are in decimal format and hashes are in hexadecimal format For the same chunk, the id of the chunk in the has-chunk-fi will be the same as the id of that chunk in the master-chunks -file id chunk-hash Get Chunk File The format of the file is exactly same as the has-chunk-file. It contains a list of the ids and hashes the peer wishes to download. As in the master chunk file. the ids in decimal format and hashes are in hexadecimal format. For the same chunk of data, the id in the get-chunk-file might not be the same as the id of that chunk in the master-chunks-file Rather, the id here refers to the position of the chunk in the file that the user wants to save to id chunk-hash Peer list file This file contains the list of all peers in the network. The format of each line <id> <peer-address> <peer-port> The id is a decimal number, peer-address the IP address in dotted decimal format, and the port is port integer in decimal. It will be easiest to just run all hosts on different localhost ports
DATA packet to acknowledge a previous packet and do not send data in a ACK packet. This means that for any DATA packet the ACK num will be invalid and for any ACK packet the SEQ num field will be invalid. Invalid fields still take up space in the packet header, but their value should be ignored by the peer receiving the packet. 4.7 File Formats Chunks File: File: <path to the file which needs sharing> Chunks: id chunk-hash ..... ..... The master-chunks-file has above format. The first line specifies the file that needs to be shared among the peers. The peer should only read the chunks it is provided with in the peer‘s has-chunks-file parameter. All the chunks have a fixed size of 512KB. If the file size is not a multiple of 512KB then it will be padded appropriately. All lines after ―Chunks:‖ contain chunk ids and the corresponding hash value of the chunk. The hash is the SHA-1 hash of the chunk, represented as a hexadecimal number (it will not have a starting ―0x‖). The chunk id is a decimal integer, specifying the offset of the chunk in the master data file. If the chunk id is i, then the chunk‘s content starts at an offset of i ×512k bytes into the master data file. Has Chunk File This file contains a list of the ids and hashes of the chunks a particular peer has. As in the master chunk file, the ids are in decimal format and hashes are in hexadecimal format. For the same chunk, the id of the chunk in the has-chunk-file will be the same as the id of that chunk in the master-chunks-file. id chunk-hash id chunk-hash ..... Get Chunk File The format of the file is exactly same as the has-chunk-file. It contains a list of the ids and hashes the peer wishes to download. As in the master chunk file, the ids in decimal format and hashes are in hexadecimal format. For the same chunk of data, the id in the get-chunk-file might NOT be the same as the id of that chunk in the master-chunks-file. Rather, the id here refers to the position of the chunk in the file that the user wants to save to. id chunk-hash id chunk-hash ..... Peer List File This file contains the list of all peers in the network. The format of each line is: <id> <peer-address> <peer-port> The id is a decimal number, peer-address the IP address in dotted decimal format, and the port is port integer in decimal. It will be easiest to just run all hosts on different localhost ports. 7