示例#1
0
        public static MainPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            MainPacket tmpPacket = new MainPacket();
            tmpPacket.header = header;

            int offset = 0;

            tmpPacket.blocksize = BitConverter.ToUInt64(bytes, index + offset);
            offset += sizeof(UInt64);
            tmpPacket.recoverablefilecount = BitConverter.ToUInt32(bytes, index + offset);
            offset += sizeof(UInt32);

            tmpPacket.totalfilecount = ((uint)header.length - ((uint)header.GetSize() + sizeof(UInt64) + sizeof(UInt32))) / (16 * sizeof(byte));

            for (int i = 0; i < tmpPacket.totalfilecount; i++)
            {
                byte[] fileid = new byte[16];
                Buffer.BlockCopy(bytes, index + offset, fileid, 0, fileid.Length * sizeof(byte));
                offset += fileid.Length * sizeof(byte);
                tmpPacket.fileids.Add(fileid);
            }

            System.Threading.Tasks.Task.Factory.StartNew((b) =>
            {
                //FastCRC32.FastCRC32 crc32 = new FastCRC32.FastCRC32((ulong)b);
                FastCRC32.FastCRC32 crc32 = FastCRC32.FastCRC32.GetCRC32Instance((ulong)b);
            }, tmpPacket.blocksize);

            return tmpPacket;
        }
示例#2
0
        public byte[] fileid = new byte[16]; // MD5hash of file_hash_16k, file_length, file_name

        #endregion Fields

        #region Methods

        public static FileVerificationPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            FileVerificationPacket tmpPacket = new FileVerificationPacket();
            tmpPacket.header = header;

            int offset = 0;

            Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte));
            offset += tmpPacket.fileid.Length * sizeof(byte);

            int nbEntries = ((int)header.length - header.GetSize() - (16 * sizeof(byte))) / FileVerificationEntry.GetSize();

            tmpPacket.entries = new List<FileVerificationEntry>();

            tmpPacket.blockcount = (ulong)((header.length - (ulong)tmpPacket.GetSize()) / (ulong)FileVerificationEntry.GetSize());

            for (int i = 0; i < nbEntries; i++)
            {
                FileVerificationEntry entry = new FileVerificationEntry();

                Buffer.BlockCopy(bytes, index + offset, entry.hash, 0, entry.hash.Length * sizeof(byte));
                offset += entry.hash.Length * sizeof(byte);
                entry.crc = BitConverter.ToUInt32(bytes, index + offset);
                offset += sizeof(UInt32);

                tmpPacket.entries.Add(entry);
            }

            return tmpPacket;
        }
示例#3
0
        public string name; // Name of the file, padded with 1 to 3 zero bytes to reach

        #endregion Fields

        #region Methods

        public static FileDescriptionPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            FileDescriptionPacket tmpPacket = new FileDescriptionPacket();
            tmpPacket.header = header;

            int offset = 0;

            Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte));
            offset += tmpPacket.fileid.Length * sizeof(byte);
            Buffer.BlockCopy(bytes, index + offset, tmpPacket.hashfull, 0, tmpPacket.hashfull.Length * sizeof(byte));
            offset += tmpPacket.hashfull.Length * sizeof(byte);
            Buffer.BlockCopy(bytes, index + offset, tmpPacket.hash16k, 0, tmpPacket.hash16k.Length * sizeof(byte));
            offset += tmpPacket.hash16k.Length * sizeof(byte);
            tmpPacket.length = BitConverter.ToUInt64(bytes, index + offset);
            offset += sizeof(UInt64);

            // Name is specific to read since it's dependant of packet.length
            int name_offset = index + offset;
            int name_size = (int)header.length - header.GetSize() - tmpPacket.fileid.Length * sizeof(byte) - tmpPacket.hashfull.Length * sizeof(byte) - tmpPacket.hash16k.Length * sizeof(byte) - sizeof(UInt64);

            byte[] name = new byte[name_size];
            Buffer.BlockCopy(bytes, name_offset, name, 0, name_size);

            tmpPacket.name = ToolKit.ByteArrayToString(name).TrimEnd('\0');

            return tmpPacket;
        }
        public static FileVerificationPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            FileVerificationPacket tmpPacket = new FileVerificationPacket();

            tmpPacket.header = header;

            int offset = 0;

            Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte));
            offset += tmpPacket.fileid.Length * sizeof(byte);

            int nbEntries = ((int)header.length - header.GetSize() - (16 * sizeof(byte))) / FileVerificationEntry.GetSize();

            tmpPacket.entries = new List <FileVerificationEntry>();

            tmpPacket.blockcount = (ulong)((header.length - (ulong)tmpPacket.GetSize()) / (ulong)FileVerificationEntry.GetSize());

            for (int i = 0; i < nbEntries; i++)
            {
                FileVerificationEntry entry = new FileVerificationEntry();

                Buffer.BlockCopy(bytes, index + offset, entry.hash, 0, entry.hash.Length * sizeof(byte));
                offset   += entry.hash.Length * sizeof(byte);
                entry.crc = BitConverter.ToUInt32(bytes, index + offset);
                offset   += sizeof(UInt32);

                tmpPacket.entries.Add(entry);
            }

            return(tmpPacket);
        }
        public static FileDescriptionPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            FileDescriptionPacket tmpPacket = new FileDescriptionPacket();

            tmpPacket.header = header;

            int offset = 0;

            Buffer.BlockCopy(bytes, index + offset, tmpPacket.fileid, 0, tmpPacket.fileid.Length * sizeof(byte));
            offset += tmpPacket.fileid.Length * sizeof(byte);
            Buffer.BlockCopy(bytes, index + offset, tmpPacket.hashfull, 0, tmpPacket.hashfull.Length * sizeof(byte));
            offset += tmpPacket.hashfull.Length * sizeof(byte);
            Buffer.BlockCopy(bytes, index + offset, tmpPacket.hash16k, 0, tmpPacket.hash16k.Length * sizeof(byte));
            offset          += tmpPacket.hash16k.Length * sizeof(byte);
            tmpPacket.length = BitConverter.ToUInt64(bytes, index + offset);
            offset          += sizeof(UInt64);

            // Name is specific to read since it's dependant of packet.length
            int name_offset = index + offset;
            int name_size   = (int)header.length - header.GetSize() - tmpPacket.fileid.Length * sizeof(byte) - tmpPacket.hashfull.Length * sizeof(byte) - tmpPacket.hash16k.Length * sizeof(byte) - sizeof(UInt64);

            byte[] name = new byte[name_size];
            Buffer.BlockCopy(bytes, name_offset, name, 0, name_size);

            tmpPacket.name = ToolKit.ByteArrayToString(name).TrimEnd('\0');

            return(tmpPacket);
        }
