Ejemplo n.º 1
0
        protected override bool ReadProperties(BinaryReader reader)
        {
            BlockType blockType = (BlockType)((BitConverter.ToUInt16(Header.Extensions, 0) & Block.BlockTypeMask) >> 8);

            switch (blockType)
            {
            case BlockType.Receive:
                Block = new ReceiveBlock();
                break;

            case BlockType.Send:
                Block = new SendBlock();
                break;

            case BlockType.Open:
                Block = new OpenBlock();
                break;

            case BlockType.Change:
                Block = new ChangeBlock();
                break;
            }

            Block.ReadFromStream(reader);
            return(true);
        }
Ejemplo n.º 2
0
        public void TestOpenFirstBlock()
        {
            _controller = new ControllerThread(_chain, default(OptimizedLineage), _inbox = BoundedInbox.Create(),
                                               _outbox = BoundedInbox.Create());

            var messageAllocation = new Span <byte>(new byte[OpenBlock.SizeInBytes]);

            var openBlock = new OpenBlock(1, 5, BlockAlias.GenesisParent);

            // Serialize message to put it into the inbox
            MessageSerializers.ClientSerializeOpenBlock(openBlock, messageAllocation);

            _inbox.TryWrite(messageAllocation);

            _controller.DoWork();

            var result = _outbox.Peek();

            Assert.Equal(MessageType.OpenedBlock, ClientServerMessage.GetMessageType(result));
            var response = MessageSerializers.ClientDeserializeOpenedBlock(result);

            Assert.Equal(1U, response.RequestId);
            Assert.Equal(5U, response.ClientId);
            Assert.Equal(_1, response.Alias);

            var tmpId = response.UncommittedBlockId;

            Console.WriteLine(tmpId);
        }
Ejemplo n.º 3
0
        public TempBlockId TestOpenBlock()
        {
            Setup();

            var messageAllocation = new Span <byte>(new byte[OpenBlock.SizeInBytes]);

            var openBlock = new OpenBlock(1, 5, _3);

            // Serialize message to put it into the inbox
            MessageSerializers.ClientSerializeOpenBlock(openBlock, messageAllocation);

            _inbox.TryWrite(messageAllocation);

            _controller.DoWork();

            var result = _outbox.Peek();

            Assert.Equal(MessageType.OpenedBlock, ClientServerMessage.GetMessageType(result));
            var response = MessageSerializers.ClientDeserializeOpenedBlock(result);

            Assert.Equal(1U, response.RequestId);
            Assert.Equal(5U, response.ClientId);
            Assert.Equal(_9, response.Alias);

            return(response.UncommittedBlockId);
        }
