Esempio n. 1
0
 /// <summary>
 /// Special case constructor, used for the genesis node, cloneAsHeader and unit tests.
 /// </summary>
 internal BlockMessage(P2PNetworkParameters netParams) : base(netParams)
 {
     // Set up a few basic things. We are not complete after this though.
     _version          = 1;
     _difficultyTarget = 0x1d07fff8;
     _time             = (uint)P2PConnectionManager.GetUTCNowWithOffset();
     _prevBlockHash    = new byte[32];
 }
Esempio n. 2
0
 /// <summary>
 /// Construct a peer address from a memorized or hardcoded address.
 /// </summary>
 public PeerAddress(IPAddress addr, ushort port, ulong services, P2PNetworkParameters netParams, bool isInVersionMessage = false) : base(netParams)
 {
     _addr               = addr;
     _port               = port;
     _time               = (uint)P2PConnectionManager.GetUTCNowWithOffset();
     ProtocolVersion     = netParams.ClientVersion;
     _services           = services;
     _isInVersionMessage = isInVersionMessage;
 }
Esempio n. 3
0
 public VersionMessage(IPAddress remoteIpAddress, ushort remotePort, Socket sock, uint newBestHeight, uint remoteClientVersion, P2PNetworkParameters netParams, ulong remoteServices = (ulong)P2PNetworkParameters.NODE_NETWORK.FULL_NODE) : base(netParams)
 {
     _localServices    = P2PNetParameters.Services;
     _time             = P2PConnectionManager.GetUTCNowWithOffset();
     _myAddr           = new PeerAddress(IPAddress.Loopback, Convert.ToUInt16(((IPEndPoint)sock.LocalEndPoint).Port), netParams.Services, P2PNetParameters, true);
     _theirAddr        = new PeerAddress(remoteIpAddress, remotePort, remoteServices, P2PNetParameters, true);
     _nonce            = P2PNetworkParameters.VersionConnectNonce;
     _userAgent        = P2PNetworkParameters.UserAgentString;
     _startBlockHeight = newBestHeight;
     _relay            = P2PNetParameters.Relay;
 }
Esempio n. 4
0
        private bool pCheckTimestamp()
        {
            var currentTime = P2PConnectionManager.GetUTCNowWithOffset();

            if (_time > currentTime + _allowedTimeDrift)
            {
#if (DEBUG)
                Console.WriteLine("Block too far in future");
#endif
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        protected override void Parse()
        {
            // Format of a serialized address:
            //   uint32 timestamp
            //   uint64 services   (flags determining what the node can do)
            //   16 bytes IP address
            //   2 bytes port num
            if (!_isInVersionMessage)
            {
                if (ProtocolVersion > 31402)
                {
                    _time = ReadUint32();
                }
                else
                {
                    _time = uint.MaxValue;
                }
            }
            else
            {
                _time = (uint)P2PConnectionManager.GetUTCNowWithOffset();
            }
            _services = ReadUint64();
            var addrBytes = ReadBytes(16);

            if (new BigInteger(addrBytes, 0, 12).Equals(BigInteger.ValueOf(0xFFFF)))
            {
                var newBytes = new byte[4];
                Array.Copy(addrBytes, 12, newBytes, 0, 4);
                addrBytes = newBytes;
            }
            _addr = new IPAddress(addrBytes);
            _port = Convert.ToUInt16((Bytes[Cursor++] << 8) | Bytes[Cursor++]);

            Bytes = null;
        }