Beispiel #1
0
        public VersionPayload GetVersionPayload()
        {
            var to        = new IPAddressPayload(DateTime.UtcNow, 1, To, Port);
            var from      = new IPAddressPayload(DateTime.UtcNow, 0, From, Port);
            var userAgent = new StringPayload("/WinPrime-0.1.0/");

            return(new VersionPayload(70001, 1, DateTime.UtcNow, to, from, 0, userAgent, 0, true));
        }
        public VersionPayload(byte[] bytes)
        {
            Version   = BitConverter.ToInt32(bytes, 0);
            Services  = BitConverter.ToUInt64(bytes, 4);
            TimeStamp = new DateTime(BitConverter.ToInt64(bytes, 12));
            var remaining = bytes.Skip(20);

            // AddressTo
            var missingTimeStampBytes = new byte[] {
                0x00, 0x00, 0x00, 0x00,
            };
            var addressToBytes = missingTimeStampBytes
                                 .Concat(remaining.Take(26))
                                 .ToArray();

            AddressTo = new IPAddressPayload(addressToBytes);
            remaining = remaining.Skip(26);

            // AddressFrom
            var addressFromBytes = missingTimeStampBytes
                                   .Concat(remaining.Take(26))
                                   .ToArray();

            AddressFrom = new IPAddressPayload(addressFromBytes);
            remaining   = remaining.Skip(26);

            Nonce     = BitConverter.ToUInt64(remaining.ToArray(), 0);
            remaining = remaining.Skip(8);

            UserAgent = new StringPayload(remaining.ToArray());
            remaining = remaining.Skip(UserAgent.ToBytes().Length);

            StartHeight = BitConverter.ToUInt32(remaining.ToArray(), 0);
            remaining   = remaining.Skip(4);

            if (remaining.Count() != 0)
            {
                Relay = BitConverter.ToBoolean(remaining.ToArray(), 0);
            }
        }
 public VersionPayload(
     Int32 version,
     UInt64 services,
     DateTime timeStamp,
     IPAddressPayload addressTo,
     IPAddressPayload addressFrom,
     UInt64 nonce,
     StringPayload userAgent,
     UInt32 startHeight,
     Boolean relay
     )
 {
     Version     = version;
     Services    = services;
     TimeStamp   = timeStamp;
     AddressTo   = addressTo;
     AddressFrom = addressFrom;
     Nonce       = nonce;
     UserAgent   = userAgent;
     StartHeight = startHeight;
     Relay       = relay;
 }