Example #1
0
        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());
        }
Example #2
0
        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());
        }
Example #3
0
        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());
        }
Example #4
0
        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());
        }
Example #5
0
        public static byte[] NotInterested()
        {
            PacketGenerator rs = new PacketGenerator();

            rs.WriteInt(1);  //Length
            rs.WriteByte(3); //ID
            return(rs.GetByteArray());
        }
Example #6
0
        public static byte[] Unchoke()
        {
            PacketGenerator rs = new PacketGenerator();

            rs.WriteInt(1);  //Length
            rs.WriteByte(1); //ID
            return(rs.GetByteArray());
        }
Example #7
0
        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());
        }
Example #8
0
        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());
        }