Exemple #1
0
        /// <inheritdoc/>
        public override DateTimeOffset?GetBlockPerceivedTime(HashDigest <SHA256> blockHash)
        {
            byte[] key = BlockKey(blockHash);
            if (_blockPerceptionDb.Get(key) is { } bytes)
            {
                long unixTimeMs = NetworkOrderBitsConverter.ToInt64(bytes);
                return(DateTimeOffset.FromUnixTimeMilliseconds(unixTimeMs));
            }

            return(null);
        }
        private static void RoundTripInt64(long num, params byte[] bytes)
        {
            byte[] buffer = NetworkOrderBitsConverter.GetBytes(num);

            Assert.Equal(8, buffer.Length);
            Assert.Equal(bytes, buffer);

            Assert.Equal(num, NetworkOrderBitsConverter.ToInt64(buffer));

            NetworkOrderBitsConverter.PutInt64(num, buffer);

            Assert.Equal(bytes, buffer);

            Assert.Equal(num, NetworkOrderBitsConverter.ToInt64(buffer));
        }
        public void TrySignalFailedTest()
        {
            OutgoingSocketMock socket = new OutgoingSocketMock((ref Msg msg, TimeSpan timeout, bool more) =>
            {
                Assert.AreEqual(TimeSpan.Zero, timeout);
                Assert.AreEqual(8, msg.Data.Length);

                long value = NetworkOrderBitsConverter.ToInt64(msg.Data);

                Assert.AreEqual(0x7766554433221100L, value);

                Assert.IsFalse(more);
                return(false);
            });

            Assert.IsFalse(socket.TrySignalOK());
        }
        public void SignalTest()
        {
            OutgoingSocketMock socket = new OutgoingSocketMock((ref Msg msg, TimeSpan timeout, bool more) =>
            {
                Assert.AreEqual(SendReceiveConstants.InfiniteTimeout, timeout);
                Assert.AreEqual(8, msg.Data.Length);

                long value = NetworkOrderBitsConverter.ToInt64(msg.Data);

                Assert.AreEqual(0x7766554433221100L, value);

                Assert.IsFalse(more);
                return(true);
            });

            socket.SignalOK();
        }
        public void TrySignalTest()
        {
            var socket = new MockOutgoingSocket((ref Msg msg, TimeSpan timeout, bool more) =>
            {
                Assert.Equal(TimeSpan.Zero, timeout);
                Assert.Equal(8, msg.Data.Length);

                var value = NetworkOrderBitsConverter.ToInt64(msg.Data);

                Assert.Equal(0x7766554433221100L, value);

                Assert.False(more);
                return(true);
            });

            Assert.True(socket.TrySignalOK());
        }
Exemple #6
0
        /// <inheritdoc cref="BaseStore.GetBlockPerceivedTime(BlockHash)"/>
        public override DateTimeOffset?GetBlockPerceivedTime(BlockHash blockHash)
        {
            try
            {
                byte[] key = BlockKey(blockHash);
                if (_blockPerceptionDb.Get(key) is { } bytes)
                {
                    long unixTimeMs = NetworkOrderBitsConverter.ToInt64(bytes);
                    return(DateTimeOffset.FromUnixTimeMilliseconds(unixTimeMs));
                }
            }
            catch (Exception e)
            {
                LogUnexpectedException(nameof(GetBlockPerceivedTime), e);
            }

            return(null);
        }
        public void TestInt32()
        {
            byte[] buffer = NetworkOrderBitsConverter.GetBytes((long)1);

            Assert.AreEqual(buffer[7], 1);
            Assert.AreEqual(0, buffer[0]);

            long num = NetworkOrderBitsConverter.ToInt64(buffer);

            Assert.AreEqual(1, num);

            NetworkOrderBitsConverter.PutInt64(72057594037927936, buffer, 0);

            Assert.AreEqual(1, buffer[0]);
            Assert.AreEqual(0, buffer[7]);

            num = NetworkOrderBitsConverter.ToInt64(buffer);

            Assert.AreEqual(72057594037927936, num);
        }