示例#6
0
        public static MainPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            MainPacket tmpPacket = new MainPacket();

            tmpPacket.header = header;

            int offset = 0;

            tmpPacket.blocksize = BitConverter.ToUInt64(bytes, index + offset);
            offset += sizeof(UInt64);
            tmpPacket.recoverablefilecount = BitConverter.ToUInt32(bytes, index + offset);
            offset += sizeof(UInt32);

            tmpPacket.totalfilecount = ((uint)header.length - ((uint)header.GetSize() + sizeof(UInt64) + sizeof(UInt32))) / (16 * sizeof(byte));

            for (int i = 0; i < tmpPacket.totalfilecount; i++)
            {
                byte[] fileid = new byte[16];
                Buffer.BlockCopy(bytes, index + offset, fileid, 0, fileid.Length * sizeof(byte));
                offset += fileid.Length * sizeof(byte);
                tmpPacket.fileids.Add(fileid);
            }

            System.Threading.Tasks.Task.Factory.StartNew((b) =>
            {
                //FastCRC32.FastCRC32 crc32 = new FastCRC32.FastCRC32((ulong)b);
                FastCRC32.FastCRC32 crc32 = FastCRC32.FastCRC32.GetCRC32Instance((ulong)b);
            }, tmpPacket.blocksize);

            return(tmpPacket);
        }
示例#7
0
        public static RecoveryPacket Create(PacketHeader header, byte[] bytes, int index, string filename, int file_offset)
        {
            RecoveryPacket tmpPacket = new RecoveryPacket();

            tmpPacket.header = header;

            int offset = 0;

            tmpPacket.exponent = BitConverter.ToUInt32(bytes, index + offset);
            offset            += sizeof(UInt32);

            tmpPacket.offset   = index + offset + file_offset;
            tmpPacket.length   = (int)header.length - header.GetSize() - sizeof(UInt32);
            tmpPacket.filename = filename;

            tmpPacket.diskfile = new DiskFile();
            tmpPacket.diskfile.Open(filename);

            tmpPacket.datablock = new DataBlock();
            // Set the data block to immediatly follow the header on disk
            tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)tmpPacket.offset);
            tmpPacket.datablock.SetLength((ulong)tmpPacket.length);

            return(tmpPacket);
        }
示例#8
0
        public static CreatorPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            CreatorPacket tmpPacket = new CreatorPacket();
            tmpPacket.header = header;

            int offset = 0;

            // Name is specific to read since it's dependant of packet.length
            int name_offset = index + offset;
            int name_size = (int)header.length - header.GetSize();

            byte[] name = new byte[name_size];
            Buffer.BlockCopy(bytes, name_offset, name, 0, name_size);

            tmpPacket.client = ToolKit.ByteArrayToString(name);

            return tmpPacket;
        }
示例#9
0
        public static CreatorPacket Create(PacketHeader header, byte[] bytes, int index)
        {
            CreatorPacket tmpPacket = new CreatorPacket();

            tmpPacket.header = header;

            int offset = 0;

            // Name is specific to read since it's dependant of packet.length
            int name_offset = index + offset;
            int name_size   = (int)header.length - header.GetSize();

            byte[] name = new byte[name_size];
            Buffer.BlockCopy(bytes, name_offset, name, 0, name_size);

            tmpPacket.client = ToolKit.ByteArrayToString(name);

            return(tmpPacket);
        }
示例#10
0
        public static RecoveryPacket Create(PacketHeader header, byte[] bytes, int index, string filename, int file_offset)
        {
            RecoveryPacket tmpPacket = new RecoveryPacket();
            tmpPacket.header = header;

            int offset = 0;

            tmpPacket.exponent = BitConverter.ToUInt32(bytes, index + offset);
            offset += sizeof(UInt32);

            tmpPacket.offset = index + offset + file_offset;
            tmpPacket.length = (int)header.length - header.GetSize() - sizeof(UInt32);
            tmpPacket.filename = filename;

            tmpPacket.diskfile = new DiskFile();
            tmpPacket.diskfile.Open(filename);

            tmpPacket.datablock = new DataBlock();
            // Set the data block to immediatly follow the header on disk
            tmpPacket.datablock.SetLocation(tmpPacket.diskfile, (ulong)tmpPacket.offset);
            tmpPacket.datablock.SetLength((ulong)tmpPacket.length);

            return tmpPacket;
        }
示例#11
0
 public int GetSize()
 {
     return(header.GetSize() + sizeof(UInt32));
 }