Beispiel #1
0
        public void TestControlHandshake()
        {
            ControlHandshake packet = NanoPacketFactory
                                      .ParsePacket(ResourcesProvider.GetBytes("tcp_control_handshake.bin", ResourceType.Nano), _context)
                                      as ControlHandshake;

            Assert.NotNull(packet);
            Assert.NotNull(packet.Header);
            Assert.Equal <NanoChannel>(NanoChannel.TcpBase, packet.Channel);
            Assert.Equal <ControlHandshakeType>(ControlHandshakeType.SYN, packet.Type);
            Assert.Equal <ushort>(40084, packet.ConnectionId);
        }
        /// <summary>
        /// Initialize nano protocol
        /// </summary>
        /// <returns></returns>
        public async Task InitializeProtocolAsync()
        {
            if (ProtocolInitialized)
            {
                throw new NanoException("Protocol is already initialized");
            }

            Task awaitChannels = WaitForChannelsAsync();

            ControlHandshake response = await SendControlHandshakeAsync(ConnectionId);

            if (response.Type != ControlHandshakeType.ACK)
            {
                throw new NotSupportedException(
                          $"Invalid ControlHandshake type received {response.Type}");
            }

            await awaitChannels;

            await OpenChannelsAsync();

            ProtocolInitialized = true;
        }