public static byte[] Have(int piece) { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(5); //Length rs.WriteByte(4); //ID rs.WriteInt(piece); //Payload: Piece ID return(rs.GetByteArray()); }
public static byte[] Cancel(int pieceid, int piece_begin_offset, int piecelength) //Same parameters as 'Request' message { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(13); //Length rs.WriteByte(8); //ID rs.WriteInt(pieceid); //Payload: Piece ID [index] rs.WriteInt(piece_begin_offset); //Payload: Byte Offset [begin] rs.WriteInt(piecelength); //Payload: Piece Read Length [length] return(rs.GetByteArray()); }
public static byte[] Piece(int pieceid, int piece_begin_offset, byte[] piece_part) //WARNING: USE REQUESTED AMOUNT OF BYTES (MAX 16KB) AT A TIME, SEND IN MULTIPLE REQUESTS { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(9 + piece_part.Length); //Length rs.WriteByte(7); //ID rs.WriteInt(pieceid); //Payload: Piece ID [index] rs.WriteInt(piece_begin_offset); //Payload: Byte Offset [begin] rs.WriteByteArray(piece_part); //Payload: Piece Block [block] return(rs.GetByteArray()); }
public static byte[] Request(int pieceid, int piece_begin_offset, int piecelength) //WARNING: USE 16 KILOBYTES (2^14) AT A TIME, DOWNLOAD IN MULTIPLE REQUESTS { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(13); //Length rs.WriteByte(6); //ID rs.WriteInt(pieceid); //Payload: Piece ID [index] rs.WriteInt(piece_begin_offset); //Payload: Byte Offset [begin] rs.WriteInt(piecelength); //Payload: Piece Read Length [length] return(rs.GetByteArray()); }
public static byte[] NotInterested() { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(1); //Length rs.WriteByte(3); //ID return(rs.GetByteArray()); }
public static byte[] Unchoke() { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(1); //Length rs.WriteByte(1); //ID return(rs.GetByteArray()); }
public static byte[] BitField(byte[] bitfield) { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(1 + bitfield.Length); //Length rs.WriteByte(5); //ID rs.WriteByteArray(bitfield); //Payload: Bitfield return(rs.GetByteArray()); }
public static byte[] Port(short listen_port) //Used for DHT, currently unimplemented { PacketGenerator rs = new PacketGenerator(); rs.WriteInt(3); //Length rs.WriteByte(9); //ID rs.WriteShort(listen_port); return(rs.GetByteArray()); }