예제 #1
0
            void createRejectPayload()
            {
                List <byte> rejectPayload = new List <byte>();

                rejectPayload.AddRange(VarString.GetBytes(MessageTypeRejected));
                rejectPayload.Add((byte)RejectionCode);
                rejectPayload.AddRange(VarString.GetBytes(RejectionReason));
                rejectPayload.AddRange(ExtraData);

                Payload = rejectPayload.ToArray();
            }
예제 #2
0
            void deserializePayload()
            {
                int startIndex = 0;

                MessageTypeRejected = VarString.GetString(Payload, ref startIndex);

                RejectionCode = Payload[startIndex];
                startIndex   += 1;

                RejectionReason = VarString.GetString(Payload, ref startIndex);

                deserializeExtraData(ref startIndex);
            }
예제 #3
0
            void DeserializePayload()
            {
                int startIndex = 0;

                ProtocolVersion = BitConverter.ToUInt32(Payload, startIndex);
                startIndex     += 4;

                NetworkServicesLocal = BitConverter.ToUInt64(Payload, startIndex);
                startIndex          += 8;

                UnixTimeSeconds = BitConverter.ToInt64(Payload, startIndex);
                startIndex     += 8;

                NetworkServicesRemote = BitConverter.ToUInt64(Payload, startIndex);
                startIndex           += 8;

                IPAddressRemote = new IPAddress(Payload.Skip(startIndex).Take(16).ToArray());
                startIndex     += 16;

                PortRemote  = BitConverter.ToUInt16(Payload, startIndex);
                startIndex += 2;

                // This is ignored as it is the same as above
                // NetworkServicesLocal = BitConverter.ToUInt64(Payload, startIndex);
                startIndex += 8;

                IPAddressLocal = new IPAddress(Payload.Skip(startIndex).Take(16).ToArray());
                startIndex    += 16;

                PortLocal   = BitConverter.ToUInt16(Payload, startIndex);
                startIndex += 2;

                Nonce       = BitConverter.ToUInt64(Payload, startIndex);
                startIndex += 8;

                UserAgent = VarString.GetString(Payload, ref startIndex);

                BlockchainHeight = BitConverter.ToInt32(Payload, startIndex);
                startIndex      += 4;

                if (startIndex == Payload.Length)
                {
                    RelayOption = 0x01;
                }
                else
                {
                    RelayOption = Payload[startIndex];
                    startIndex += 1;
                }
            }
예제 #4
0
            public void SerializePayload()
            {
                List <byte> versionPayload = new List <byte>();

                versionPayload.AddRange(BitConverter.GetBytes(ProtocolVersion));
                versionPayload.AddRange(BitConverter.GetBytes(NetworkServicesLocal));
                versionPayload.AddRange(BitConverter.GetBytes(UnixTimeSeconds));
                versionPayload.AddRange(BitConverter.GetBytes(NetworkServicesRemote));
                versionPayload.AddRange(IPAddressRemote.GetAddressBytes());
                versionPayload.AddRange(GetBytes(PortRemote));
                versionPayload.AddRange(BitConverter.GetBytes(NetworkServicesLocal));
                versionPayload.AddRange(IPAddressLocal.GetAddressBytes());
                versionPayload.AddRange(GetBytes(PortLocal));
                versionPayload.AddRange(BitConverter.GetBytes(Nonce));
                versionPayload.AddRange(VarString.GetBytes(UserAgent));
                versionPayload.AddRange(BitConverter.GetBytes(BlockchainHeight));
                versionPayload.Add(RelayOption);

                Payload = versionPayload.ToArray();
            }