Ejemplo n.º 4
0
        public void SerializeDeserializeOpenBlock()
        {
            var openBlock = new OpenBlock(3, 4, new BlockAlias(987623));

            MessageSerializers.ClientSerializeOpenBlock(openBlock, _buffer);
            var newOpenBlock = MessageSerializers.DeserializeOpenBlock(_buffer);

            Assert.True(openBlock.ClientId == newOpenBlock.ClientId &&
                        openBlock.RequestId == newOpenBlock.RequestId &&
                        openBlock.RequestType == newOpenBlock.RequestType &&
                        openBlock.ParentHandle == newOpenBlock.ParentHandle);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Skip over a complete block of unknown content
        /// </summary>
        public override bool Parse(ItemFactory itemFactory, ITextProvider text, TokenStream tokens)
        {
            // Save the opening token for this block
            OpenBlock = Children.AddCurrentAndAdvance(tokens, null);

            CssTokenType matchingEndType = GetMatchingTokenType(OpenBlock.TokenType);

            Debug.Assert(matchingEndType != CssTokenType.Unknown);

            // Search for the matching end of the block
            bool invalidBlock = false;

            while (!invalidBlock &&
                   tokens.CurrentToken.TokenType != matchingEndType &&
                   !tokens.CurrentToken.IsScopeBlocker())
            {
                // Treat the contents of the block as property values so that units, functions, etc. get parsed
                ParseItem pi = PropertyValueHelpers.ParsePropertyValue(this, itemFactory, text, tokens);

                if (pi != null)
                {
                    Children.Add(pi);
                }
                else
                {
                    switch (tokens.CurrentToken.TokenType)
                    {
                    case CssTokenType.CloseCurlyBrace:
                    case CssTokenType.CloseFunctionBrace:
                    case CssTokenType.CloseSquareBracket:
                        // Found a non-matching end brace/bracket, so stop parsing
                        invalidBlock = true;
                        break;

                    default:
                        Children.AddUnknownAndAdvance(itemFactory, text, tokens);
                        break;
                    }
                }
            }

            if (tokens.CurrentToken.TokenType == matchingEndType)
            {
                CloseBlock = Children.AddCurrentAndAdvance(tokens, null);
            }
            else
            {
                OpenBlock.AddParseError(ParseErrorType.CloseBraceMismatch, ParseErrorLocation.AfterItem);
            }

            return(Children.Count > 0);
        }
Ejemplo n.º 6
0
        public TempBlockId terab_utxo_open_block()
        {
            Setup();

            TempBlockId?result = null;

            _socket.ExpectConnected(() => true);
            _socket.ExpectConnected(() => true);
            _socket.ExpectConnected(() => true);
            _socket.ExpectAvailable(() => OpenBlock.SizeInBytes);

            _socket.ExpectReceive(data =>
            {
                data.Clear();
                Assert.True(data.Length >= OpenBlock.SizeInBytes);

                var openBlock = new OpenBlock(1, 0, _zero);
                // Serialize message to put it into the inbox
                MessageSerializers.ClientSerializeOpenBlock(openBlock, data);
                return(OpenBlock.SizeInBytes);
            });

            _socket.ExpectConnected(() => true);
            _socket.ExpectAvailable(() => 0);

            _socket.ExpectConnected(() => true);
            _socket.ExpectSend(data =>
            {
                Assert.Equal(OpenedBlock.SizeInBytes, data.Length);
                OpenedBlock openedBlock = MessageSerializers.ClientDeserializeOpenedBlock(data);
                Assert.Equal(OpenedBlock.SizeInBytes, BitConverter.ToInt32(data));
                Assert.Equal((uint)1, openedBlock.RequestId); // request ID
                Assert.Equal((uint)0, openedBlock.ClientId);  // client ID field empty
                result = openedBlock.UncommittedBlockId;
                return(OpenedBlock.SizeInBytes);
            });

            _dispatcher.ListenToConnections();

            _controllerThread.DoWork();

            _dispatcher.SendResponses();

            _socket.ExpectAllDone();

            return(result.Value);
        }
Ejemplo n.º 7
0
        public static void ClientSerializeOpenBlock(OpenBlock openBlock, Span <byte> toWrite)
        {
            // length of the given span
            if (toWrite.Length < OpenBlock.SizeInBytes)
            {
                throw new ArgumentException(
                          $"Given Span of length {toWrite.Length} too short to write {OpenBlock.SizeInBytes} bytes of {nameof(OpenBlock)} request");
            }

            var editor = new SpanBinaryEditor(toWrite);

            var messageHeader = new MessageHeader(OpenBlock.SizeInBytes, openBlock.RequestId,
                                                  openBlock.ClientId, MessageInfo.FromType(openBlock.RequestType));

            WriteMessageHeader(ref messageHeader, ref editor);

            editor.WriteUInt32(openBlock.ParentHandle.Value);
        }
Ejemplo n.º 8
0
 public void Visit(OpenBlock block)
 {
     FillValue(block);
 }
Ejemplo n.º 9
0
 public void Visit(OpenBlock block)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 10
0
 public void PutBlock(UInt256 blockHash, OpenBlock block, UInt256 successorHash = null)
 {
     ThrowHelper.Sanity.ThrowIfTrue(block == null || GetBlock(successorHash) != null);
 }