Beispiel #1
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            HighestVersion = BitConverter.ToUInt32(data, offset);
            Services       = BitConverter.ToUInt64(data, offset + 4);
            Timestamp      = BitConverter.ToUInt64(data, offset + 12);

            RecvServices = BitConverter.ToUInt64(data, offset + 20);
            var rip = new byte[16];

            Buffer.BlockCopy(data, offset + 28, rip, 0, 16);
            RecvIp   = new IPAddress(rip);
            RecvPort = BitConverter.ToUInt16(data, offset + 44);

            TransServices = BitConverter.ToUInt64(data, offset + 46);
            var tip = new byte[16];

            Buffer.BlockCopy(data, offset + 54, tip, 0, 16);
            TransIp   = new IPAddress(tip);
            TransPort = BitConverter.ToUInt16(data, offset + 70);

            Nonce           = BitConverter.ToUInt64(data, offset + 72);
            UserAgentLength = new VarInt(0);
            UserAgentLength.ReadFromPayload(data, offset + 80);

            var noffset = offset + 80 + UserAgentLength.Size;

            UserAgent   = Encoding.ASCII.GetString(data, noffset, UserAgentLength);
            StartHeight = BitConverter.ToUInt32(data, noffset + UserAgentLength);
            Relay       = BitConverter.ToBoolean(data, noffset + UserAgentLength + 4);
        }
Beispiel #2
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            Version   = BitConverter.ToUInt32(data, offset);
            HashCount = new VarInt(0);
            HashCount.ReadFromPayload(data, 4);

            Hashes = new Hash[HashCount];

            for (var x = 0; x < HashCount; x++)
            {
                var ch = new Hash()
                {
                    HashBytes = new byte[32]
                };
                Buffer.BlockCopy(data, offset + 4 + HashCount.Size + (ch.HashBytes.Length * x), ch.HashBytes, 0, ch.HashBytes.Length);

                Hashes[x] = ch;
            }

            StopHash = new Hash()
            {
                HashBytes = new byte[32]
            };
            Buffer.BlockCopy(data, offset + 4 + HashCount.Size + (HashCount * 32), StopHash.HashBytes, 0, StopHash.HashBytes.Length);
        }
Beispiel #3
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            ElementCount = new VarInt(0);
            ElementCount.ReadFromPayload(data, offset);

            Elements = new byte[ElementCount];
            Buffer.BlockCopy(Elements, offset + ElementCount, Elements, 0, ElementCount);
        }
Beispiel #4
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            FilterBytes = new VarInt(0);
            FilterBytes.ReadFromPayload(data, offset);

            Filter = new byte[FilterBytes];
            Buffer.BlockCopy(data, offset + FilterBytes.Size, Filter, 0, Filter.Length);

            HashFunctions = BitConverter.ToUInt32(data, offset + FilterBytes + FilterBytes.Size);
            Tweak         = BitConverter.ToUInt32(data, offset + FilterBytes + FilterBytes.Size + 4);
            Flags         = data[offset + FilterBytes + FilterBytes.Size + 8];
        }
Beispiel #5
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            Count = new VarInt(0);
            Count.ReadFromPayload(data, offset);
            Header = new BlockHeader[Count];

            for (var x = 0; x < Count; x++)
            {
                var bh = new BlockHeader();
                bh.ReadFromPayload(data, offset + Count.Size + (80 * x));

                Header[x] = bh;
            }
        }
Beispiel #6
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            Count = new VarInt(0);
            Count.ReadFromPayload(data, offset);
            Inventory = new Inventory[Count];

            //read all
            for (var x = 0; x < Count; x++)
            {
                var ni = new Inventory();
                ni.ReadFromPayload(data, offset + Count.Size + (36 * x));

                Inventory[x] = ni;
            }
        }
Beispiel #7
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            IpCount = new VarInt(0);
            IpCount.ReadFromPayload(data, offset);

            var ipOffset = offset + IpCount.Size;

            Ips = new IP[IpCount];
            for (var x = 0; x < IpCount; x++)
            {
                var ip = new IP();
                ip.ReadFromPayload(data, ipOffset);
                Ips[x]    = ip;
                ipOffset += ip.Size;
            }
        }
Beispiel #8
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            MessageLength = new VarInt(0);
            MessageLength.ReadFromPayload(data, offset);

            Message = Encoding.ASCII.GetString(data, offset + MessageLength.Size, MessageLength);
            Code    = data[offset + MessageLength + MessageLength.Size];

            ReasonLength = new VarInt(0);
            ReasonLength.ReadFromPayload(data, offset + MessageLength + MessageLength.Size + 1);

            Reason = Encoding.ASCII.GetString(data, offset + MessageLength + MessageLength.Size + 1 + ReasonLength.Size, ReasonLength);
            var of = offset + MessageLength + MessageLength.Size + 1 + ReasonLength.Size + ReasonLength;

            Extra = new byte[data.Length - of]; // ew no length = we have to rely on the length of the buffer (reading more "Extra" than we should)
            Buffer.BlockCopy(data, of, Extra, 0, Extra.Length);
        }
Beispiel #9
0
        public void ReadFromPayload(byte[] data, int offset)
        {
            BlockHeader = new BlockHeader();
            BlockHeader.ReadFromPayload(data, offset);

            Transactions = BitConverter.ToUInt32(data, offset + 80);
            HashCount    = new VarInt(0);
            HashCount.ReadFromPayload(data, offset + 84);
            Hashes = new Hash[HashCount];

            for (var x = 0; x < HashCount; x++)
            {
                var nh = new Hash();
                nh.ReadFromPayload(data, offset + 84 + HashCount.Size + (x * 32));

                Hashes[x] = nh;
            }

            FlagByteCount = new VarInt(0);
            FlagByteCount.ReadFromPayload(data, offset + 84 + HashCount.Size + (HashCount * 32));

            Flags = new byte[FlagByteCount];
            Buffer.BlockCopy(data, offset + 84 + HashCount.Size + (HashCount * 32) + FlagByteCount.Size, Flags, 0, Flags.Length);
        }