internal void SendControlHandshake()
        {
            var payload = new Packets.ControlHandshake(ControlHandshakeType.SYN,
                                                       ConnectionId);
            var packet = new RtpPacket(RtpPayloadType.Control, payload);

            SendOnControlSocket(packet);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private async Task <ControlHandshake> SendControlHandshakeAsync(ushort connectionId,
                                                                        ControlHandshakeType type = ControlHandshakeType.SYN)
        {
            var packet = new Packets.ControlHandshake(type, connectionId)
            {
                Channel = NanoChannel.TcpBase
            };

            return(await _transport.WaitForMessageAsync <ControlHandshake>(
                       TimeSpan.FromSeconds(5),
                       async() => await _transport.SendAsync(packet)));
        }
Beispiel #3
0
        public static INanoPacket ParsePacket(byte[] data, NanoChannelContext context)
        {
            EndianReader packetReader = new EndianReader(data);
            RtpHeader    header       = new RtpHeader();

            header.Deserialize(packetReader);
            NanoPayloadType payloadType = header.PayloadType;

            // It might be NanoChannel.Unknown at this point, if ChannelCreate
            // packet was not processed yet
            // It gets processed at the end of the function
            NanoChannel channel = context.GetChannel(header.ChannelId);

            INanoPacket packet        = null;
            long        payloadOffset = packetReader.Position;

            switch (payloadType)
            {
            // FIXME: Create from Attribute is broken
            case NanoPayloadType.UDPHandshake:
                packet = new UdpHandshake();
                break;

            case NanoPayloadType.ControlHandshake:
                packet = new ControlHandshake();
                break;

            case NanoPayloadType.ChannelControl:
                // Read type to pinpoint exact payload
                ChannelControlType cct =
                    (ChannelControlType)packetReader.ReadUInt32LE();
                packet = CreateFromChannelControlType(cct);
                break;

            case NanoPayloadType.Streamer:
                packet = CreateFromStreamerHeader(packetReader, channel);
                break;

            default:
                throw new NanoPackingException(
                          $"Unknown packet type received: {payloadType}");
            }

            if (packet == null)
            {
                throw new NanoPackingException("Failed to find matching body for packet");
            }

            packetReader.Seek(payloadOffset, SeekOrigin.Begin);
            packet.Deserialize(packetReader);
            packet.Header = header;

            if (packet as ChannelCreate != null)
            {
                string channelName = ((ChannelCreate)packet).Name;
                channel = NanoChannelClass.GetIdByClassName(channelName);
            }

            if (channel == NanoChannel.Unknown)
            {
                throw new NanoPackingException("ParsePacket: INanoPacket.Channel is UNKNOWN");
            }

            packet.Channel = channel;
            return(packet);
        }